-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path_serialization.py
More file actions
37 lines (26 loc) · 1.14 KB
/
_serialization.py
File metadata and controls
37 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import json
from ._page_inputs import Actions, Geolocation, Screenshot
try:
from web_poet.serialization import SerializedLeafData, register_serialization
except ImportError:
pass
else:
def _serialize_Actions(o: Actions) -> SerializedLeafData:
return {"results.json": json.dumps(o.results).encode()}
def _deserialize_Actions(cls: type[Actions], data: SerializedLeafData) -> Actions:
return cls(results=json.loads(data["results.json"]))
register_serialization(_serialize_Actions, _deserialize_Actions)
def _serialize_Geolocation(o: Geolocation) -> SerializedLeafData:
return {}
def _deserialize_Geolocation(
cls: type[Geolocation], data: SerializedLeafData
) -> Geolocation:
return cls()
register_serialization(_serialize_Geolocation, _deserialize_Geolocation)
def _serialize_Screenshot(o: Screenshot) -> SerializedLeafData:
return {"body": o.body}
def _deserialize_Screenshot(
cls: type[Screenshot], data: SerializedLeafData
) -> Screenshot:
return cls(body=data["body"])
register_serialization(_serialize_Screenshot, _deserialize_Screenshot)