<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from . . import util <EOL> from . . sql import operators <EOL> from . base import ( ONETOMANY , MANYTOONE , MANYTOMANY , <EOL> EXT_CONTINUE , EXT_STOP , NOT_EXTENSION ) <EOL> from . base import ( InspectionAttr , InspectionAttr , <EOL> InspectionAttrInfo , _MappedAttribute ) <EOL> import collections <EOL> from . . import inspect <EOL> MapperExtension = SessionExtension = AttributeExtension = None <EOL> __all__ = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> class MapperProperty ( _MappedAttribute , InspectionAttr , util . MemoizedSlots ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:key>' , <EOL> '<STR_LIT:info>' <EOL> ) <EOL> cascade = frozenset ( ) <EOL> """<STR_LIT>""" <EOL> is_property = True <EOL> """<STR_LIT>""" <EOL> def _memoized_attr_info ( self ) : <EOL> """<STR_LIT>""" <EOL> return { } <EOL> def setup ( self , context , entity , path , adapter , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def create_row_processor ( self , context , path , <EOL> mapper , result , adapter , populators ) : <EOL> """<STR_LIT>""" <EOL> def cascade_iterator ( self , type_ , state , visited_instances = None , <EOL> halt_on = None ) : <EOL> """<STR_LIT>""" <EOL> return iter ( ( ) ) <EOL> def set_parent ( self , parent , init ) : <EOL> """<STR_LIT>""" <EOL> self . parent = parent <EOL> def instrument_class ( self , mapper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _configure_started = False <EOL> self . _configure_finished = False <EOL> def init ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _configure_started = True <EOL> self . do_init ( ) <EOL> self . _configure_finished = True <EOL> @ property <EOL> def class_attribute ( self ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( self . parent . class_ , self . key ) <EOL> def do_init ( self ) : <EOL> """<STR_LIT>""" <EOL> def post_instrument_class ( self , mapper ) : <EOL> """<STR_LIT>""" <EOL> def merge ( self , session , source_state , source_dict , dest_state , <EOL> dest_dict , load , _recursive , _resolve_conflict_map ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> id ( self ) , getattr ( self , '<STR_LIT:key>' , '<STR_LIT>' ) ) <EOL> class PropComparator ( operators . ColumnOperators ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> def __init__ ( self , prop , parentmapper , adapt_to_entity = None ) : <EOL> self . prop = self . property = prop <EOL> self . _parententity = adapt_to_entity or parentmapper <EOL> self . _adapt_to_entity = adapt_to_entity <EOL> def __clause_element__ ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" % self ) <EOL> def _query_clause_element ( self ) : <EOL> return self . __clause_element__ ( ) <EOL> def adapt_to_entity ( self , adapt_to_entity ) : <EOL> """<STR_LIT>""" <EOL> return self . __class__ ( self . prop , self . _parententity , adapt_to_entity ) <EOL> @ property <EOL> def _parentmapper ( self ) : <EOL> """<STR_LIT>""" <EOL> return inspect ( self . _parententity ) . mapper <EOL> @ property <EOL> def adapter ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _adapt_to_entity is None : <EOL> return None <EOL> else : <EOL> return self . _adapt_to_entity . _adapt_element <EOL> @ property <EOL> def info ( self ) : <EOL> return self . property . info <EOL> @ staticmethod <EOL> def any_op ( a , b , ** kwargs ) : <EOL> return a . any ( b , ** kwargs ) <EOL> @ staticmethod <EOL> def has_op ( a , b , ** kwargs ) : <EOL> return a . has ( b , ** kwargs ) <EOL> @ staticmethod <EOL> def of_type_op ( a , class_ ) : <EOL> return a . of_type ( class_ ) <EOL> def of_type ( self , class_ ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( PropComparator . of_type_op , class_ ) <EOL> def any ( self , criterion = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( PropComparator . any_op , criterion , ** kwargs ) <EOL> def has ( self , criterion = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . operate ( PropComparator . has_op , criterion , ** kwargs ) <EOL> class StrategizedProperty ( MapperProperty ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = '<STR_LIT>' , '<STR_LIT>' <EOL> strategy_wildcard_key = None <EOL> def _get_context_loader ( self , context , path ) : <EOL> load = None <EOL> search_path = dict . __getitem__ ( path , self ) <EOL> for path_key in ( <EOL> search_path . _loader_key , <EOL> search_path . _wildcard_path_loader_key , <EOL> search_path . _default_path_loader_key <EOL> ) : <EOL> if path_key in context . attributes : <EOL> load = context . attributes [ path_key ] <EOL> break <EOL> return load <EOL> def _get_strategy ( self , key ) : <EOL> try : <EOL> return self . _strategies [ key ] <EOL> except KeyError : <EOL> cls = self . _strategy_lookup ( * key ) <EOL> self . _strategies [ key ] = self . _strategies [ <EOL> cls ] = strategy = cls ( self ) <EOL> return strategy <EOL> def _get_strategy_by_cls ( self , cls ) : <EOL> return self . _get_strategy ( cls . _strategy_keys [ <NUM_LIT:0> ] ) <EOL> def setup ( <EOL> self , context , entity , path , adapter , ** kwargs ) : <EOL> loader = self . _get_context_loader ( context , path ) <EOL> if loader and loader . strategy : <EOL> strat = self . _get_strategy ( loader . strategy ) <EOL> else : <EOL> strat = self . strategy <EOL> strat . setup_query ( context , entity , path , loader , adapter , ** kwargs ) <EOL> def create_row_processor ( <EOL> self , context , path , mapper , <EOL> result , adapter , populators ) : <EOL> loader = self . _get_context_loader ( context , path ) <EOL> if loader and loader . strategy : <EOL> strat = self . _get_strategy ( loader . strategy ) <EOL> else : <EOL> strat = self . strategy <EOL> strat . create_row_processor ( <EOL> context , path , loader , <EOL> mapper , result , adapter , populators ) <EOL> def do_init ( self ) : <EOL> self . _strategies = { } <EOL> self . strategy = self . _get_strategy_by_cls ( self . strategy_class ) <EOL> def post_instrument_class ( self , mapper ) : <EOL> if not self . parent . non_primary and not mapper . class_manager . _attr_has_impl ( self . key ) : <EOL> self . strategy . init_class_attribute ( mapper ) <EOL> _all_strategies = collections . defaultdict ( dict ) <EOL> @ classmethod <EOL> def strategy_for ( cls , ** kw ) : <EOL> def decorate ( dec_cls ) : <EOL> if '<STR_LIT>' not in dec_cls . __dict__ : <EOL> dec_cls . _strategy_keys = [ ] <EOL> key = tuple ( sorted ( kw . items ( ) ) ) <EOL> cls . _all_strategies [ cls ] [ key ] = dec_cls <EOL> dec_cls . _strategy_keys . append ( key ) <EOL> return dec_cls <EOL> return decorate <EOL> @ classmethod <EOL> def _strategy_lookup ( cls , * key ) : <EOL> for prop_cls in cls . __mro__ : <EOL> if prop_cls in cls . _all_strategies : <EOL> strategies = cls . _all_strategies [ prop_cls ] <EOL> try : <EOL> return strategies [ key ] <EOL> except KeyError : <EOL> pass <EOL> raise Exception ( "<STR_LIT>" % ( cls , key ) ) <EOL> class MapperOption ( object ) : <EOL> """<STR_LIT>""" <EOL> propagate_to_loaders = False <EOL> """<STR_LIT>""" <EOL> def process_query ( self , query ) : <EOL> """<STR_LIT>""" <EOL> def process_query_conditionally ( self , query ) : <EOL> """<STR_LIT>""" <EOL> self . process_query ( query ) <EOL> class LoaderStrategy ( object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:key>' <EOL> def __init__ ( self , parent ) : <EOL> self . parent_property = parent <EOL> self . is_class_level = False <EOL> self . parent = self . parent_property . parent <EOL> self . key = self . parent_property . key <EOL> def init_class_attribute ( self , mapper ) : <EOL> pass <EOL> def setup_query ( self , context , entity , path , loadopt , adapter , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def create_row_processor ( self , context , path , loadopt , mapper , <EOL> result , adapter , populators ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return str ( self . parent_property ) </s>
