Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/psycopg2/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/psycopg2/__pycache__/extras.cpython-311.pyc

�

�܋f�����dZddlZddlZddlZddlmZm	Z	ddl
ZddlZddlm
Zddl
mZddl
mZddl
mZmZdd	lmZdd
lmZmZmZmZmZddl m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.dd
l/m0Z0Gd�de��Z1Gd�de��Z2Gd�de1��Z3Gd�de4��Z5Gd�de��Z6Gd�de1��Z7Gd�de	��Z8Gd�de��Z9Gd�de��Z:ed ��d!���Z;e<e;��e:_;Gd"�d#e��Z=Gd$�d%e��Z>Gd&�d'e=��Z?Gd(�d)e>��Z@Gd*�d+e��ZAGd,�d-e��ZBGd.�d/eC��ZDGd0�d1e��ZGd2�d3��ZEdId4�ZFGd5�d6��ZGdId7�ZHd8�ZId9�ZJGd:�d;��ZK		dJd=�ZLGd>�d?��ZMdKd@�ZNdA�ZOdLdC�ZPdMdD�ZQdE�ZRejSdFejTdG��zdHz��ZUdS)Nz�Miscellaneous goodies for psycopg2

This module is a generic place used to hold little helper functions
and classes until a better place in the distribution is found.
�N)�
namedtuple�OrderedDict)�
extensions�)�cursor)�
connection)�adapt�quote_ident)�	lru_cache)�REPLICATION_PHYSICAL�REPLICATION_LOGICAL�ReplicationConnection�ReplicationCursor�ReplicationMessage)�json�Json�
register_json�register_default_json�register_default_jsonb)�Range�NumericRange�	DateRange�
DateTimeRange�DateTimeTZRange�register_range�RangeAdapter�RangeCaster)�register_ipaddressc�L��eZdZdZ�fd�Z�fd�Zd�fd�	Z�fd�Z�fd�Z�xZ	S)	�DictCursorBasez%Base class for all dict-like cursors.c���d|vr|d}|d=ntd���t��j|i|��d|_d|_||_dS)N�row_factoryz;DictCursorBase can't be instantiated without a row factory.F)�NotImplementedError�super�__init__�_query_executed�	_prefetchr")�self�args�kwargsr"�	__class__s    ��b/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib64/python3.11/site-packages/psycopg2/extras.pyr%zDictCursorBase.__init__Dst����F�"�"� ��/�K��}�%�%�%�M�O�O�
O������$�)�&�)�)�)�$������&�����c����|jr t�����}|jr|���|js t�����}|S�N)r'r$�fetchoner&�_build_index�r(�resr+s  �r,r0zDictCursorBase.fetchoneP�c����>�	%��'�'�"�"�$�$�C���	 ��������~�	%��'�'�"�"�$�$�C��
r-Nc����|jr!t���|��}|jr|���|js!t���|��}|Sr/)r'r$�	fetchmanyr&r1)r(�sizer3r+s   �r,r6zDictCursorBase.fetchmanyYsg����>�	*��'�'�#�#�D�)�)�C���	 ��������~�	*��'�'�#�#�D�)�)�C��
r-c����|jr t�����}|jr|���|js t�����}|Sr/)r'r$�fetchallr&r1r2s  �r,r9zDictCursorBase.fetchallbr4r-c#�h�K�	|jr/t�����}t|��}|jr|���|js/t�����}t|��}|V�	t|��V��#t$rYdSwxYwr/)r'r$�__iter__�nextr&r1�
StopIteration)r(r3�firstr+s   �r,r;zDictCursorBase.__iter__ks������	��~�
"��g�g�&�&�(�(���S�	�	���#�
$��!�!�#�#�#��>�
"��g�g�&�&�(�(���S�	�	���K�K�K�
 ��3�i�i����
 ���	�	�	��F�F�	���s�BB#�#
B1�0B1r/)
�__name__�
__module__�__qualname__�__doc__r%r0r6r9r;�
__classcell__�r+s@r,r r As��������/�/�
'�
'�
'�
'�
'�������������������������r-r c�"��eZdZdZ�fd�Z�xZS)�DictConnectionz2A connection that uses `DictCursor` automatically.c�z��|�d|jpt��t��j|i|��S�N�cursor_factory)�
setdefaultrI�
DictCursorr$r�r(r)r*r+s   �r,rzDictConnection.cursors=������*�D�,?�,M�:�N�N�N��u�w�w�~�t�.�v�.�.�.r-�r?r@rArBrrCrDs@r,rFrF}s>�������<�<�/�/�/�/�/�/�/�/�/r-rFc�@��eZdZdZ�fd�Zd�fd�	Zd�fd�	Zd�Z�xZS)rKz�A cursor that keeps a list of column name -> index mappings__.

    .. __: https://docs.python.org/glossary.html#term-mapping
    c�\��t|d<t��j|i|��d|_dS)Nr"T)�DictRowr$r%r'rLs   �r,r%zDictCursor.__init__�s4��� '��}�������$�)�&�)�)�)�����r-Nc�|��t��|_d|_t���||��S�NT)r�indexr&r$�execute�r(�query�varsr+s   �r,rTzDictCursor.execute�s.��� �]�]��
�#����w�w���u�d�+�+�+r-c�|��t��|_d|_t���||��SrR)rrSr&r$�callproc�r(�procnamerWr+s   �r,rYzDictCursor.callproc�s0��� �]�]��
�#����w�w����$�/�/�/r-c��|jrO|jrJtt|j����D]}||j|j|d<�d|_dSdSdS)NrF)r&�description�range�lenrS)r(�is  r,r1zDictCursor._build_index�sw����	)�D�$4�	)��3�t�/�0�0�1�1�
7�
7��56��
�4�+�A�.�q�1�2�2�#(�D� � � �	)�	)�	)�	)r-r/�	r?r@rArBr%rTrYr1rCrDs@r,rKrK�s����������
�����
,�,�,�,�,�,�
0�0�0�0�0�0�
)�)�)�)�)�)�)r-rKc�z��eZdZdZdZd�Z�fd�Z�fd�Z�fd�Zd�Z	�fd�Z
dd
�Zd�Zd�Z
�fd
�Zd�Zd�Z�xZS)rPz6A row object that allow by-column-name access to data.��_indexc�X�|j|_dgt|j��z|dd�<dSr/)rSrdr_r])r(rs  r,r%zDictRow.__init__�s.���l����&�3�v�1�2�2�2��Q�Q�Q���r-c���t|ttf��s
|j|}t	���|��Sr/)�
isinstance�int�slicerdr$�__getitem__)r(�xr+s  �r,rjzDictRow.__getitem__�s<����!�c�5�\�*�*�	���A��A��w�w�"�"�1�%�%�%r-c���t|ttf��s
|j|}t	���||��dSr/)rgrhrirdr$�__setitem__)r(rk�vr+s   �r,rmzDictRow.__setitem__�sD����!�c�5�\�*�*�	���A��A�
�����A�q�!�!�!�!�!r-c�V����t��j���fd��jD��S)Nc3�H�K�|]}|��j|��fV��dSr/rc��.0�n�gr(s  ��r,�	<genexpr>z DictRow.items.<locals>.<genexpr>�s8�����<�<�1��A�A�d�k�!�n�%�%�&�<�<�<�<�<�<r-�r$rjrd�r(rtr+s`@�r,�itemsz
DictRow.items�s0������G�G���<�<�<�<�<���<�<�<�<r-c�*�t|j��Sr/)�iterrd�r(s r,�keyszDictRow.keys�s���D�K� � � r-c�V����t��j���fd��jD��S)Nc3�D�K�|]}��j|��V��dSr/rcrqs  ��r,ruz!DictRow.values.<locals>.<genexpr>�s3�����7�7�a���$�+�a�.�!�!�7�7�7�7�7�7r-rvrws`@�r,�valueszDictRow.values�s0������G�G���7�7�7�7�7�4�;�7�7�7�7r-Nc�8�	||S#t$r|cYSwxYwr/)�	Exception)r(rk�defaults   r,�getzDictRow.get�s4��	���7�N���	�	�	��N�N�N�	���s�
��c�D�t|�����Sr/)rrxr{s r,�copyzDictRow.copy�s���4�:�:�<�<�(�(�(r-c��||jvSr/rc)r(rks  r,�__contains__zDictRow.__contains__�s���D�K��r-c�D��t�����Sr/)r$�
__reduce__)r(r+s �r,r�zDictRow.__reduce__�s����w�w�!�!�#�#�#r-c�H�|dd�|j���fSr/)rdr�r{s r,�__getstate__zDictRow.__getstate__�s#���A�A�A�w���(�(�*�*�*�*r-c�:�|d|dd�<|d|_dS�Nrrrc)r(�datas  r,�__setstate__zDictRow.__setstate__�s"���q�'��Q�Q�Q���1�g����r-r/)r?r@rArB�	__slots__r%rjrmrxr|rr�r�r�r�r�r�rCrDs@r,rPrP�s�������@�@��I�3�3�3�&�&�&�&�&�
"�"�"�"�"�
=�=�=�=�=�!�!�!�8�8�8�8�8�����)�)�)� � � �$�$�$�$�$�+�+�+�������r-rPc�"��eZdZdZ�fd�Z�xZS)�RealDictConnectionz6A connection that uses `RealDictCursor` automatically.c�z��|�d|jpt��t��j|i|��SrH)rJrI�RealDictCursorr$rrLs   �r,rzRealDictConnection.cursor�s=������*�D�,?�,Q�>�R�R�R��u�w�w�~�t�.�v�.�.�.r-rMrDs@r,r�r��s>�������@�@�/�/�/�/�/�/�/�/�/r-r�c�@��eZdZdZ�fd�Zd�fd�	Zd�fd�	Zd�Z�xZS)r�aQA cursor that uses a real dict as the base type for rows.

    Note that this cursor is extremely specialized and does not allow
    the normal access (using integer indices) to fetched data. If you need
    to access database rows both as a dictionary and a list, then use
    the generic `DictCursor` instead of `!RealDictCursor`.
    c�N��t|d<t��j|i|��dS)Nr")�RealDictRowr$r%rLs   �r,r%zRealDictCursor.__init__�s/��� +��}�������$�)�&�)�)�)�)�)r-Nc�d��g|_d|_t���||��SrR)�column_mappingr&r$rTrUs   �r,rTzRealDictCursor.execute�s+��� ���#����w�w���u�d�+�+�+r-c�d��g|_d|_t���||��SrR)r�r&r$rYrZs   �r,rYzRealDictCursor.callproc�s-��� ���#����w�w����$�/�/�/r-c�d�|jr&|jr!d�|jD��|_d|_dSdSdS)Nc��g|]
}|d��S�r��rr�ds  r,�
<listcomp>z/RealDictCursor._build_index.<locals>.<listcomp>�s��"B�"B�"B�A�1�Q�4�"B�"B�"Br-F)r&r]r�r{s r,r1zRealDictCursor._build_index�sR����	)�D�$4�	)�"B�"B��1A�"B�"B�"B�D��#(�D� � � �	)�	)�	)�	)r-r/rarDs@r,r�r��s����������*�*�*�*�*�,�,�,�,�,�,�
0�0�0�0�0�0�
)�)�)�)�)�)�)r-r�c�,��eZdZdZ�fd�Z�fd�Z�xZS)r�z.A `!dict` subclass representing a data record.c���|r.t|dt��r|d}|dd�}nd}t��j|i|��|�3|jr|js|���|j|t<dSdSr�)rg�_cursorr$r%r]r�r1r�)r(r)r*rr+s    �r,r%zRealDictRow.__init__�s�����	�J�t�A�w��0�0�	��!�W�F�����8�D�D��F������$�)�&�)�)�)����!�
&�&�*?�
&��#�#�%�%�%�
!'� 5�D������r-c���t|vrU|t}t���|||��|t|��dz
kr|t=dSt���||��dS)Nr)r�r$rmr_)r(�key�value�mappingr+s    �r,rmzRealDictRow.__setitem__sy����$����;�'�G��G�G������e�4�4�4��c�'�l�l�Q�&�&�&���%��F�
�����C��'�'�'�'�'r-)r?r@rArBr%rmrCrDs@r,r�r��sW�������8�8�6�6�6�6�6�&
(�
(�
(�
(�
(�
(�
(�
(�
(r-r�c�"��eZdZdZ�fd�Z�xZS)�NamedTupleConnectionz8A connection that uses `NamedTupleCursor` automatically.c�z��|�d|jpt��t��j|i|��SrH)rJrI�NamedTupleCursorr$rrLs   �r,rzNamedTupleConnection.cursors>������*�D�,?�,S�CS�T�T�T��u�w�w�~�t�.�v�.�.�.r-rMrDs@r,r�r�s>�������B�B�/�/�/�/�/�/�/�/�/r-r�c���eZdZdZdZdZd
�fd�	Z�fd�Zd
�fd�	Z�fd�Z	d
�fd�	Z
�fd	�Z�fd
�Zd�Z
ed���Z�xZS)r�a�A cursor that generates results as `~collections.namedtuple`.

    `!fetch*()` methods will return named tuples instead of regular tuples, so
    their elements can be accessed both as regular numeric items as well as
    attributes.

        >>> nt_cur = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
        >>> rec = nt_cur.fetchone()
        >>> rec
        Record(id=1, num=100, data="abc'def")
        >>> rec[1]
        100
        >>> rec.data
        "abc'def"
    Nic�V��d|_t���||��Sr/)�Recordr$rTrUs   �r,rTzNamedTupleCursor.execute6s"�������w�w���u�d�+�+�+r-c�V��d|_t���||��Sr/)r�r$�executemanyrUs   �r,r�zNamedTupleCursor.executemany:s$�������w�w�"�"�5�$�/�/�/r-c�V��d|_t���||��Sr/)r�r$rYrZs   �r,rYzNamedTupleCursor.callproc>s$�������w�w����$�/�/�/r-c���t�����}|�9|j}|�|���x}|_|�|��SdSr/)r$r0r��_make_nt�_make)r(�t�ntr+s   �r,r0zNamedTupleCursor.fetchoneBsT����G�G�������=���B��z�#'�=�=�?�?�2��T�[��8�8�A�;�;��	�=r-c����t���|��}|j}|�|���x}|_t	t|j|����Sr/)r$r6r�r��list�mapr�)r(r7�tsr�r+s    �r,r6zNamedTupleCursor.fetchmanyJsT���
�W�W�
�
�t�
$�
$��
�[��
�:�#�}�}���.�B����C���"�%�%�&�&�&r-c����t�����}|j}|�|���x}|_t	t|j|����Sr/)r$r9r�r�r�r�r�)r(r�r�r+s   �r,r9zNamedTupleCursor.fetchallQsR���
�W�W�
�
�
�
��
�[��
�:�#�}�}���.�B����C���"�%�%�&�&�&r-c#�L�K�	t�����}t|��}|j}|�|���x}|_|�|��V�	|�t|����V��%#t$rYdSwxYwr/)r$r;r<r�r�r�r=)r(�itr�r�r+s    �r,r;zNamedTupleCursor.__iter__Xs������
	����!�!�#�#�B��R���A���B��z�#'�=�=�?�?�2��T�[��(�(�1�+�+����
)��h�h�t�B�x�x�(�(�(�(�(�
)���	�	�	��F�F�	���s�BB�
B#�"B#c�z�|jrtd�|jD����nd}|�|��S)Nc3�&K�|]}|dV��
dS)rNr�r�s  r,ruz,NamedTupleCursor._make_nt.<locals>.<genexpr>is&����3�3�Q�A�a�D�3�3�3�3�3�3r-r�)r]�tuple�_cached_make_nt)r(r�s  r,r�zNamedTupleCursor._make_nthsB��7;�7G�O�e�3�3�$�"2�3�3�3�3�3�3�R���#�#�C�(�(�(r-c���g}|D]Y}t�d|��}|ddksd|dcxkrdkrnnd|z}|�|���Ztd|��}|S)N�_r�0�9�fr�)�	_re_clean�sub�appendr)�clsr��fields�sr�s     r,�_do_make_ntzNamedTupleCursor._do_make_ntls������	�	�A��
�
�c�1�%�%�A���t�s�{�{�c�Q�q�T�0�0�0�0�S�0�0�0�0�0��!�G���M�M�!�����
��&�
)�
)���	r-r/)r?r@rArBr��	MAX_CACHErTr�rYr0r6r9r;r��classmethodr�rCrDs@r,r�r�#s����������F��I�,�,�,�,�,�,�0�0�0�0�0�0�0�0�0�0�0������'�'�'�'�'�'�'�'�'�'�'������ )�)�)�����[�����r-r�ic�,�|�|��Sr/)r�)r�r�s  r,r�r�{s���?�?�3���r-c�@��eZdZdZd�Zd�Zd�Zd�Zd�Z�fd�Z	�xZ
S)�LoggingConnectionz~A connection that logs all queries to a file or logger__ object.

    .. __: https://docs.python.org/library/logging.html
    c��||_tr4t|tjtjf��r|j|_dS|j|_dS)z�Initialize the connection to log to `!logobj`.

        The `!logobj` parameter can be an open file object or a Logger/LoggerAdapter
        instance from the standard logging module.
        N)�_logobj�_loggingrg�Logger�
LoggerAdapter�_logtologger�log�
_logtofile)r(�logobjs  r,�
initializezLoggingConnection.initialize�sP������	'�
����(�*@�A�C�C�	'��(�D�H�H�H���D�H�H�Hr-c��|S)z�Filter the query before logging it.

        This is the method to overwrite to filter unwanted queries out of the
        log or to add some extra data to the output. The default implementation
        just does nothing.
        r��r(�msg�curss   r,�filterzLoggingConnection.filter�s	���
r-c��|�||��}|rit|t��r+|�tj|jd��}|j�|tj
z��dSdS)N�replace)r�rg�bytes�decode�_ext�	encodings�encodingr��write�_os�linesepr�s   r,r�zLoggingConnection._logtofile�sy���k�k�#�t�$�$���	2��#�u�%�%�
K��j�j����
�!>�	�J�J���L���s�S�[�0�1�1�1�1�1�	2�	2r-c�n�|�||��}|r|j�|��dSdSr/)r�r��debugr�s   r,r�zLoggingConnection._logtologger�sC���k�k�#�t�$�$���	$��L���s�#�#�#�#�#�	$�	$r-c�P�t|d��s|�d���dS)Nr�z3LoggingConnection object has not been initialize()d)�hasattr�ProgrammingErrorr{s r,�_checkzLoggingConnection._check�s?���t�Y�'�'�	G��'�'�E�G�G�
G�	G�	Gr-c���|���|�d|jpt��t	��j|i|��SrH)r�rJrI�
LoggingCursorr$rrLs   �r,rzLoggingConnection.cursor�sJ������
�
�
����*�D�,?�,P�=�Q�Q�Q��u�w�w�~�t�.�v�.�.�.r-)r?r@rArBr�r�r�r�r�rrCrDs@r,r�r��s����������
'�'�'����2�2�2�$�$�$�
G�G�G�
/�/�/�/�/�/�/�/�/r-r�c�0��eZdZdZd�fd�	Zd�fd�	Z�xZS)r�zCA cursor that logs queries using its connection logging facilities.Nc����	t���||��|j�|j|��S#|j�|j|��wxYwr/)r$rTrr�rVrUs   �r,rTzLoggingCursor.execute�sZ���	2��7�7�?�?�5�$�/�/��O����
�D�1�1�1�1��D�O����
�D�1�1�1�1�����!A�"A'c����	t���||��|j�|j|��S#|j�|j|��wxYwr/)r$rYrr�rVrZs   �r,rYzLoggingCursor.callproc�s\���	2��7�7�#�#�H�d�3�3��O����
�D�1�1�1�1��D�O����
�D�1�1�1�1���r�r/)r?r@rArBrTrYrCrDs@r,r�r��sa�������M�M�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2�2r-r�c�&�eZdZdZdd�Zd�Zd�ZdS)�MinTimeLoggingConnectiona�A connection that logs queries based on execution time.

    This is just an example of how to sub-class `LoggingConnection` to
    provide some extra filtering for the logged queries. Both the
    `initialize()` and `filter()` methods are overwritten to make sure
    that only queries executing for more than ``mintime`` ms are logged.

    Note that this connection uses the specialized cursor
    `MinTimeLoggingCursor`.
    rc�J�t�||��||_dSr/)r�r��_mintime)r(r��mintimes   r,r�z#MinTimeLoggingConnection.initialize�s#���$�$�T�6�2�2�2���
�
�
r-c��tj��|jz
dz}||jkrTt	|t
��r+|�tj|j	d��}|�tj�d|�d�SdS)Ni�r�z  (execution time: z ms))�_time�time�	timestampr�rgr�r�r�r�r�r�r�)r(r�r�r�s    r,r�zMinTimeLoggingConnection.filter�s{��
�Z�\�\�D�N�
*�d�2���t�}����#�u�%�%�
K��j�j����
�!>�	�J�J���B�3�;�B�B�1�B�B�B�B��r-c�p�|�d|jpt��tj|g|�Ri|��SrH)rJrI�MinTimeLoggingCursorr�r)r(r)r*s   r,rzMinTimeLoggingConnection.cursor�sJ�����*���7�#7�	9�	9�	9� �'��>�t�>�>�>�v�>�>�>r-Nr�)r?r@rArBr�r�rr�r-r,r�r��sS������	�	� � � � �C�C�C�?�?�?�?�?r-r�c�"�eZdZdZdd�Zdd�ZdS)rz=The cursor sub-class companion to `MinTimeLoggingConnection`.Nc�j�tj��|_t�|||��Sr/)r�rrr�rT)r(rVrWs   r,rTzMinTimeLoggingCursor.execute�s'���������$�$�T�5�$�7�7�7r-c�j�tj��|_t�|||��Sr/)r�rrr�rY)r(r[rWs   r,rYzMinTimeLoggingCursor.callproc�s'���������%�%�d�H�d�;�;�;r-r/)r?r@rArBrTrYr�r-r,rr�sB������G�G�8�8�8�8�<�<�<�<�<�<r-rc���eZdZ�fd�Z�xZS)�LogicalReplicationConnectionc�N��t|d<t��j|i|��dS�N�replication_type)r
r$r%rLs   �r,r%z%LogicalReplicationConnection.__init__�s0���%8��!�"������$�)�&�)�)�)�)�)r-�r?r@rAr%rCrDs@r,rr��8�������*�*�*�*�*�*�*�*�*r-rc���eZdZ�fd�Z�xZS)�PhysicalReplicationConnectionc�N��t|d<t��j|i|��dSr
)rr$r%rLs   �r,r%z&PhysicalReplicationConnection.__init__�s0���%9��!�"������$�)�&�)�)�)�)�)r-rrDs@r,rr�r
r-rc��eZdZdZdS)�StopReplicationa
    Exception used to break out of the endless loop in
    `~ReplicationCursor.consume_stream()`.

    Subclass of `~exceptions.Exception`.  Intentionally *not* inherited from
    `~psycopg2.Error` as occurrence of this exception does not indicate an
    error.
    N)r?r@rArBr�r-r,rr�s��������	�Dr-rc�2�eZdZdZd
