This repository has been archived by the owner on Apr 18, 2020. It is now read-only.
-
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.
Started on a JSON serializer rather than my custom JSON hackery.
- Loading branch information
Showing
5 changed files
with
44 additions
and
33 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
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
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,32 @@ | ||
import six | ||
import sys | ||
import json | ||
from django.core.serializers.json import Serializer | ||
from django.core.serializers.base import DeserializationError | ||
from django.core.serializers.python import Deserializer as PythonDeserializer | ||
|
||
|
||
class BigBuildJSONSerializer(Serializer): | ||
""" | ||
A custom JSON serializer for bigbuild models. | ||
""" | ||
pass | ||
|
||
|
||
def BigBuildJSONDeserializer(stream_or_string, **options): | ||
""" | ||
Deserialize a stream or string of JSON data. | ||
""" | ||
if not isinstance(stream_or_string, (bytes, six.string_types)): | ||
stream_or_string = stream_or_string.read() | ||
if isinstance(stream_or_string, bytes): | ||
stream_or_string = stream_or_string.decode('utf-8') | ||
try: | ||
objects = json.loads(stream_or_string) | ||
for obj in PythonDeserializer(objects, **options): | ||
yield obj | ||
except GeneratorExit: | ||
raise | ||
except Exception as e: | ||
# Map to deserializer error | ||
six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2]) |