zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
U
¸ý°d*{ã@s‚dZddlmZddlmZddlZddlZddlm    Z    ddl
m Z ddl m Z ddl mZdd    lmZdd
lmZdd lmZd d l
mZd dl
mZd dlmZd dlmZe d¡ZGdd„deƒZGdd„deƒZGdd„de jƒZGdd„deƒZGdd„deƒZ Gdd„deƒZ!Gdd„deƒZ"Gd d!„d!eƒZ#Gd"d#„d#eƒZ$Gd$d%„d%eƒZ%e%j& '¡\Z(Z)Gd&d'„d'e ƒZ*e*Z+dS)(a†G
.. dialect:: postgresql+psycopg2
    :name: psycopg2
    :dbapi: psycopg2
    :connectstring: postgresql+psycopg2://user:password@host:port/dbname[?key=value&key=value...]
    :url: https://pypi.org/project/psycopg2/
 
.. _psycopg2_toplevel:
 
psycopg2 Connect Arguments
--------------------------
 
Keyword arguments that are specific to the SQLAlchemy psycopg2 dialect
may be passed to :func:`_sa.create_engine()`, and include the following:
 
 
* ``isolation_level``: This option, available for all PostgreSQL dialects,
  includes the ``AUTOCOMMIT`` isolation level when using the psycopg2
  dialect.   This option sets the **default** isolation level for the
  connection that is set immediately upon connection to the database before
  the connection is pooled.  This option is generally superseded by the more
  modern :paramref:`_engine.Connection.execution_options.isolation_level`
  execution option, detailed at :ref:`dbapi_autocommit`.
 
  .. seealso::
 
    :ref:`psycopg2_isolation_level`
 
    :ref:`dbapi_autocommit`
 
 
* ``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"-style queries.  See the referenced
  section below for details.
 
  .. seealso::
 
    :ref:`psycopg2_executemany_mode`
 
.. tip::
 
    The above keyword arguments are **dialect** keyword arguments, meaning
    that they are passed as explicit keyword arguments to :func:`_sa.create_engine()`::
 
        engine = create_engine(
            "postgresql+psycopg2://scott:tiger@localhost/test",
            isolation_level="SERIALIZABLE",
        )
 
    These should not be confused with **DBAPI** connect arguments, which
    are passed as part of the :paramref:`_sa.create_engine.connect_args`
    dictionary and/or are passed in the URL query string, as detailed in
    the section :ref:`custom_dbapi_args`.
 
.. _psycopg2_ssl:
 
SSL Connections
---------------
 
The psycopg2 module has a connection argument named ``sslmode`` for
controlling its behavior regarding secure (SSL) connections. The default is
``sslmode=prefer``; it will attempt an SSL connection and if that fails it
will fall back to an unencrypted connection. ``sslmode=require`` may be used
to ensure that only secure connections are established.  Consult the
psycopg2 / libpq documentation for further options that are available.
 
Note that ``sslmode`` is specific to psycopg2 so it is included in the
connection URI::
 
    engine = sa.create_engine(
        "postgresql+psycopg2://scott:tiger@192.168.0.199:5432/test?sslmode=require"
    )
 
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 \
    <https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PQCONNECTDBPARAMS>`_
 
.. _psycopg2_multi_host:
 
Specifying 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.  Tokens may consist of
``host::port`` or just ``host``; in the latter case, the default port
is selected by libpq.  In the example below, three host connections
are specified, for ``HostA::PortA``, ``HostB`` connecting to the default port,
and ``HostC::PortC``::
 
    create_engine(
        "postgresql+psycopg2://user:password@/dbname?host=HostA:PortA&host=HostB&host=HostC:PortC"
    )
 
As an alternative, libpq query string format also may be used; this specifies
``host`` and ``port`` as single query string arguments with comma-separated
lists - the default port can be chosen by indicating an empty value
in the comma separated list::
 
    create_engine(
        "postgresql+psycopg2://user:password@/dbname?host=HostA,HostB,HostC&port=PortA,,PortC"
    )
 
With either URL style, connections to each host is attempted based on a
configurable strategy, which may be configured using the libpq
``target_session_attrs`` parameter.  Per libpq this defaults to ``any``
which indicates a connection to each host is then attempted until a connection is successful.
Other strategies include ``primary``, ``prefer-standby``, etc.  The complete
list is documented by PostgreSQL at
`libpq connection strings <https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING>`_.
 
For example, to indicate two hosts using the ``primary`` strategy::
 
    create_engine(
        "postgresql+psycopg2://user:password@/dbname?host=HostA:PortA&host=HostB&host=HostC:PortC&target_session_attrs=primary"
    )
 
.. versionchanged:: 1.4.40 Port specification in psycopg2 multiple host format
   is repaired, previously ports were not correctly interpreted in this context.
   libpq comma-separated format is also now supported.
 
.. versionadded:: 1.3.20 Support for multiple hosts in PostgreSQL connection
   string.
 
.. seealso::
 
    `libpq connection strings <https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING>`_ - please refer
    to this section in the libpq documentation for complete background on multiple host support.
 
 
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.
  Defaults to False, meaning cursors are buffered by default.
 
* ``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:`.BufferedRowCursorResult`, and if omitted the
  buffer will grow to ultimately store 1000 rows at a time.
 
  .. versionchanged:: 1.4  The ``max_row_buffer`` size can now be greater than
     1000, and the buffer will grow to that size.
 
.. _psycopg2_batch_mode:
 
.. _psycopg2_executemany_mode:
 
Psycopg2 Fast Execution Helpers
-------------------------------
 
Modern versions of psycopg2 include a feature known as
`Fast Execution Helpers \
<https://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 at least
an order of magnitude.
 
SQLAlchemy implements a native form of the "insert many values"
handler that will rewrite a single-row INSERT statement to accommodate for
many values at once within an extended VALUES clause; this handler is
equivalent to psycopg2's ``execute_values()`` handler; an overview of this
feature and its configuration are at :ref:`engine_insertmanyvalues`.
 
.. versionadded:: 2.0 Replaced psycopg2's ``execute_values()`` fast execution
   helper with a native SQLAlchemy mechanism referred towards as
   :ref:`insertmanyvalues <engine_insertmanyvalues>`.
 
The psycopg2 dialect retains the ability to use the psycopg2-specific
``execute_batch()`` feature, although it is not expected that this is a widely
used feature.  The use of this extension may be enabled using the
``executemany_mode`` flag which may be passed to :func:`_sa.create_engine`::
 
    engine = create_engine(
        "postgresql+psycopg2://scott:tiger@host/dbname",
        executemany_mode='values_plus_batch')
 
 
Possible options for ``executemany_mode`` include:
 
* ``values_only`` - this is the default value.  SQLAlchemy's native
  :ref:`insertmanyvalues <engine_insertmanyvalues>` handler is used for qualifying
  INSERT statements, assuming
  :paramref:`_sa.create_engine.use_insertmanyvalues` is left at
  its default value of ``True``.  This handler rewrites simple
  INSERT statements to include multiple VALUES clauses so that many
  parameter sets can be inserted with one statement.
 
* ``'values_plus_batch'``- SQLAlchemy's native
  :ref:`insertmanyvalues <engine_insertmanyvalues>` handler is used for qualifying
  INSERT statements, assuming
  :paramref:`_sa.create_engine.use_insertmanyvalues` is left at its default
  value of ``True``. Then, psycopg2's ``execute_batch()`` handler is used for
  qualifying UPDATE and DELETE statements when executed with multiple parameter
  sets. When using this mode, the :attr:`_engine.CursorResult.rowcount`
  attribute will not contain a value for executemany-style executions against
  UPDATE and DELETE statements.
 
.. versionchanged:: 2.0 Removed the ``'batch'`` and ``'None'`` options
   from psycopg2 ``executemany_mode``.  Control over batching for INSERT
   statements is now configured via the
   :paramref:`_sa.create_engine.use_insertmanyvalues` engine-level parameter.
 
The term "qualifying statements" refers to the statement being executed
being a Core :func:`_expression.insert`, :func:`_expression.update`
or :func:`_expression.delete` construct, and **not** a plain textual SQL
string or one constructed using :func:`_expression.text`.  It also may **not** be
a special "extension" statement such as an "ON CONFLICT" "upsert" statement.
When using the ORM, all insert/update/delete statements used by the ORM flush process
are qualifying.
 
The "page size" for the psycopg2 "batch" strategy can be affected
by using the ``executemany_batch_page_size`` parameter, which defaults to
100.
 
For the "insertmanyvalues" feature, the page size can be controlled using the
:paramref:`_sa.create_engine.insertmanyvalues_page_size` parameter,
which defaults to 1000.  An example of modifying both parameters
is below::
 
    engine = create_engine(
        "postgresql+psycopg2://scott:tiger@host/dbname",
        executemany_mode='values_plus_batch',
        insertmanyvalues_page_size=5000, executemany_batch_page_size=500)
 
.. seealso::
 
    :ref:`engine_insertmanyvalues` - background on "insertmanyvalues"
 
    :ref:`tutorial_multiple_parameters` - 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.
 
 
.. _psycopg2_unicode:
 
Unicode with Psycopg2
----------------------
 
The psycopg2 DBAPI driver supports Unicode data transparently.
 
The client character encoding can be controlled for the psycopg2 dialect
in the following ways:
 
* For PostgreSQL 9.1 and above, the ``client_encoding`` parameter may be
  passed in the database URL; this parameter is consumed by the underlying
  ``libpq`` PostgreSQL client library::
 
    engine = create_engine("postgresql+psycopg2://user:pass@host/dbname?client_encoding=utf8")
 
  Alternatively, the above ``client_encoding`` value may be passed using
  :paramref:`_sa.create_engine.connect_args` for programmatic establishment with
  ``libpq``::
 
    engine = create_engine(
        "postgresql+psycopg2://user:pass@host/dbname",
        connect_args={'client_encoding': 'utf8'}
    )
 
* For all PostgreSQL versions, psycopg2 supports a client-side encoding
  value that will be passed to database connections when they are first
  established.  The SQLAlchemy psycopg2 dialect supports this using the
  ``client_encoding`` parameter passed to :func:`_sa.create_engine`::
 
      engine = create_engine(
          "postgresql+psycopg2://user:pass@host/dbname",
          client_encoding="utf8"
      )
 
  .. tip:: The above ``client_encoding`` parameter admittedly is very similar
      in appearance to usage of the parameter within the
      :paramref:`_sa.create_engine.connect_args` dictionary; the difference
      above is that the parameter is consumed by psycopg2 and is
      passed to the database connection using ``SET client_encoding TO
      'utf8'``; in the previously mentioned style, the parameter is instead
      passed through psycopg2 and consumed by the ``libpq`` library.
 
* A common way to set up client encoding with PostgreSQL databases is to
  ensure it is configured within the server-side postgresql.conf file;
  this is the recommended way to set encoding for a server that is
  consistently of one encoding in all databases::
 
    # postgresql.conf file
 
    # client_encoding = sql_ascii # actually, defaults to database
                                 # encoding
    client_encoding = utf8
 
 
 
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.
 
é)Ú annotationsN)Úcasté)Úranges)Ú_PGDialect_common_psycopg)Ú"_PGExecutionContext_common_psycopg)ÚPGIdentifierPreparer)ÚJSON)ÚJSONBé)Útypes)Úutil)Ú FastIntFlag)Úparse_user_argument_for_enumzsqlalchemy.dialects.postgresqlc@seZdZdd„ZdS)Ú_PGJSONcCsdS©N©©ÚselfÚdialectÚcoltyperrú^d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/dialects/postgresql/psycopg2.pyÚresult_processorísz_PGJSON.result_processorN©Ú__name__Ú
__module__Ú __qualname__rrrrrrìsrc@seZdZdd„ZdS)Ú_PGJSONBcCsdSrrrrrrròsz_PGJSONB.result_processorNrrrrrrñsrc@s eZdZdZdd„Zdd„ZdS)Ú_Psycopg2RangeÚnonecs$ttt|ƒj|jƒ‰‡fdd„}|S)Ncs&t|tjƒr"ˆ|j|j|j|jƒ}|Sr)Ú
isinstancerÚRangeÚlowerÚupperÚboundsÚempty©Úvalue©Zpsycopg2_RangerrÚto_rangeÿs ÿz/_Psycopg2Range.bind_processor.<locals>.to_range)ÚgetattrrÚPGDialect_psycopg2Ú_psycopg2_extrasÚ_psycopg2_range_cls)rrr)rr(rÚbind_processorùs 
þ z_Psycopg2Range.bind_processorcCs dd„}|S)NcSs2|dk    r.tj|j|j|jr |jnd|j d}|S)Nz[))r$r%)rr!Z_lowerZ_upperZ_boundsr&rrrr)    süz1_Psycopg2Range.result_processor.<locals>.to_ranger)rrrr)rrrrs
z_Psycopg2Range.result_processorN)rrrr-r.rrrrrrösrc@seZdZdZdS)Ú_Psycopg2NumericRangeZ NumericRangeN©rrrr-rrrrr/sr/c@seZdZdZdS)Ú_Psycopg2DateRangeZ    DateRangeNr0rrrrr1sr1c@seZdZdZdS)Ú_Psycopg2DateTimeRangeZ DateTimeRangeNr0rrrrr2sr2c@seZdZdZdS)Ú_Psycopg2DateTimeTZRangeZDateTimeTZRangeNr0rrrrr3"sr3c@s eZdZdZdd„Zdd„ZdS)ÚPGExecutionContext_psycopg2NcCs| |j¡dSr)Ú _log_noticesÚcursor©rrrrÚ    post_exec)sz%PGExecutionContext_psycopg2.post_execcCsL|jjrt|jjtjƒsdS|jjD]}t | ¡¡q$g|jjdd…<dSr)Ú
connectionZnoticesr Úcollections_abcÚIterableÚloggerÚinfoÚrstrip)rr6Únoticerrrr5,s
ÿ z(PGExecutionContext_psycopg2._log_notices)rrrZ_psycopg2_fetched_rowsr8r5rrrrr4&sr4c@s eZdZdS)ÚPGIdentifierPreparer_psycopg2N)rrrrrrrr@>sr@c@seZdZdZdZdS)ÚExecutemanyModerrN)rrrÚEXECUTEMANY_VALUESÚEXECUTEMANY_VALUES_PLUS_BATCHrrrrrABsrAcsFeZdZdZdZdZdZdZeZ    e
Z dZ dZ dZdZe ejeeejeeeejeejeejeejeej e!ej"e#i    ¡Zd1dd    „Z$‡fd
d „Z%e&d d „ƒZ'ej(dd„ƒZ)ej(dd„ƒZ*ej(dd„ƒZ+dd„Z,dd„Z-dd„Z.dd„Z/dd„Z0dd„Z1d2d!d"„Z2d#d$„Z3d%d&„Z4d3d'd(„Z5d4d)d*„Z6d5d+d,„Z7ej8d-d.„ƒZ9d/d0„Z:‡Z;S)6r+Úpsycopg2TZpyformatF)rrÚ values_onlyédcKsˆtj|f|Žt|tdgtdgidƒ|_||_|jr„t|jdƒr„t     
d|jj ¡}|rrt dd„|  dd    d
¡Dƒƒ|_|jd kr„td ƒ‚dS) NrEZvalues_plus_batchÚexecutemany_modeÚ __version__z(\d+)\.(\d+)(?:\.(\d+))?css|]}|dk    rt|ƒVqdSr)Úint)Ú.0ÚxrrrÚ    <genexpr>†sz.PGDialect_psycopg2.__init__.<locals>.<genexpr>rér )rMéz+psycopg2 version 2.7 or higher is required.)rÚ__init__rrBrCrGÚexecutemany_batch_page_sizeÚdbapiÚhasattrÚreÚmatchrHÚtupleÚgroupÚpsycopg2_versionÚ ImportError)rrGrPÚkwargsÚmrrrrOns*þú     ÿ
 
