@@ -1805,7 +1805,7 @@ def _read_options(self, options):
18051805 if code in [1 , 2988 , 2989 , 19372 , 19373 ]: # https://www.ietf.org/archive/id/draft-tuexen-opsawg-pcapng-05.html#name-options-format
18061806 if code not in opts :
18071807 opts [code ] = []
1808- cast ( List [ bytes ], opts [code ]) .append (options [4 :4 + length ])
1808+ opts [code ].append (options [4 :4 + length ])
18091809 else :
18101810 opts [code ] = options [4 :4 + length ]
18111811 if code == 0 :
@@ -1827,9 +1827,9 @@ def _read_block_idb(self, block, _):
18271827 options = self .default_options .copy () # type: Dict[str, Any]
18281828 for c , v in options_raw .items ():
18291829 if isinstance (v , list ):
1830- # If the option is a list, we take the last value
1831- # (as per pcapng spec)
1832- v = v [- 1 ]
1830+ # Spec allows multiple occurrences (see https://www.ietf.org/archive/id/draft-tuexen-opsawg-pcapng-05.html#section-4.2-8.6)
1831+ # but does not define which to use. We take the first for backward compatibility.
1832+ v = v [0 ]
18331833 if c == 9 :
18341834 length = len (v )
18351835 if length == 1 :
@@ -1886,7 +1886,6 @@ def _read_block_epb(self, block, size):
18861886 process_information = {}
18871887 for code , value in options .items ():
18881888 if code in [0x8001 , 0x8003 ]: # PCAPNG_EPB_PIB_INDEX, PCAPNG_EPB_E_PIB_INDEX
1889- value = cast (bytes , value )
18901889 try :
18911890 proc_index = struct .unpack (self .endian + "I" , value )[0 ]
18921891 except struct .error :
@@ -1903,7 +1902,6 @@ def _read_block_epb(self, block, size):
19031902 comments = options .get (1 , None )
19041903 epb_flags_raw = options .get (2 , None )
19051904 if epb_flags_raw :
1906- epb_flags_raw = cast (bytes , epb_flags_raw )
19071905 try :
19081906 epb_flags , = struct .unpack (self .endian + "I" , epb_flags_raw )
19091907 except struct .error :
@@ -2049,7 +2047,6 @@ def _read_block_pib(self, block, _):
20492047 # Get Options
20502048 options = self ._read_options (block )
20512049 for code , value in options .items ():
2052- value = cast (bytes , value )
20532050 if code == 2 :
20542051 process_information ["name" ] = value .decode ("ascii" , "backslashreplace" )
20552052 elif code == 4 :
@@ -2588,7 +2585,7 @@ def _write_block_epb(self,
25882585
25892586 # Options
25902587 opts = b''
2591- if comments is not None and len (comments ) > 0 :
2588+ if comments and len (comments ):
25922589 for c in comments :
25932590 comment = bytes_encode (c )
25942591 opts += struct .pack (self .endian + "HH" , 1 , len (comment ))
0 commit comments