Skip to content

Commit

Permalink
Merge pull request #162 from openpreserve/fix/pylint-issues-2
Browse files Browse the repository at this point in the history
FIX - Pylint if simplification
  • Loading branch information
carlwilson authored Oct 10, 2019
2 parents 553a722 + c55a4a5 commit b424d3f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 48 deletions.
5 changes: 2 additions & 3 deletions fido/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def query_yes_no(question, default='yes'):
choice = rinput().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
if choice in valid:
return valid[choice]
else:
print('Please respond with "yes" or "no" (or "y" or "n").')
print('Please respond with "yes" or "no" (or "y" or "n").')
60 changes: 29 additions & 31 deletions fido/fido.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ def __init__(self, quiet=False, bufsize=None, container_bufsize=None, printnomat
def _escape_char(self, c):
if c in '\n':
return '\\n'
elif c == '\r':
if c == '\r':
return '\\r'
elif c in self._special:
if c in self._special:
return '\\' + c
else:
(high, low) = divmod(ord(c), 16)
return '\\x' + self._hex[high] + self._hex[low]
(high, low) = divmod(ord(c), 16)
return '\\x' + self._hex[high] + self._hex[low]

def escape(self, string):
"""
Expand Down Expand Up @@ -387,7 +386,7 @@ def identify_contents(self, filename, fileobj=None, type=False, extension=True):
"""
if not type:
return
elif type == 'zip':
if type == 'zip':
self.walk_zip(filename, fileobj, extension=extension)
elif type == 'tar':
self.walk_tar(filename, fileobj, extension=extension)
Expand Down Expand Up @@ -460,7 +459,7 @@ def identify_stream(self, stream, filename, extension=True):
self.current_file = filename
matches = self.match_extensions(self.current_file)
# we have to reset self.current_file if not on Windows
if (os.name != "nt"):
if os.name != "nt":
self.current_file = 'STDIN'
self.handle_matches(self.current_file, matches, time.clock() - t0, "extension")

Expand Down Expand Up @@ -529,30 +528,29 @@ def get_buffers(self, stream, length=None, seekable=False):
eofbuffer = prevbuffer if len(buffer) == 0 else prevbuffer[-(self.bufsize - len(buffer)):] + buffer
break
return bofbuffer, eofbuffer, bytes_read
bytes_unread = length - len(bofbuffer)
if bytes_unread == 0:
eofbuffer = bofbuffer
elif bytes_unread < self.bufsize:
# The buffs overlap
eofbuffer = bofbuffer[bytes_unread:] + self.blocking_read(stream, bytes_unread)
elif bytes_unread == self.bufsize:
eofbuffer = self.blocking_read(stream, self.bufsize)
elif seekable: # easy case when we can just seek!
stream.seek(length - self.bufsize)
eofbuffer = self.blocking_read(stream, self.bufsize)
else:
bytes_unread = length - len(bofbuffer)
if bytes_unread == 0:
eofbuffer = bofbuffer
elif bytes_unread < self.bufsize:
# The buffs overlap
eofbuffer = bofbuffer[bytes_unread:] + self.blocking_read(stream, bytes_unread)
elif bytes_unread == self.bufsize:
eofbuffer = self.blocking_read(stream, self.bufsize)
elif seekable: # easy case when we can just seek!
stream.seek(length - self.bufsize)
eofbuffer = self.blocking_read(stream, self.bufsize)
else:
# We have more to read and know how much.
# n*bufsize + r = length
(n, r) = divmod(bytes_unread, self.bufsize)
# skip n-1*bufsize bytes
for unused_i in range(1, n):
self.blocking_read(stream, self.bufsize)
# skip r bytes
self.blocking_read(stream, r)
# and read the remaining bufsize bytes into the eofbuffer
eofbuffer = self.blocking_read(stream, self.bufsize)
return bofbuffer, eofbuffer, bytes_to_read
# We have more to read and know how much.
# n*bufsize + r = length
(n, r) = divmod(bytes_unread, self.bufsize)
# skip n-1*bufsize bytes
for unused_i in range(1, n):
self.blocking_read(stream, self.bufsize)
# skip r bytes
self.blocking_read(stream, r)
# and read the remaining bufsize bytes into the eofbuffer
eofbuffer = self.blocking_read(stream, self.bufsize)
return bofbuffer, eofbuffer, bytes_to_read

def walk_zip(self, filename, fileobj=None, extension=True):
"""
Expand Down Expand Up @@ -627,7 +625,7 @@ def as_good_as_any(self, f1, match_list):
for (f2, _) in match_list:
if f1 == f2:
continue
elif f1_puid in self.puid_has_priority_over_map[self.get_puid(f2)]:
if f1_puid in self.puid_has_priority_over_map[self.get_puid(f2)]:
return False
return True

Expand Down
26 changes: 12 additions & 14 deletions fido/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,25 @@ def compare_formats(f1, f2):
return 1
if f1ID < f2ID:
return - 1
elif f1ID == f2ID:
if f1ID == f2ID:
return 0
else:
return 1
return 1
return sorted(formatlist, cmp=compare_formats)


def fido_position(pronom_position):
"""Return BOF/EOF/VAR instead of the more verbose pronom position names."""
if pronom_position == 'Absolute from BOF':
return 'BOF'
elif pronom_position == 'Absolute from EOF':
if pronom_position == 'Absolute from EOF':
return 'EOF'
elif pronom_position == 'Variable':
if pronom_position == 'Variable':
return 'VAR'
elif pronom_position == 'Indirect From BOF':
if pronom_position == 'Indirect From BOF':
return 'IFB'
else: # to make sure FIDO does not crash (IFB aftermath)
sys.stderr.write("Unknown pronom PositionType:" + pronom_position)
return 'VAR'
# to make sure FIDO does not crash (IFB aftermath)
sys.stderr.write("Unknown pronom PositionType:" + pronom_position)
return 'VAR'


def _convert_err_msg(msg, c, i, chars, buf):
Expand Down Expand Up @@ -365,13 +364,12 @@ def doByte(chars, i, littleendian, esc=True):
def _escape_char(c):
if c in '\n':
return '\\n'
elif c == '\r':
if c == '\r':
return '\\r'
elif c in _special:
if c in _special:
return '\\' + c
else:
(high, low) = divmod(ord(c), 16)
return '\\x' + _hex[high] + _hex[low]
(high, low) = divmod(ord(c), 16)
return '\\x' + _hex[high] + _hex[low]


def escape(string):
Expand Down

0 comments on commit b424d3f

Please sign in to comment.