|
60 | 60 |
|
61 | 61 | DECODE_EXCEPTIONS = (IndexError, struct.error, IncomingDecodeError) |
62 | 62 |
|
63 | | -UNPACK_3H = struct.Struct(b'!3H').unpack |
64 | | -UNPACK_6H = struct.Struct(b'!6H').unpack |
65 | | -UNPACK_HH = struct.Struct(b'!HH').unpack |
66 | | -UNPACK_HHiH = struct.Struct(b'!HHiH').unpack |
| 63 | +UNPACK_3H = struct.Struct(b'!3H').unpack_from |
| 64 | +UNPACK_6H = struct.Struct(b'!6H').unpack_from |
| 65 | +UNPACK_HH = struct.Struct(b'!HH').unpack_from |
| 66 | +UNPACK_HHiH = struct.Struct(b'!HHiH').unpack_from |
67 | 67 |
|
68 | 68 | _seen_logs: Dict[str, Union[int, tuple]] = {} |
69 | 69 |
|
@@ -184,9 +184,9 @@ def __repr__(self) -> str: |
184 | 184 | ] |
185 | 185 | ) |
186 | 186 |
|
187 | | - def _unpack(self, unpacker: Callable[[bytes], tuple], length: int) -> tuple: |
| 187 | + def _unpack(self, unpacker: Callable[[bytes, int], tuple], length: int) -> tuple: |
188 | 188 | self.offset += length |
189 | | - return unpacker(self.data[self.offset - length : self.offset]) |
| 189 | + return unpacker(self.data, self.offset - length) |
190 | 190 |
|
191 | 191 | def _read_header(self) -> None: |
192 | 192 | """Reads header portion of packet""" |
@@ -224,7 +224,8 @@ def _read_others(self) -> None: |
224 | 224 | n = self.num_answers + self.num_authorities + self.num_additionals |
225 | 225 | for _ in range(n): |
226 | 226 | domain = self._read_name() |
227 | | - type_, class_, ttl, length = self._unpack(UNPACK_HHiH, 10) |
| 227 | + type_, class_, ttl, length = UNPACK_HHiH(self.data, self.offset) |
| 228 | + self.offset += 10 |
228 | 229 | end = self.offset + length |
229 | 230 | rec = None |
230 | 231 | try: |
|
0 commit comments