<s> """<STR_LIT>""" <EOL> import datetime <EOL> from django . utils import datetime_safe <EOL> from django . utils import simplejson <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> output = d . strftime ( "<STR_LIT>" % ( self . DATE_FORMAT , self . TIME_FORMAT ) ) <EOL> return "<STR_LIT>" % ( output , d . microsecond ) <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> output = o . strftime ( self . TIME_FORMAT ) <EOL> return "<STR_LIT>" % ( output , o . microsecond ) <EOL> elif isinstance ( o , decimal . Decimal ) : <EOL> return str ( o ) <EOL> else : <EOL> return super ( DjangoJSONEncoder , self ) . default ( o ) </s>
