dfindexeddb 20241105__py3-none-any.whl → 20251109__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. dfindexeddb/indexeddb/chromium/blink.py +116 -74
  2. dfindexeddb/indexeddb/chromium/definitions.py +148 -125
  3. dfindexeddb/indexeddb/chromium/record.py +426 -324
  4. dfindexeddb/indexeddb/chromium/v8.py +100 -78
  5. dfindexeddb/indexeddb/cli.py +122 -118
  6. dfindexeddb/indexeddb/firefox/definitions.py +7 -4
  7. dfindexeddb/indexeddb/firefox/gecko.py +98 -74
  8. dfindexeddb/indexeddb/firefox/record.py +66 -24
  9. dfindexeddb/indexeddb/safari/definitions.py +5 -3
  10. dfindexeddb/indexeddb/safari/record.py +68 -51
  11. dfindexeddb/indexeddb/safari/webkit.py +85 -71
  12. dfindexeddb/indexeddb/types.py +4 -1
  13. dfindexeddb/leveldb/cli.py +146 -138
  14. dfindexeddb/leveldb/definitions.py +6 -2
  15. dfindexeddb/leveldb/descriptor.py +70 -56
  16. dfindexeddb/leveldb/ldb.py +39 -33
  17. dfindexeddb/leveldb/log.py +41 -30
  18. dfindexeddb/leveldb/plugins/chrome_notifications.py +30 -18
  19. dfindexeddb/leveldb/plugins/interface.py +5 -6
  20. dfindexeddb/leveldb/plugins/manager.py +10 -9
  21. dfindexeddb/leveldb/record.py +71 -62
  22. dfindexeddb/leveldb/utils.py +21 -13
  23. dfindexeddb/utils.py +36 -31
  24. dfindexeddb/version.py +2 -2
  25. dfindexeddb-20251109.dist-info/METADATA +222 -0
  26. dfindexeddb-20251109.dist-info/RECORD +40 -0
  27. {dfindexeddb-20241105.dist-info → dfindexeddb-20251109.dist-info}/WHEEL +1 -1
  28. dfindexeddb-20241105.dist-info/AUTHORS +0 -12
  29. dfindexeddb-20241105.dist-info/METADATA +0 -424
  30. dfindexeddb-20241105.dist-info/RECORD +0 -41
  31. {dfindexeddb-20241105.dist-info → dfindexeddb-20251109.dist-info}/entry_points.txt +0 -0
  32. {dfindexeddb-20241105.dist-info → dfindexeddb-20251109.dist-info/licenses}/LICENSE +0 -0
  33. {dfindexeddb-20241105.dist-info → dfindexeddb-20251109.dist-info}/top_level.txt +0 -0
@@ -15,21 +15,33 @@
15
15
  """Parsers for v8 javascript serialized objects."""
16
16
  from __future__ import annotations
17
17
 
18
- from dataclasses import dataclass
19
- from datetime import datetime
20
18
  import io
21
19
  import os
22
- from typing import Any, BinaryIO, Dict, Optional, Set, Tuple, Union
23
-
24
- from dfindexeddb import errors
25
- from dfindexeddb import utils
20
+ from dataclasses import dataclass
21
+ from datetime import datetime
22
+ from typing import (
23
+ TYPE_CHECKING,
24
+ Any,
25
+ BinaryIO,
26
+ Dict,
27
+ Optional,
28
+ Set,
29
+ Tuple,
30
+ Union,
31
+ )
32
+
33
+ from dfindexeddb import errors, utils
26
34
  from dfindexeddb.indexeddb import types
27
35
  from dfindexeddb.indexeddb.chromium import definitions
28
36
 
37
+ if TYPE_CHECKING:
38
+ from dfindexeddb.indexeddb.chromium import blink
39
+
29
40
 
30
41
  @dataclass
31
42
  class ArrayBufferView:
32
43
  """A parsed Javascript ArrayBufferView."""
44
+
33
45
  buffer: bytes
34
46
  tag: definitions.V8ArrayBufferViewTag
35
47
  offset: int
@@ -52,7 +64,7 @@ class ValueDeserializer:
52
64
 
