<s> """<STR_LIT>""" <EOL> from collections import defaultdict <EOL> from . _compat import with_metaclass , iteritems <EOL> SEQS = ( tuple , list , set , frozenset ) <EOL> class ConfigDict ( defaultdict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , initial = None ) : <EOL> super ( ConfigDict , self ) . __init__ ( ConfigDict ) <EOL> initial = initial or { } <EOL> for key , value in iteritems ( initial ) : <EOL> self . __setitem__ ( key , value ) <EOL> def __setitem__ ( self , key , value ) : <EOL> def transform ( primitive ) : <EOL> if isinstance ( primitive , dict ) : <EOL> return ConfigDict ( primitive ) <EOL> elif isinstance ( primitive , SEQS ) : <EOL> seq = type ( primitive ) <EOL> return seq ( transform ( v ) for v in primitive ) <EOL> else : <EOL> return primitive <EOL> super ( ConfigDict , self ) . __setitem__ ( key , transform ( value ) ) <EOL> def __getitem__ ( self , key ) : <EOL> return super ( ConfigDict , self ) . __getitem__ ( key ) <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return ConfigDict ( self ) <EOL> def patch ( self , overrides ) : <EOL> """<STR_LIT>""" <EOL> overrides = overrides or { } <EOL> for key , value in iteritems ( overrides ) : <EOL> current = self . get ( key ) <EOL> if isinstance ( value , dict ) and isinstance ( current , dict ) : <EOL> current . patch ( value ) <EOL> else : <EOL> self [ key ] = value <EOL> __setattr__ = __setitem__ <EOL> __getattr__ = __getitem__ <EOL> class AutoPropDescriptor ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , default_prop ) : <EOL> self . default_prop = default_prop <EOL> self . name = default_prop . __name__ <EOL> self . assigned = '<STR_LIT:_>' + self . name <EOL> def __get_assigned__ ( self , instance ) : <EOL> return getattr ( instance , self . assigned , None ) <EOL> def __set_assigned__ ( self , instance , value ) : <EOL> return setattr ( instance , self . assigned , value ) <EOL> def __get__ ( self , instance , owner ) : <EOL> value = self . __get_assigned__ ( instance ) <EOL> return value or self . default_prop ( instance ) <EOL> def __set__ ( self , instance , value ) : <EOL> self . __set_assigned__ ( instance , value ) <EOL> class AutoPropMetaClass ( type ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( mcs , cname , cbases , cattrs ) : <EOL> autoprops = { name : member <EOL> for name , member in iteritems ( cattrs ) <EOL> if getattr ( member , '<STR_LIT>' , False ) } <EOL> for name , member in iteritems ( autoprops ) : <EOL> cattrs [ name ] = AutoPropDescriptor ( member ) <EOL> return super ( AutoPropMetaClass , mcs ) . __new__ ( <EOL> mcs , cname , cbases , cattrs ) <EOL> class AutoProp ( with_metaclass ( AutoPropMetaClass , object ) ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def default ( function ) : <EOL> """<STR_LIT>""" <EOL> function . autoprop = True <EOL> return function </s>
