python-arango-async 0.0.1__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.
- arangoasync/__init__.py +5 -0
- arangoasync/aql.py +760 -0
- arangoasync/auth.py +121 -0
- arangoasync/client.py +239 -0
- arangoasync/collection.py +1688 -0
- arangoasync/compression.py +139 -0
- arangoasync/connection.py +515 -0
- arangoasync/cursor.py +262 -0
- arangoasync/database.py +1533 -0
- arangoasync/errno.py +1168 -0
- arangoasync/exceptions.py +379 -0
- arangoasync/executor.py +168 -0
- arangoasync/http.py +182 -0
- arangoasync/job.py +214 -0
- arangoasync/logger.py +3 -0
- arangoasync/request.py +107 -0
- arangoasync/resolver.py +119 -0
- arangoasync/response.py +65 -0
- arangoasync/result.py +9 -0
- arangoasync/serialization.py +111 -0
- arangoasync/typings.py +1646 -0
- arangoasync/version.py +1 -0
- python_arango_async-0.0.1.dist-info/METADATA +142 -0
- python_arango_async-0.0.1.dist-info/RECORD +27 -0
- python_arango_async-0.0.1.dist-info/WHEEL +5 -0
- python_arango_async-0.0.1.dist-info/licenses/LICENSE +21 -0
- python_arango_async-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
__all__ = [
|
|
2
|
+
"Serializer",
|
|
3
|
+
"Deserializer",
|
|
4
|
+
"JsonSerializer",
|
|
5
|
+
"JsonDeserializer",
|
|
6
|
+
"DefaultSerializer",
|
|
7
|
+
"DefaultDeserializer",
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from abc import ABC, abstractmethod
|
|
12
|
+
from typing import Generic, Sequence, TypeVar
|
|
13
|
+
|
|
14
|
+
from arangoasync.exceptions import DeserializationError, SerializationError
|
|
15
|
+
from arangoasync.typings import Json, Jsons
|
|
16
|
+
|
|
17
|
+
T = TypeVar("T")
|
|
18
|
+
U = TypeVar("U")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Serializer(ABC, Generic[T]): # pragma: no cover
|
|
22
|
+
"""Abstract base class for serialization.
|
|
23
|
+
|
|
24
|
+
Custom serialization classes should inherit from this class.
|
|
25
|
+
Please be mindful of the performance implications.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
def dumps(self, data: T | Sequence[T | str]) -> str:
|
|
30
|
+
"""Serialize any generic data.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
data: Data to serialize.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
str: Serialized data.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
SerializationError: If the data cannot be serialized.
|
|
40
|
+
"""
|
|
41
|
+
raise NotImplementedError
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Deserializer(ABC, Generic[T, U]): # pragma: no cover
|
|
45
|
+
"""Abstract base class for deserialization.
|
|
46
|
+
|
|
47
|
+
Custom deserialization classes should inherit from this class.
|
|
48
|
+
Please be mindful of the performance implications.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
@abstractmethod
|
|
52
|
+
def loads(self, data: bytes) -> T:
|
|
53
|
+
"""Deserialize response data.
|
|
54
|
+
|
|
55
|
+
Will be called on generic server data (such as server status) and
|
|
56
|
+
single documents.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
data (bytes): Data to deserialize.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
Deserialized data.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
DeserializationError: If the data cannot be deserialized.
|
|
66
|
+
"""
|
|
67
|
+
raise NotImplementedError
|
|
68
|
+
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def loads_many(self, data: bytes) -> U:
|
|
71
|
+
"""Deserialize response data.
|
|
72
|
+
|
|
73
|
+
Will only be called when deserializing a list of documents.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
data (bytes): Data to deserialize.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Deserialized data.
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
DeserializationError: If the data cannot be deserialized.
|
|
83
|
+
"""
|
|
84
|
+
raise NotImplementedError
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class JsonSerializer(Serializer[Json]):
|
|
88
|
+
"""JSON serializer."""
|
|
89
|
+
|
|
90
|
+
def dumps(self, data: Json | Sequence[str | Json]) -> str:
|
|
91
|
+
try:
|
|
92
|
+
return json.dumps(data, separators=(",", ":"))
|
|
93
|
+
except Exception as e:
|
|
94
|
+
raise SerializationError("Failed to serialize data to JSON.") from e
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class JsonDeserializer(Deserializer[Json, Jsons]):
|
|
98
|
+
"""JSON deserializer."""
|
|
99
|
+
|
|
100
|
+
def loads(self, data: bytes) -> Json:
|
|
101
|
+
try:
|
|
102
|
+
return json.loads(data) # type: ignore[no-any-return]
|
|
103
|
+
except Exception as e:
|
|
104
|
+
raise DeserializationError("Failed to deserialize data from JSON.") from e
|
|
105
|
+
|
|
106
|
+
def loads_many(self, data: bytes) -> Jsons:
|
|
107
|
+
return self.loads(data) # type: ignore[return-value]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
DefaultSerializer = JsonSerializer
|
|
111
|
+
DefaultDeserializer = JsonDeserializer
|