Skip to content

Commit

Permalink
Fix PEP 8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Aug 30, 2022
1 parent c3107a2 commit e5ea562
Show file tree
Hide file tree
Showing 29 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion hachoir/core/dict.py
Expand Up @@ -168,7 +168,7 @@ def insert(self, index, key, value):
_index = index
if index < 0:
index += len(self._value_list)
if not(0 <= index <= len(self._value_list)):
if not (0 <= index <= len(self._value_list)):
raise IndexError("Insert error: index '%s' is invalid" % _index)
for item_key, item_index in self._index.items():
if item_index >= index:
Expand Down
4 changes: 2 additions & 2 deletions hachoir/core/tools.py
Expand Up @@ -493,7 +493,7 @@ def timestampUNIX(value):
"""
if not isinstance(value, (float, int)):
raise TypeError("timestampUNIX(): an integer or float is required")
if not(0 <= value <= 2147483647):
if not (0 <= value <= 2147483647):
raise ValueError("timestampUNIX(): value have to be in 0..2147483647")
return UNIX_TIMESTAMP_T0 + timedelta(seconds=value)

Expand All @@ -514,7 +514,7 @@ def timestampMac32(value):
"""
if not isinstance(value, (float, int)):
raise TypeError("an integer or float is required")
if not(0 <= value <= 4294967295):
if not (0 <= value <= 4294967295):
return "invalid Mac timestamp (%s)" % value
return MAC_TIMESTAMP_T0 + timedelta(seconds=value)

Expand Down
6 changes: 3 additions & 3 deletions hachoir/editor/typed_field.py
Expand Up @@ -101,7 +101,7 @@ def __init__(self, parent, name, *args):
self._is_altered = True

def _setValue(self, value):
if not(0 <= value < (1 << self._size)):
if not (0 <= value < (1 << self._size)):
raise ValueError("Invalid value, must be in range %s..%s"
% (0, (1 << self._size) - 1))
self._value = value
Expand Down Expand Up @@ -248,7 +248,7 @@ def _setValue(self, value):
else:
valid = self.VALID_VALUE_UNSIGNED
minval, maxval = valid[self._size]
if not(minval <= value <= maxval):
if not (minval <= value <= maxval):
raise ValueError("Invalid value, must be in range %s..%s"
% (minval, maxval))
self._value = value
Expand All @@ -274,7 +274,7 @@ def __init__(self, parent, name, *args):
EditableFixedField.__init__(self, parent, name, value, 32)

def _setValue(self, value):
if not(self.minval <= value <= self.maxval):
if not (self.minval <= value <= self.maxval):
raise ValueError("Invalid value, must be in range %s..%s"
% (self.minval, self.maxval))
self._value = value
Expand Down
2 changes: 1 addition & 1 deletion hachoir/field/byte_field.py
Expand Up @@ -20,7 +20,7 @@ class RawBytes(Field):

def __init__(self, parent, name, length, description="Raw data"):
assert issubclass(parent.__class__, Field)
if not(0 < length <= MAX_LENGTH):
if not (0 < length <= MAX_LENGTH):
raise FieldError("Invalid RawBytes length (%s)!" % length)
Field.__init__(self, parent, name, length * 8, description)
self._display = None
Expand Down
2 changes: 1 addition & 1 deletion hachoir/field/generic_field_set.py
Expand Up @@ -117,7 +117,7 @@ def _getSize(self):
_getSize, doc="Size in bits, may create all fields to get size")

def _getCurrentSize(self):
assert not(self.done)
assert not (self.done)
return self._current_size
current_size = property(_getCurrentSize)

Expand Down
4 changes: 2 additions & 2 deletions hachoir/field/padding.py
Expand Up @@ -23,7 +23,7 @@ def __init__(self, parent, name, nbits, description="Padding", pattern=None):
self._display_pattern = self.checkPattern()

def checkPattern(self):
if not(config.check_padding_pattern):
if not (config.check_padding_pattern):
return False
if self.pattern != 0:
return False
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self, parent, name, nbytes,
self._display_pattern = self.checkPattern()

