Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/postgresql/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/postgresql/__pycache__/psycopg2.cpython-311.pyc

�

�܋f�����dZddlmZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZddlm
Z
ddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z 	dd
l!mZ"n
#e#$rdZ"YnwxYwej$d��Z%Gd�dej&��Z'Gd�de
��Z(Gd�de��Z)Gd �d!e��Z*Gd"�d#e��Z+Gd$�d%e��Z,ej-��Z.Gd&�d'e
��Z/Gd(�d)e��Z0Gd*�d+e��Z1ej2d,��Z3ej2d-��Z4ej2d.��Z5Gd/�d0e��Z6e6Z7dS)1a	I
.. dialect:: postgresql+psycopg2
    :name: psycopg2
    :dbapi: psycopg2
    :connectstring: postgresql+psycopg2://user:password@host:port/dbname[?key=value&key=value...]
    :url: http://pypi.python.org/pypi/psycopg2/

psycopg2 Connect Arguments
-----------------------------------

psycopg2-specific keyword arguments which are accepted by
:func:`_sa.create_engine()` are:

* ``server_side_cursors``: Enable the usage of "server side cursors" for SQL
  statements which support this feature. What this essentially means from a
  psycopg2 point of view is that the cursor is created using a name, e.g.
  ``connection.cursor('some name')``, which has the effect that result rows
  are not immediately pre-fetched and buffered after statement execution, but
  are instead left on the server and only retrieved as needed. SQLAlchemy's
  :class:`~sqlalchemy.engine.ResultProxy` uses special row-buffering
  behavior when this feature is enabled, such that groups of 100 rows at a
  time are fetched over the wire to reduce conversational overhead.
  Note that the :paramref:`.Connection.execution_options.stream_results`
  execution option is a more targeted
  way of enabling this mode on a per-execution basis.

* ``use_native_unicode``: Enable the usage of Psycopg2 "native unicode" mode
  per connection.  True by default.

  .. seealso::

    :ref:`psycopg2_disable_native_unicode`

* ``isolation_level``: This option, available for all PostgreSQL dialects,
  includes the ``AUTOCOMMIT`` isolation level when using the psycopg2
  dialect.

  .. seealso::

    :ref:`psycopg2_isolation_level`

* ``client_encoding``: sets the client encoding in a libpq-agnostic way,
  using psycopg2's ``set_client_encoding()`` method.

  .. seealso::

    :ref:`psycopg2_unicode`

* ``executemany_mode``, ``executemany_batch_page_size``,
  ``executemany_values_page_size``: Allows use of psycopg2
  extensions for optimizing "executemany"-stye queries.  See the referenced
  section below for details.

  .. seealso::

    :ref:`psycopg2_executemany_mode`

* ``use_batch_mode``: this is the previous setting used to affect "executemany"
  mode and is now deprecated.


Unix Domain Connections
------------------------

psycopg2 supports connecting via Unix domain connections.   When the ``host``
portion of the URL is omitted, SQLAlchemy passes ``None`` to psycopg2,
which specifies Unix-domain communication rather than TCP/IP communication::

    create_engine("postgresql+psycopg2://user:password@/dbname")

By default, the socket file used is to connect to a Unix-domain socket
in ``/tmp``, or whatever socket directory was specified when PostgreSQL
was built.  This value can be overridden by passing a pathname to psycopg2,
using ``host`` as an additional keyword argument::

    create_engine("postgresql+psycopg2://user:password@/dbname?host=/var/lib/postgresql")

.. seealso::

    `PQconnectdbParams \
    <http://www.postgresql.org/docs/9.1/static/libpq-connect.html#LIBPQ-PQCONNECTDBPARAMS>`_

.. _psycopg2_multi_host:

Specfiying multiple fallback hosts
------------------------------------

psycopg2 supports multiple connection points in the connection string.
When the ``host`` parameter is used multiple times in the query section of
the URL, SQLAlchemy will create a single string of the host and port
information provided to make the connections::

    create_engine(
        "postgresql+psycopg2://user:password@/dbname?host=HostA:port1&host=HostB&host=HostC"
    )

A connection to each host is then attempted until either a connection is successful
or all connections are unsuccessful in which case an error is raised.

.. versionadded:: 1.3.20 Support for multiple hosts in PostgreSQL connection
   string.

.. seealso::

    `PQConnString \
    <https://www.postgresql.org/docs/10/libpq-connect.html#LIBPQ-CONNSTRING>`_

Empty DSN Connections / Environment Variable Connections
---------------------------------------------------------

The psycopg2 DBAPI can connect to PostgreSQL by passing an empty DSN to the
libpq client library, which by default indicates to connect to a localhost
PostgreSQL database that is open for "trust" connections.  This behavior can be
further tailored using a particular set of environment variables which are
prefixed with ``PG_...``, which are  consumed by ``libpq`` to take the place of
any or all elements of the connection string.

