o
    èã¤gU  ã                   @  s  d dl mZ d dlmZ d dl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 ejr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 ddlmZ ddlmZ G dd„ dƒZd"d d!„Z dS )#é    )Úannotations)Ú
attrgetterN)ÚAny)ÚCallable)Úcast)ÚOptional)ÚType)ÚUnioné   )Úurlé   )Úutil)ÚEngine)Ú_CoreAnyExecuteParams)ÚCoreExecuteOptionsParameter)ÚDialect)ÚURL)Ú
Executable)ÚSchemaDropper)ÚSchemaGenerator)ÚHasSchemaAttr)Ú
SchemaItemc                   @  sž   e Zd ZU d+dd„Zeeedd„ ƒƒZd	ed
< eeee	dƒƒƒZ
ded< eeedd„ ƒƒZded< d,dd„Zd-dd„Zd.dd„Zd/d!d"„Z	#	#d0d1d)d*„Zd#S )2ÚMockConnectionÚdialectr   ÚexecuteúCallable[..., Any]c                 C  s   || _ || _d S ©N)Ú_dialectÚ_execute_impl)Úselfr   r   © r    úX/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/sqlalchemy/engine/mock.pyÚ__init__%   s   
zMockConnection.__init__c                 C  ó   | S r   r    ©Úsr    r    r!   Ú<lambda>)   s    zMockConnection.<lambda>r   Úenginer   c                 C  s   | j jS r   )r   Únamer$   r    r    r!   r&   +   s    Ústrr(   Úkwargsr   Úreturnc                 K  r#   r   r    )r   r*   r    r    r!   Úconnect-   ó   zMockConnection.connectÚobjr   úOptional[str]c                 C  s   |j S r   )Úschema)r   r.   r    r    r!   Úschema_for_object0   s   z MockConnection.schema_for_objectÚkwc                 K  r#   r   r    )r   r2   r    r    r!   Úexecution_options3   r-   z MockConnection.execution_optionsÚvisitorcallableú+Type[Union[SchemaGenerator, SchemaDropper]]Úelementr   ÚNonec                 K  s&   d|d< || j | fi |¤Ž |¡ d S )NFÚ
checkfirst)r   Útraverse_single)r   r4   r6   r*   r    r    r!   Ú_run_ddl_visitor6   s   zMockConnection._run_ddl_visitorNr   Ú
parametersúOptional[_CoreAnyExecuteParams]r3   ú%Optional[CoreExecuteOptionsParameter]c                 C  s   |   ||¡S r   )r   )r   r.   r;   r3   r    r    r!   r   ?   s   zMockConnection.execute)r   r   r   r   )r*   r   r+   r   )r.   r   r+   r/   )r2   r   r+   r   )r4   r5   r6   r   r*   r   r+   r7   )NN)r.   r   r;   r<   r3   r=   r+   r   )Ú__name__Ú
__module__Ú__qualname__r"   r   r   Úpropertyr'   Ú__annotations__r   r   r(   r,   r1   r3   r:   r   r    r    r    r!   r   $   s   
 




ür   r   úUnion[str, URL]Úexecutorr   r2   r+   c                 K  sT   t  | ¡}| ¡ }i }t |¡D ]}||v r| |¡||< q|di |¤Ž}t||ƒS )a?  Create a "mock" engine used for echoing DDL.

    This is a utility function used for debugging or storing the output of DDL
    sequences as generated by :meth:`_schema.MetaData.create_all`
    and related methods.

    The function accepts a URL which is used only to determine the kind of
    dialect to be used, as well as an "executor" callable function which
    will receive a SQL expression object and parameters, which can then be
    echoed or otherwise printed.   The executor's return value is not handled,
    nor does the engine allow regular string statements to be invoked, and
    is therefore only useful for DDL that is sent to the database without
    receiving any results.

    E.g.::

        from sqlalchemy import create_mock_engine


        def dump(sql, *multiparams, **params):
            print(sql.compile(dialect=engine.dialect))


        engine = create_mock_engine("postgresql+psycopg2://", dump)
        metadata.create_all(engine, checkfirst=False)

    :param url: A string URL which typically needs to contain only the
     database backend name.

    :param executor: a callable which receives the arguments ``sql``,
     ``*multiparams`` and ``**params``.  The ``sql`` parameter is typically
     an instance of :class:`.ExecutableDDLElement`, which can then be compiled
     into a string using :meth:`.ExecutableDDLElement.compile`.

    .. versionadded:: 1.4 - the :func:`.create_mock_engine` function replaces
       the previous "mock" engine strategy used with
       :func:`_sa.create_engine`.

    .. seealso::

        :ref:`faq_ddl_as_string`

    Nr    )Ú_urlÚmake_urlÚget_dialectr   Úget_cls_kwargsÚpopr   )r   rD   r2   ÚuÚdialect_clsÚdialect_argsÚkr   r    r    r!   Úcreate_mock_engineH   s   
0€
rN   )r   rC   rD   r   r2   r   r+   r   )!Ú
__future__r   Úoperatorr   Útypingr   r   r   r   r   r	   Ú r   rE   r   ÚTYPE_CHECKINGÚbaser   Ú
interfacesr   r   r   r   Úsql.baser   Úsql.ddlr   r   Ú
sql.schemar   r   r   rN   r    r    r    r!   Ú<module>   s0   $