d�Zd�Z		dd�Zd	�ZdS)rz;A cursor used for communication on replication connections.Nc�z�dt||���d�}|�|jj}|tkr-|�t	jd���|dt||����z
}nK|tkr|�t	jd���|dz
}n$t	jdt|�������|�|��dS)	z"Create streaming replication slot.zCREATE_REPLICATION_SLOT � NzAoutput plugin name is required to create logical replication slot�LOGICAL zIcannot specify output plugin name when creating physical replication slot�PHYSICAL�unrecognized replication type: )	r
rrr
�psycopg2r�r�reprrT)r(�	slot_name�	slot_type�
output_plugin�commands     r,�create_replication_slotz)ReplicationCursor.create_replication_slot
s���M�[��D�-I�-I�L�L�L������8�I��+�+�+��$��/�/�0�0�0�
�D�+�m�T�"B�"B�D�D�D�G�G�
�.�
.�
.��(��/�0�1�1�1�
�z�!�G�G��+�C�$�y�/�/�C�C�E�E�
E�	
���W�����r-c�V�dt||����}|�|��dS)z Drop streaming replication slot.zDROP_REPLICATION_SLOT N)r
rT)r(rrs   r,�drop_replication_slotz'ReplicationCursor.drop_replication_slot+s4��J�;�y�$�+G�+G�I�I�����W�����r-rF�
c	���d}|�|jj}|tkr4|r|dt||���d�z
}nt	jd���|dz
}nI|tkr|r|dt||���d�z
}n$t	jdt|�������t|��turG|�
d��}	t|	d	d
��d�dt|	dd
��d
��}	n|dz	dzd�d|dzd
��}	||	z
}|d	kr'|tkrt	jd���|d|��z
}|r�|tkrt	jd���|dz
}|���D]Q\}
}|�
d��s|dz
}|t|
|���dtt|������z
}�R|dz
}|�|||���dS)zStart replication stream.zSTART_REPLICATION NzSLOT rz-slot name is required for logical replicationrr�/r��Xr�08X� l��z/cannot specify timeline for logical replicationz
 TIMELINE z=cannot specify output plugin options for physical replicationz (�(z, �))r��status_interval)rrr
r
rr�rr�type�str�splitrhrx�endswith�_A�start_replication_expert)r(rr�	start_lsn�timeline�optionsr�r+r�lsn�krns            r,�start_replicationz#ReplicationCursor.start_replication1s���
'������8�I��+�+�+��
E��B�;�y�$�#?�#?�B�B�B�B����/�C�E�E�E�
�z�!�G�G�
�.�
.�
.��
C��B�;�y�$�#?�#?�B�B�B�B����+�C�$�y�/�/�C�C�E�E�
E��	�?�?�c�!�!��/�/�#�&�&�C���Q���_�_�>�>�>��S��V�R���>�>�>�C�C��"�_�z�1�R�R�R�i�*�6L�R�R�R�C��3����q�=�=��/�/�/��/�E�G�G�G�
�.�H�.�.�.�G��
	��0�0�0��/�S�U�U�U�
�t�O�G��
�
���
B�
B���1��'�'��,�,�$��t�O�G��k�!�T�2�2�A�A�R��A���Z�Z�A�A�A����s�N�G��%�%��F�O�	&�	E�	E�	E�	E�	Er-c�4�|j���Sr/)r�filenor{s r,r9zReplicationCursor.filenols����%�%�'�'�'r-�NN)NNrrNFr")r?r@rArBrr!r7r9r�r-r,rr
sm������E�E�����<���=>�DF�8E�8E�8E�8E�v(�(�(�(�(r-rc�*�eZdZdZd�Zd�Zd�Zd�ZdS)�UUID_adapterz�Adapt Python's uuid.UUID__ type to PostgreSQL's uuid__.

    .. __: https://docs.python.org/library/uuid.html
    .. __: https://www.postgresql.org/docs/current/static/datatype-uuid.html
    c��||_dSr/��_uuid)r(�uuids  r,r%zUUID_adapter.__init__y�
����
�
�
r-c�&�|tjur|SdSr/�r��	ISQLQuote�r(�protos  r,�__conform__zUUID_adapter.__conform__|����D�N�"�"��K�#�"r-c�>�d|j�d��d��S)N�'�'::uuid�utf8)r?�encoder{s r,�	getquotedzUUID_adapter.getquoted�s#��'�D�J�'�'�'�/�/��7�7�7r-c��d|j�d�S)NrJrKr>r{s r,�__str__zUUID_adapter.__str__�s��&�4�:�&�&�&�&r-N)r?r@rArBr%rGrNrPr�r-r,r<r<rsZ��������������8�8�8�'�'�'�'�'r-r<c����ddl�|sd}d}n&t|ttf��r|\}}n|}d}t	j|fd�fd���t_t	j|fdtj��t_t	j	tj|��t	j	tj|��t	j
�jt��tjS)aRCreate the UUID type and an uuid.UUID adapter.

    :param oids: oid for the PostgreSQL :sql:`uuid` type, or 2-items sequence
        with oids of the type and the array. If not specified, use PostgreSQL
        standard oids.
    :param conn_or_curs: where to register the typecaster. If not specified,
        register it globally.
    rNi�i��UUIDc�6��|r��|��pdSr/)rR)r�rr@s  �r,�<lambda>zregister_uuid.<locals>.<lambda>�s����!9�$�)�)�D�/�/�!A�T�r-zUUID[])r@rgr�r�r��new_typerR�new_array_type�	UUIDARRAY�
register_type�register_adapterr<)�oids�conn_or_curs�oid1�oid2r@s    @r,�
register_uuidr^�s�����K�K�K��������	�D�4��-�	(�	(���
��d�d������
�t�h��A�A�A�A�C�C�D�I��(�$��(�D�I�F�F�D�N���t�y�,�/�/�/���t�~�|�4�4�4���$�)�\�2�2�2��9�r-c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�InetaCWrap a string to allow for correct SQL-quoting of inet values.

    Note that this adapter does NOT check the passed value to make
    sure it really is an inet-compatible address but DOES call adapt()
    on it to make sure it is impossible to execute an SQL-injection
    by passing an evil value to the initializer.
    c��||_dSr/)�addr)r(rbs  r,r%z
Inet.__init__�s
����	�	�	r-c�0�|jj�d|j�d�S)Nr)r*)r+r?rbr{s r,�__repr__z
Inet.__repr__�s ���.�)�:�:�D�I�:�:�:�:r-c��||_dSr/)�_conn�r(�conns  r,�preparezInet.prepare�rAr-c��t|j��}t|d��r|�|j��|���dzS)Nris::inet)r0rbr�rirfrN)r(�objs  r,rNzInet.getquoted�sH�����m�m���3�	�"�"�	$��K�K��
�#�#�#��}�}����*�*r-c�&�|tjur|SdSr/rCrEs  r,rGzInet.__conform__�rHr-c�*�t|j��Sr/)r-rbr{s r,rPzInet.__str__�s���4�9�~�~�r-N)
r?r@rArBr%rdrirNrGrPr�r-r,r`r`�sx�����������;�;�;����+�+�+��������r-r`c���ddl}|�dt��|sd}d}n&t|tt
f��r|\}}n|}d}t
j|fdd���t_t
j	|fdtj��t_
t
jtj|��t
jtj
|��tjS)	aLCreate the INET type and an Inet adapter.

    :param oid: oid for the PostgreSQL :sql:`inet` type, or 2-items sequence
        with oids of the type and the array. If not specified, use PostgreSQL
        standard oids.
    :param conn_or_curs: where to register the typecaster. If not specified,
        register it globally.
    rNz4the inet adapter is deprecated, it's not very usefuliei�INETc�(�|rt|��pdSr/)r`)r�rs  r,rTzregister_inet.<locals>.<lambda>�s���!4�$�t�*�*�!<��r-�	INETARRAY)�warnings�warn�DeprecationWarningrgr�r�r�rUrorVrqrX)�oidr[rrr\r]s     r,�
register_inetrv�s����O�O�O��M�M�>������������	�C�$���	'�	'���
��d�d������
�t�h��<�<�>�>�D�I��(�$��;��	�J�J�D�N���t�y�,�/�/�/���t�~�|�4�4�4��9�r-c��ddl}ddlm}m}m}		|���}||krdS||kr+|�|���ggg��nI||kr+|�g|���gg��n|�d|�����n$#t$r|�	��Y��wxYw��)aRWait until a connection or cursor has data available.

    The function is an example of a wait callback to be registered with
    `~psycopg2.extensions.set_wait_callback()`. This function uses
    :py:func:`~select.select()` to wait for data to become available, and
    therefore is able to handle/receive SIGINT/KeyboardInterrupt.
    rN)�POLL_OK�	POLL_READ�
POLL_WRITETzbad state from poll: )
�select�psycopg2.extensionsrxryrz�pollr9�OperationalError�KeyboardInterrupt�cancel)rhr{rxryrz�states      r,�wait_selectr��s����M�M�M�B�B�B�B�B�B�B�B�B�B��
	��I�I�K�K�E��������)�#�#��
�
�t�{�{�}�}�o�r�2�6�6�6�6��*�$�$��
�
�b�4�;�;�=�=�/�2�6�6�6�6��+�+�,K�E�,K�,K�L�L�L��� �	�	�	��K�K�M�M�M��H�	����s�B(�A:B(�(C	�C	c���|�tjd���t|d��r#|j}|�t
���}n|}|�t
���}||fS)zEReturn the connection and a DBAPI cursor from a connection or cursor.Nz no connection or cursor providedrT)rI)rr�r�rrr�)r[rhr�s   r,�_solve_conn_cursr�sk�����'�(J�K�K�K��|�Y�'�'�3��&���{�{�'�{�2�2������{�{�'�{�2�2����:�r-c��eZdZdZd�Zd�Zd�Zd�ZeZe	j
de	j��Ze
e	j
d��fd���Ze
d	���Ze
d
���ZdS)�
HstoreAdapterz)Adapt a Python dict to the hstore syntax.c��||_dSr/)�wrapped)r(r�s  r,r%zHstoreAdapter.__init__s
������r-c�P�||_|jjdkr|j|_dSdS)Ni�_)rh�info�server_version�_getquoted_8rNrgs  r,rizHstoreAdapter.prepares1����	��9�#�e�+�+�!�.�D�N�N�N�,�+r-c���|jsdStj}g}|j���D]�\}}||��}|�|j��|���}|�:||��}|�|j��|���}nd}|�d|zdz|zdz����dd�|��zdzS)z*Use the operators available in PG pre-9.0.�
''::hstoreNsNULL�(s => �)s||)	r�r�r	rxrirhrNr��join)r(r	�rvr6rns     r,r�zHstoreAdapter._getquoted_8 s����|�	!� �=��
��
���L�&�&�(�(�
	5�
	5�D�A�q���a���A�
�I�I�d�i� � � ����
�
�A��}��E�!�H�H���	�	�$�)�$�$�$��K�K�M�M�����
�I�I�d�Q�h��(�1�,�t�3�4�4�4�4��e�j�j��n�n�$�t�+�+r-c��|jsdStjt|j�������}|�|j��tjt|j�������}|�|j��d|���zdz|���zdzS)z(Use the hstore(text[], text[]) function.r�shstore(s, r�)	r�r�r	r�r|rirhrrN)r(r6rns   r,�_getquoted_9zHstoreAdapter._getquoted_98s����|�	!� �=��J�t�D�L�-�-�/�/�0�0�1�1��	�	�	�$�)�����J�t�D�L�/�/�1�1�2�2�3�3��	�	�	�$�)�����A�K�K�M�M�)�E�1�A�K�K�M�M�A�D�H�Hr-am
        # hstore key:
        # a string of normal or escaped chars
        "((?: [^"\\] | \\. )*)"
        \s*=>\s* # hstore value
        (?:
            NULL # the value can be null - not catched
            # or a quoted string like the key
            | "((?: [^"\\] | \\. )*)"
        )
        (?:\s*,\s*|$) # pairs separated by comma or end of string.
    z\\(.)c���|�dSi}d}|j�|��D]�}|�|���|krtjd|�����|�d|�d����}|�d��}|�|�d|��}|||<|���}��|t|��krtjd|�����|S)z�Parse an hstore representation in a Python string.

        The hstore is represented as something like::

            "a"=>"1", "b"=>"2"

        with backslash-escaped strings.
        Nrz"error parsing hstore pair at char �\1r�z/error parsing hstore: unparsed data after char )	�
_re_hstore�finditer�startr�InterfaceErrorr��group�endr_)	r(r��cur�_bsdecr�r��mr6rns	         r,�parsezHstoreAdapter.parseRs��
�9��4�
������)�)�!�,�,�
	�
	�A��y�A�G�G�I�I��.�.��-�@��@�@�B�B�B��
�
�5�!�'�'�!�*�*�-�-�A�����
�
�A��}��J�J�u�a�(�(���B�q�E��E�E�G�G�E�E��3�q�6�6�>�>��)�I�%�I�I�K�K�
K��	r-c��|�dS|�tj|jj��}|�||��S)z2Parse an hstore returning unicode keys and values.N)r�r�r�rr�r�)r(r�r�s   r,�
parse_unicodezHstoreAdapter.parse_unicodess?��
�9��4�
�H�H�T�^�C�N�$;�<�=�=���z�z�!�S�!�!�!r-c��t|��\}}|j}|jjdkrdpd}gg}}|�d|�d���|D]8}|�|d��|�|d���9|tjkr|js|�	��t|��t|��fS)zBReturn the lists of OID of the hstore and hstore[] types.
        �9�typarray�NULLzSELECT t.oid, z\
FROM pg_type t JOIN pg_namespace ns
    ON typnamespace = ns.oid
WHERE typname = 'hstore';
rr)r��statusr�r�rTr�r��STATUS_IN_TRANSACTION�
autocommit�rollbackr�)	r(r[rhr��conn_statusr��rv0�rv1rZs	         r,�get_oidszHstoreAdapter.get_oids|s���&�l�3�3�
��d��k���9�+�u�4�C��M�v���r�S��	
��������	�	�	�
�	 �	 �D��J�J�t�A�w�����J�J�t�A�w�����
�4�5�5�5���
6��M�M�O�O�O��S�z�z�5��:�:�%�%r-N)r?r@rArBr%rir�r�rN�_re�compile�VERBOSEr�r�r�r�r�r�r-r,r�r�s�������3�3����/�/�/�,�,�,�0	I�	I�	I��I�����

����J��#.�3�;�x�#8�#8�����[��@�"�"��[�"��&�&��[�&�&�&r-r�Fc�L�|�Ht�|��}|�|dstjd���|d}|d}t	|t
��r|f}|�2t	|t
��r|f}nt
d�|D����}tj|dtj	��}tj
||r|pd��tjtt��|r2tj
|d|��}tj
||r|pd��dSdS)aRegister adapter and typecaster for `!dict`\-\ |hstore| conversions.

    :param conn_or_curs: a connection or cursor: the typecaster will be
        registered only on this object unless *globally* is set to `!True`
    :param globally: register the adapter globally, not only on *conn_or_curs*
    :param unicode: if `!True`, keys and values returned from the database
        will be `!unicode` instead of `!str`. The option is not available on
        Python 3
    :param oid: the OID of the |hstore| type if known. If not, it will be
        queried on *conn_or_curs*.
    :param array_oid: the OID of the |hstore| array type if known. If not, it
        will be queried on *conn_or_curs*.

    The connection or cursor passed to the function will be used to query the
    database and look for the OID of the |hstore| type (which may be different
    across databases). If querying is not desirable (e.g. with
    :ref:`asynchronous connections <async-support>`) you may specify it in the
    *oid* parameter, which can be found using a query such as :sql:`SELECT
    'hstore'::regtype::oid`. Analogously you can obtain a value for *array_oid*
    using a query such as :sql:`SELECT 'hstore[]'::regtype::oid`.

    Note that, when passing a dictionary from Python to the database, both
    strings and unicode keys and values are supported. Dictionaries returned
    from the database have keys/values according to the *unicode* parameter.

    The |hstore| contrib module must be already installed in the database
    (executing the ``hstore.sql`` script in your ``contrib`` directory).
    Raise `~psycopg2.ProgrammingError` if the type is not found.
    Nrz\hstore type not found in the database. please install it from your 'contrib/hstore.sql' filerc��g|]}|�|��Sr�r�)rrrks  r,r�z#register_hstore.<locals>.<listcomp>�s��9�9�9�Q�q�9�q�9�9�9r-�HSTORE�HSTOREARRAY)r�r�rr�rgrhr�r�rUr�rXrY�dictrV)r[�globally�unicoderu�	array_oidr�r�s       r,�register_hstorer��sI��>�{��$�$�\�2�2���;�c�!�f�;��+�H�I�I�
I��A��I��a�&�C��#�s�����f�����i��%�%�	;�"��I�I��9�9�)�9�9�9�:�:�I��]�3��-�*=�
>�
>�F���v�8�|�<��D��E�E�E���$�
�.�.�.��O��)�)�]�F�K�K����;�H��(E��(M��N�N�N�N�N�O�Or-c��eZdZdZdd�Zd�Zd�Zejdej	��Z
ejd��Zed���Z
d	�Zed
���ZdS)�CompositeCasteramHelps conversion of a PostgreSQL composite type into a Python object.

    The class is usually created by the `register_composite()` function.
    You may want to create and register manually instances of the class if
    querying the database at registration time is not desirable (such as when
    using an :ref:`asynchronous connections <async-support>`).

    Nc�X�||_||_||_||_d�|D��|_d�|D��|_|�||j��tj|f||j	��|_
|r&tj|f|�d�|j
��|_dSd|_dS)Nc��g|]
}|d��Sr�r��rr�as  r,r�z,CompositeCaster.__init__.<locals>.<listcomp>����-�-�-�!��1��-�-�-r-c��g|]
}|d��S)rr�r�s  r,r�z,CompositeCaster.__init__.<locals>.<listcomp>�r�r-�ARRAY)
�name�schemarur��attnames�atttypes�_create_typer�rUr��
typecasterrV�array_typecaster)r(r�ru�attrsr�r�s      r,r%zCompositeCaster.__init__�s�����	�������"���-�-�u�-�-�-��
�-�-�u�-�-�-��
����$��
�.�.�.��-����d�j�A�A����	)�$(�$7����n�n�n�d�o�%?�%?�D�!�!�!�%)�D�!�!�!r-c�h��|�dS|�|��}t|��t|j��kr>tjdt|j��|jt|��fz����fd�t
|j|��D��}|�|��S)Nz9expecting %d components for the type %s, %d found insteadc�B��g|]\}}��||����Sr�)�cast)rrru�tokenr�s   �r,r�z)CompositeCaster.parse.<locals>.<listcomp>�s;���:�:�:���U��)�)�C��'�'�:�:�:r-)�tokenizer_r�r�	DataErrorr��zip�make)r(r�r��tokensrs  `  r,r�zCompositeCaster.parse�s�����9��4����q�!�!���v�;�;�#�d�m�,�,�,�,��$�K��T�]�#�#�T�Y��F���<�=�>�>�
>�:�:�:�:�!�$�-��8�8�:�:�:���y�y�� � � r-c�,�|�|��S)aReturn a new Python object representing the data being casted.

        *values* is the list of attributes, already casted into their Python
        representation.

        You can subclass this method to :ref:`customize the composite cast
        <custom-composite>`.
        )�_ctor)r(rs  r,r�zCompositeCaster.makes���z�z�&�!�!�!r-z�
  \(? ([,)])                        # an empty token, representing NULL
| \(? " ((?: [^"] | "")*) " [,)]    # or a quoted string
| \(? ([^",)]+) [,)]                # or an unquoted string
    z	(["\\])\1c	���g}|j�|��D]�}|�tjd|�����|�d���|�d���F|�d���B|�|j�d|�d��������|�|�d������|S)Nzcan't parse type: rr�r��)�_re_tokenizer�rr�r�r��_re_undoubler�)r(r�r�r�s    r,r�zCompositeCaster.tokenizes���
���"�+�+�A�.�.�	&�	&�A��y��-�.H�1�.H�.H�I�I�I��w�w�q�z�z�%��	�	�$�����������'��	�	�$�+�/�/��q�w�w�q�z�z�B�B�C�C�C�C��	�	�!�'�'�!�*�*�%�%�%�%��	r-c��t�d|��}t||��|_|jj|_dS)Nr�)r�r�rr,r�r�)r(r�r�s   r,r�zCompositeCaster._create_type#s5���}�}�S�$�'�'���t�X�.�.��	��Y�_��
�
�
r-c��t|��\}}|j}d|vr|�dd��\}}n|}d}|jjdkrdpd}|�d|z||f��|���}	|	s�	d}
|jtjkr|�d	��d
}
|�d|z|f��|���}	|	r|	dd
}|	dd}n#tj
$rYnwxYw|
r|�d��n#|
r|�d��wwxYw|tjkr|js|���|	stj
d|�d����|	dd}|	dd}d�|	D��}
||||
||���S)z}Return a `CompositeCaster` instance for the type *name*.

        Raise `ProgrammingError` if the type is not found.
        �.r�publicr�r�r�z�SELECT t.oid, %s, attname, atttypid
FROM pg_type t
JOIN pg_namespace ns ON typnamespace = ns.oid
JOIN pg_attribute a ON attrelid = typrelid
WHERE typname = %%s AND nspname = %%s
    AND attnum > 0 AND NOT attisdropped
ORDER BY attnum;
FzSAVEPOINT register_typeTz�SELECT t.oid, %s, attname, atttypid, typname, nspname
FROM pg_type t
JOIN pg_namespace ns ON typnamespace = ns.oid
JOIN pg_attribute a ON attrelid = typrelid
WHERE t.oid = %%s::regtype
    AND attnum > 0 AND NOT attisdropped
ORDER BY attnum;
r��z#ROLLBACK TO SAVEPOINT register_typezPostgreSQL type 'z' not foundc�.�g|]}|d|df��S)r�r�r�)rr�rs  r,r�z,CompositeCaster._from_db.<locals>.<listcomp>us$��1�1�1�q�q��t�Q�q�T�l�1�1�1r-)r�r�)
r�r�r.r�r�rTr9r�r�rr�r�r�)r(r�r[rhr�r�r��tnamer��recs�	savepoint�type_oidr��
type_attrss              r,�_from_dbzCompositeCaster._from_db(sS��&�l�3�3�
��d��k���$�;�;� �J�J�s�A�.�.�M�F�E�E��E��F��9�+�u�4�C��M�v��	
���������	!�	!�	!��}�}�����	H�
H�!�	��;�$�"<�<�<��L�L�!:�;�;�;� $�I�������������}�}�����(� ��G�A�J�E�!�!�W�Q�Z�F���
�,�
�
�
���
�����H��L�L�!F�G�G�G����H��L�L�!F�G�G�G�G�H�����$�4�4�4�T�_�4��M�M�O�O�O��	7��+�5�D�5�5�5�7�7�
7���7�1�:����G�A�J�	�1�1�D�1�1�1�
��t�E�8�Z���0�0�0�	0s+�AC=�
3D*�=D�D*�D�D*�*Er:)r?r@rArBr%r�r�r�r�r�r�r�r�r�r�r�r�r-r,r�r��s���������)�)�)�)� 
!�
!�
!�
"�
"�
"��3�;� �

��	��L��3�;�|�,�,�L�����[��%�%�%�
�O0�O0��[�O0�O0�O0r-r�c���|�t}|�||��}tj|j|r|pd��|j�tj|j|r|pd��|S)aRegister a typecaster to convert a composite type into a tuple.

    :param name: the name of a PostgreSQL composite type, e.g. created using
        the |CREATE TYPE|_ command
    :param conn_or_curs: a connection or cursor used to find the type oid and
        components; the typecaster is registered in a scope limited to this
        object, unless *globally* is set to `!True`
    :param globally: if `!False` (default) register the typecaster only on
        *conn_or_curs*, otherwise register it globally
    :param factory: if specified it should be a `CompositeCaster` subclass: use
        it to :ref:`customize how to cast composite types <custom-composite>`
    :return: the registered `CompositeCaster` or *factory* instance
        responsible for the conversion
    N)r�r�r�rXr�r�)r�r[r��factory�casters     r,�register_compositer�{s�����!��
�
�
�d�L�
1�
1�F���v�(�h�,�*G�<�*O�4�P�P�P�
��*����#��\�%B�l�%J�d�	L�	L�	L��Mr-c#��K�g}t|��}		t|��D]$}|�t|�����%|V�g}n#t$r
|r|V�YdSwxYw�T)zwConsume an iterable and return it in chunks.

    Every chunk is at most `page_size`. Never return an empty chunk.
    TN)rzr^r�r<r=)�seq�	page_size�pager�r`s     r,�	_paginater��s�����
�D�	
�c���B�	�	��9�%�%�
&�
&�����D��H�H�%�%�%�%��J�J�J��D�D���	�	�	��
��
�
�
��F�F�	����
	s�:A�A%�$A%�dc����t||���D]9}��fd�|D��}��d�|�����:dS)a�Execute groups of statements in fewer server roundtrips.

    Execute *sql* several times, against all parameters set (sequences or
    mappings) found in *argslist*.

    The function is semantically similar to

    .. parsed-literal::

        *cur*\.\ `~cursor.executemany`\ (\ *sql*\ , *argslist*\ )

    but has a different implementation: Psycopg will join the statements into
    fewer multi-statement commands, each one containing at most *page_size*
    statements, resulting in a reduced number of server roundtrips.

    After the execution of the function the `cursor.rowcount` property will
    **not** contain a total result.

    �r�c�<��g|]}���|����Sr�)�mogrify)rrr)r��sqls  ��r,r�z!execute_batch.<locals>.<listcomp>�s'���8�8�8�4����C��&�&�8�8�8r-�;N)r�rTr�)r�r��argslistr�r��sqlss``    r,�
execute_batchr��sg����(�(�i�8�8�8�%�%��8�8�8�8�8�4�8�8�8�����D�I�I�d�O�O�$�$�$�$�%�%r-c	���ddlm}t||��r|�|��}t|t��s/|�tj|jj	��}t|��\}}|rgnd}	t||���D]�}
|�2dd�dgt|
d��z��zdz}|dd�}|
D]@}|�|�||����|�d���A||d	d�<|�d
�|����|r'|	�|�������|	S)aA	Execute a statement using :sql:`VALUES` with a sequence of parameters.

    :param cur: the cursor to use to execute the query.

    :param sql: the query to execute. It must contain a single ``%s``
        placeholder, which will be replaced by a `VALUES list`__.
        Example: ``"INSERT INTO mytable (id, f1, f2) VALUES %s"``.

    :param argslist: sequence of sequences or dictionaries with the arguments
        to send to the query. The type and content must be consistent with
        *template*.

    :param template: the snippet to merge to every item in *argslist* to
        compose the query.

        - If the *argslist* items are sequences it should contain positional
          placeholders (e.g. ``"(%s, %s, %s)"``, or ``"(%s, %s, 42)``" if there
          are constants value...).

        - If the *argslist* items are mappings it should contain named
          placeholders (e.g. ``"(%(id)s, %(f1)s, 42)"``).

        If not specified, assume the arguments are sequence and use a simple
        positional template (i.e.  ``(%s, %s, ...)``), with the number of
        placeholders sniffed by the first element in *argslist*.

    :param page_size: maximum number of *argslist* items to include in every
        statement. If there are more items the function will execute more than
        one statement.

    :param fetch: if `!True` return the query results into a list (like in a
        `~cursor.fetchall()`).  Useful for queries with :sql:`RETURNING`
        clause.

    .. __: https://www.postgresql.org/docs/current/static/queries-values.html

    After the execution of the function the `cursor.rowcount` property will
    **not** contain a total result.

    While :sql:`INSERT` is an obvious candidate for this function it is
    possible to use it with other statements, for example::

        >>> cur.execute(
        ... "create table test (id int primary key, v1 int, v2 int)")

        >>> execute_values(cur,
        ... "INSERT INTO test (id, v1, v2) VALUES %s",
        ... [(1, 2, 3), (4, 5, 6), (7, 8, 9)])

        >>> execute_values(cur,
        ... """UPDATE test SET v1 = data.v1 FROM (VALUES %s) AS data (id, v1)
        ... WHERE test.id = data.id""",
        ... [(1, 20), (4, 50)])

        >>> cur.execute("select * from test order by id")
        >>> cur.fetchall()
        [(1, 20, 3), (4, 50, 6), (7, 8, 9)])

    r)�
ComposableNr�r��,s%sr����r-)�psycopg2.sqlr�rg�	as_stringr�rMr�r�rr��
_split_sqlr�r�r_r�r�rT�extendr9)
r�r�r��templater��fetchr��pre�post�resultr��partsr)s
             r,�execute_valuesr�sy��x(�'�'�'�'�'��#�z�"�"�!��m�m�C� � ��
�c�5�!�!�B��j�j�����(?�@�A�A���3���I�C���
"�R�R�d�F��(�i�8�8�8�
*�
*�����d�i�i���#�d�1�g�,�,�(>�?�?�?�$�F�H��A�A�A����	�	�D��L�L����X�t�4�4�5�5�5��L�L��������b�c�c�
����C�H�H�U�O�O�$�$�$��	*��M�M�#�,�,�.�.�)�)�)���Mr-c���gx}}g}tjd|��}|D]�}t|��dks|dd�dkr|�|���9|dd�dkr||ur|}�Nt	d���|dd�dkr|�d����t	d|dd��d	d
��z���||urt	d���||fS)z�Split *sql* on a single ``%s`` placeholder.

    Split on the %s, perform %% replacement and return pre, post lists of
    snippets.
    s(%.)r�Nr�%�sz1the query contains more than one '%s' placeholderz"unsupported format character: '%s'�asciir�z.the query doesn't contain any '%s' placeholder)r�r.r_r��
ValueErrorr�)r��currrrr�r�s      r,rrs$���O�D�3�
�D�
�Y�x��
%�
%�F��8�8���u�:�:��?�?�e�B�Q�B�i�4�/�/��K�K����������9�����s�{�{���� �G�I�I�I�
�1�2�2�Y�$�
�
��K�K�������A�����)�"�"�7�I�6�6�7�8�8�
8��s�{�{��I�J�J�J���9�r-�[z  !"#$%&'()*+,-./:;<=>?@[\]^`{|}~�]r:)FFNN)FN)r�)Nr�F)VrB�osr�rr��rer��collectionsrr�loggingr�rrr�rr�r�_connectionr	r0r
�	functoolsr�psycopg2._psycopgrr
r�_replicationConnectionr�_replicationCursorr�psycopg2._jsonrrrrr�psycopg2._rangerrrrrrrr�psycopg2._ipaddressrr rFrKr�rPr�r�r�r�r�r�r�r�r�r�rrrr�rr<r^r`rvr�r�r�r�r�r�r�r�rrr��escaper�r�r-r,�<module>r!s�����8������������/�/�/�/�/�/�/�/���������'�'�'�'�'�'�)�)�)�)�)�)�1�1�1�1�1�1�0�0�0�0�0�0�0�0���������������������N�N�N�N�N�N�N�N�N�N�N�N�N�N�
/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�3�2�2�2�2�2�9�9�9�9�9�W�9�9�9�x/�/�/�/�/�[�/�/�/�)�)�)�)�)��)�)�)�83�3�3�3�3�d�3�3�3�l/�/�/�/�/��/�/�/�)�)�)�)�)�^�)�)�)�8 (� (� (� (� (�+� (� (� (�F/�/�/�/�/�;�/�/�/�U�U�U�U�U�w�U�U�U�p��3��� � ��� �$/�;��#?�#?�� �0/�0/�0/�0/�0/��0/�0/�0/�f
2�
2�
2�
2�
2�G�
2�
2�
2� ?�?�?�?�?�0�?�?�?�8	<�	<�	<�	<�	<�=�	<�	<�	<�*�*�*�*�*�#9�*�*�*�*�*�*�*�*�$:�*�*�*�		�		�		�		�		�i�		�		�		�c(�c(�c(�c(�c(�*�c(�c(�c(�P'�'�'�'�'�'�'�'�*����D��������>����B���8���E&�E&�E&�E&�E&�E&�E&�E&�P;@�(,�9O�9O�9O�9O�x`0�`0�`0�`0�`0�`0�`0�`0�F����8���&%�%�%�%�2T�T�T�T�n���B
�C�K��*�#�*�9�
:�
:�:�S�@�
B�
B�	�	�	r-

Hacked By AnonymousFox1.0, Coded By AnonymousFox