For this form, the URL can be passed without any elements other than the
initial scheme::

    engine = create_engine('postgresql+psycopg2://')

In the above form, a blank "dsn" string is passed to the ``psycopg2.connect()``
function which in turn represents an empty DSN passed to libpq.

.. versionadded:: 1.3.2 support for parameter-less connections with psycopg2.

.. seealso::

    `Environment Variables\
    <https://www.postgresql.org/docs/current/libpq-envars.html>`_ -
    PostgreSQL documentation on how to use ``PG_...``
    environment variables for connections.

.. _psycopg2_execution_options:

Per-Statement/Connection Execution Options
-------------------------------------------

The following DBAPI-specific options are respected when used with
:meth:`_engine.Connection.execution_options`,
:meth:`.Executable.execution_options`,
:meth:`_query.Query.execution_options`,
in addition to those not specific to DBAPIs:

* ``isolation_level`` - Set the transaction isolation level for the lifespan
  of a :class:`_engine.Connection` (can only be set on a connection,
  not a statement
  or query).   See :ref:`psycopg2_isolation_level`.

* ``stream_results`` - Enable or disable usage of psycopg2 server side
  cursors - this feature makes use of "named" cursors in combination with
  special result handling methods so that result rows are not fully buffered.
  If ``None`` or not set, the ``server_side_cursors`` option of the
  :class:`_engine.Engine` is used.

* ``max_row_buffer`` - when using ``stream_results``, an integer value that
  specifies the maximum number of rows to buffer at a time.  This is
  interpreted by the :class:`.BufferedRowResultProxy`, and if omitted the
  buffer will grow to ultimately store 1000 rows at a time.

  .. versionadded:: 1.0.6

.. _psycopg2_batch_mode:

.. _psycopg2_executemany_mode:

Psycopg2 Fast Execution Helpers
-------------------------------

Modern versions of psycopg2 include a feature known as
`Fast Execution Helpers \
<http://initd.org/psycopg/docs/extras.html#fast-execution-helpers>`_, which
have been shown in benchmarking to improve psycopg2's executemany()
performance, primarily with INSERT statements, by multiple orders of magnitude.
SQLAlchemy allows this extension to be used for all ``executemany()`` style
calls invoked by an :class:`_engine.Engine`
when used with :ref:`multiple parameter
sets <execute_multiple>`, which includes the use of this feature both by the
Core as well as by the ORM for inserts of objects with non-autogenerated
primary key values, by adding the ``executemany_mode`` flag to
:func:`_sa.create_engine`::

    engine = create_engine(
        "postgresql+psycopg2://scott:tiger@host/dbname",
        executemany_mode='batch')


.. versionchanged:: 1.3.7  - the ``use_batch_mode`` flag has been superseded
   by a new parameter ``executemany_mode`` which provides support both for
   psycopg2's ``execute_batch`` helper as well as the ``execute_values``
   helper.

Possible options for ``executemany_mode`` include:

* ``None`` - By default, psycopg2's extensions are not used, and the usual
  ``cursor.executemany()`` method is used when invoking batches of statements.

* ``'batch'`` - Uses ``psycopg2.extras.execute_batch`` so that multiple copies
  of a SQL query, each one corresponding to a parameter set passed to
  ``executemany()``, are joined into a single SQL string separated by a
  semicolon.   This is the same behavior as was provided by the
  ``use_batch_mode=True`` flag.

* ``'values'``- For Core :func:`_expression.insert`
  constructs only (including those
  emitted by the ORM automatically), the ``psycopg2.extras.execute_values``
  extension is used so that multiple parameter sets are grouped into a single
  INSERT statement and joined together with multiple VALUES expressions.   This
  method requires that the string text of the VALUES clause inside the
  INSERT statement is manipulated, so is only supported with a compiled
  :func:`_expression.insert` construct where the format is predictable.
  For all other
  constructs,  including plain textual INSERT statements not rendered  by the
  SQLAlchemy expression language compiler, the
  ``psycopg2.extras.execute_batch``  method is used.   It is therefore important
  to note that **"values" mode implies that "batch" mode is also used for
  all statements for which "values" mode does not apply**.

For both strategies, the ``executemany_batch_page_size`` and
``executemany_values_page_size`` arguments control how many parameter sets
should be represented in each execution.  Because "values" mode implies a
fallback down to "batch" mode for non-INSERT statements, there are two
independent page size arguments.  For each, the default value of ``None`` means
to use psycopg2's defaults, which at the time of this writing are quite low at
100.   For the ``execute_values`` method, a number as high as 10000 may prove
to be performant, whereas for ``execute_batch``, as the number represents
full statements repeated, a number closer to the default of 100 is likely
more appropriate::

    engine = create_engine(
        "postgresql+psycopg2://scott:tiger@host/dbname",
        executemany_mode='values',
        executemany_values_page_size=10000, executemany_batch_page_size=500)


