o znhw&@sdZddlmZddlmZddlmZddlmZddlmZdd lmZ dd lm Z dd l m Z iZ Gd d d eZGdddeZGdddeZeGdddeZeGdddeZedS)aqStrategies for creating new instances of Engine types. These are semi-private implementation classes which provide the underlying behavior for the "strategy" keyword argument available on :func:`~sqlalchemy.engine.create_engine`. Current available options are ``plain``, ``threadlocal``, and ``mock``. New strategies can be added via new ``EngineStrategy`` classes. ) attrgetter)base) threadlocal)url)event)pool)util)schemac@s eZdZdZddZddZdS)EngineStrategyzAn adaptor that processes input arguments and produces an Engine. Provides a ``create`` method that receives input arguments and produces an instance of base.Engine or a subclass. cCs|t|j<dSN) strategiesname)selfrG/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/strategies.py__init__(szEngineStrategy.__init__cOt)z/Given arguments, returns a new Engine instance.NotImplementedError)rargskwargsrrrcreate+szEngineStrategy.createN)__name__ __module__ __qualname____doc__rrrrrrr s r c@seZdZdZddZdS)DefaultEngineStrategyz#Base class for built-in strategies.c s4t|}|}|jdddd|}||ddr/d'fdd }nj}i}tD] }|vrE||||<q9dd} | durmi} t j D] }|vrd||| |<qXj d(i| } | |d<|D]} | |qsd(i| |\ |d it|d d} | durd'fd d } |d | }|dd}|dur|}di}dddddddddd }t|D]}|||}|vr||||<q|D]} | ||q||fi|} nt| tjjr| ji} n| } | _|j}i}t|D]}|vr$||||<qdd}rFtddddDjj| jj|jf|| |fi||r~rnfd d!}t| d"|t| d#|fd$d%}tj| d"|dd& |ur| |D]} | qS))Npluginplugins_coerce_configFcs(||}|jvrj||}|Sr )popengine_config_types)keydefaultvalue) dialect_clsrrr pop_kwargBs  z/DefaultEngineStrategy.create..pop_kwargmoduledbapi connect_argsr csBjrjjD]}||}|dur|SqjiSr ) _has_eventsdispatch do_connectconnect)connection_recordfn connection)cargscparamsdialectrrr/js z-DefaultEngineStrategy.create..connectcreator poolclassr5pool_logging_name echo_pool pool_timeout pool_recycle pool_eventspool_threadlocalpool_reset_on_return pool_pre_ping pool_use_lifo) logging_nameechotimeoutrecycleeventsuse_threadlocalreset_on_returnpre_pinguse_lifo _initializeTzInvalid argument(s) %s sent to create_engine(), using configuration %s/%s/%s. Please check that the keyword arguments are appropriate for this combination of components.,css|]}d|VqdS)z'%s'Nr).0krrr sz/DefaultEngineStrategy.create..cs$t|d|}|dur dS|dS)N _sqla_unwrap)getattr)dbapi_connectionr0conn) do_on_connectrr on_connects  z0DefaultEngineStrategy.create..on_connect first_connectr/cs4tj|dd}t|_||jdS)NF)r2r,)r Connectionr immutabledict_execution_options initialize do_rollbackr2)rQr0c)r5enginerrrUs   z3DefaultEngineStrategy.create..first_connect)_once_unless_exceptionr r)!rmake_url_instantiate_pluginsqueryr"_get_entrypointget_dialect_clsr get_cls_kwargsget_func_kwargsr*handle_dialect_kwargscreate_connect_argsupdatelistget_pool_classgethandle_pool_kwargs isinstancepoollib dbapi_proxy_DBProxyget_pool_dialect engine_cls TypeErrorjoin __class__rrTrlistenengine_created)r name_or_urlrur entrypointr( dialect_argsrMr* dbapi_argsrr r/r6r7 pool_args translatetk engineclass engine_argsrJrTrUr)r3r4r5r'rSr\rrr4s                     zDefaultEngineStrategy.createN)rrrrrrrrrr1s rc@eZdZdZdZejZdS)PlainEngineStrategyz*Strategy for configuring a regular Engine.plainN)rrrrrrEnginerrrrrrr rc@r)ThreadLocalEngineStrategyz=Strategy for configuring an Engine with threadlocal behavior.rN)rrrrrrTLEnginerrrrrrrrrc@s.eZdZdZdZddZGdddejZdS)MockEngineStrategyzStrategy for configuring an Engine-like object with mocked execution. Produces a single mock Connectable object which dispatches statement execution to a passed-in function. mockc KsVt|}|}i}t|D] }||vr||||<q|di|}t||S)Nr)rr^ get_dialectr rcr"rMockConnection) rrxexecutorrryr'r{rMr5rrrrs  zMockEngineStrategy.createc@seZdZddZeddZeedZeddZe dZ dd Z d d Z d d ZddZddZddZ dddZddZdS)z!MockEngineStrategy.MockConnectioncCs||_||_dSr )rqexecute)rr5rrrrr s z*MockEngineStrategy.MockConnection.__init__cC|Sr rsrrrsz*MockEngineStrategy.MockConnection.rqcCs|jjSr )rqrrrrrrsNcKrr rrrrrrcontextual_connectz4MockEngineStrategy.MockConnection.contextual_connectcKrr rrrrrr/rz)MockEngineStrategy.MockConnection.connectcKrr r)rkwrrrexecution_optionsrz3MockEngineStrategy.MockConnection.execution_optionscKs|jj||fd|i|S)Nr\)rqcompiler)r statement parametersrrrrrsz*MockEngineStrategy.MockConnection.compilercK4d|d<ddlm}|j|j|fi||dSNF checkfirstr)ddl)sqlalchemy.enginerSchemaGeneratorr5traverse_singlerentityrrrrrr#  z(MockEngineStrategy.MockConnection.createcKrr)rr SchemaDropperr5rrrrrdrop+rz&MockEngineStrategy.MockConnection.dropcKs&d|d<||j|fi||dS)NFr)r5r)rvisitorcallableelementr2rrrr _run_visitor3sz.MockEngineStrategy.MockConnection._run_visitorcOrr r)robject_ multiparamsparamsrrrr;sz)MockEngineStrategy.MockConnection.executer )rrrrpropertyr\rr5rr _schema_getterschema_for_objectrr/rrrrrrrrrrr s     rN) rrrrrrr Connectablerrrrrrs rN)roperatorrrrrrr rmr sqlr robjectr rrrrrrrrs&       + P