<s> """<STR_LIT>""" <EOL> import collections <EOL> import decimal <EOL> import sys <EOL> from io import StringIO <EOL> import yaml <EOL> from django . core . serializers . base import DeserializationError <EOL> from django . core . serializers . python import ( <EOL> Deserializer as PythonDeserializer , Serializer as PythonSerializer , <EOL> ) <EOL> from django . db import models <EOL> from django . utils import six <EOL> try : <EOL> from yaml import CSafeLoader as SafeLoader <EOL> from yaml import CSafeDumper as SafeDumper <EOL> except ImportError : <EOL> from yaml import SafeLoader , SafeDumper <EOL> class DjangoSafeDumper ( SafeDumper ) : <EOL> def represent_decimal ( self , data ) : <EOL> return self . represent_scalar ( '<STR_LIT>' , str ( data ) ) <EOL> def represent_ordered_dict ( self , data ) : <EOL> return self . represent_mapping ( '<STR_LIT>' , data . items ( ) ) <EOL> DjangoSafeDumper . add_representer ( decimal . Decimal , DjangoSafeDumper . represent_decimal ) <EOL> DjangoSafeDumper . add_representer ( collections . OrderedDict , DjangoSafeDumper . represent_ordered_dict ) <EOL> class Serializer ( PythonSerializer ) : <EOL> """<STR_LIT>""" <EOL> internal_use_only = False <EOL> def handle_field ( self , obj , field ) : <EOL> if isinstance ( field , models . TimeField ) and getattr ( obj , field . name ) is not None : <EOL> self . _current [ field . name ] = str ( getattr ( obj , field . name ) ) <EOL> else : <EOL> super ( Serializer , self ) . handle_field ( obj , field ) <EOL> def end_serialization ( self ) : <EOL> yaml . dump ( self . objects , self . stream , Dumper = DjangoSafeDumper , ** self . options ) <EOL> def getvalue ( self ) : <EOL> return super ( PythonSerializer , self ) . getvalue ( ) <EOL> def Deserializer ( stream_or_string , ** options ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( stream_or_string , bytes ) : <EOL> stream_or_string = stream_or_string . decode ( '<STR_LIT:utf-8>' ) <EOL> if isinstance ( stream_or_string , six . string_types ) : <EOL> stream = StringIO ( stream_or_string ) <EOL> else : <EOL> stream = stream_or_string <EOL> try : <EOL> for obj in PythonDeserializer ( yaml . load ( stream , Loader = SafeLoader ) , ** 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> ] ) </s>