.. seealso::

    :ref:`execute_multiple` - General information on using the
    :class:`_engine.Connection`
    object to execute statements in such a way as to make
    use of the DBAPI ``.executemany()`` method.

.. versionchanged:: 1.3.7 - Added support for
   ``psycopg2.extras.execute_values``.   The ``use_batch_mode`` flag is
   superseded by the ``executemany_mode`` flag.


.. _psycopg2_unicode:

Unicode with Psycopg2
----------------------

By default, the psycopg2 driver uses the ``psycopg2.extensions.UNICODE``
extension, such that the DBAPI receives and returns all strings as Python
Unicode objects directly - SQLAlchemy passes these values through without
change.   Psycopg2 here will encode/decode string values based on the
current "client encoding" setting; by default this is the value in
the ``postgresql.conf`` file, which often defaults to ``SQL_ASCII``.
Typically, this can be changed to ``utf8``, as a more useful default::

    # postgresql.conf file

    # client_encoding = sql_ascii # actually, defaults to database
                                 # encoding
    client_encoding = utf8

A second way to affect the client encoding is to set it within Psycopg2
locally.   SQLAlchemy will call psycopg2's
:meth:`psycopg2:connection.set_client_encoding` method
on all new connections based on the value passed to
:func:`_sa.create_engine` using the ``client_encoding`` parameter::

    # set_client_encoding() setting;
    # works for *all* PostgreSQL versions
    engine = create_engine("postgresql://user:pass@host/dbname",
                           client_encoding='utf8')

This overrides the encoding specified in the PostgreSQL client configuration.
When using the parameter in this way, the psycopg2 driver emits
``SET client_encoding TO 'utf8'`` on the connection explicitly, and works
in all PostgreSQL versions.

Note that the ``client_encoding`` setting as passed to
:func:`_sa.create_engine`
is **not the same** as the more recently added ``client_encoding`` parameter
now supported by libpq directly.   This is enabled when ``client_encoding``
is passed directly to ``psycopg2.connect()``, and from SQLAlchemy is passed
using the :paramref:`_sa.create_engine.connect_args` parameter::

    engine = create_engine(
        "postgresql://user:pass@host/dbname",
        connect_args={'client_encoding': 'utf8'})

    # using the query string is equivalent
    engine = create_engine("postgresql://user:pass@host/dbname?client_encoding=utf8")

The above parameter was only added to libpq as of version 9.1 of PostgreSQL,
so using the previous method is better for cross-version support.

.. _psycopg2_disable_native_unicode:

Disabling Native Unicode
^^^^^^^^^^^^^^^^^^^^^^^^

SQLAlchemy can also be instructed to skip the usage of the psycopg2
``UNICODE`` extension and to instead utilize its own unicode encode/decode
services, which are normally reserved only for those DBAPIs that don't
fully support unicode directly.  Passing ``use_native_unicode=False`` to
:func:`_sa.create_engine` will disable usage of ``psycopg2.extensions.
UNICODE``.
SQLAlchemy will instead encode data itself into Python bytestrings on the way
in and coerce from bytes on the way back,
using the value of the :func:`_sa.create_engine` ``encoding`` parameter, which
defaults to ``utf-8``.
SQLAlchemy's own unicode encode/decode functionality is steadily becoming
obsolete as most DBAPIs now support unicode fully.

Bound Parameter Styles
----------------------

The default parameter style for the psycopg2 dialect is "pyformat", where
SQL is rendered using ``%(paramname)s`` style.   This format has the limitation
that it does not accommodate the unusual case of parameter names that
actually contain percent or parenthesis symbols; as SQLAlchemy in many cases
generates bound parameter names based on the name of a column, the presence
of these characters in a column name can lead to problems.

There are two solutions to the issue of a :class:`_schema.Column`
that contains
one of these characters in its name.  One is to specify the
:paramref:`.schema.Column.key` for columns that have such names::

    measurement = Table('measurement', metadata,
        Column('Size (meters)', Integer, key='size_meters')
    )

Above, an INSERT statement such as ``measurement.insert()`` will use
``size_meters`` as the parameter name, and a SQL expression such as
``measurement.c.size_meters > 10`` will derive the bound parameter name
from the ``size_meters`` key as well.

.. versionchanged:: 1.0.0 - SQL expressions will use
   :attr:`_schema.Column.key`
   as the source of naming when anonymous bound parameters are created
   in SQL expressions; previously, this behavior only applied to
   :meth:`_schema.Table.insert` and :meth:`_schema.Table.update`
   parameter names.