ÿzPGDialect_psycopg2.__init__cs6tƒ |¡|jo"| |jj¡dk    |_|jtk    |_    dSr)
ÚsuperÚ
initializeÚuse_native_hstoreÚ _hstore_oidsr9Údbapi_connectionÚ_has_native_hstorerGrCÚsupports_sane_multi_rowcount©rr9©Ú    __class__rrr\s  ÿþÿzPGDialect_psycopg2.initializecCs ddl}|S)Nr)rD)ÚclsrDrrrÚ import_dbapi›szPGDialect_psycopg2.import_dbapicCsddlm}|S)Nr)Ú
extensions)rDrg)rergrrrÚ_psycopg2_extensions¡s z'PGDialect_psycopg2._psycopg2_extensionscCsddlm}|S)Nr©Úextras)rDrj)rerjrrrr,§s z#PGDialect_psycopg2._psycopg2_extrascCs |j}|j|j|j|j|jdœS)N)Z
AUTOCOMMITzREAD COMMITTEDzREAD UNCOMMITTEDzREPEATABLE READZ SERIALIZABLE)rhZISOLATION_LEVEL_AUTOCOMMITZISOLATION_LEVEL_READ_COMMITTEDZ ISOLATION_LEVEL_READ_UNCOMMITTEDZISOLATION_LEVEL_REPEATABLE_READZISOLATION_LEVEL_SERIALIZABLE)rrgrrrÚ_isolation_lookup­sûz$PGDialect_psycopg2._isolation_lookupcCs| |j|¡dSr)Úset_isolation_levelrk)rr_Úlevelrrrrl¸sz&PGDialect_psycopg2.set_isolation_levelcCs
||_dSr©Úreadonly©rr9r'rrrÚ set_readonly»szPGDialect_psycopg2.set_readonlycCs|jSrrnrbrrrÚ get_readonly¾szPGDialect_psycopg2.get_readonlycCs
||_dSr©Z
deferrablerprrrÚset_deferrableÁsz!PGDialect_psycopg2.set_deferrablecCs|jSrrsrbrrrÚget_deferrableÄsz!PGDialect_psycopg2.get_deferrablecsªˆj‰g‰ˆjdk    r*‡fdd„}ˆ |¡ˆjrF‡fdd„}ˆ |¡ˆjrjˆjrj‡‡fdd„}ˆ |¡ˆjrŽˆjrއ‡fdd„}ˆ |¡ˆr¢‡fdd„}|SdSdS)Ncs| ˆj¡dSr)Zset_client_encodingÚclient_encoding©Ú
dbapi_connr7rrÚ
on_connectÍsz1PGDialect_psycopg2.on_connect.<locals>.on_connectcsˆ d|¡dSr)Z register_uuidrwrirrryÔscs<ˆ |¡}|dk    r8|\}}d|i}||d<ˆj|f|ŽdS)NÚoidÚ    array_oid)r^Zregister_hstore)rxZ hstore_oidsrzr{Úkw©rjrrrryÛs 
cs$ˆj|ˆjdˆj|ˆjddS)N)Úloads)Zregister_default_jsonÚ_json_deserializerZregister_default_jsonbrwr}rrryçsÿÿcsˆD] }||ƒqdSrr)rxÚfn)Úfnsrrryós)r,rvÚappendrQr]r)rryr)rjrrrryÇs$
 
 
 
 
 zPGDialect_psycopg2.on_connectNcCsF|jtkr6|jrd|ji}ni}|jj|||f|Žn | ||¡dS)NZ    page_size)rGrCrPr,Z execute_batchZ executemany)rr6Z    statementÚ
