U kfS@s$ddlmZddlmZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z d d l m Z d d l mZejrd dlmZd dlmZd dlmZd dlmZd dl mZd dlmZd dlmZd dlmZd dlmZd dlmZGdddZdddddddZ dS)) annotations) attrgetterN)Any)Callable)cast)Optional)Type)Union)url)util)Engine)_CoreAnyExecuteParams)CoreExecuteOptionsParameter)Dialect)URL) Executable) SchemaDropper)SchemaGenerator) HasSchemaAttr) SchemaItemc@seZdZUdddddZeeeddZded <eeee d Z ded <eeed dZ d ed<dddddZ dddddZ dddddZddddddd Zd(d"d#d$dd%d&d'Zd!S))MockConnectionrzCallable[..., Any])dialectexecutecCs||_||_dSN)_dialect _execute_impl)selfrrrF/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/engine/mock.py__init__%szMockConnection.__init__cCs|Srrsrrr )zMockConnection.renginerrcCs|jjSr)rnamer"rrr r$+r%strr'r)kwargsreturncKs|Srr)rr)rrr connect-szMockConnection.connectrz Optional[str])objr*cCs|jSr)Zschema)rr,rrr schema_for_object0sz MockConnection.schema_for_object)kwr*cKs|Srr)rr.rrr execution_options3sz MockConnection.execution_optionsz+Type[Union[SchemaGenerator, SchemaDropper]]rNone)visitorcallableelementr)r*cKs"d|d<||j|f||dS)NFZ checkfirst)rZtraverse_single)rr1r2r)rrr _run_ddl_visitor6szMockConnection._run_ddl_visitorNrzOptional[_CoreAnyExecuteParams]z%Optional[CoreExecuteOptionsParameter])r, parametersr/r*cCs |||Sr)r)rr,r4r/rrr r?szMockConnection.execute)NN)__name__ __module__ __qualname__r!rrpropertyr&__annotations__rrr'r+r-r/r3rrrrr r$s  rzUnion[str, URL]r)r executorr.r*cKsPt|}|}i}t|D]}||kr ||||<q |f|}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` )_urlZmake_url get_dialectr Zget_cls_kwargspopr)r r:r.uZ dialect_clsZ dialect_argskrrrr create_mock_engineHs.  r@)! __future__roperatorrtypingrrrrrr r r;r TYPE_CHECKINGbaserZ interfacesrrrrZsql.baserZsql.ddlrrZ sql.schemarrrr@rrrr s.                    $