The other solution is to use a positional format; psycopg2 allows use of the
"format" paramstyle, which can be passed to
:paramref:`_sa.create_engine.paramstyle`::

    engine = create_engine(
        'postgresql://scott:tiger@localhost:5432/test', paramstyle='format')

With the above engine, instead of a statement like::

    INSERT INTO measurement ("Size (meters)") VALUES (%(Size (meters))s)
    {'Size (meters)': 1}

we instead see::

    INSERT INTO measurement ("Size (meters)") VALUES (%s)
    (1, )

Where above, the dictionary style is converted into a tuple with positional
style.


Transactions
------------

The psycopg2 dialect fully supports SAVEPOINT and two-phase commit operations.

.. _psycopg2_isolation_level:

Psycopg2 Transaction Isolation Level
-------------------------------------

As discussed in :ref:`postgresql_isolation_level`,
all PostgreSQL dialects support setting of transaction isolation level
both via the ``isolation_level`` parameter passed to :func:`_sa.create_engine`
,
as well as the ``isolation_level`` argument used by
:meth:`_engine.Connection.execution_options`.  When using the psycopg2 dialect
, these
options make use of psycopg2's ``set_isolation_level()`` connection method,
rather than emitting a PostgreSQL directive; this is because psycopg2's
API-level setting is always emitted at the start of each transaction in any
case.

The psycopg2 dialect supports these constants for isolation level:

* ``READ COMMITTED``
* ``READ UNCOMMITTED``
* ``REPEATABLE READ``
* ``SERIALIZABLE``
* ``AUTOCOMMIT``

.. seealso::

    :ref:`postgresql_isolation_level`

    :ref:`pg8000_isolation_level`


NOTICE logging
---------------

The psycopg2 dialect will log PostgreSQL NOTICE messages
via the ``sqlalchemy.dialects.postgresql`` logger.  When this logger
is set to the ``logging.INFO`` level, notice messages will be logged::

    import logging

    logging.getLogger('sqlalchemy.dialects.postgresql').setLevel(logging.INFO)

Above, it is assumed that logging is configured externally.  If this is not
the case, configuration such as ``logging.basicConfig()`` must be utilized::

    import logging

    logging.basicConfig()   # log messages to stdout
    logging.getLogger('sqlalchemy.dialects.postgresql').setLevel(logging.INFO)

.. seealso::

    `Logging HOWTO <https://docs.python.org/3/howto/logging.html>`_ - on the python.org website

.. _psycopg2_hstore:

HSTORE type
------------

The ``psycopg2`` DBAPI includes an extension to natively handle marshalling of
the HSTORE type.   The SQLAlchemy psycopg2 dialect will enable this extension
by default when psycopg2 version 2.4 or greater is used, and
it is detected that the target database has the HSTORE type set up for use.
In other words, when the dialect makes the first
connection, a sequence like the following is performed:

1. Request the available HSTORE oids using
   ``psycopg2.extras.HstoreAdapter.get_oids()``.
   If this function returns a list of HSTORE identifiers, we then determine
   that the ``HSTORE`` extension is present.
   This function is **skipped** if the version of psycopg2 installed is
   less than version 2.4.

2. If the ``use_native_hstore`` flag is at its default of ``True``, and
   we've detected that ``HSTORE`` oids are available, the
   ``psycopg2.extensions.register_hstore()`` extension is invoked for all
   connections.

The ``register_hstore()`` extension has the effect of **all Python
dictionaries being accepted as parameters regardless of the type of target
column in SQL**. The dictionaries are converted by this extension into a
textual HSTORE expression.  If this behavior is not desired, disable the
use of the hstore extension by setting ``use_native_hstore`` to ``False`` as
follows::

    engine = create_engine("postgresql+psycopg2://scott:tiger@localhost/test",
                use_native_hstore=False)

The ``HSTORE`` type is **still supported** when the
``psycopg2.extensions.register_hstore()`` extension is not used.  It merely
means that the coercion between Python dictionaries and the HSTORE
string format, on both the parameter side and the result side, will take
place within SQLAlchemy's own marshalling logic, and not that of ``psycopg2``
which may be more performant.

�)�absolute_importN�)�_DECIMAL_TYPES)�_FLOAT_TYPES)�
_INT_TYPES)�ENUM)�
PGCompiler)�	PGDialect)�PGExecutionContext)�PGIdentifierPreparer)�UUID)�HSTORE)�JSON)�JSONB�)�exc)�
processors)�types)�util)�result)�elements)�collections_abczsqlalchemy.dialects.postgresqlc��eZdZd�Zd�ZdS)�
_PGNumericc��dS�N�)�self�dialects  �^/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py�bind_processorz_PGNumeric.bind_processors���t�c�@�|jrX|tvr$tjtj|j��S|tvs	|tvrdStj
d|z���|tvrdS|tvs	|tvrtjStj
d|z���)NzUnknown PG numeric type: %d)�	asdecimalrr�to_decimal_processor_factory�decimal�Decimal�_effective_decimal_return_scalerrr�InvalidRequestError�to_float)rr�coltypes   r �result_processorz_PGNumeric.result_processors����>�	��,�&�&�!�>��O�T�%I�����N�*�*�g��.C�.C��t��-�1�G�;�����,�&�&��t��N�*�*�g��.C�.C�!�*�*��-�1�G�;���r"N��__name__�
__module__�__qualname__r!r,rr"r rrs2�������������r"rc���eZdZ�fd�Z�xZS)�_PGEnumc���tjr|jdurd|_tt|���||��S)NT�
force_nocheck)r�py2k�_expect_unicode�superr2r,�rrr+�	__class__s   �r r,z_PGEnum.result_processor sD����9�
	3��-��5�5�$3�D� ��W�d�#�#�4�4�W�g�F�F�Fr"�r.r/r0r,�
__classcell__�r9s@r r2r2sA�������G�G�G�G�G�G�G�G�Gr"r2c�(��eZdZ�fd�Z�fd�Z�xZS)�	_PGHStorec�f��|jrdStt|���|��Sr)�_has_native_hstorer7r>r!)rrr9s  �r r!z_PGHStore.bind_processor0s2����%�	B��4���D�)�)�8�8��A�A�Ar"c�h��|jrdStt|���||��Sr)r@r7r>r,r8s   �r r,z_PGHStore.result_processor6s4����%�	M��4���D�)�)�:�:�7�G�L�L�Lr")r.r/r0r!r,r;r<s@r r>r>/s_�������B�B�B�B�B�M�M�M�M�M�M�M�M�Mr"r>c���eZdZ�fd�Z�xZS)�_PGJSONc�h��|jrdStt|���||��Sr)�_has_native_jsonr7rCr,r8s   �r r,z_PGJSON.result_processor>s4����#�	K��4���$�'�'�8�8��'�J�J�Jr"r:r<s@r rCrC=sA�������K�K�K�K�K�K�K�K�Kr"rCc���eZdZ�fd�Z�xZS)�_PGJSONBc�h��|jrdStt|���||��Sr)�_has_native_jsonbr7rGr,r8s   �r r,z_PGJSONB.result_processorFs4����$�	L��4���4�(�(�9�9�'�7�K�K�Kr"r:r<s@r rGrGEsA�������L�L�L�L�L�L�L�L�Lr"rGc��eZdZd�Zd�ZdS)�_PGUUIDc�0�|js|jrd�}|SdSdS)Nc�(�|�t|��}|Sr)�_python_UUID��values r �processz'_PGUUID.bind_processor.<locals>.processQs���$�(��/�/�E��r"��as_uuid�use_native_uuid)rrrQs   r r!z_PGUUID.bind_processorN�@���|�	�� 7�	�
�
�
�
�N�	�	�	�	r"c�0�|js|jrd�}|SdSdS)Nc�(�|�t|��}|Sr)�strrOs r rQz)_PGUUID.result_processor.<locals>.process[s���$���J�J�E��r"rR)rrr+rQs    r r,z_PGUUID.result_processorXrUr"Nr-rr"r rKrKMs2�������������r"rKc� �eZdZd�Zd�Zd�ZdS)�PGExecutionContext_psycopg2c���dtt|����dd��dtt����dd���}|j�|��S)N�c_��_)�hex�id�_server_side_id�_dbapi_connection�cursor)r�idents  r �create_server_side_cursorz5PGExecutionContext_psycopg2.create_server_side_cursorgs\���!��D���]�]�1�2�2�.�.�.��O�4E�4E�0F�0F�q�r�r�0J�0J�K���%�,�,�U�3�3�3r"c��|�|j��|jrtj|��Stj|��Sr)�_log_noticesrc�_is_server_side�_result�BufferedRowResultProxy�ResultProxy)rs r �get_result_proxyz,PGExecutionContext_psycopg2.get_result_proxymsE�����$�+�&�&�&���	-��1�$�7�7�7��&�t�,�,�,r"c��|jjr$t|jjtj��sdS|jjD].}t
�|������/g|jjdd�<dSr)�
connection�notices�
isinstancer�Iterable�logger�info�rstrip)rrc�notices   r rgz(PGExecutionContext_psycopg2._log_noticesus���
� �(�	�
���%��'?�1
�1
�	�
�F��'�/�	)�	)�F�
�K�K��
�
���(�(�(�(�')���!�!�!�!�$�$�$r"N)r.r/r0rerlrgrr"r rZrZfsA������4�4�4�-�-�-�*�*�*�*�*r"rZc� ��eZdZd�fd�	Z�xZS)�PGCompiler_psycopg2Fc����tt|��j|fd|i|��}|s9|jjr-|dtj|j��j|fd|i|����z
}|S)N�skip_bind_expressionz::)r7rw�visit_bindparam�type�	_is_arrayr�
TypeClause�_compiler_dispatch)r�	bindparamry�kw�textr9s     �r rzz#PGCompiler_psycopg2.visit_bindparam�s����?�u�(�$�/�/�?��
�
�,@�
�DF�
�
��
$�	�	��(@�	��D�F��#�I�N�3�3�F����/C��GI�����
�D�
�r")F)r.r/r0rzr;r<s@r rwrw�s=�������
�
�
�
�
�
�
�
�
�
r"rwc��eZdZdS)�PGIdentifierPreparer_psycopg2N)r.r/r0rr"r r�r��s�������Dr"r��executemany_default�executemany_batch�executemany_valuesc���eZdZdZejrdZdZdZdZ	e
ZeZ
eZdZedddd	d
���ZdZdZdZej�dejfg��Zejejejeee ej!e e"e#e$e%ej$e%e&e'e(e)i��Zej*d
���									dd���Z+�fd�Z,e-d���Z.e-d���Z/e-d���Z0ej1d���Z2d�Z3d�Z4dd�Z5ej6d���Z7d�Z8d�Z9�xZ:S)�PGDialect_psycopg2�psycopg2FT�pyformat)rr)r]�)r]r��)r]r�	)r]r�r)r]r�)�native_json�native_jsonb�sane_multi_rowcount�	array_oid�hstore_adapter�use_native_unicode)z1.3.7zJThe psycopg2 use_batch_mode flag is superseded by executemany_mode='batch')�use_batch_modeNc
	��tj|fi|
