Fix type comparison from '==' to 'is'
This commit is contained in:
parent
bb0ab89615
commit
97c99f51b3
|
@ -204,7 +204,7 @@ if __name__ == "__main__":
|
|||
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
|
||||
|
|
|
@ -514,9 +514,9 @@ class IPFIXFieldTypes:
|
|||
: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
|
||||
|
@ -575,7 +575,7 @@ class IPFIXDataTypes:
|
|||
:return:
|
||||
"""
|
||||
fields = ["signed8", "signed16", "signed32", "signed64"]
|
||||
if type(dt) == DataType:
|
||||
if type(dt) is DataType:
|
||||
return dt.type in fields
|
||||
return dt in fields
|
||||
|
||||
|
@ -587,7 +587,7 @@ class IPFIXDataTypes:
|
|||
:return:
|
||||
"""
|
||||
fields = ["float32", "float64"]
|
||||
if type(dt) == DataType:
|
||||
if type(dt) is DataType:
|
||||
return dt.type in fields
|
||||
return dt in fields
|
||||
|
||||
|
@ -601,7 +601,7 @@ class IPFIXDataTypes:
|
|||
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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue