<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import datetime <EOL> import decimal <EOL> import json <EOL> import sys <EOL> from django . core . serializers . base import DeserializationError <EOL> from django . core . serializers . python import Serializer as PythonSerializer <EOL> from django . core . serializers . python import Deserializer as PythonDeserializer <EOL> from django . utils import six <EOL> from django . utils . timezone import is_aware <EOL> class Serializer ( PythonSerializer ) : <EOL> """<STR_LIT>""" <EOL> internal_use_only = False <EOL> def start_serialization ( self ) : <EOL> if json . __version__ . split ( '<STR_LIT:.>' ) >= [ '<STR_LIT:2>' , '<STR_LIT:1>' , '<STR_LIT:3>' ] : <EOL> self . options . update ( { '<STR_LIT>' : False } ) <EOL> self . _current = None <EOL> self . json_kwargs = self . options . copy ( ) <EOL> self . json_kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . json_kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . stream . write ( "<STR_LIT:[>" ) <EOL> def end_serialization ( self ) : <EOL> if self . options . get ( "<STR_LIT>" ) : <EOL> self . stream . write ( "<STR_LIT:\n>" ) <EOL> self . stream . write ( "<STR_LIT:]>" ) <EOL> if self . options . get ( "<STR_LIT>" ) : <EOL> self . stream . write ( "<STR_LIT:\n>" ) <EOL> def end_object ( self , obj ) : <EOL> indent = self . options . get ( "<STR_LIT>" ) <EOL> if not self . first : <EOL> self . stream . write ( "<STR_LIT:U+002C>" ) <EOL> if not indent : <EOL> self . stream . write ( "<STR_LIT:U+0020>" ) <EOL> if indent : <EOL> self . stream . write ( "<STR_LIT:\n>" ) <EOL> json . dump ( self . get_dump_object ( obj ) , self . stream , <EOL> cls = DjangoJSONEncoder , ** self . json_kwargs ) <EOL> self . _current = None <EOL> def getvalue ( self ) : <EOL> return super ( PythonSerializer , self ) . getvalue ( ) <EOL> def Deserializer ( stream_or_string , ** options ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( stream_or_string , ( bytes , six . string_types ) ) : <EOL> stream_or_string = stream_or_string . read ( ) <EOL> if isinstance ( stream_or_string , bytes ) : <EOL> stream_or_string = stream_or_string . decode ( '<STR_LIT:utf-8>' ) <EOL> try : <EOL> objects = json . loads ( stream_or_string ) <EOL> for obj in PythonDeserializer ( objects , ** options ) : <EOL> yield obj <EOL> except GeneratorExit : <EOL> raise <EOL> except Exception as e : <EOL> six . reraise ( DeserializationError , DeserializationError ( e ) , sys . exc_info ( ) [ <NUM_LIT:2> ] ) <EOL> class DjangoJSONEncoder ( json . JSONEncoder ) : <EOL> """<STR_LIT>""" <EOL> def default ( self , o ) : <EOL> if isinstance ( o , datetime . datetime ) : <EOL> r = o . isoformat ( ) <EOL> if o . microsecond : <EOL> r = r [ : <NUM_LIT> ] + r [ <NUM_LIT> : ] <EOL> if r . endswith ( '<STR_LIT>' ) : <EOL> r = r [ : - <NUM_LIT:6> ] + '<STR_LIT>' <EOL> return r <EOL> elif isinstance ( o , datetime . date ) : <EOL> return o . isoformat ( ) <EOL> elif isinstance ( o , datetime . time ) : <EOL> if is_aware ( o ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> r = o . isoformat ( ) <EOL> if o . microsecond : <EOL> r = r [ : <NUM_LIT:12> ] <EOL> return r <EOL> elif isinstance ( o , decimal . Decimal ) : <EOL> return str ( o ) <EOL> else : <EOL> return super ( DjangoJSONEncoder , self ) . default ( o ) <EOL> DateTimeAwareJSONEncoder = DjangoJSONEncoder </s>