��||_||_||_||_||_||_tj	�
|tdgtdgtdgid��|_|	rt|_||_||_|jrkt%|jd��rXt'jd|jj��}|r9t-d�|�ddd	��D����|_dSdSdSdS)
N�batch�values�executemany_mode�__version__z(\d+)\.(\d+)(?:\.(\d+))?c3�8K�|]}|�t|��V��dSr)�int)�.0�xs  r �	<genexpr>z.PGDialect_psycopg2.__init__.<locals>.<genexpr>�s1����.�.� ��
�C��F�F�
�
�
�
�.�.r"rr]r)r
�__init__�server_side_cursorsr��use_native_hstorerT�supports_unicode_binds�client_encodingr�symbol�parse_user_argument�EXECUTEMANY_DEFAULT�EXECUTEMANY_BATCH�EXECUTEMANY_VALUESr��executemany_batch_page_size�executemany_values_page_size�dbapi�hasattr�re�matchr��tuple�group�psycopg2_version)rr�r�r�r�rTr�r�r�r��kwargs�ms            r r�zPGDialect_psycopg2.__init__�sK��(	��4�*�*�6�*�*�*�#6�� �"4���!2���.���&8��#�.���!%�� ?� ?��#�d�V�!�G�9�"�X�J�
�

�!
�!
����	6�$5�D�!�+F��(�,H��)��:�	�'�$�*�m�<�<�	���4�d�j�6L�M�M�A��
�(-�.�.�$%�G�G�A�q�!�$4�$4�.�.�.�)�)��%�%�%�	�	�	�	�
�
r"c�f��tt|���|��|jo|�|j��du|_|j|jdk|_	|j|jdk|_
|j|jdko
|jtu|_
dS)Nr�r�r�)r7r��
initializer��_hstore_oidsrnr@r��FEATURE_VERSION_MAPrErIr�r��supports_sane_multi_rowcount)rrnr9s  �r r�zPGDialect_psycopg2.initializes����
� �$�'�'�2�2�:�>�>�>��"�
E��!�!�*�"7�8�8��D�	
��

�!�T�%=�m�%L�L�	
��
�!�T�%=�n�%M�M�	
��
�!��'�(=�>�
?�
=��%�)<�<�	
�)�)�)r"c��ddl}|S)Nr)r�)�clsr�s  r r�zPGDialect_psycopg2.dbapis�������r"c��ddlm}|S)Nr)�
extensions)r�r�)r�r�s  r �_psycopg2_extensionsz'PGDialect_psycopg2._psycopg2_extensionss��'�'�'�'�'�'��r"c��ddlm}|S)Nr)�extras)r�r�)r�r�s  r �_psycopg2_extrasz#PGDialect_psycopg2._psycopg2_extras"s��#�#�#�#�#�#��
r"c�l�|���}|j|j|j|j|jd�S)N)�
AUTOCOMMITzREAD COMMITTEDzREAD UNCOMMITTEDzREPEATABLE READ�SERIALIZABLE)r��ISOLATION_LEVEL_AUTOCOMMIT�ISOLATION_LEVEL_READ_COMMITTED� ISOLATION_LEVEL_READ_UNCOMMITTED�ISOLATION_LEVEL_REPEATABLE_READ�ISOLATION_LEVEL_SERIALIZABLE)rr�s  r �_isolation_lookupz$PGDialect_psycopg2._isolation_lookup(s@���.�.�0�0�
�$�?�(�G� *� K�)�I�&�C�
�
�	
r"c
�@�	|j|�dd��}ne#t$rX}tjtjd|�d|j�dd�|j������|���Yd}~nd}~wwxYw|�	|��dS)Nr^� zInvalid value 'z2' for isolation_level. Valid isolation levels for z are z, )�replace_context)
r��replace�KeyErrorr�raise_r�
ArgumentError�name�join�set_isolation_level)rrn�level�errs    r r�z&PGDialect_psycopg2.set_isolation_level3s���
	��*�5�=�=��c�+B�+B�C�E�E���	�	�	��K��!�!��u�u�d�i�i�i����4�3I�)J�)J�)J�L���
!$�

