<s> from __future__ import ( absolute_import , division , print_function , <EOL> unicode_literals ) <EOL> import weakref <EOL> class Raw ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> sentinel = object ( ) <EOL> class Object ( dict ) : <EOL> """<STR_LIT>""" <EOL> __members__ = None <EOL> __methods__ = None <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> self . __dict__ [ '<STR_LIT>' ] = kwargs . pop ( '<STR_LIT>' ) <EOL> super ( Object , self ) . __init__ ( * args , ** kwargs ) <EOL> self . __dict__ [ '<STR_LIT>' ] = weakref . WeakValueDictionary ( ) <EOL> self . __dict__ [ '<STR_LIT>' ] = set ( ) <EOL> for k in self . keys ( ) : <EOL> self [ k ] = self . pop ( k ) <EOL> def __wrap ( self , value ) : <EOL> if isinstance ( value , ( tuple , set , frozenset ) ) : <EOL> return type ( value ) ( [ self . __wrap ( v ) for v in value ] ) <EOL> elif isinstance ( value , list ) and not isinstance ( value , Collection ) : <EOL> return Collection ( value , self . __class__ ) <EOL> elif isinstance ( value , Object ) : <EOL> return value <EOL> elif isinstance ( value , Raw ) : <EOL> return value . value <EOL> elif isinstance ( value , dict ) : <EOL> if isinstance ( self , CaseInsensitiveObject ) : <EOL> return CaseInsensitiveObject ( value ) <EOL> else : <EOL> return Object ( value ) <EOL> else : <EOL> return value <EOL> def __protect__ ( self , key , value = sentinel ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( key , list ) : <EOL> key = key . split ( '<STR_LIT:.>' ) if isinstance ( key , basestring ) else [ key ] <EOL> key , path = key . pop ( <NUM_LIT:0> ) , key <EOL> if len ( path ) > <NUM_LIT:0> : <EOL> self . get ( key ) . protect ( path , value ) <EOL> elif value is not sentinel : <EOL> self [ key ] = value <EOL> if key not in self : <EOL> raise KeyError ( '<STR_LIT>' % key ) <EOL> self . __PROTECTED__ . add ( key ) <EOL> def __setattr__ ( self , name , value ) : <EOL> bad_ids = dir ( self ) <EOL> bad_ids . append ( '<STR_LIT>' ) <EOL> bad_ids . append ( '<STR_LIT>' ) <EOL> if name in self . __PROTECTED__ : <EOL> raise KeyError ( '<STR_LIT>' % name ) <EOL> if name not in bad_ids : <EOL> if self . __dict__ . get ( '<STR_LIT>' ) : <EOL> parent , pname = self . __dict__ . pop ( '<STR_LIT>' ) <EOL> parent [ pname ] = self <EOL> if name in self . __CACHE__ : <EOL> del self . __CACHE__ [ name ] <EOL> dict . __setitem__ ( self , name , self . __wrap ( value ) ) <EOL> else : <EOL> print ( "<STR_LIT>" % name ) <EOL> print ( "<STR_LIT>" % bad_ids ) <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> def __getattr__ ( self , key ) : <EOL> return self . get ( key ) <EOL> def __getitem__ ( self , key , default = sentinel ) : <EOL> if not isinstance ( key , list ) : <EOL> key = key . split ( '<STR_LIT:.>' ) if isinstance ( key , basestring ) else [ key ] <EOL> key , path = key . pop ( <NUM_LIT:0> ) , key <EOL> if len ( path ) > <NUM_LIT:0> : <EOL> return self . get ( key ) . __getitem__ ( path , default ) <EOL> elif key not in self : <EOL> if default is sentinel : <EOL> return self . __CACHE__ . setdefault ( <EOL> key , self . __class__ ( __PARENT__ = ( self , key ) ) ) <EOL> else : <EOL> return default <EOL> else : <EOL> return dict . get ( self , key ) <EOL> get = __getitem__ <EOL> def __contains__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( key , list ) : <EOL> key = key . split ( '<STR_LIT:.>' ) if isinstance ( key , basestring ) else [ key ] <EOL> this , next = key . pop ( <NUM_LIT:0> ) , key <EOL> if this in self . iterkeys ( ) : <EOL> if len ( next ) > <NUM_LIT:0> : <EOL> return next in self . get ( this ) <EOL> else : <EOL> return True <EOL> else : <EOL> return False <EOL> has_key = __contains__ <EOL> def setdefault ( self , key , default = None ) : <EOL> if key not in self : <EOL> self [ key ] = default <EOL> return self . get ( key ) <EOL> def __setitem__ ( self , key , value ) : <EOL> if not isinstance ( key , list ) : <EOL> key = key . split ( '<STR_LIT:.>' ) if isinstance ( key , basestring ) else [ key ] <EOL> key , path = key . pop ( <NUM_LIT:0> ) , key <EOL> if len ( path ) > <NUM_LIT:0> : <EOL> self . setdefault ( key , { } ) . __setitem__ ( path , value ) <EOL> else : <EOL> self . __setattr__ ( key , value ) <EOL> set = __setitem__ <EOL> def __delitem__ ( self , key ) : <EOL> if not isinstance ( key , list ) : <EOL> key = key . split ( '<STR_LIT:.>' ) if isinstance ( key , basestring ) else [ key ] <EOL> key , path = key . pop ( <NUM_LIT:0> ) , key <EOL> if len ( path ) > <NUM_LIT:0> : <EOL> self . get ( key ) . __delitem__ ( path ) <EOL> else : <EOL> if key not in self : <EOL> pass <EOL> else : <EOL> dict . __delitem__ ( self , key ) <EOL> __delattr__ = __delitem__ <EOL> class CaseInsensitiveObject ( Object ) : <EOL> """<STR_LIT>""" <EOL> def __protect__ ( self , key , value = sentinel ) : <EOL> Object . __protect__ ( self , key . lower ( ) , value ) <EOL> def __getitem__ ( self , key , default = sentinel ) : <EOL> if isinstance ( key , list ) : <EOL> key = [ x . lower ( ) if isinstance ( x , basestring ) else x for x in key ] <EOL> elif isinstance ( key , basestring ) : <EOL> key = key . lower ( ) <EOL> return Object . __getitem__ ( self , key , default ) <EOL> get = __getitem__ <EOL> def __setattr__ ( self , key , value ) : <EOL> if isinstance ( key , basestring ) : <EOL> key = key . lower ( ) <EOL> return Object . __setattr__ ( self , key , value ) <EOL> def __contains__ ( self , key ) : <EOL> if not isinstance ( key , list ) : <EOL> key = key . split ( '<STR_LIT:.>' ) if isinstance ( key , basestring ) else [ key ] <EOL> if isinstance ( key [ <NUM_LIT:0> ] , basestring ) : <EOL> key [ <NUM_LIT:0> ] = key [ <NUM_LIT:0> ] . lower ( ) <EOL> return Object . __contains__ ( self , key ) <EOL> has_key = __contains__ <EOL> def __getattr__ ( self , key ) : <EOL> if key in self : <EOL> return self . get ( key ) <EOL> else : <EOL> return Object . __getattr__ ( self , key ) <EOL> def __delattr__ ( self , key ) : <EOL> if isinstance ( key , basestring ) : <EOL> key = key . lower ( ) <EOL> return Object . __delattr__ ( self , key ) <EOL> __delitem__ = __delattr__ <EOL> class Collection ( list ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , alist = None , default = Object ) : <EOL> if alist is None : <EOL> alist = ( ) <EOL> super ( Collection , self ) . __init__ ( alist ) <EOL> self . __default = default <EOL> for i in xrange ( <NUM_LIT:0> , len ( self ) ) : <EOL> self [ i ] = self [ i ] <EOL> def __wrap ( self , value ) : <EOL> if isinstance ( value , dict ) : <EOL> return self . __default ( value ) <EOL> elif isinstance ( value , self . __class__ ) : <EOL> return value <EOL> elif isinstance ( value , list ) : <EOL> return self . __class__ ( value , self . __default ) <EOL> else : <EOL> return value <EOL> def __setitem__ ( self , key , value ) : <EOL> super ( Collection , self ) . __setitem__ ( key , self . __wrap ( value ) ) <EOL> def __getslice__ ( self , s , e ) : <EOL> return self . __class__ ( super ( Collection , self ) . __getslice__ ( s , e ) , <EOL> self . __default ) <EOL> def append ( self , value ) : <EOL> list . append ( self , self . __wrap ( value ) ) <EOL> def extend ( self , alist ) : <EOL> for i in alist : <EOL> self . append ( i ) <EOL> def insert ( self , key , value ) : <EOL> list . insert ( self , key , self . __wrap ( value ) ) <EOL> def shift ( self ) : <EOL> return self . pop ( <NUM_LIT:0> ) <EOL> def unshift ( self , value ) : <EOL> self . insert ( <NUM_LIT:0> , value ) <EOL> push = append </s>
