<s> """<STR_LIT>""" <EOL> import copy <EOL> import re <EOL> RE_TYPE = type ( re . compile ( "<STR_LIT>" ) ) <EOL> class SON ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , data = None , ** kwargs ) : <EOL> self . __keys = [ ] <EOL> dict . __init__ ( self ) <EOL> self . update ( data ) <EOL> self . update ( kwargs ) <EOL> def __new__ ( cls , * args , ** kwargs ) : <EOL> instance = super ( SON , cls ) . __new__ ( cls , * args , ** kwargs ) <EOL> instance . __keys = [ ] <EOL> return instance <EOL> def __repr__ ( self ) : <EOL> result = [ ] <EOL> for key in self . __keys : <EOL> result . append ( "<STR_LIT>" % ( key , self [ key ] ) ) <EOL> return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( result ) <EOL> def __setitem__ ( self , key , value ) : <EOL> if key not in self : <EOL> self . __keys . append ( key ) <EOL> dict . __setitem__ ( self , key , value ) <EOL> def __delitem__ ( self , key ) : <EOL> self . __keys . remove ( key ) <EOL> dict . __delitem__ ( self , key ) <EOL> def keys ( self ) : <EOL> return list ( self . __keys ) <EOL> def copy ( self ) : <EOL> other = SON ( ) <EOL> other . update ( self ) <EOL> return other <EOL> def __iter__ ( self ) : <EOL> for k in self . keys ( ) : <EOL> yield k <EOL> def has_key ( self , key ) : <EOL> return key in self . keys ( ) <EOL> def __contains__ ( self , key ) : <EOL> return key in self . keys ( ) <EOL> def iteritems ( self ) : <EOL> for k in self : <EOL> yield ( k , self [ k ] ) <EOL> def iterkeys ( self ) : <EOL> return self . __iter__ ( ) <EOL> def itervalues ( self ) : <EOL> for _ , v in self . iteritems ( ) : <EOL> yield v <EOL> def values ( self ) : <EOL> return [ v for _ , v in self . iteritems ( ) ] <EOL> def items ( self ) : <EOL> return [ ( key , self [ key ] ) for key in self ] <EOL> def clear ( self ) : <EOL> for key in self . keys ( ) : <EOL> del self [ key ] <EOL> def setdefault ( self , key , default = None ) : <EOL> try : <EOL> return self [ key ] <EOL> except KeyError : <EOL> self [ key ] = default <EOL> return default <EOL> def pop ( self , key , * args ) : <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> raise TypeError ( "<STR_LIT>" + repr ( <NUM_LIT:1> + len ( args ) ) ) <EOL> try : <EOL> value = self [ key ] <EOL> except KeyError : <EOL> if args : <EOL> return args [ <NUM_LIT:0> ] <EOL> raise <EOL> del self [ key ] <EOL> return value <EOL> def popitem ( self ) : <EOL> try : <EOL> k , v = self . iteritems ( ) . next ( ) <EOL> except StopIteration : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> del self [ k ] <EOL> return ( k , v ) <EOL> def update ( self , other = None , ** kwargs ) : <EOL> if other is None : <EOL> pass <EOL> elif hasattr ( other , '<STR_LIT>' ) : <EOL> for k , v in other . iteritems ( ) : <EOL> self [ k ] = v <EOL> elif hasattr ( other , '<STR_LIT>' ) : <EOL> for k in other . keys ( ) : <EOL> self [ k ] = other [ k ] <EOL> else : <EOL> for k , v in other : <EOL> self [ k ] = v <EOL> if kwargs : <EOL> self . update ( kwargs ) <EOL> def get ( self , key , default = None ) : <EOL> try : <EOL> return self [ key ] <EOL> except KeyError : <EOL> return default <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , SON ) : <EOL> return len ( self ) == len ( other ) and self . items ( ) == other . items ( ) <EOL> return self . to_dict ( ) == other <EOL> def __ne__ ( self , other ) : <EOL> return not self == other <EOL> def __len__ ( self ) : <EOL> return len ( self . keys ( ) ) <EOL> def to_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> def transform_value ( value ) : <EOL> if isinstance ( value , list ) : <EOL> return [ transform_value ( v ) for v in value ] <EOL> if isinstance ( value , SON ) : <EOL> value = dict ( value ) <EOL> if isinstance ( value , dict ) : <EOL> for k , v in value . iteritems ( ) : <EOL> value [ k ] = transform_value ( v ) <EOL> return value <EOL> return transform_value ( dict ( self ) ) <EOL> def __deepcopy__ ( self , memo ) : <EOL> out = SON ( ) <EOL> val_id = id ( self ) <EOL> if val_id in memo : <EOL> return memo . get ( val_id ) <EOL> memo [ val_id ] = out <EOL> for k , v in self . iteritems ( ) : <EOL> if not isinstance ( v , RE_TYPE ) : <EOL> v = copy . deepcopy ( v , memo ) <EOL> out [ k ] = v <EOL> return out </s>