�
�
�
�
�
�
�
�
�����	����	�&�&�u�-�-�-�-�-s�!$�
B�AB�Bc�<���������������g��j��fd�}��|���j��fd�}��|���jr!�jr�fd�}��|���jr!�jr�fd�}��|���jr"�jr��fd�}��|���jr"�j	r��fd�}��|���r�fd�}|SdS)Nc�<��|��j��dSr)�set_client_encodingr���connrs �r �
on_connectz1PGDialect_psycopg2.on_connect.<locals>.on_connectIs ����(�(��)=�>�>�>�>�>r"c�>����|�j��dSr)r��isolation_levelr�s �r r�z1PGDialect_psycopg2.on_connect.<locals>.on_connectPs"����(�(��t�/C�D�D�D�D�Dr"c�4����d|��dSr)�
register_uuid)r�r�s �r r�z1PGDialect_psycopg2.on_connect.<locals>.on_connectWs����$�$�T�4�0�0�0�0�0r"c�t�����j|�����j|��dSr)�
register_type�UNICODE�UNICODEARRAY)r�r�s �r r�z1PGDialect_psycopg2.on_connect.<locals>.on_connect^s;����(�(��);�T�B�B�B��(�(��)@�$�G�G�G�G�Gr"c�����|��}|�E|\}}d|i}tjrd|d<�j�jdkr||d<�j|fi|��dSdS)N�oidT�unicoder�)r�rr5r�r��register_hstore)r��hstore_oidsr�r�r�r�rs     ��r r�z1PGDialect_psycopg2.on_connect.<locals>.on_connectfs����"�/�/��5�5���*�%0�N�C�����B��y�-�(,��9�
��-��3�K�@�A�A�+4��;��*�F�*�4�6�6�2�6�6�6�6�6�+�*r"c����jr��|�j����jr��|�j���dSdS)N)�loads)rE�register_default_json�_json_deserializerrI�register_default_jsonb)r�r�rs ��r r�z1PGDialect_psycopg2.on_connect.<locals>.on_connectxsy����(���0�0��D�$;�1�����)���1�1��D�$;�2�������r"c�(���D]
}||���dSrr)r��fn�fnss  �r r�z1PGDialect_psycopg2.on_connect.<locals>.on_connect�s+������B��B�t�H�H�H�H��r")
r�r�r��appendr�r�rTr�r�r�)rr�r�r�r�s` @@@r r�zPGDialect_psycopg2.on_connectBs��������&�&�(�(���.�.�0�0�
�����+�
?�
?�
?�
?�
?�
�J�J�z�"�"�"���+�
E�
E�
E�
E�
E�
�J�J�z�"�"�"��:�	#�$�.�	#�
1�
1�
1�
1�
1�
�J�J�z�"�"�"��:�	#�$�1�	#�
H�
H�
H�
H�
H�
�J�J�z�"�"�"��:�	#�$�0�	#�
7�
7�
7�
7�
7�
7�
�J�J�z�"�"�"��:�	#�$�1�	#�
�
�
�
�
�
�
�J�J�z�"�"�"��	�
�
�
�
�
����4r"c���|jtur|�||��dS|jtur+|r)|jr"|jjrd|jjz}||vrd}nd}|rO|�|d��}|jr
d|ji}ni}|�	��j
|||fd|i|��dS|jr
d|ji}ni}|�	��j|||fi|��dS)Nz(%s)z%s�	page_size�template)
r�r��executemanyr��isinsert�compiled�insert_single_values_exprr�r�r��execute_valuesr��
execute_batch)rrc�	statement�
parameters�contextr�r�s       r �do_executemanyz!PGDialect_psycopg2.do_executemany�s��� �$7�7�7����y�*�5�5�5��F�
�!�%7�7�7��
8�� �
8�� �:�
8���)�C�C�
�"��2�2�%)�"��!%���	�
"�)�)�*<�d�C�C�I��0�
�%�t�'H�I�����2�D�!�!�#�#�2����
�
�,�	
�
�
�
�
�
�
��/�
�%�t�'G�H�����1�D�!�!�#�#�1��	�:�
�
�17�
�
�
�
�
r"c��|j|jdkrB|���}|j�|��}|�|dr
|dd�SdS)Nr�rr])r�r�r��
HstoreAdapter�get_oids)rr�r��oidss    r r�zPGDialect_psycopg2._hstore_oids�sb��� �D�$<�=M�$N�N�N��*�*�,�,�F��'�0�0��6�6�D���D��G���A�a�C�y� ��tr"c���|�d���}d}d|jvr't|jdttf��}|r_d|vrt|d��|d<|�|j��|r#d�|jd��|d<g|fS|jrC|�|j��|r#d�|jd��|d<g|fSdg|fS)N�user)�usernameF�host�port�,�)�translate_connect_args�queryrp�listr�r��updater�)r�url�opts�is_multihosts    r �create_connect_argsz&PGDialect_psycopg2.create_connect_args�s���)�)�6�)�:�:�����S�Y���%�c�i��&7�$���G�G�L��	 ���~�~�"�4��<�0�0��V���K�K��	�"�"�"��
;�"�x�x��	�&�(9�:�:��V����:��
�Y�		 ��K�K��	�"�"�"��
;�"�x�x��	�&�(9�:�:��V����:���D�$�<�r"c��t||jj��rjt|dd��rdSt	|���d��d}dD],}|�|��}|dkrd|d|�vrdS�-dS)N�closedFT�
r)
zterminating connectionzclosed the connectionzconnection not openz"could not receive data from serverzcould not send data to serverzconnection already closedzcursor already closedz!losed the connection unexpectedlyz'connection has been closed unexpectedlyz&SSL SYSCALL error: Bad file descriptorzSSL SYSCALL error: EOF detectedz.SSL error: decryption failed or bad record macz&SSL SYSCALL error: Operation timed out�")rpr��Error�getattrrX�	partition�find)r�ernrc�str_e�msg�idxs       r �
is_disconnectz PGDialect_psycopg2.is_disconnect�s����a���)�*�*�#	 �
�z�8�U�3�3�
��t���F�F�$�$�T�*�*�1�-�E��
 �
 ��,�j�j��o�o���!�8�8��5��#��;� 6� 6��4�4���ur")	FTNTTNNNNr);r.r/r0�driverrr5�supports_unicode_statements�supports_server_side_cursors�default_paramstyler�rZ�execution_ctx_clsrw�statement_compilerr��preparerr��dictr�r@rErIr
�engine_config_types�union�asbool�update_copy�colspecs�sqltypes�Numericrrr2�Enumrr>rrCrrGr
rK�deprecated_paramsr�r��classmethodr�r�r��memoized_propertyr�r�r�r��memoized_instancemethodr�rrr;r<s@r r�r��sd�������
�F��y�,�&+�#�#'� �#��#(� �3��,��,�H����$���%�������������#�7�=�=�
���	,�-���� �t������j��'��M�7��I��'��M�7��8��'�		
���H��T��
����"������$(�%)��+�+�+���+�Z
�
�
�
�
�(����[��
����[��
����[��

��
�
���
�
.�
.�
.�J�J�J�X-�-�-�-�^
�!���"�!�� � � �6%�%�%�%�%�%�%r"r�)8�__doc__�
__future__rr&�loggingr��baserrrrr	r
rrr
�hstorer�jsonrrr	rrrr,r�enginerri�sqlrr�uuidrN�ImportError�	getLoggerrrr-rr2r>rCrGrK�counterrarZrwr�r�r�r�r�r�rrr"r �<module>r?s��W�W�p'�&�&�&�&�&���������	�	�	�	� � � � � � �������������������������������$�$�$�$�$�$�&�&�&�&�&�&�������������������������������������!�!�!�!�!�!�������'�'�'�'�'�'�������#�#�#�#�#�#��)�)�)�)�)�)�)�������L�L�L�����
��	�;�	<�	<��������!����:
G�
G�
G�
G�
G�d�
G�
G�
G� M�M�M�M�M��M�M�M�K�K�K�K�K�d�K�K�K�L�L�L�L�L�u�L�L�L������d����,�$�,�.�.��*�*�*�*�*�"4�*�*�*�B�����*����"	�	�	�	�	�$8�	�	�	�"�d�k�"7�8�8���D�K� 3�4�4�� �T�[�!5�6�6��e�e�e�e�e��e�e�e�P���s�B�B�B

Hacked By AnonymousFox1.0, Coded By AnonymousFox