parametersÚcontextrYrrrÚdo_executemanyûs
 ÿÿz!PGDialect_psycopg2.do_executemanycCs|j |¡dSr)r9Z    tpc_begin©rr9ÚxidrrrÚdo_begin_twophasesz$PGDialect_psycopg2.do_begin_twophasecCs|j ¡dSr)r9Z tpc_preparer†rrrÚdo_prepare_twophase
sz&PGDialect_psycopg2.do_prepare_twophasecCs.|r$|j|jjkr| ¡||ƒn|ƒdSr)ÚstatusrhZ STATUS_READYÚrollback)rrxZ    operationr‡ÚrecoverrrrÚ _do_twophase s
 
zPGDialect_psycopg2._do_twophasecCs |jj}|j||j||ddS©N)rŒ)r9r_rZ tpc_rollback©rr9r‡Z is_preparedrŒrxrrrÚdo_rollback_twophasesÿz'PGDialect_psycopg2.do_rollback_twophasecCs |jj}|j||j||ddSrŽ)r9r_rZ
tpc_commitrrrrÚdo_commit_twophasesÿz%PGDialect_psycopg2.do_commit_twophasecCs6|j}|j |¡}|dk    r.|dr.|dd…SdSdS)NrrM)r,Z HstoreAdapterZget_oids)rr_rjZoidsrrrr^%s
  zPGDialect_psycopg2._hstore_oidscCsft||jjƒrbt|ddƒrdSt|ƒ d¡d}dD],}| |¡}|dkr4d|d|…kr4dSq4dS)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 error: decryption failed or bad record macz&SSL SYSCALL error: Bad file descriptorzSSL SYSCALL error: EOF detectedz&SSL SYSCALL error: Operation timed outzSSL SYSCALL error: Bad addressú")r rQÚErrorr*ÚstrÚ    partitionÚfind)rÚer9r6Zstr_eÚmsgÚidxrrrÚ is_disconnect/s 
z PGDialect_psycopg2.is_disconnect)rErF)N)F)TF)TF)<rrrZdriverZsupports_statement_cacheZsupports_server_side_cursorsZdefault_paramstylerar4Zexecution_ctx_clsr@ÚpreparerrWZ!use_insertmanyvalues_wo_returningZreturns_native_bytesr`r Z update_copyrZcolspecsr    rÚsqltypesr
rrZ    INT4RANGEr/Z    INT8RANGEZNUMRANGEZ    DATERANGEr1ZTSRANGEr2Z    TSTZRANGEr3rOr\Ú classmethodrfZmemoized_propertyrhr,rkrlrqrrrtruryr…rˆr‰rrr‘Zmemoized_instancemethodr^rœÚ __classcell__rrrcrr+Ms€÷þý
! 
 
 
 
 
4
 
    ÿ
    ÿ
 
    r+),Ú__doc__Ú
__future__rÚcollections.abcÚabcr:ÚloggingrSÚtypingrÚrZ_psycopg_commonrrÚbaserÚjsonr    r
r ržr rrÚ    getLoggerr<rrZAbstractRangeImplrr/r1r2r3r4r@rAÚ __members__ÚvaluesrBrCr+rrrrrÚ<module>    sJQ             
 ý