o
    iw&                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ	 dd
lm
Z
 ddlmZ i ZG dd deZG dd deZG dd deZe  G dd deZe  G dd deZe  dS )aq  Strategies 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    e Zd ZdZdd Zdd ZdS )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.

    c                 C   s   | t | j< d S N)
strategiesname)self r   W/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/sqlalchemy/engine/strategies.py__init__(   s   zEngineStrategy.__init__c                 O      t  )z/Given arguments, returns a new Engine instance.NotImplementedError)r   argskwargsr   r   r   create+   s   zEngineStrategy.createN)__name__
__module____qualname____doc__r   r   r   r   r   r   r       s    r   c                   @   s   e Zd ZdZdd ZdS )DefaultEngineStrategyz#Base class for built-in strategies.c              
      s4  t |}|}|jdd  dd  | }||ddr/d'fdd	}nj}i }tD ]}|v rE||||< q9dd }	|	d u rmi }
t	j
D ]}|v rd|||
|< qXj
d(i |
}	|	|d< |D ]}|| qsd(i ||\ |d	i  t  |d
d }|d u rd' fdd	}|d|}|dd }|d u r|}di}dddddddddd	}t|D ]}|||}|v r||||< q|D ]}||| q||fi |}nt|tjjr|j i }n|}|_| j}i }t|D ]}|v r$||||< qdd}rFtdddd D jj|jj|jf |||fi ||r~ rnfd d!}t|d"| t|d#| fd$d%}tj|d"|dd&   |ur|  |D ]}|  qS ))Npluginplugins_coerce_configFc                    s(    | |}|  jv r j|  |}|S r   )popengine_config_types)keydefaultvalue)dialect_clsr   r   r   	pop_kwargB   s   
z/DefaultEngineStrategy.create.<locals>.pop_kwargmoduledbapiconnect_argsr	   c                    sB   j rjjD ]}||  }|d ur|  S qj i S r   )_has_eventsdispatch
do_connectconnect)connection_recordfn
connection)cargscparamsdialectr   r   r/   j   s   z-DefaultEngineStrategy.create.<locals>.connectcreator	poolclassr5   pool_logging_name	echo_poolpool_timeoutpool_recyclepool_eventspool_threadlocalpool_reset_on_returnpool_pre_pingpool_use_lifo)	logging_nameechotimeoutrecycleeventsuse_threadlocalreset_on_returnpre_pinguse_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.,c                 s   s    | ]}d | V  qdS )z'%s'Nr   ).0kr   r   r   	<genexpr>   s    z/DefaultEngineStrategy.create.<locals>.<genexpr>c                    s$   t | d| }|d u rd S  | d S )N_sqla_unwrap)getattr)dbapi_connectionr0   conn)do_on_connectr   r   
on_connect   s   z0DefaultEngineStrategy.create.<locals>.on_connectfirst_connectr/   c                    s4   t j| dd}t |_ |  |j d S )NF)r2   r,   )r   
Connectionr
   immutabledict_execution_options
initializedo_rollbackr2   )rQ   r0   c)r5   enginer   r   rU      s   

z3DefaultEngineStrategy.create.<locals>.first_connect)_once_unless_exceptionr   r   )!r   make_url_instantiate_pluginsqueryr"   _get_entrypointget_dialect_clsr
   get_cls_kwargsget_func_kwargsr*   handle_dialect_kwargscreate_connect_argsupdatelistget_pool_classgethandle_pool_kwargs
isinstancepoollibdbapi_proxy_DBProxyget_pool_dialect
engine_cls	TypeErrorjoin	__class__r   rT   r   listenengine_created)r   name_or_urlr   ur    
entrypointr(   dialect_argsrM   r*   
dbapi_argsr   r	   r/   r6   r7   	pool_args	translatetkengineclassengine_argsrJ   rT   rU   r   )r3   r4   r5   r'   rS   r\   r   r   r   4   s   











zDefaultEngineStrategy.createN)r   r   r   r   r   r   r   r   r   r   1   s    r   c                   @      e Zd ZdZdZejZdS )PlainEngineStrategyz*Strategy for configuring a regular Engine.plainN)r   r   r   r   r   r   Enginerr   r   r   r   r   r          
r   c                   @   r   )ThreadLocalEngineStrategyz=Strategy for configuring an Engine with threadlocal behavior.r   N)r   r   r   r   r   r   TLEnginerr   r   r   r   r   r      r   r   c                   @   s.   e Zd ZdZdZdd ZG dd dejZdS )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           	      K   sV   t |}| }i }t|D ]}||v r||||< q|di |}t||S )Nr   )r   r^   get_dialectr
   rc   r"   r   MockConnection)	r   rx   executorr   ry   r'   r{   rM   r5   r   r   r   r      s   
zMockEngineStrategy.createc                   @   s   e Zd Zdd Zedd ZeedZedd Ze	
dZdd	 Zd
d Zdd Zdd Zdd Zdd Z	dddZdd ZdS )z!MockEngineStrategy.MockConnectionc                 C   s   || _ || _d S r   )rq   execute)r   r5   r   r   r   r   r     s   
z*MockEngineStrategy.MockConnection.__init__c                 C      | S r   r   sr   r   r   <lambda>  s    z*MockEngineStrategy.MockConnection.<lambda>rq   c                 C   s   | j jS r   )rq   r   r   r   r   r   r     s    Nc                 K   r   r   r   r   r   r   r   r   contextual_connect     z4MockEngineStrategy.MockConnection.contextual_connectc                 K   r   r   r   r   r   r   r   r/     r   z)MockEngineStrategy.MockConnection.connectc                 K   r   r   r   )r   kwr   r   r   execution_options  r   z3MockEngineStrategy.MockConnection.execution_optionsc                 K   s   | j j||fd| i|S )Nr\   )rq   compiler)r   	statement
parametersr   r   r   r   r     s   z*MockEngineStrategy.MockConnection.compilerc                 K   4   d|d< ddl m} |j| j| fi || d S NF
checkfirstr   )ddl)sqlalchemy.enginer   SchemaGeneratorr5   traverse_singler   entityr   r   r   r   r   r   #  
   z(MockEngineStrategy.MockConnection.createc                 K   r   r   )r   r   SchemaDropperr5   r   r   r   r   r   drop+  r   z&MockEngineStrategy.MockConnection.dropc                 K   s&   d|d< || j | fi || d S )NFr   )r5   r   )r   visitorcallableelementr2   r   r   r   r   _run_visitor3  s   z.MockEngineStrategy.MockConnection._run_visitorc                 O   r   r   r   )r   object_multiparamsparamsr   r   r   r   ;  s   z)MockEngineStrategy.MockConnection.executer   )r   r   r   r   propertyr\   r   r5   r   r   _schema_getterschema_for_objectr   r/   r   r   r   r   r   r   r   r   r   r   r   
  s    
	
r   N)	r   r   r   r   r   r   r   Connectabler   r   r   r   r   r      s
    r   N)r   operatorr    r   r   r   r   r	   rm   r
   sqlr   r   objectr   r   r   r   r   r   r   r   r   <module>   s&   
 +
P