53
65
  LATEST_VERSION = 15
54
66
 
55
- def __init__(self, stream: BinaryIO, delegate):
67
+ def __init__(self, stream: BinaryIO, delegate: blink.V8ScriptValueDecoder):
56
68
  """Initializes a ValueDeserializer.
57
69
 
58
70
  Args:
@@ -63,8 +75,8 @@ class ValueDeserializer:
63
75
  self.decoder = utils.StreamDecoder(stream)
64
76
  self.delegate = delegate
65
77
  self.next_id = 0
66
- self.objects = {}
67
- self.version = None
78
+ self.objects: dict[int, Any] = {}
79
+ self.version = 0
68
80
 
69
81
  def GetWireFormatVersion(self) -> int:
70
82
  """Returns the underlying wire format version.
@@ -82,22 +94,23 @@ class ValueDeserializer:
82
94
  return False
83
95
  return True
84
96
 
85
- def ReadObjectWrapper(self):
97
+ def ReadObjectWrapper(self) -> Any:
86
98
  """Deserializes a V8 object from the current decoder position."""
87
99
  original_position = self.decoder.stream.tell()
88
100
  result = self._ReadObject()
89
101
  if result is None and self.version == 13:
90
102
  self.decoder.stream.seek(original_position, os.SEEK_SET)
91
103
  result = self._ReadObject()
92
- raise NotImplementedError('ValueDeserializer.ReadObjectWrapper v13')
104
+ raise NotImplementedError("ValueDeserializer.ReadObjectWrapper v13")
93
105
  return result
94
106
 
95
- def ReadObjectUsingEntireBufferForLegacyFormat(self):
107
+ def ReadObjectUsingEntireBufferForLegacyFormat(self) -> Any:
96
108
  """Reads an object, consuming the entire buffer."""
97
109
  raise NotImplementedError(
98
- 'ValueDeserializer.ReadObjectUsingEntireBufferForLegacyFormat')
110
+ "ValueDeserializer.ReadObjectUsingEntireBufferForLegacyFormat"
111
+ )
99
112
 
100
- def ReadValue(self):
113
+ def ReadValue(self) -> Any:
101
114
  """Reads the Javascript value."""
102
115
  if self.GetWireFormatVersion() > 0:
103
116
  return self.ReadObjectWrapper()
@@ -117,8 +130,9 @@ class ValueDeserializer:
117
130
  return definitions.V8SerializationTag(tag_value[0])
118
131
  except ValueError as error:
119
132
  raise errors.ParserError(
120
- f'Invalid v8 tag value {tag_value} at offset'
121
- f' {self.decoder.stream.tell()}') from error
133
+ f"Invalid v8 tag value {tag_value!r} at offset"
134
+ f" {self.decoder.stream.tell()}"
135
+ ) from error
122
136
 
123
137
  def _ReadTag(self) -> definitions.V8SerializationTag:
124
138
  """Returns the next non-padding serialization tag.
@@ -131,11 +145,13 @@ class ValueDeserializer:
131
145
  try:
132
146
  tag = definitions.V8SerializationTag(tag_value[0])
133
147
  except ValueError as error:
134
- raise errors.ParserError(f'Invalid v8 tag value {tag_value}') from error
148
+ raise errors.ParserError(
149
+ f"Invalid v8 tag value {tag_value!r}"
150
+ ) from error
135
151
  if tag != definitions.V8SerializationTag.PADDING:
136
152
  return tag
137
153
 
138
- def _ConsumeTag(self, peeked_tag: definitions.V8SerializationTag):
154
+ def _ConsumeTag(self, peeked_tag: definitions.V8SerializationTag) -> None:
139
155
  """Consumes the next serialization tag.
140
156
 
141
157
  Args:
@@ -146,9 +162,9 @@ class ValueDeserializer:
146
162
  """
147
163
  tag = self._ReadTag()
148
164
  if tag != peeked_tag:
149
- raise errors.ParserError(f'Unexpected tag {tag} found.')
165
+ raise errors.ParserError(f"Unexpected tag {tag} found.")
150
166
 
151
- def _ReadObject(self):
167
+ def _ReadObject(self) -> Any:
152
168
  """Reads a Javascript object from the current position."""
153
169
  _, result = self._ReadObjectInternal()
154
170
  tag = self._PeekTag()
@@ -165,6 +181,8 @@ class ValueDeserializer:
165
181
  a tuple of the serialization tag and the parsed object.
166
182
  """