def checkPattern(self):
if not(config.check_padding_pattern):
if not (config.check_padding_pattern):
return False
if self.pattern is None:
return False
Expand Down
2 changes: 1 addition & 1 deletion hachoir/field/vector.py
Expand Up @@ -7,7 +7,7 @@ def __init__(self, parent, name, nb_items, item_class, item_name="item", descrip
# Sanity checks
assert issubclass(item_class, Field)
assert isinstance(item_class.static_size, int)
if not(0 < nb_items):
if not (0 < nb_items):
raise ParserError('Unable to create empty vector "%s" in %s'
% (name, parent.path))
size = nb_items * item_class.static_size
Expand Down
6 changes: 3 additions & 3 deletions hachoir/grep.py
Expand Up @@ -169,11 +169,11 @@ def searchFile(self, filename, pattern, case_sensitive=True):
def runGrep(values, pattern, filenames):
grep = ConsoleGrep()
grep.display_filename = (1 < len(filenames))
grep.display_address = not(values.no_addr)
grep.display_address = not values.no_addr
grep.display_path = values.path
grep.display_value = not(values.no_value)
grep.display_value = not values.no_value
grep.display_percent = values.percent
grep.display = not(values.bench)
grep.display = not values.bench
for filename in filenames:
grep.searchFile(filename, pattern, case_sensitive=values.case)

Expand Down
4 changes: 2 additions & 2 deletions hachoir/metadata/main.py
Expand Up @@ -85,7 +85,7 @@ def processFile(values, filename,

with parser:
# Extract metadata
extract_metadata = not(values.mime or values.type)
extract_metadata = not (values.mime or values.type)
if extract_metadata:
try:
metadata = extractMetadata(parser, values.quality)
Expand Down Expand Up @@ -124,7 +124,7 @@ def processFile(values, filename,


def processFiles(values, filenames, display=True):
human = not(values.raw)
human = not values.raw
ok = True
priority = int(values.level) * 100 + 99
display_filename = (1 < len(filenames))
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/archive/bzip2_parser.py
Expand Up @@ -218,7 +218,7 @@ class Bzip2Parser(Parser):
def validate(self):
if self.stream.readBytes(0, 3) != b'BZh':
return "Wrong file signature"
if not("1" <= self["blocksize"].value <= "9"):
if not ("1" <= self["blocksize"].value <= "9"):
return "Wrong blocksize"
return True

Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/archive/mar.py
Expand Up @@ -44,7 +44,7 @@ def validate(self):
return "Invalid magic"
if self["version"].value != 3:
return "Invalid version"
if not(1 <= self["nb_file"].value <= MAX_NB_FILE):
if not (1 <= self["nb_file"].value <= MAX_NB_FILE):
return "Invalid number of file"
return True

Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/audio/id3.py
Expand Up @@ -451,7 +451,7 @@ def createFields(self):

if size:
cls = None
if not(is_compressed):
if not is_compressed:
tag = self["tag"].value
if tag in ID3_Chunk.handler:
cls = ID3_Chunk.handler[tag]
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/audio/itunesdb.py
Expand Up @@ -128,7 +128,7 @@ def createFields(self):
yield padding
for i in range(self["entry_count"].value):
yield UInt32(self, "index[" + str(i) + "]", "Index of the " + str(i) + "nth mhit")
elif(self["type"].value < 15) or (self["type"].value > 17) or (self["type"].value >= 200):
elif (self["type"].value < 15) or (self["type"].value > 17) or (self["type"].value >= 200):
yield UInt32(self, "unknown[]")
yield UInt32(self, "unknown[]")
yield UInt32(self, "position", "Position")
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/audio/midi.py
Expand Up @@ -29,7 +29,7 @@ def __init__(self, parent, name, description=None):
while True:
bits = stream.readBits(addr, 8, parent.endian)
value = (value << 7) + (bits & 127)
if not(bits & 128):
if not (bits & 128):
break
addr += 8
self._size += 8
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/file_system/ext2.py
Expand Up @@ -747,7 +747,7 @@ def __init__(self, stream, **args):
def validate(self):
if self.stream.readBytes((1024 + 56) * 8, 2) != b"\x53\xEF":
return "Invalid magic number"
if not(0 <= self["superblock/log_block_size"].value <= 2):
if not (0 <= self["superblock/log_block_size"].value <= 2):
return "Invalid (log) block size"
if self["superblock/inode_size"].value not in (0, 128):
return "Unsupported inode size"
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/image/jpeg.py
Expand Up @@ -205,7 +205,7 @@ class SOSComponent(FieldSet):
def createFields(self):
comp_id = UInt8(self, "component_id")
yield comp_id
if not(1 <= comp_id.value <= self["../nr_components"].value):
if not (1 <= comp_id.value <= self["../nr_components"].value):
raise ParserError("JPEG error: Invalid component-id")
yield Bits(self, "dc_coding_table", 4, "DC entropy coding table destination selector")
yield Bits(self, "ac_coding_table", 4, "AC entropy coding table destination selector")
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/image/wmf.py
Expand Up @@ -597,7 +597,7 @@ def createFields(self):
yield UInt32(self, "max_record_size", "The size of largest record in 16-bit words")
yield UInt16(self, "nb_params", "Not Used (always 0)")

while not(self.eof):
while not self.eof:
yield Function(self, "func[]")

def isEMF(self):
Expand Down
6 changes: 3 additions & 3 deletions hachoir/parser/misc/mapsforge_map.py
Expand Up @@ -41,7 +41,7 @@ def __init__(self, parent, name, description=None):
size += 1
assert size < 100, "UIntVBE is too large"

if not(haveMoreData):
if not haveMoreData:
break

self._size = size * 8
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, parent, name, description=None):
size += 1
assert size < 100, "IntVBE is too large"

if not(haveMoreData):
if not haveMoreData:
break

if isNegative:
Expand Down Expand Up @@ -142,7 +142,7 @@ def __init__(self, parent, name, zoomIntervalCfg, **kw):
def createFields(self):
numLevels = int(self.zoomIntervalCfg[
"max_zoom_level"].value - self.zoomIntervalCfg["min_zoom_level"].value) + 1
assert(numLevels < 50)
assert (numLevels < 50)
for i in range(numLevels):
yield TileZoomTable(self, "zoom_table_entry[]")
yield UIntVbe(self, "first_way_offset")
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/misc/ole2.py
Expand Up @@ -211,7 +211,7 @@ def validate(self):
return "Unknown major version (%s)" % self["header/ver_maj"].value
if self["header/endian"].value not in (b"\xFF\xFE", b"\xFE\xFF"):
return "Unknown endian (%s)" % self["header/endian"].raw_display
if not(MIN_BIG_BLOCK_LOG2 <= self["header/bb_shift"].value <= MAX_BIG_BLOCK_LOG2):
if not (MIN_BIG_BLOCK_LOG2 <= self["header/bb_shift"].value <= MAX_BIG_BLOCK_LOG2):
return "Invalid (log 2 of) big block size (%s)" % self["header/bb_shift"].value
if self["header/bb_shift"].value < self["header/sb_shift"].value:
return "Small block size (log2=%s) is bigger than big block size (log2=%s)!" \
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/video/asf.py
Expand Up @@ -355,7 +355,7 @@ def validate(self):
if self.stream.readBytes(0, len(magic)) != magic:
return "Invalid magic"
header = self[0]
if not(30 <= header["size"].value <= MAX_HEADER_SIZE):
if not (30 <= header["size"].value <= MAX_HEADER_SIZE):
return "Invalid header size (%u)" % header["size"].value
return True

Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/video/mpeg_ts.py
Expand Up @@ -134,7 +134,7 @@ def is_m2ts(self):
# FIXME: detect using file content, not file name
# maybe detect sync at offset+4 bytes?
source = self.stream.source
if not(source and source.startswith("file:")):
if not (source and source.startswith("file:")):
return True
filename = source[5:].lower()
return filename.endswith((".m2ts", ".mts"))
Expand Down
2 changes: 1 addition & 1 deletion hachoir/parser/video/mpeg_video.py
Expand Up @@ -244,7 +244,7 @@ def createFields(self):
yield Bits(self, "sync[]", 4) # =2, or 3 if has_dts=True
yield Timestamp(self, "pts")
if self["has_dts"].value:
if not(self["has_pts"].value):
if not self["has_pts"].value:
raise ParserError("Invalid PTS/DTS values")
yield Bits(self, "sync[]", 4) # =1
yield Timestamp(self, "dts")
Expand Down
2 changes: 1 addition & 1 deletion hachoir/regex/parser.py
Expand Up @@ -164,7 +164,7 @@ def _parse(text, start=0, until=None):
if char == 'b':
new_regex = RegexWord()
else:
if not(char in REGEX_COMMAND_CHARACTERS or char in " '"):
if not (char in REGEX_COMMAND_CHARACTERS or char in " '"):
raise SyntaxError(
"Operator '\\%s' is not supported" % char)
new_regex = RegexString(char)
Expand Down
2 changes: 1 addition & 1 deletion hachoir/strip.py
Expand Up @@ -278,7 +278,7 @@ def main():
if parser:
editor = createEditor(parser)
ok &= stripEditor(editor, filename + ".new",
level, not(values.quiet))
level, not values.quiet)
else:
ok = False
if ok:
Expand Down
2 changes: 1 addition & 1 deletion hachoir/subfile/main.py
Expand Up @@ -85,7 +85,7 @@ def main():
stream = FileInputStream(filename)
with stream:
subfile = SearchSubfile(stream, values.offset, values.size)
subfile.verbose = not(values.quiet)
subfile.verbose = not values.quiet
subfile.debug = values.debug
if output:
subfile.setOutput(output)
Expand Down
4 changes: 2 additions & 2 deletions hachoir/subfile/search.py
Expand Up @@ -95,7 +95,7 @@ def main(self):
print("[!] Memory error!", file=stderr)
self.mainFooter()
self.stream.close()
return not(main_error)
return (not main_error)

def mainHeader(self):
# Fix slice size if needed
Expand Down Expand Up @@ -149,7 +149,7 @@ def processParser(self, offset, parser):
if parser.content_size is not None:
text += " size=%s (%s)" % (parser.content_size //
8, humanFilesize(parser.content_size // 8))
if not(parser.content_size) or parser.content_size // 8 < FILE_MAX_SIZE:
if not parser.content_size or parser.content_size // 8 < FILE_MAX_SIZE:
text += ": " + parser.description
else:
text += ": " + parser.__class__.__name__
Expand Down
2 changes: 1 addition & 1 deletion hachoir/urwid.py
Expand Up @@ -295,7 +295,7 @@ def update(self, node):
text += "= %s" % display
if node.field.description and self.flags & self.display_description:
description = node.field.description
if not(self.flags & self.human_size):
if not (self.flags & self.human_size):
description = makePrintable(description, "ASCII")
text += ": %s" % description
if self.flags & self.display_size and node.field.size or self.flags & self.display_type:
Expand Down
2 changes: 1 addition & 1 deletion hachoir/wx/field_view/stubs.py
Expand Up @@ -32,7 +32,7 @@ def field_type_name(field):


def convert_size(from_field, to_type):
if not(('Byte' in field_type_name(from_field)) ^ ('Byte' in to_type.__name__)):
if not (('Byte' in field_type_name(from_field)) ^ ('Byte' in to_type.__name__)):
return from_field.size
elif 'Byte' in field_type_name(from_field):
return from_field.size * 8
Expand Down
2 changes: 1 addition & 1 deletion tests/test_metadata.py
Expand Up @@ -126,7 +126,7 @@ def check_attr(self, metadata, name, value):

# Check type
if type(read) != type(value) \
and not(isinstance(value, int) and isinstance(value, int)):
and not (isinstance(value, int) and isinstance(value, int)):
if self.verbose:
sys.stdout.write("wrong type (%s instead of %s)!\n"
% (type(read).__name__, type(value).__name__))
Expand Down

0 comments on commit e5ea562

Please sign in to comment.