diff --git a/netflow/analyzer.py b/netflow/analyzer.py index 71338b7..7448b84 100644 --- a/netflow/analyzer.py +++ b/netflow/analyzer.py @@ -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 diff --git a/netflow/ipfix.py b/netflow/ipfix.py index 57276ce..b5121a2 100644 --- a/netflow/ipfix.py +++ b/netflow/ipfix.py @@ -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 diff --git a/netflow/utils.py b/netflow/utils.py index 395eb21..c4603d9 100644 --- a/netflow/utils.py +++ b/netflow/utils.py @@ -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)