21
21
__all__ = ['PCAPNG' ]
22
22
23
23
if TYPE_CHECKING :
24
+ from pcapkit .foundation .extraction import Extractor
24
25
from pcapkit .protocols .data .misc .pcapng import PCAPNG as Data_PCAPNG
25
26
from pcapkit .protocols .data .misc .pcapng import CustomBlock as Data_CustomBlock
26
27
from pcapkit .protocols .data .misc .pcapng import \
@@ -107,6 +108,16 @@ def module(cls) -> 'str':
107
108
"""Engine module name."""
108
109
return 'pcapkit.foundation.engine.pcapng'
109
110
111
+ ##########################################################################
112
+ # Data models.
113
+ ##########################################################################
114
+
115
+ def __init__ (self , extractor : 'Extractor' ) -> 'None' :
116
+ self ._ctx = None # type: ignore[assignment]
117
+ self ._ctx_list = []
118
+
119
+ super ().__init__ (extractor )
120
+
110
121
##########################################################################
111
122
# Methods.
112
123
##########################################################################
@@ -200,8 +211,8 @@ def read_frame(self) -> 'P_PCAPNG':
200
211
self ._write_file (block .info , name = f'Custom { len (self ._ctx .custom )} ' )
201
212
202
213
elif block .info .type == Enum_BlockType .Enhanced_Packet_Block :
203
- if info .interface_id >= len (self ._ctx .interfaces ):
204
- raise FormatError (f'PCAP-NG: [EPB] invalid interface ID: { info .interface_id } ' )
214
+ if block . info .interface_id >= len (self ._ctx .interfaces ):
215
+ raise FormatError (f'PCAP-NG: [EPB] invalid interface ID: { block . info .interface_id } ' )
205
216
break
206
217
207
218
elif block .info .type == Enum_BlockType .Simple_Packet_Block :
@@ -210,8 +221,8 @@ def read_frame(self) -> 'P_PCAPNG':
210
221
break
211
222
212
223
elif block .info .type == Enum_BlockType .Packet_Block :
213
- if info .interface_id >= len (self ._ctx .interfaces ):
214
- raise FormatError (f'PCAP-NG: [Packet] invalid interface ID: { info .interface_id } ' )
224
+ if block . info .interface_id >= len (self ._ctx .interfaces ):
225
+ raise FormatError (f'PCAP-NG: [Packet] invalid interface ID: { block . info .interface_id } ' )
215
226
216
227
warn ('PCAP-NG: [Packet] deprecated block type' , DeprecatedFormatWarning ,
217
228
stacklevel = stacklevel ())
@@ -277,9 +288,9 @@ def _write_file(self, block: 'Data_PCAPNG', *, name: 'str') -> 'None':
277
288
278
289
if ext ._flag_f :
279
290
ofile = ext ._ofile (f'{ ext ._ofnm } /{ name } .{ ext ._fext } ' )
280
- ofile (self . _ctx .to_dict (), name = name )
291
+ ofile (block .to_dict (), name = name )
281
292
else :
282
- ext ._ofile (self . _ctx .to_dict (), name = name )
293
+ ext ._ofile (block .to_dict (), name = name )
283
294
ofile = ext ._ofile
284
295
ext ._offmt = ofile .kind
285
296
0 commit comments