L i7!zddlmZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z d d l mZd dl mZd dlmZd dlmZddl mZddl mZddl mZddlmZddlmZddlmZddlmZej<rBd dlmZd dlm Z d dlm!Z!d dlm"Z"d dlm#Z#ddl$m%Z%ddlm&Z&dd lm'Z'dd!lm(Z(dd"lm)Z)dd#l*m+Z+e d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d$d% d;d-Z,e d d?d4Z.e d$d$d$d$d$d$d$d$d5 d@d6Z/e dAd7Z/dAd8Z/ed'd&d+d)d9d*d(d,d:Z0y)B) annotationsN)Any)Callable)cast)Dict)List)Optional)overload)Type)Union)base)url)DBAPIConnection)create_mock_engine)event)exc)util)_AdhocProxiedConnection)ConnectionPoolEntry)compiler) immutabledict)Engine)_ExecuteOptions) _ParamStyle)IsolationLevel)URL) _EchoFlagType)_CreatorFnType)_CreatorWRecFnType)_ResetStyleArgType)Pool)Literal.) connect_argsconvert_unicodecreatorecho echo_poolenable_from_lintingexecution_optionshide_parametersimplicit_returninginsertmanyvalues_page_sizeisolation_leveljson_deserializerjson_serializer label_length logging_namemax_identifier_length max_overflowmodule paramstylepool poolclasspool_logging_name pool_pre_ping pool_size pool_recyclepool_reset_on_return pool_timeout pool_use_lifopluginsquery_cache_sizeuse_insertmanyvaluesr)r:r;r=r>r?r@c yN)"rr%r&r'r(r)r*r+futurer,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCkwargss" ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/engine/create.py create_enginerJ0sJc yrErFrrHs rIrJrJXsBErK)1.4a"The :paramref:`_sa.create_engine.strategy` keyword is deprecated, and the only argument accepted is 'mock'; please use :func:`.create_mock_engine` going forward. For general customization of create_engine which may have been accomplished using strategies, see :class:`.CreateEnginePlugin`.)rNaThe :paramref:`_sa.create_engine.empty_in_strategy` keyword is deprecated, and no longer has any effect. All IN expressions are now rendered using the "expanding parameter" strategy which renders a set of boundexpressions, or an "empty set" SELECT, at statement executiontime.)2.0zvThe :paramref:`_sa.create_engine.implicit_returning` parameter is deprecated and will be removed in a future release. )strategyempty_in_strategyr-c   !dvr:jd}|dk(r t|fiStjd|zjddt j |}|j \}}|j}jdd}|r|j|n|j|jddr d0d1fd }n j}i}tjD]} | vs|| || <jd d} | i} d jvr j} n^td rFtj j"r'tj$d ddj"} n j} tj&| D]} | vs|| | | <| d2i| } | |d <|j)dt*j,jdd} | r|dxxt*j.zcc<|D]}|j1|d2i|j3|\}j5|didvr.tj6drtj$ddt9||dd}| d0 d3fd }|d|}|dd}|j;|}di}tj|D](} t<j?| | }|vs|||| <*|D]}|jA||||fi|}n|_!t|drX|jDjFur@tjd|jHjJdjFsdndd d!"|d#dstjd$tLjN}i}tj|D]} | vs|| || <jd%d}r`tQd&d'jSd(Dd)jHjJd*|jHjJd*|jJd+ |||fi|!|rjU| r# d4 fd, }tWjX|d-|j[}|rtWjX|d-| d4!fd. }tWjX|d-|d/j]!|ur|j]!|D]}|j]!!S)5aAHCreate a new :class:`_engine.Engine` instance. The standard calling form is to send the :ref:`URL ` as the first positional argument, usually a string that indicates database dialect and connection arguments:: engine = create_engine("postgresql+psycopg2://scott:tiger@localhost/test") .. note:: Please review :ref:`database_urls` for general guidelines in composing URL strings. In particular, special characters, such as those often part of passwords, must be URL encoded to be properly parsed. Additional keyword arguments may then follow it which establish various options on the resulting :class:`_engine.Engine` and its underlying :class:`.Dialect` and :class:`_pool.Pool` constructs:: engine = create_engine( "mysql+mysqldb://scott:tiger@hostname/dbname", pool_recycle=3600, echo=True, ) The string form of the URL is ``dialect[+driver]://user:password@host/dbname[?key=value..]``, where ``dialect`` is a database name such as ``mysql``, ``oracle``, ``postgresql``, etc., and ``driver`` the name of a DBAPI, such as ``psycopg2``, ``pyodbc``, ``cx_oracle``, etc. Alternatively, the URL can be an instance of :class:`~sqlalchemy.engine.url.URL`. ``**kwargs`` takes a wide variety of options which are routed towards their appropriate components. Arguments may be specific to the :class:`_engine.Engine`, the underlying :class:`.Dialect`, as well as the :class:`_pool.Pool`. Specific dialects also accept keyword arguments that are unique to that dialect. Here, we describe the parameters that are common to most :func:`_sa.create_engine()` usage. Once established, the newly resulting :class:`_engine.Engine` will request a connection from the underlying :class:`_pool.Pool` once :meth:`_engine.Engine.connect` is called, or a method which depends on it such as :meth:`_engine.Engine.execute` is invoked. The :class:`_pool.Pool` in turn will establish the first actual DBAPI connection when this request is received. The :func:`_sa.create_engine` call itself does **not** establish any actual DBAPI connections directly. .. seealso:: :doc:`/core/engines` :doc:`/dialects/index` :ref:`connections_toplevel` :param connect_args: a dictionary of options which will be passed directly to the DBAPI's ``connect()`` method as additional keyword arguments. See the example at :ref:`custom_dbapi_args`. :param creator: a callable which returns a DBAPI connection. This creation function will be passed to the underlying connection pool and will be used to create all new database connections. Usage of this function causes connection parameters specified in the URL argument to be bypassed. This hook is not as flexible as the newer :meth:`_events.DialectEvents.do_connect` hook which allows complete control over how a connection is made to the database, given the full set of URL arguments and state beforehand. .. seealso:: :meth:`_events.DialectEvents.do_connect` - event hook that allows full control over DBAPI connection mechanics. :ref:`custom_dbapi_args` :param echo=False: if True, the Engine will log all statements as well as a ``repr()`` of their parameter lists to the default log handler, which defaults to ``sys.stdout`` for output. If set to the string ``"debug"``, result rows will be printed to the standard output as well. The ``echo`` attribute of ``Engine`` can be modified at any time to turn logging on and off; direct control of logging is also available using the standard Python ``logging`` module. .. seealso:: :ref:`dbengine_logging` - further detail on how to configure logging. :param echo_pool=False: if True, the connection pool will log informational output such as when connections are invalidated as well as when connections are recycled to the default log handler, which defaults to ``sys.stdout`` for output. If set to the string ``"debug"``, the logging will include pool checkouts and checkins. Direct control of logging is also available using the standard Python ``logging`` module. .. seealso:: :ref:`dbengine_logging` - further detail on how to configure logging. :param empty_in_strategy: No longer used; SQLAlchemy now uses "empty set" behavior for IN in all cases. :param enable_from_linting: defaults to True. Will emit a warning if a given SELECT statement is found to have un-linked FROM elements which would cause a cartesian product. .. versionadded:: 1.4 .. seealso:: :ref:`change_4737` :param execution_options: Dictionary execution options which will be applied to all connections. See :meth:`~sqlalchemy.engine.Connection.execution_options` :param future: Use the 2.0 style :class:`_engine.Engine` and :class:`_engine.Connection` API. As of SQLAlchemy 2.0, this parameter is present for backwards compatibility only and must remain at its default value of ``True``. The :paramref:`_sa.create_engine.future` parameter will be deprecated in a subsequent 2.x release and eventually removed. .. versionadded:: 1.4 .. versionchanged:: 2.0 All :class:`_engine.Engine` objects are "future" style engines and there is no longer a ``future=False`` mode of operation. .. seealso:: :ref:`migration_20_toplevel` :param hide_parameters: Boolean, when set to True, SQL statement parameters will not be displayed in INFO logging nor will they be formatted into the string representation of :class:`.StatementError` objects. .. versionadded:: 1.3.8 .. seealso:: :ref:`dbengine_logging` - further detail on how to configure logging. :param implicit_returning=True: Legacy parameter that may only be set to True. In SQLAlchemy 2.0, this parameter does nothing. In order to disable "implicit returning" for statements invoked by the ORM, configure this on a per-table basis using the :paramref:`.Table.implicit_returning` parameter. :param insertmanyvalues_page_size: number of rows to format into an INSERT statement when the statement uses "insertmanyvalues" mode, which is a paged form of bulk insert that is used for many backends when using :term:`executemany` execution typically in conjunction with RETURNING. Defaults to 1000, but may also be subject to dialect-specific limiting factors which may override this value on a per-statement basis. .. versionadded:: 2.0 .. seealso:: :ref:`engine_insertmanyvalues` :ref:`engine_insertmanyvalues_page_size` :paramref:`_engine.Connection.execution_options.insertmanyvalues_page_size` :param isolation_level: optional string name of an isolation level which will be set on all new connections unconditionally. Isolation levels are typically some subset of the string names ``"SERIALIZABLE"``, ``"REPEATABLE READ"``, ``"READ COMMITTED"``, ``"READ UNCOMMITTED"`` and ``"AUTOCOMMIT"`` based on backend. The :paramref:`_sa.create_engine.isolation_level` parameter is in contrast to the :paramref:`.Connection.execution_options.isolation_level` execution option, which may be set on an individual :class:`.Connection`, as well as the same parameter passed to :meth:`.Engine.execution_options`, where it may be used to create multiple engines with different isolation levels that share a common connection pool and dialect. .. versionchanged:: 2.0 The :paramref:`_sa.create_engine.isolation_level` parameter has been generalized to work on all dialects which support the concept of isolation level, and is provided as a more succinct, up front configuration switch in contrast to the execution option which is more of an ad-hoc programmatic option. .. seealso:: :ref:`dbapi_autocommit` :param json_deserializer: for dialects that support the :class:`_types.JSON` datatype, this is a Python callable that will convert a JSON string to a Python object. By default, the Python ``json.loads`` function is used. .. versionchanged:: 1.3.7 The SQLite dialect renamed this from ``_json_deserializer``. :param json_serializer: for dialects that support the :class:`_types.JSON` datatype, this is a Python callable that will render a given object as JSON. By default, the Python ``json.dumps`` function is used. .. versionchanged:: 1.3.7 The SQLite dialect renamed this from ``_json_serializer``. :param label_length=None: optional integer value which limits the size of dynamically generated column labels to that many characters. If less than 6, labels are generated as "_(counter)". If ``None``, the value of ``dialect.max_identifier_length``, which may be affected via the :paramref:`_sa.create_engine.max_identifier_length` parameter, is used instead. The value of :paramref:`_sa.create_engine.label_length` may not be larger than that of :paramref:`_sa.create_engine.max_identfier_length`. .. seealso:: :paramref:`_sa.create_engine.max_identifier_length` :param logging_name: String identifier which will be used within the "name" field of logging records generated within the "sqlalchemy.engine" logger. Defaults to a hexstring of the object's id. .. seealso:: :ref:`dbengine_logging` - further detail on how to configure logging. :paramref:`_engine.Connection.execution_options.logging_token` :param max_identifier_length: integer; override the max_identifier_length determined by the dialect. if ``None`` or zero, has no effect. This is the database's configured maximum number of characters that may be used in a SQL identifier such as a table name, column name, or label name. All dialects determine this value automatically, however in the case of a new database version for which this value has changed but SQLAlchemy's dialect has not been adjusted, the value may be passed here. .. versionadded:: 1.3.9 .. seealso:: :paramref:`_sa.create_engine.label_length` :param max_overflow=10: the number of connections to allow in connection pool "overflow", that is connections that can be opened above and beyond the pool_size setting, which defaults to five. this is only used with :class:`~sqlalchemy.pool.QueuePool`. :param module=None: reference to a Python module object (the module itself, not its string name). Specifies an alternate DBAPI module to be used by the engine's dialect. Each sub-dialect references a specific DBAPI which will be imported before first connect. This parameter causes the import to be bypassed, and the given module to be used instead. Can be used for testing of DBAPIs as well as to inject "mock" DBAPI implementations into the :class:`_engine.Engine`. :param paramstyle=None: The `paramstyle `_ to use when rendering bound parameters. This style defaults to the one recommended by the DBAPI itself, which is retrieved from the ``.paramstyle`` attribute of the DBAPI. However, most DBAPIs accept more than one paramstyle, and in particular it may be desirable to change a "named" paramstyle into a "positional" one, or vice versa. When this attribute is passed, it should be one of the values ``"qmark"``, ``"numeric"``, ``"named"``, ``"format"`` or ``"pyformat"``, and should correspond to a parameter style known to be supported by the DBAPI in use. :param pool=None: an already-constructed instance of :class:`~sqlalchemy.pool.Pool`, such as a :class:`~sqlalchemy.pool.QueuePool` instance. If non-None, this pool will be used directly as the underlying connection pool for the engine, bypassing whatever connection parameters are present in the URL argument. For information on constructing connection pools manually, see :ref:`pooling_toplevel`. :param poolclass=None: a :class:`~sqlalchemy.pool.Pool` subclass, which will be used to create a connection pool instance using the connection parameters given in the URL. Note this differs from ``pool`` in that you don't actually instantiate the pool in this case, you just indicate what type of pool to be used. :param pool_logging_name: String identifier which will be used within the "name" field of logging records generated within the "sqlalchemy.pool" logger. Defaults to a hexstring of the object's id. .. seealso:: :ref:`dbengine_logging` - further detail on how to configure logging. :param pool_pre_ping: boolean, if True will enable the connection pool "pre-ping" feature that tests connections for liveness upon each checkout. .. versionadded:: 1.2 .. seealso:: :ref:`pool_disconnects_pessimistic` :param pool_size=5: the number of connections to keep open inside the connection pool. This used with :class:`~sqlalchemy.pool.QueuePool` as well as :class:`~sqlalchemy.pool.SingletonThreadPool`. With :class:`~sqlalchemy.pool.QueuePool`, a ``pool_size`` setting of 0 indicates no limit; to disable pooling, set ``poolclass`` to :class:`~sqlalchemy.pool.NullPool` instead. :param pool_recycle=-1: this setting causes the pool to recycle connections after the given number of seconds has passed. It defaults to -1, or no timeout. For example, setting to 3600 means connections will be recycled after one hour. Note that MySQL in particular will disconnect automatically if no activity is detected on a connection for eight hours (although this is configurable with the MySQLDB connection itself and the server configuration as well). .. seealso:: :ref:`pool_setting_recycle` :param pool_reset_on_return='rollback': set the :paramref:`_pool.Pool.reset_on_return` parameter of the underlying :class:`_pool.Pool` object, which can be set to the values ``"rollback"``, ``"commit"``, or ``None``. .. seealso:: :ref:`pool_reset_on_return` :ref:`dbapi_autocommit_skip_rollback` - a more modern approach to using connections with no transactional instructions :param pool_timeout=30: number of seconds to wait before giving up on getting a connection from the pool. This is only used with :class:`~sqlalchemy.pool.QueuePool`. This can be a float but is subject to the limitations of Python time functions which may not be reliable in the tens of milliseconds. .. note: don't use 30.0 above, it seems to break with the :param tag :param pool_use_lifo=False: use LIFO (last-in-first-out) when retrieving connections from :class:`.QueuePool` instead of FIFO (first-in-first-out). Using LIFO, a server-side timeout scheme can reduce the number of connections used during non- peak periods of use. When planning for server-side timeouts, ensure that a recycle or pre-ping strategy is in use to gracefully handle stale connections. .. versionadded:: 1.3 .. seealso:: :ref:`pool_use_lifo` :ref:`pool_disconnects` :param plugins: string list of plugin names to load. See :class:`.CreateEnginePlugin` for background. .. versionadded:: 1.2.3 :param query_cache_size: size of the cache used to cache the SQL string form of queries. Set to zero to disable caching. The cache is pruned of its least recently used items when its size reaches N * 1.5. Defaults to 500, meaning the cache will always store at least 500 SQL statements when filled, and will grow up to 750 items at which point it is pruned back down to 500 by removing the 250 least recently used items. Caching is accomplished on a per-statement basis by generating a cache key that represents the statement's structure, then generating string SQL for the current dialect only if that key is not present in the cache. All statements support caching, however some features such as an INSERT with a large set of parameters will intentionally bypass the cache. SQL logging will indicate statistics for each statement whether or not it were pull from the cache. .. note:: some ORM functions related to unit-of-work persistence as well as some attribute loading strategies will make use of individual per-mapper caches outside of the main cache. .. seealso:: :ref:`sql_caching` .. versionadded:: 1.4 :param skip_autocommit_rollback: When True, the dialect will unconditionally skip all calls to the DBAPI ``connection.rollback()`` method if the DBAPI connection is confirmed to be in "autocommit" mode. The availability of this feature is dialect specific; if not available, a ``NotImplementedError`` is raised by the dialect when rollback occurs. .. seealso:: :ref:`dbapi_autocommit_skip_rollback` .. versionadded:: 2.0.43 :param use_insertmanyvalues: True by default, use the "insertmanyvalues" execution style for INSERT..RETURNING statements by default. .. versionadded:: 2.0 .. seealso:: :ref:`engine_insertmanyvalues` rPmockzunknown strategy: %rrQN _is_asyncF_coerce_configcrj||}|jvrj||}|SrE)popengine_config_types)keydefaultvalue dialect_clsrHs rI pop_kwargz create_engine..pop_kwargAs=JJsG,Ek555< 77.connectsk""!**55*B!%'7$5ugF"J"-)) *#7??E5W5 5rKr'r9rl _is_asyncioz Pool class z cannot be used with znon-zasyncio enginepcls)coderGzIThe 'future' parameter passed to create_engine() may only be set to True. _initializezInvalid argument(s) ,c3&K|] }d|z yw)z'%s'NrF).0ks rI z create_engine..s4!4sz. sent to create_engine(), using configuration /z^. Please check that the keyword arguments are appropriate for this combination of components.cJ|yrErF)dbapi_connectionrg do_on_connects rI on_connectz!create_engine..on_connects%000./rKrfcztjt||ddd}tj|_ j ||js)|jsj|jyyy#|js)|jsj|jwwwxYw)NF)rirc_allow_revalidate_allow_autobegin) r Connectionrr EMPTY_DICT_execution_options initialize invalidatedclosed do_rollbackri)ryrgcrlengines rI first_connectz$create_engine..first_connects2$&7"#("' A$(??A  6""1%}}QXX'' 5 .6}q}}QXX'' 5 .6}s B7B:)_once_unless_exceptionrE)rYstrrZ Optional[Any]returnrrF)rgzOptional[ConnectionPoolEntry]rr)ryrrgrrNone)/rWrr ArgumentError_urlmake_url_instantiate_plugins_get_entrypointget_async_dialect_clsget_dialect_clsrget_cls_kwargs__dict__r^hasattrinspectismethodr_warn_deprecatedget_func_kwargs setdefaultr NO_LINTINGCOLLECT_CARTESIAN_PRODUCTShandle_dialect_kwargscreate_connect_argsupdateasboollistget_dialect_pool_class_pool_translate_kwargsgethandle_pool_kwargs_dialectrmis_async __class____name__rr TypeErrorjoinon_connect_urlrlisten_builtin_onconnectengine_created)"rrHstraturA entrypointrTr] dialect_argsrur_ dbapi_args dbapi_methr*plugin cargs_tupr8rfr'r9 pool_argstk engineclass engine_argsrqr{builtin_on_connectrrjrkrlr\rzrs" ` @@@@@@rIrJrJ\sZV :& F?%c4V4 4##$:U$BC C JJ"D) cA//7Aw""$J ;.I 66q9  003  zz"E*  JJ L   -+ ;'lLO+ JJx &E } [11 1$11J [' *w/?/?   0   11< >++   %**J$11J%%j1 -AF{ )! 1  -(Z(!L.0C0CD **%:DA'(H,O,OO(@$$[,?@)L)G#66q9Y NN9^R017"t{{7;K3L'M  )  OE VT "D |@D 6< 6  6Iw/k40  66q9I( $$Y/ -A'++Aq1BV|(} !  -  `. A select set of keyword arguments will be "coerced" to their expected type based on string values. The set of arguments is extensible per-dialect using the ``engine_config_types`` accessor. :param configuration: A dictionary (typically produced from a config file, but this is not a requirement). Items whose keys start with the value of 'prefix' will have that prefix stripped, and will then be passed to :func:`_sa.create_engine`. :param prefix: Prefix to match and then strip from keys in 'configuration'. :param kwargs: Each keyword argument to ``engine_from_config()`` itself overrides the corresponding item taken from the 'configuration' dictionary. Keyword arguments should *not* be prefixed. NTrUr) startswithlenrrWrJ) configurationprefixrHrYoptionsrs rIengine_from_configrsH!  >>& ! CKMM#..G !%G  NN6 ++e C  ( ((s*A$)r9r3pre_pingsizerecyclereset_on_returntimeoutuse_lifoc yrErF) rr9r3rrrrrrrHs rIcreate_pool_from_urlrIs rKc yrErFrMs rIrrYsGJrKc tD]"}||vs|j||t|<$t|fi|ddi}|jS)aZCreate a pool instance from the given url. If ``poolclass`` is not provided the pool class used is selected using the dialect specified in the URL. The arguments passed to :func:`_sa.create_pool_from_url` are identical to the pool argument passed to the :func:`_sa.create_engine` function. .. versionadded:: 2.0.10 rqF)rrWrJr8)rrHrYrs rIrr]sT&B &=28**S/F)#. /B3 <& Optional[_ResetStyleArgType]r?floatr@rrAz List[str]rBrrCrrHrrr)rrrHrrr)rzUnion[str, _url.URL]rHrrr)z sqlalchemy.)rzDict[str, Any]rrrHrrr)rrr9rr3rrrrrrrrrrrrrrHrrr#)rrrHrrr#)1 __future__rrtypingrrrrrr r r r rnrrr interfacesrrSrrrrr8rrsqlrr TYPE_CHECKINGrrrrrlogrr r!r"r# util.typingr$rJdeprecated_paramsrrrrFrKrIrs# '$*&  +'*#%))% $'9<" #),(+&)&),/*-"%+.(+&) 9<!$E$ $!$ $ 7 $  $$$'$ $$&$!$$$$*$ (!$" #$$%$&)'$()$* +$,&-$. /$0$1$23$45$67$89$:7;$<=$>?$@A$BC$DE$FG$H I$ $N E E%0e 10e R2?*)!*)+.*)JM*) *)Z '*47   $       2         J J*'+!!1##  rK