167
183
  tag = self._ReadTag()
184
+ parsed_object: Any = None
185
+
168
186
  if tag == definitions.V8SerializationTag.VERIFY_OBJECT_COUNT:
169
187
  _ = self.decoder.DecodeUint32Varint()
170
188
  parsed_object = self._ReadObject()
@@ -206,7 +224,8 @@ class ValueDeserializer:
206
224
  definitions.V8SerializationTag.FALSE_OBJECT,
207
225
  definitions.V8SerializationTag.NUMBER_OBJECT,
208
226
  definitions.V8SerializationTag.BIGINT_OBJECT,
209
- definitions.V8SerializationTag.STRING_OBJECT):
227
+ definitions.V8SerializationTag.STRING_OBJECT,
228
+ ):
210
229
  parsed_object = self._ReadJSPrimitiveWrapper(tag)
211
230
  elif tag == definitions.V8SerializationTag.REGEXP:
212
231
  parsed_object = self._ReadJSRegExp()
@@ -216,25 +235,29 @@ class ValueDeserializer:
216
235
  parsed_object = self._ReadJSSet()
217
236
  elif tag == definitions.V8SerializationTag.ARRAY_BUFFER:
218
237
  parsed_object = self._ReadJSArrayBuffer(
219
- is_shared=False, is_resizable=False)
238
+ is_shared=False, is_resizable=False
239
+ )
220
240
  elif tag == definitions.V8SerializationTag.RESIZABLE_ARRAY_BUFFER:
221
241
  parsed_object = self._ReadJSArrayBuffer(
222
- is_shared=False, is_resizable=True)
242
+ is_shared=False, is_resizable=True
243
+ )
223
244
  elif tag == definitions.V8SerializationTag.SHARED_ARRAY_BUFFER:
224
245
  parsed_object = self._ReadJSArrayBuffer(
225
- is_shared=True, is_resizable=False)
246
+ is_shared=True, is_resizable=False
247
+ )
226
248
  elif tag == definitions.V8SerializationTag.ERROR:
227
- parsed_object = self._ReadJSError()
249
+ self._ReadJSError()
228
250
  elif tag == definitions.V8SerializationTag.WASM_MODULE_TRANSFER:
229
- parsed_object = self._ReadWasmModuleTransfer()
251
+ self._ReadWasmModuleTransfer()
230
252
  elif tag == definitions.V8SerializationTag.WASM_MEMORY_TRANSFER:
231
- parsed_object = self._ReadWasmMemory()
253
+ self._ReadWasmMemory()
232
254
  elif tag == definitions.V8SerializationTag.HOST_OBJECT:
233
255
  parsed_object = self.ReadHostObject()
234
256
  elif (
235
- tag == definitions.V8SerializationTag.SHARED_OBJECT and
236
- self.version >= 15):
237
- parsed_object = self.ReadSharedObject()
257
+ tag == definitions.V8SerializationTag.SHARED_OBJECT
258
+ and self.version >= 15
259
+ ):
260
+ self.ReadSharedObject()
238
261
  elif self.version < 13:
239
262
  self.decoder.stream.seek(-1, os.SEEK_CUR)
240
263
  parsed_object = self.ReadHostObject()
@@ -253,7 +276,7 @@ class ValueDeserializer:
253
276
 
254
277
  str_obj = self._ReadObject()
255
278
  if not isinstance(str_obj, str):
256
- raise errors.ParserError('Not a string')
279
+ raise errors.ParserError("Not a string")
257
280
  return str_obj
258
281
 
259
282
  def ReadBigInt(self) -> int:
@@ -268,7 +291,7 @@ class ValueDeserializer:
268
291
  """Reads a UTF-8 string from the current position."""
269
292
  count = self.decoder.DecodeUint32Varint()[1]
