<s> """<STR_LIT>""" <EOL> import datetime <EOL> import decimal <EOL> from StringIO import StringIO <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 datetime_safe <EOL> from django . utils import simplejson <EOL> class Serializer ( PythonSerializer ) : <EOL> """<STR_LIT>""" <EOL> internal_use_only = False <EOL> def end_serialization ( self ) : <EOL> simplejson . dump ( self . objects , self . stream , cls = DjangoJSONEncoder , ** self . options ) <EOL> def getvalue ( self ) : <EOL> if callable ( getattr ( self . stream , '<STR_LIT>' , None ) ) : <EOL> return self . stream . getvalue ( ) <EOL> def Deserializer ( stream_or_string , ** options ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( stream_or_string , basestring ) : <EOL> stream = StringIO ( stream_or_string ) <EOL> else : <EOL> stream = stream_or_string <EOL> for obj in PythonDeserializer ( simplejson . load ( stream ) , ** options ) : <EOL> yield obj <EOL> class DjangoJSONEncoder ( simplejson . JSONEncoder ) : <EOL> """<STR_LIT>""" <EOL> DATE_FORMAT = "<STR_LIT>" <EOL> TIME_FORMAT = "<STR_LIT>" <EOL> def default ( self , o ) : <EOL> if isinstance ( o , datetime . datetime ) : <EOL> d = datetime_safe . new_datetime ( o ) <EOL> return d . strftime ( "<STR_LIT>" % ( self . DATE_FORMAT , self . TIME_FORMAT ) ) <EOL> elif isinstance ( o , datetime . date ) : <EOL> d = datetime_safe . new_date ( o ) <EOL> return d . strftime ( self . DATE_FORMAT ) <EOL> elif isinstance ( o , datetime . time ) : <EOL> return o . strftime ( self . TIME_FORMAT ) <EOL> elif isinstance ( o , decimal . Decimal ) : <EOL> return str ( o ) <EOL> else : <EOL> return super ( DjangoJSONEncoder , self ) . default ( o ) <EOL> DateTimeAwareJSONEncoder = DjangoJSONEncoder </s>
