-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55b1749
commit 1946fe4
Showing
119 changed files
with
369 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Wed Nov 27 02:09:40 AM PST 2024 | ||
Wed Nov 27 06:22:42 PM PST 2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Wed Nov 27 02:06:07 AM PST 2024 | ||
Wed Nov 27 06:19:51 PM PST 2024 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
""" | ||
Serialize data to/from JSON | ||
""" | ||
|
||
import datetime | ||
import decimal | ||
import json, ijson | ||
import uuid | ||
|
||
from django.core.serializers.base import DeserializationError | ||
from django.core.serializers.python import Deserializer as PythonDeserializer | ||
from django.core.serializers.python import Serializer as PythonSerializer | ||
from django.utils.duration import duration_iso_string | ||
from django.utils.functional import Promise | ||
from django.utils.timezone import is_aware | ||
|
||
|
||
class Serializer(PythonSerializer): | ||
"""Convert a queryset to JSON.""" | ||
|
||
internal_use_only = False | ||
|
||
def _init_options(self): | ||
self._current = None | ||
self.json_kwargs = self.options.copy() | ||
self.json_kwargs.pop("stream", None) | ||
self.json_kwargs.pop("fields", None) | ||
if self.options.get("indent"): | ||
# Prevent trailing spaces | ||
self.json_kwargs["separators"] = (",", ": ") | ||
self.json_kwargs.setdefault("cls", DjangoJSONEncoder) | ||
self.json_kwargs.setdefault("ensure_ascii", False) | ||
|
||
def start_serialization(self): | ||
self._init_options() | ||
self.stream.write("[") | ||
|
||
def end_serialization(self): | ||
if self.options.get("indent"): | ||
self.stream.write("\n") | ||
self.stream.write("]") | ||
if self.options.get("indent"): | ||
self.stream.write("\n") | ||
|
||
def end_object(self, obj): | ||
# self._current has the field data | ||
indent = self.options.get("indent") | ||
if not self.first: | ||
self.stream.write(",") | ||
if not indent: | ||
self.stream.write(" ") | ||
if indent: | ||
self.stream.write("\n") | ||
json.dump(self.get_dump_object(obj), self.stream, **self.json_kwargs) | ||
self._current = None | ||
|
||
def getvalue(self): | ||
# Grandparent super | ||
return super(PythonSerializer, self).getvalue() | ||
|
||
|
||
def Deserializer(stream_or_string, **options): | ||
"""Deserialize a stream or string of JSON data.""" | ||
if not isinstance(stream_or_string, (bytes, str)): | ||
stream_or_string = stream_or_string.read() | ||
if isinstance(stream_or_string, bytes): | ||
stream_or_string = stream_or_string.decode() | ||
try: | ||
# with open('/home/team/lotteh/data/security.json', 'r') as f: | ||
yield from PythonDeserializer(ijson.items(stream_or_string, 'item'), **options) | ||
except (GeneratorExit, DeserializationError): | ||
raise | ||
except Exception as exc: | ||
raise DeserializationError() from exc | ||
|
||
|
||
class DjangoJSONEncoder(json.JSONEncoder): | ||
""" | ||
JSONEncoder subclass that knows how to encode date/time, decimal types, and | ||
UUIDs. | ||
""" | ||
|
||
def default(self, o): | ||
# See "Date Time String Format" in the ECMA-262 specification. | ||
if isinstance(o, datetime.datetime): | ||
r = o.isoformat() | ||
if o.microsecond: | ||
r = r[:23] + r[26:] | ||
if r.endswith("+00:00"): | ||
r = r.removesuffix("+00:00") + "Z" | ||
return r | ||
elif isinstance(o, datetime.date): | ||
return o.isoformat() | ||
elif isinstance(o, datetime.time): | ||
if is_aware(o): | ||
raise ValueError("JSON can't represent timezone-aware times.") | ||
r = o.isoformat() | ||
if o.microsecond: | ||
r = r[:12] | ||
return r | ||
elif isinstance(o, datetime.timedelta): | ||
return duration_iso_string(o) | ||
elif isinstance(o, (decimal.Decimal, uuid.UUID, Promise)): | ||
return str(o) | ||
else: | ||
return super().default(o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.