270
293
  buffer = self.decoder.ReadBytes(count=count)[1]
271
- return buffer.decode('utf-8')
294
+ return buffer.decode("utf-8")
272
295
 
273
296
  def ReadOneByteString(self) -> str:
274
297
  """Reads a one-byte string from the current position.
@@ -277,13 +300,13 @@ class ValueDeserializer:
277
300
  """
278
301
  length = self.decoder.DecodeUint32Varint()[1]
279
302
  buffer = self.decoder.ReadBytes(count=length)[1]
280
- return buffer.decode('latin-1')
303
+ return buffer.decode("latin-1")
281
304
 
282
305
  def ReadTwoByteString(self) -> str:
283
306
  """Reads a UTF-16-LE string from the current position."""
284
307
  length = self.decoder.DecodeUint32Varint()[1]
285
308
  buffer = self.decoder.ReadBytes(count=length)[1]
286
- return buffer.decode('utf-16-le')
309
+ return buffer.decode("utf-16-le")
287
310
 
288
311
  def ReadExpectedString(self) -> Optional[str]:
289
312
  """Reads a string from the current position, None if there is no tag or
@@ -303,14 +326,14 @@ class ValueDeserializer:
303
326
  _, raw_bytes = self.decoder.ReadBytes(count=byte_length)
304
327
 
305
328
  if tag == definitions.V8SerializationTag.ONE_BYTE_STRING:
306
- return raw_bytes.decode('latin-1')
329
+ return raw_bytes.decode("latin-1")
307
330
  if tag == definitions.V8SerializationTag.TWO_BYTE_STRING:
308
- return raw_bytes.decode('utf-16-le')
331
+ return raw_bytes.decode("utf-16-le")
309
332
  if tag == definitions.V8SerializationTag.UTF8_STRING:
310
- return raw_bytes.decode('utf-8')
311
- raise errors.ParserError(f'Unexpected serialization tag {tag}.')
333
+ return raw_bytes.decode("utf-8")
334
+ raise errors.ParserError(f"Unexpected serialization tag {tag}.")
312
335
 
313
- def _ReadJSObject(self) -> Dict:
336
+ def _ReadJSObject(self) -> Dict[int, Any]:
314
337
  """Reads a JSObject from the current position.
315
338
 
316
339
  Raises:
@@ -318,21 +341,22 @@ class ValueDeserializer:
318
341
  read.
319
342
  """
320
343
  next_id = self._GetNextId()
321
- js_object = {}
344
+ js_object: Dict[int, Any] = {}
322
345
 
323
346
  num_properties = self._ReadJSObjectProperties(
324
- js_object, definitions.V8SerializationTag.END_JS_OBJECT)
347
+ js_object, definitions.V8SerializationTag.END_JS_OBJECT
348
+ )
325
349
  _, expected_number_properties = self.decoder.DecodeUint32Varint()
326
350
  if expected_number_properties != num_properties:
327
- raise errors.ParserError('Unexpected number of properties')
351
+ raise errors.ParserError("Unexpected number of properties")
328
352
 
329
353
  self.objects[next_id] = js_object
330
354
  return js_object
331
355
 
332
356
  def _ReadJSObjectProperties(
333
357
  self,
334
- js_object: Union[Dict, types.JSArray],
335
- end_tag: definitions.V8SerializationTag
358
+ js_object: Union[Dict[int, Any], types.JSArray],
359
+ end_tag: definitions.V8SerializationTag,
336
360
  ) -> int:
337
361
  """Reads key-value properties and sets them to the given js_object.
338
362
 
@@ -375,14 +399,15 @@ class ValueDeserializer:
375
399
  js_array.values.append(types.Undefined())
376
400
 
377
401
  num_properties = self._ReadJSObjectProperties(
378
- js_array.properties, definitions.V8SerializationTag.END_SPARSE_JS_ARRAY)
402
+ js_array.properties, definitions.V8SerializationTag.END_SPARSE_JS_ARRAY
403
+ )
379
404
  _, expected_num_properties = self.decoder.DecodeUint32Varint()
380
405
  _, expected_length = self.decoder.DecodeUint32Varint()
