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:
|
if args.match_host:
|
||||||
try:
|
try:
|
||||||
match_host = ipaddress.ip_address(args.match_host)
|
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))
|
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
|
# Using a file and using stdin differ in their further usage for gzip.open
|
||||||
|
|
|
@ -514,9 +514,9 @@ class IPFIXFieldTypes:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
item = None
|
item = None
|
||||||
if type(key) == int:
|
if type(key) is int:
|
||||||
item = cls.by_id(key)
|
item = cls.by_id(key)
|
||||||
elif type(key) == str:
|
elif type(key) is str:
|
||||||
item = cls.by_name(key)
|
item = cls.by_name(key)
|
||||||
if not item:
|
if not item:
|
||||||
return None
|
return None
|
||||||
|
@ -575,7 +575,7 @@ class IPFIXDataTypes:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
fields = ["signed8", "signed16", "signed32", "signed64"]
|
fields = ["signed8", "signed16", "signed32", "signed64"]
|
||||||
if type(dt) == DataType:
|
if type(dt) is DataType:
|
||||||
return dt.type in fields
|
return dt.type in fields
|
||||||
return dt in fields
|
return dt in fields
|
||||||
|
|
||||||
|
@ -587,7 +587,7 @@ class IPFIXDataTypes:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
fields = ["float32", "float64"]
|
fields = ["float32", "float64"]
|
||||||
if type(dt) == DataType:
|
if type(dt) is DataType:
|
||||||
return dt.type in fields
|
return dt.type in fields
|
||||||
return dt in fields
|
return dt in fields
|
||||||
|
|
||||||
|
@ -601,7 +601,7 @@ class IPFIXDataTypes:
|
||||||
fields = ["octetArray", "string",
|
fields = ["octetArray", "string",
|
||||||
"macAddress", "ipv4Address", "ipv6Address",
|
"macAddress", "ipv4Address", "ipv6Address",
|
||||||
"dateTimeMicroseconds", "dateTimeNanoseconds"]
|
"dateTimeMicroseconds", "dateTimeNanoseconds"]
|
||||||
if type(dt) == DataType:
|
if type(dt) is DataType:
|
||||||
return dt.type in fields
|
return dt.type in fields
|
||||||
return dt in fields
|
return dt in fields
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@ def get_export_version(data):
|
||||||
return struct.unpack('!H', data[:2])[0]
|
return struct.unpack('!H', data[:2])[0]
|
||||||
|
|
||||||
|
|
||||||
def parse_packet(data: Union[str, bytes], templates: Dict = None) -> Union[V1ExportPacket, V5ExportPacket,
|
def parse_packet(data: Union[str, bytes], templates: Dict = None) \
|
||||||
V9ExportPacket, IPFIXExportPacket]:
|
-> Union[V1ExportPacket, V5ExportPacket, V9ExportPacket, IPFIXExportPacket]:
|
||||||
"""
|
"""
|
||||||
Parse an exported packet, either from string (hex) or from bytes.
|
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).
|
:param templates: The templates dictionary with keys 'netflow' and 'ipfix' (created if not existing).
|
||||||
:return: The parsed packet, or an exception.
|
:return: The parsed packet, or an exception.
|
||||||
"""
|
"""
|
||||||
if type(data) == str:
|
if type(data) is str:
|
||||||
# hex dump as string
|
# hex dump as string
|
||||||
data = bytes.fromhex(data)
|
data = bytes.fromhex(data)
|
||||||
elif type(data) == bytes:
|
elif type(data) is bytes:
|
||||||
# check representation based on utf-8 decoding result
|
# check representation based on utf-8 decoding result
|
||||||
try:
|
try:
|
||||||
# hex dump as bytes, but not hex
|
# 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:
|
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 "
|
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(
|
"templates, create a 'templates' dict and pass it into the 'parse_packet' function."
|
||||||
"NetFlow v9" if version == 9 else "IPFIX"))
|
.format("NetFlow v9" if version == 9 else "IPFIX"))
|
||||||
|
|
||||||
if version == 1:
|
if version == 1:
|
||||||
return V1ExportPacket(data)
|
return V1ExportPacket(data)
|
||||||
|
|
Loading…
Reference in a new issue