<s> import sys <EOL> import yaml <EOL> from yaml . loader import SafeLoader , Loader <EOL> from yaml . dumper import SafeDumper <EOL> from yaml . constructor import ConstructorError <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> from ordereddict import OrderedDict <EOL> else : <EOL> from collections import OrderedDict <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class BaseOrderedDictLoader ( object ) : <EOL> def construct_yaml_map ( self , node ) : <EOL> data = OrderedDict ( ) <EOL> yield data <EOL> value = self . construct_mapping ( node ) <EOL> data . update ( value ) <EOL> def construct_mapping ( self , node , deep = False ) : <EOL> if isinstance ( node , yaml . MappingNode ) : <EOL> self . flatten_mapping ( node ) <EOL> else : <EOL> raise ConstructorError ( None , <EOL> None , <EOL> '<STR_LIT>' % node . id , <EOL> node . start_mark ) <EOL> mapping = OrderedDict ( ) <EOL> for key_node , value_node in node . value : <EOL> key = self . construct_object ( key_node , deep = deep ) <EOL> try : <EOL> hash ( key ) <EOL> except TypeError as exc : <EOL> raise ConstructorError ( '<STR_LIT>' , <EOL> node . start_mark , <EOL> '<STR_LIT>' % exc , <EOL> key_node . start_mark ) <EOL> value = self . construct_object ( value_node , deep = deep ) <EOL> mapping [ key ] = value <EOL> return mapping <EOL> class OrderedDictLoader ( BaseOrderedDictLoader , Loader ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class OrderedDictSafeLoader ( BaseOrderedDictLoader , SafeLoader ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def add_ordereddict_constructor ( cls ) : <EOL> cls . add_constructor ( <EOL> u'<STR_LIT>' , <EOL> cls . construct_yaml_map <EOL> ) <EOL> cls . add_constructor ( <EOL> u'<STR_LIT>' , <EOL> cls . construct_yaml_map <EOL> ) <EOL> add_ordereddict_constructor ( OrderedDictLoader ) <EOL> add_ordereddict_constructor ( OrderedDictSafeLoader ) <EOL> class OrderedDictSafeDumper ( SafeDumper ) : <EOL> """<STR_LIT>""" <EOL> def represent_ordereddict ( self , data ) : <EOL> return self . represent_mapping ( u'<STR_LIT>' , list ( data . items ( ) ) ) <EOL> OrderedDictSafeDumper . add_representer ( <EOL> OrderedDict , <EOL> OrderedDictSafeDumper . represent_ordereddict <EOL> ) <EOL> yaml . add_representer ( <EOL> OrderedDict , <EOL> OrderedDictSafeDumper . represent_ordereddict <EOL> ) </s>