381
406
 
382
407
  if num_properties != expected_num_properties:
383
- raise errors.ParserError('Unexpected property length')
408
+ raise errors.ParserError("Unexpected property length")
384
409
  if length != expected_length:
385
- raise errors.ParserError('Unexpected array length')
410
+ raise errors.ParserError("Unexpected array length")
386
411
  self.objects[next_id] = js_array
387
412
  return js_array
388
413
 
@@ -408,13 +433,14 @@ class ValueDeserializer:
408
433
  js_array.values.append(array_object)
409
434
 
410
435
  num_properties = self._ReadJSObjectProperties(
411
- js_array.properties, definitions.V8SerializationTag.END_DENSE_JS_ARRAY)
436
+ js_array.properties, definitions.V8SerializationTag.END_DENSE_JS_ARRAY
437
+ )
412
438
  _, expected_num_properties = self.decoder.DecodeUint32Varint()
413
439
  _, expected_length = self.decoder.DecodeUint32Varint()
414
440
  if num_properties != expected_num_properties:
415
- raise errors.ParserError('Unexpected property length')
441
+ raise errors.ParserError("Unexpected property length")
416
442
  if length != expected_length:
417
- raise errors.ParserError('Unexpected array length')
443
+ raise errors.ParserError("Unexpected array length")
418
444
  self.objects[next_id] = js_array
419
445
  return js_array
420
446
 
@@ -423,13 +449,12 @@ class ValueDeserializer:
423
449
  next_id = self._GetNextId()
424
450
 
425
451
  _, value = self.decoder.DecodeDouble()
426
- result = datetime.utcfromtimestamp(value/1000.0)
452
+ result = datetime.utcfromtimestamp(value / 1000.0)
427
453
  self.objects[next_id] = result
428
454
  return result
429
455
 
430
456
  def _ReadJSPrimitiveWrapper(
431
- self,
432
- tag: definitions.V8SerializationTag
457
+ self, tag: definitions.V8SerializationTag
433
458
  ) -> Union[bool, float, int, str]:
434
459
  """Reads a Javascript wrapped primitive.
435
460
 
@@ -446,7 +471,7 @@ class ValueDeserializer:
446
471
  next_id = self._GetNextId()
447
472
 
448
473
  if tag == definitions.V8SerializationTag.TRUE_OBJECT:
449
- value = True
474
+ value: Union[bool, float, int, str] = True
450
475
  elif tag == definitions.V8SerializationTag.FALSE_OBJECT:
451
476
  value = False
452
477
  elif tag == definitions.V8SerializationTag.NUMBER_OBJECT:
@@ -456,7 +481,7 @@ class ValueDeserializer:
456
481
  elif tag == definitions.V8SerializationTag.STRING_OBJECT:
457
482
  value = self.ReadString()
458
483
  else:
459
- raise errors.ParserError(f'Invalid tag {tag}')
484
+ raise errors.ParserError(f"Invalid tag {tag}")
460
485
 
461
486
  self.objects[next_id] = value
462
487
  return value
@@ -489,7 +514,7 @@ class ValueDeserializer:
489
514
 
490
515
  _, expected_length = self.decoder.DecodeUint32Varint()
491
516
  if len(js_map) * 2 != expected_length:
492
- raise errors.ParserError('unexpected length')
517
+ raise errors.ParserError("unexpected length")
493
518
 
494
519
  self.objects[next_id] = js_map
495
520
  return js_map
@@ -512,16 +537,12 @@ class ValueDeserializer:
512
537
 
513
538
  _, expected_length = self.decoder.DecodeUint32Varint()
514
539
  if len(js_set) != expected_length:
515
- raise ValueError('unexpected length')
540
+ raise ValueError("unexpected length")
516
541
 
517
542
  self.objects[next_id] = js_set
518
543
  return js_set
519
544
 
520
- def _ReadJSArrayBuffer(
521
- self,
522
- is_shared: bool,
523
- is_resizable: bool
524
- ) -> bytes:
545
+ def _ReadJSArrayBuffer(self, is_shared: bool, is_resizable: bool) -> bytes:
525
546
  """Reads a Javascript ArrayBuffer from the current position.
