Skip to content

Commit

Permalink
Fix type comparison from '==' to 'is'
Browse files Browse the repository at this point in the history
  • Loading branch information
bitkeks committed Aug 19, 2023
1 parent bb0ab89 commit 97c99f5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion netflow/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def total_packets(self):
if args.match_host:
try:
match_host = ipaddress.ip_address(args.match_host)
except ValueError as ex:
except ValueError:
exit("IP address '{}' is neither IPv4 nor IPv6".format(args.match_host))

# Using a file and using stdin differ in their further usage for gzip.open
Expand Down
10 changes: 5 additions & 5 deletions netflow/ipfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,9 @@ def get_type_unpack(cls, key: Union[int, str]) -> Optional[DataType]:
:return:
"""
item = None
if type(key) == int:
if type(key) is int:
item = cls.by_id(key)
elif type(key) == str:
elif type(key) is str:
item = cls.by_name(key)
if not item:
return None
Expand Down Expand Up @@ -575,7 +575,7 @@ def is_signed(cls, dt: Union[DataType, str]) -> bool:
:return:
"""
fields = ["signed8", "signed16", "signed32", "signed64"]
if type(dt) == DataType:
if type(dt) is DataType:
return dt.type in fields
return dt in fields

Expand All @@ -587,7 +587,7 @@ def is_float(cls, dt: Union[DataType, str]) -> bool:
:return:
"""
fields = ["float32", "float64"]
if type(dt) == DataType:
if type(dt) is DataType:
return dt.type in fields
return dt in fields

Expand All @@ -601,7 +601,7 @@ def is_bytes(cls, dt: Union[DataType, str]) -> bool:
fields = ["octetArray", "string",
"macAddress", "ipv4Address", "ipv6Address",
"dateTimeMicroseconds", "dateTimeNanoseconds"]
if type(dt) == DataType:
if type(dt) is DataType:
return dt.type in fields
return dt in fields

Expand Down
12 changes: 6 additions & 6 deletions netflow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def get_export_version(data):
return struct.unpack('!H', data[:2])[0]


def parse_packet(data: Union[str, bytes], templates: Dict = None) -> Union[V1ExportPacket, V5ExportPacket,
V9ExportPacket, IPFIXExportPacket]:
def parse_packet(data: Union[str, bytes], templates: Dict = None) \
-> Union[V1ExportPacket, V5ExportPacket, V9ExportPacket, IPFIXExportPacket]:
"""
Parse an exported packet, either from string (hex) or from bytes.
Expand Down Expand Up @@ -66,10 +66,10 @@ def parse_packet(data: Union[str, bytes], templates: Dict = None) -> Union[V1Exp
:param templates: The templates dictionary with keys 'netflow' and 'ipfix' (created if not existing).
:return: The parsed packet, or an exception.
"""
if type(data) == str:
if type(data) is str:
# hex dump as string
data = bytes.fromhex(data)
elif type(data) == bytes:
elif type(data) is bytes:
# check representation based on utf-8 decoding result
try:
# hex dump as bytes, but not hex
Expand All @@ -83,8 +83,8 @@ def parse_packet(data: Union[str, bytes], templates: Dict = None) -> Union[V1Exp

if version in [9, 10] and templates is None:
raise ValueError("{} packet detected, but no templates dict was passed! For correct parsing of packets with "
"templates, create a 'templates' dict and pass it into the 'parse_packet' function.".format(
"NetFlow v9" if version == 9 else "IPFIX"))
"templates, create a 'templates' dict and pass it into the 'parse_packet' function."
.format("NetFlow v9" if version == 9 else "IPFIX"))

if version == 1:
return V1ExportPacket(data)
Expand Down

0 comments on commit 97c99f5

Please sign in to comment.