526
547
 
527
548
  Args:
@@ -529,10 +550,10 @@ class ValueDeserializer:
529
550
  is_resizable: True if the buffer is resizable, False otherwise.
530
551
  """
531
552
  next_id = self._GetNextId()
532
- array_buffer = b''
553
+ array_buffer = b""
533
554
 
534
555
  if is_shared:
535
- raise NotImplementedError('Shared ArrayBuffer not supported yet')
556
+ raise NotImplementedError("Shared ArrayBuffer not supported yet")
536
557
 
537
558
  _, byte_length = self.decoder.DecodeUint32Varint()
538
559
  max_byte_length = byte_length
@@ -547,7 +568,7 @@ class ValueDeserializer:
547
568
  self.objects[next_id] = array_buffer
548
569
  return array_buffer
549
570
 
550
- def _ReadJSArrayBufferView(self, buffer):
571
+ def _ReadJSArrayBufferView(self, buffer: bytes) -> ArrayBufferView:
551
572
  """Reads a JSArrayBufferView from the current position."""
552
573
  _, tag = self.decoder.ReadBytes(1)
553
574
  _, byte_offset = self.decoder.DecodeUint32Varint()
@@ -563,26 +584,27 @@ class ValueDeserializer:
563
584
  tag=definitions.V8ArrayBufferViewTag(tag[0]),
564
585
  offset=byte_offset,
565
586
  length=byte_length,
566
- flags=flags)
587
+ flags=flags,
588
+ )
567
589
 
568
- def _ReadJSError(self):
590
+ def _ReadJSError(self) -> None:
569
591
  """Reads a Javascript error from the current position."""
570
- raise NotImplementedError('ValueDeserializer.ReadJSError')
592
+ raise NotImplementedError("ValueDeserializer.ReadJSError")
571
593
 
572
- def _ReadWasmModuleTransfer(self):
594
+ def _ReadWasmModuleTransfer(self) -> None:
573
595
  """Reads a Wasm module transfer object from the current position."""
574
- raise NotImplementedError('ValueDeserializer.ReadWasmModuleTransfer')
596
+ raise NotImplementedError("ValueDeserializer.ReadWasmModuleTransfer")
575
597
 
576
- def _ReadWasmMemory(self):
598
+ def _ReadWasmMemory(self) -> None:
577
599
  """Reads a Wasm memory object from the current position."""
578
- raise NotImplementedError('ValueDeserializer.ReadWasmMemory')
600
+ raise NotImplementedError("ValueDeserializer.ReadWasmMemory")
579
601
 
580
- def ReadSharedObject(self) -> Any:
602
+ def ReadSharedObject(self) -> None:
581
603
  """Reads a shared object from the current position."""
582
- #_, shared_object_id = self.decoder.DecodeUint32Varint()
583
- raise NotImplementedError('ValueDeserializer.ReadSharedObject')
604
+ # _, shared_object_id = self.decoder.DecodeUint32Varint()
605
+ raise NotImplementedError("ValueDeserializer.ReadSharedObject")
584
606
 
585
- def ReadHostObject(self):
607
+ def ReadHostObject(self) -> Any:
586
608
  """Reads a Host object using the delegate object.
587
609
 
588
610
  Raises:
@@ -590,7 +612,7 @@ class ValueDeserializer:
590
612
  """
591
613
  next_id = self._GetNextId()
592
614
  if not self.delegate:
593
- raise errors.ParserError('No delegate to read host object.')
615
+ raise errors.ParserError("No delegate to read host object.")
594
616
  host_object = self.delegate.ReadHostObject()
595
617
  self.objects[next_id] = host_object
596
618
  return host_object
@@ -612,5 +634,5 @@ class ValueDeserializer:
612
634
  stream = io.BytesIO(data)
613
635
  deserializer = cls(stream, delegate)
614
636
  if not deserializer.ReadHeader():
615
- raise errors.ParserError('Invalid V8 header')
637
+ raise errors.ParserError("Invalid V8 header")
616
638
  return deserializer.ReadObjectWrapper()