https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/__pycache__/pgdb.cpython-310.pyc
o

���^O��@s$dZddlmZmZzddlTWnTeydddlZddlZejdkraej	dkraej
d�ej�D],Z
ej
�ej
�e
d��r^e�ej
�e
���ddlTWd�n1sWwYnq2�n�YnweZgd	�Zdd
lmZmZmZmZmZddlmZddlmadd
lmZddl m!Z!m"Z"zddl#m$Z$Wney�ddl%m$Z$Ynwddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z-ddl.m/Z0m1Z2ze3Wne4y�e5Z3Ynwze6Wne4y�e7Z6Ynwze8Wn
e4y�e7e9fZ8Ynwzddl)m:Z:Wn/e�y4ddl)m;Z;zddl<m=Z=Wne�y,Gdd�d�Z=Ynwd�dd�Z:YnwdZ>dZ?dZ@dZAzdd lBmCZCWne�yYdd!lBmDZDd"d#�ZEYnwd$d#�ZEzdd%lmFZFWne�y�Gd&d'�d'e�ZFeFed�d(�eF_Gd)ZHYnwd*ZHeId+d,d-d.d/d+d0d.d.d.d1�
ZJd2d3�ZKd4d5�ZLd�d6d7�ZMd8d9�ZNd:d;�ZOd<d=�ZPd>d?�ZQd@dA�ZRe-dB�ZSdCdD�ZTdEdF�ZUdGdH�ZVe-dI�ZWe-dJ�ZXe-dK�ZYe-dL�ZZdMdN�Z[GdOdP�dPeI�Z\e\�Z]dQdR�Z^dSdT�Z_d�dUdV�Z`GdWdX�dXe\�ZaGdYdZ�dZe7�Zbe&d[d\d]g�ZcGd^d_�d_eI�ZdGd`da�daeI�Zeeffdbdc�Zgddde�Zhe-df�Zie:dgdh�didj��ajdkdl�ZkGdmdn�dnel�Zme&dogdp��ZnGdqdr�drel�ZoepZq			d�dsdt�ZpGdudv�dver�ZsGdwdx�dx�ZtGdydz�dz�Zuesd{�Zvesd|�Zwesd}�Zxesd~�Zyesd�Zzesd��Z{esd��Z|esd��Z}esd��Z~esd��Zesd��Z�esd��Z�esd��Z�esd��Z�esd��Z�esd��Z�esd��Zesd��Z�esd��Z�et�Z�eu�Z�d�d��Z�d�d�d��Z�		d�d�d��Z�d�d��Z�d�d��Z�d�d��Z�Gd�d��d�e9�Z�d�d�d��Z�eZGd�d��d�eI�Z�Gd�d��d��Z�Gd�d��d��Z�e�d�k�re�d�e�e�d��e�e�dSdS)�aBpgdb - DB-API 2.0 compliant module for PyGreSQL.

(c) 1999, Pascal Andre <andre@via.ecp.fr>.
See package documentation for further information on copyright.

Inline documentation is sparse.
See DB-API 2.0 specification for usage information:
http://www.python.org/peps/pep-0249.html

Basic usage:

    pgdb.connect(connect_string) # open a connection
    # connect_string = 'host:database:user:password:opt'
    # All parts are optional. You may also pass host through
    # password as keyword arguments. To pass a port,
    # pass it in the host keyword parameter:
    connection = pgdb.connect(host='localhost:5432')

    cursor = connection.cursor() # open a cursor

    cursor.execute(query[, params])
    # Execute a query, binding params (a dictionary) if they are
    # passed. The binding syntax is the same as the % operator
    # for dictionaries, and no quoting is done.

    cursor.executemany(query, list of params)
    # Execute a query many times, binding each param dictionary
    # from the list.

    cursor.fetchone() # fetch one row, [value, value, ...]

    cursor.fetchall() # fetch all rows, [[value, value, ...], ...]

    cursor.fetchmany([size])
    # returns size or cursor.arraysize number of rows,
    # [[value, value, ...], ...] from result set.
    # Default cursor.arraysize is 1.

    cursor.description # returns information about the columns
    #	[(column_name, type_name, display_size,
    #		internal_size, precision, scale, null_ok), ...]
    # Note that display_size, precision, scale and null_ok
    # are not implemented.

    cursor.rowcount # number of rows available in the result set
    # Available after a call to execute.

    connection.commit() # commit transaction

    connection.rollback() # or rollback transaction

    cursor.close() # close the cursor

    connection.close() # close the connection
�)�print_function�division)�*N�nt)���PATHz	libpq.dll)6�
Connection�Cursor�Date�Time�	Timestamp�
DateFromTicks�
TimeFromTicks�TimestampFromTicks�Binary�Interval�Uuid�Hstore�Json�Literal�Type�STRING�BINARY�NUMBER�DATETIME�ROWID�BOOL�SMALLINT�INTEGER�LONG�FLOAT�NUMERIC�MONEY�DATE�TIME�	TIMESTAMP�INTERVAL�UUID�HSTORE�JSON�ARRAY�RECORD�Error�Warning�InterfaceError�
DatabaseError�	DataError�OperationalError�IntegrityError�ProgrammingError�NotSupportedError�apilevel�connect�
paramstyle�threadsafety�get_typecast�set_typecast�reset_typecast�version�__version__)�date�time�datetime�	timedelta�tzinfo)�	localtime)�Decimal)r()�isnan�isinf)�Iterable��
namedtuple)�	iskeyword)�partial)�compile)�loads�dumps)�	lru_cache)�update_wrapper)�RLockc@seZdZdd�Zdd�ZdS)rRcC�dS�N���selfrUrU�&/usr/lib/python3/dist-packages/pgdb.py�	__enter__��zRLock.__enter__cCrSrTrU)rW�exctype�excinst�exctbrUrUrX�__exit__�rZzRLock.__exit__N)�__name__�
__module__�__qualname__rYr^rUrUrUrXrR�srR�cs�fdd�}|S)z:Simplified functools.lru_cache decorator for one argument.cs�t��i��j�t��g}|dg�||ddg|dd�<�dkr&�fdd�}n�dur4����fdd�}n������fdd�}�|_t|��S)NFrcs�|�}|SrTrU��arg�res)�functionrUrX�wrapper�sz-lru_cache.<locals>.decorator.<locals>.wrappercs*�|��}|�ur|S�|�}|�|<|SrTrUrc)�cacherf�get�sentinelrUrXrg�s
cs���?�|�}|dur:�d}|\}}}}||d<||d<|d}||d<|d<||d<||d<|Wd�SWd�n1sDwY�|�}��v�\}}|�vrYnT|r�|}	||	d<||	d<|	d}�d<|d}
|d}d|d<|d<�|
=|	�|<n8|d}||||g}||d<|d<�|<t���kr�d�d<Wd�|SWd�|SWd�|SWd�|S1s�wY|S)Nr��rT��len)rd�link�root�prev�next�_argre�last�full�oldroot�oldarg�oldres)rhrfri�lock�maxsize�	root_fullrUrXrg�s`��


��
��
��
��)�objectrirR�__wrapped__rQ)rfrprg�rz)rhrfriryr{rjrX�	decorator�s
$
zlru_cache.<locals>.decoratorrU)rzrrUr~rXrP�sBrPz2.0rk�pyformat)�	signature)�
getargspeccCs
t|�jSrT)r��args��funcrUrUrX�get_args��
r�cCstt|�j�SrT)�listr��
parametersr�rUrUrXr���)�timezonec@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)r�zSimple timezone implementation.NcCsf||_|s.|jjd|jjd}|dkr!t|d�\}}|}nt|d�\}}d||f}||_dS)Ni��<rz
UTC%+03d:%02d)�offset�days�seconds�divmod�name)rWr�r��minutes�hoursrUrUrX�__init__s
ztimezone.__init__cC�|jSrT)r��rW�dtrUrUrX�	utcoffset�ztimezone.utcoffsetcCr�rT�r�r�rUrUrX�tznamer�ztimezone.tznamecCrSrTrUr�rUrUrX�dstsztimezone.dstrT)r_r`ra�__doc__r�r�r�r�rUrUrUrXr��s
r��UTCFTz+0100z+0200z-0500�+0000z-1000z-0700)
�CET�EET�EST�GMT�HST�MET�MST�UCTr��WETcCs6|�d�rt|�dkr|dS|�dd�St�|d�S)N)�+�-��00�:�r�)�
startswithrn�replace�
_timezonesri)�tzrUrUrX�_timezone_as_offset!s

r�cCsNt|�}dt|dd��t|dd��}|ddkr|}tt|d�|�S)Nr�rkrr�rr�)r�)r��intr�rB)r�r�rUrUrX�
_get_timezone)s
$r�cCs|dur|atd|�tS)z�Get or set global type to be used for decimal values.

    Note that connections cache cast functions. To be sure a global change
    is picked up by a running connection, call con.type_cache.reset_typecast().
    N�numeric)rEr;)�decimal_typerUrUrXr�1s
r�cCs|r|ddvSdS)z.Cast boolean value in database format to bool.r)�t�TNrU��valuerUrUrX�	cast_bool>s�r�cCs,|r|�dd�}td�dd�|D���SdS)z/Cast money value in database format to Decimal.�(r�r�css$�|]
}|��s|dvr|VqdS)z.-N)�isdigit)�.0�crUrUrX�	<genexpr>H��"zcast_money.<locals>.<genexpr>N)r�rE�joinr�rUrUrX�
cast_moneyDs�r�cCsdd�|��D�S)zCast an int2vector value.cS�g|]}t|��qSrU�r��r��vrUrUrX�
<listcomp>M�z#cast_int2vector.<locals>.<listcomp>)�splitr�rUrUrX�cast_int2vectorK�r�cCsh|dkrtjS|dkrtjS|��}|ddkrtjS|d}t|�dkr(tjS|��}t�||���S)zCast a date value.�	-infinity�infinity����BCr�
)r?�min�maxr�rn�date_formatrA�strptime�r��
connection�fmtrUrUrX�	cast_datePsr�cCs$t|�dkrdnd}t�||���S)zCast a time value.r�%H:%M:%S.%f�%H:%M:%S)rnrAr�r@)r�r�rUrUrX�	cast_timedsr�z(.*)([+-].*)cCsxt�|�}|r|��\}}nd}t|�dkrdnd}tr.|t|�7}|d7}t�||���St�||���j	t
|�d�S)zCast a timetz value.r�rr�r��%z�rC)�_re_timezone�match�groupsrn�
_has_timezoner�rAr��timetzr�r�)r�r�r�rUrUrX�cast_timetzms
�r�cCs�|dkrtjS|dkrtjS|��}|ddkrtjS|��}|�d�rRt|�dkrR|dd�}t|d	�d
kr;tjS|�d�rBdnd
t|d�dkrMdnddg}nt|d�dkr]tjS|t|d�dkrhdndg}t�d�	|�d�	|��S)zCast a timestamp value.r�r�r�r��-%Yrlrkr�r��%d�%d %b�%b %drr�r��%Yrr�� )
rAr�r�r�r��endswithrnr�r�r�r�rUrUrX�cast_timestamp}s&�r�cCs�|dkrtjS|dkrtjS|��}|ddkrtjS|��}|�d�r]t|�dkr]|dd�}t|d	�d
kr;tjS|�d�rBdnd
t|d�dkrMdnddg}|dd�|d}}n>|�d�rwt�	|d�}|rt|�
�\|d<}nd}n|dd�|d}}t|d�dkr�tjS|t|d�dkr�dndg}tr�|�t
|��|�d�t�d�|�d�|��St�d�|�d�|��jt|�d�S)zCast a timestamptz value.r�r�r�r�r�rlrkNrr�r�r�r�rr�r�r�z%Y-r�rr�r�r�r�)rAr�r�r�r�r�rnr�r�r�r�r��appendr�r�r�r�r�)r�r�r�r�rUrUrX�cast_timestamptz�s@�

�r�zm(?:([+-])?([0-9]+)-([0-9]+) ?)?(?:([+-]?[0-9]+)(?!:) ?)?(?:([+-])?([0-9]+):([0-9]+):([0-9]+)(?:\.([0-9]+))?)?z�(?:([+-]?[0-9]+) ?years? ?)?(?:([+-]?[0-9]+) ?mons? ?)?(?:([+-]?[0-9]+) ?days? ?)?(?:([+-])?([0-9]+):([0-9]+):([0-9]+)(?:\.([0-9]+))?)?z�@ ?(?:([+-]?[0-9]+) ?years? ?)?(?:([+-]?[0-9]+) ?mons? ?)?(?:([+-]?[0-9]+) ?days? ?)?(?:([+-]?[0-9]+) ?hours? ?)?(?:([+-]?[0-9]+) ?mins? ?)?(?:([+-])?([0-9]+)(?:\.([0-9]+))? ?secs?)? ?(ago)?z�P(?:([+-]?[0-9]+)Y)?(?:([+-]?[0-9]+)M)?(?:([+-]?[0-9]+)D)?(?:T(?:([+-]?[0-9]+)H)?(?:([+-]?[0-9]+)M)?(?:([+-])?([0-9]+)(?:\.([0-9]+))?S)?)?c
Cs&t�|�}|r0dd�|��D�}|�d�dk}dd�|D�}|\}}}}}}}	|r/|}|	}	n�t�|�}|rsdd�|��dd�D�|�d	�}}
|�d�dk}|
rZd
d�|D�ndd�|D�}|\}}}}}}}	|rr|}|	}	n�t�|�}|r�t|���r�dd�|��D�}|�d
�dk}dd�|D�}|\}}}}}}}	|r�|}|}|}|	}	nQt�|�}|r�t|���r�dd�|��D�}|�d�dk}|�d
�dk}dd�|D�}|\}}}}}}}	|r�|}|}|r�|}|}|}|	}	nt	d|��|d|d|7}t
|||||	d�S)zCast an interval value.cS�g|]}|pd�qS��0rU�r��drUrUrXr��r�z!cast_interval.<locals>.<listcomp>r�r�cSr�rUr�r�rUrUrXr��r�cSr�r�rUr�rUrUrXr��r�Nr�	cSsg|]}t|��qSrUr�r�rUrUrXr���cSr�rUr�r�rUrUrXr��r�cSr�r�rUr�rUrUrXr��r�rcSr�rUr�r�rUrUrXr��r�cSr�r�rUr�rUrUrXr��r�rcSr�rUr�r�rUrUrXr��r�zCannot parse interval: %sim��r�r�r�r��microseconds)�_re_interval_iso_8601r�r��pop�_re_interval_postgres_verbose�group�_re_interval_postgres�any�_re_interval_sql_standard�
ValueErrorrB)
r��m�secs_ago�years�monsr�r��mins�secs�usecs�ago�	hours_ago�	years_agorUrUrX�
cast_interval�sj
�
& �
�
��r
c@s�eZdZdZide�de�de�de�de�de�de�d	e�d
e�de�de�d
e�de	�de
�de
�de�de�ee
eeeeeeeeeed��ZdZdd�Zedd��Zdd�Zd%dd�Zdd�Zd%dd �Z d!d"�Z!d#d$�Z"dS)&�	Typecastsa@Dictionary mapping database types to typecast functions.

    The cast functions get passed the string representation of a value in
    the database which they need to convert to a Python object.  The
    passed string will never be None since NULL values are already
    handled before the cast function is called.
    �char�bpcharr��text�varchar�bool�bytea�int2�int4�serial�int8�oid�hstore�json�jsonb�float4�float8)r��moneyr?�intervalr@r��	timestamp�timestamptz�
int2vector�uuid�anyarray�recordNcCspt|t�std|��|j�|�}|r|�|�}|||<|S|�d�r6||dd�}|�|�}|r6|||<|S)z�Create a cast function if it is not cached.

        Note that this class never raises a KeyError,
        but returns None when no special cast function exists.
        zInvalid type: %s�_rkN)�
isinstance�str�	TypeError�defaultsri�_add_connectionr��create_array_cast)rW�typ�cast�	base_castrUrUrX�__missing__*s


�
zTypecasts.__missing__c	Cs6zt|�}WnttfyYdSwd|dd�vS)z9Check if a typecast function needs a connection argument.Fr�rkN)r�r*r)r�r�rUrUrX�_needs_connection@s�zTypecasts._needs_connectioncCs"|jr|�|�s
|St||jd�S)z@Add a connection argument to the typecast function if necessary.)r�)r�r2rL)rWr/rUrUrXr,JszTypecasts._add_connectioncCs||p|S�z6Get the typecast function for the given database type.rU)rWr.�defaultrUrUrXriP�z
Typecasts.getcCs~t|t�r|g}|dur!|D]}|�|d�|�d|d�qdSt|�s)td��|D]}|�|�||<|�d|d�q+dS)�;Set a typecast function for the specified database type(s).N�_%szCast parameter must be callable)r(�
basestringr��callabler*r,)rWr.r/r�rUrUrX�setTs
��z
Typecasts.setcCs�|j}|dur|��|�|�dSt|t�r|g}|D]8}|�|�}|rF|�|�||<d|}|�|�}|r?|�|�||<q|�|d�q|�|d�|�d|d�qdS)z�Reset the typecasts for the specified type(s) to their defaults.

        When no type is specified, all typecasts will be reset.
        Nr7)r+�clear�updater(r8rir,r�)rWr.r+r�r/rUrUrX�resetcs$


�zTypecasts.resetcs|d���fdd�}|S)z1Create an array typecast for the given base cast.r%cs
�|��SrTrU�r���basecast�
cast_arrayrUrXr/�r�z)Typecasts.create_array_cast.<locals>.castrU)rWr@r/rUr?rXr-}szTypecasts.create_array_castcs&|d�t||�����fdd�}|S)z>Create a named record typecast for the given fields and casts.r&cs��|���SrTrUr>��cast_record�castsr&rUrXr/�r�z*Typecasts.create_record_cast.<locals>.castrI)rWr��fieldsrDr/rUrBrX�create_record_cast�s
zTypecasts.create_record_castrT)#r_r`rar�r)r��unescape_bytear��long�cast_hstore�
jsondecode�floatrEr�r�r
r�r�r�r�r�rrArCr+r�r1�staticmethodr2r,rir:r=r-rFrUrUrUrXrs`
���������������

	

rcCs
t�|�S)z@Get the global typecast function for the given database type(s).��
_typecastsri�r.rUrUrXr:��
r:cCst�||�dS)z�Set a global typecast function for the given database type(s).

    Note that connections cache cast functions. To be sure a global change
    is picked up by a running connection, call con.type_cache.reset_typecast().
    N�rNr:)r.r/rUrUrXr;�sr;cCst�|�dS)a Reset the global typecasts for the given type(s) to their default.

    When no type is specified, all typecasts will be reset.

    Note that connections cache cast functions. To be sure a global change
    is picked up by a running connection, call con.type_cache.reset_typecast().
    N�rNr=rOrUrUrXr<�sr<c@s(eZdZdZeZdZdd�Zdd�ZdS)�LocalTypecastszBMap typecasts, including local composite types, to cast functions.Ncs�|�d�r�|dd�}��|�}|r|�|<|S�j�|�}|r-��|�}|�|<|S��|�}|rO�fdd�|D�}dd�|D�}��|||�}|�|<|S)z+Create a cast function if it is not cached.r'rkNcsg|]}�|j�qSrU)�type�r��fieldrVrUrXr��r�z.LocalTypecasts.__missing__.<locals>.<listcomp>cSsg|]}|j�qSrUr�rUrUrUrXr��s)r�r-r+rir,�
get_fieldsrF)rWr.r0r/rErDrUrVrXr1�s$


�

�zLocalTypecasts.__missing__cCsgS)z�Return the fields for the given record type.

        This method will be replaced with a method that looks up the fields
        using the type cache of the connection.
        rU�rWr.rUrUrXrW�szLocalTypecasts.get_fields)	r_r`rar�rNr+r�r1rWrUrUrUrXrS�srSc@seZdZdZedd��ZdS)�TypeCodez�Class representing the type_code used by the DB-API 2.0.

    TypeCode objects are strings equal to the PostgreSQL type name,
    but carry some additional information.
    c	Cs0||�}||_||_||_||_||_||_|S)z.Create a type code for a PostgreSQL data type.)rrnrT�category�delim�relid)	�clsrr�rnrTrZr[r\rWrUrUrX�create�szTypeCode.createN)r_r`rar��classmethodr^rUrUrUrXrY�srY�	FieldInfor�rTcs\eZdZdZ�fdd�Zdd�Zddd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
dd�Z�ZS)�	TypeCachez�Cache for database types.

    This cache maps type OIDs and names to TypeCode strings containing
    important information on the associated database type.
    csXtt|���|j|_|��|_t�|_|j	|j_	||j_
|jdkr'd|_dSd|_dS)z%Initialize type cache for connection.i:z�SELECT oid, typname, typlen, typtype, null as typcategory, typdelim, typrelid FROM pg_catalog.pg_type WHERE oid OPERATOR(pg_catalog.=) %sz�SELECT oid, typname, typlen, typtype, typcategory, typdelim, typrelid FROM pg_catalog.pg_type WHERE oid OPERATOR(pg_catalog.=) %sN)
�superrar��
escape_string�_escape_string�source�_srcrSrNrWr��server_version�_query_pg_type�rW�cnx��	__class__rUrXr��s




zTypeCache.__init__cCs�t|t�r|}nd|vrd|vrd|f}d|�|�f}z|j�|j|f�Wnty4d}Ynw|j�d�}|sDtd|f��|d}t	�
t|d�|dt|d	�|d
|d|dt|d
��}|||j<|t|�<|S)z8Get the type info from the database if it is not cached.�.�"�"%s"z
'%s'::regtypeNrkzType %s could not be foundrrlrr�r��)
r(r�rdrf�executerhr4�fetch�KeyErrorrYr^rr))rW�keyrre�	type_coderUrUrXr1�s&

�&�zTypeCache.__missing__NcCs"z||WSty|YSw)z&Get the type even if it is not cached.)rs)rWrtr4rUrUrXris

�z
TypeCache.getcsTt|t�s��|�}|sdS|jsdS�j�d|jf��fdd��j�d�D�S)z9Get the names and types of the fields of composite types.Nz�SELECT attname, atttypid FROM pg_catalog.pg_attribute WHERE attrelid OPERATOR(pg_catalog.=) %s AND attnum OPERATOR(pg_catalog.>) 0 AND NOT attisdropped ORDER BY attnumcs$g|]\}}t|��t|����qSrU)r`rir�)r�r�rrVrUrXr�'s�z(TypeCache.get_fields.<locals>.<listcomp>r�)r(rYrir\rfrqrrrXrUrVrXrWs

�

�zTypeCache.get_fieldscCs|j�|�Sr3rMrXrUrUrXr:*r5zTypeCache.get_typecastcCs|j�||�dS)r6NrQ)rWr.r/rUrUrXr;.r�zTypeCache.set_typecastcCs|j�|�dS)z?Reset the typecast function for the specified database type(s).NrRrXrUrUrXr<2�zTypeCache.reset_typecastcCs.|durdS|�|�}|r|tur|S||�S)z:Cast the given value according to the given database type.N)r:r))rWr�r.r/rUrUrX�typecast6s
zTypeCache.typecastrT)
r_r`rar�r�r1rirWr:r;r<rw�
__classcell__rUrUrkrXra�s

racs eZdZdZ�fdd�Z�ZS)�
_quotedictzsDictionary with auto quoting of its items.

    The quote attribute must be set to the desired quote function.
    cs|�tt|��|��SrT)�quoterbry�__getitem__)rWrtrkrUrXr{Hsz_quotedict.__getitem__)r_r`rar�r{rxrUrUrkrXryBsrycCs||�}d|_|S)z3Return DatabaseError with empty sqlstate attribute.N)�sqlstate)�msgr]�errorrUrUrX�	_db_errorNsrcCs
t|t�S)zReturn OperationalError.)rr2)r}rUrUrX�	_op_errorUrPr�z^[A-Za-z][_a-zA-Z0-9]*$ir~cCs~z$z
td|dd�jWWSty$dd�t|�D�}td|�jYWSwty>dd�tt|��D�}td|�jYSw)z>Get a namedtuple factory for row results with the given names.�RowT)�renamecSs0g|]\}}t�|�rt|�s|nd|f�qS�z	column_%d)�
_re_fieldnamer�rK)r��nr�rUrUrXr�is
��z _row_factory.<locals>.<listcomp>cSsg|]}d|f�qSr�rU)r�r�rUrUrXr�nr�)rJ�_maker*�	enumerater�rangern)�namesrUrUrX�_row_factorybs���r�cCst|�tj�adS)zwChange the size of the namedtuple factory cache.

    If maxsize is set to None, the cache can grow without bound.
    N)rPr�r}r~rUrUrX�set_row_factory_sizersr�c@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
edd��Zedd��Z
edd��Zdd�Zd7dd�Zdd�Zdd�Zdd �Zd8d"d#�Zd7d$d%�Z	d9d&d'�Z	d9d(d)�Zd*d+�ZeZed,d-��Zed.d/��Zed:d1d2��Zed3d4��Zd5d6�ZdS);r
zCursor object.cCs^||_|_|j|_|j|_|j��|_d|_|jtjur!d|_nd|_	d|_
d|_d|_dS)z3Create a cursor object for the database connection.Nr�rk)
r��_dbcnx�_cnx�
type_cachererf�_description�row_factoryr
�build_row_factory�rowcount�	arraysize�	lastrowid)rW�dbcnxrUrUrXr��s
zCursor.__init__cC�|S)z1Make cursor compatible to the iteration protocol.rUrVrUrUrX�__iter__��zCursor.__iter__cCr�)z0Enter the runtime context for the cursor object.rUrVrUrUrXrY�r�zCursor.__enter__cCs|��dS)z/Exit the runtime context for the cursor object.N)�close�rW�et�ev�tbrUrUrXr^�r5zCursor.__exit__c	sT|durdSt|ttf�rt|�}t|t�r6t|t�r+|j�|�}ttur*|�	d�}n|j�
|�}d|fSt|t�rOt|�rG|dkrEdSdSt
|�rMdS|St|ttttf�rZ|St|t�rl|jrgd	|fSd
|fSt|t�rvd|fSt|t�r�|jr�d|fSd
|St|t�r�d|fSt|t�r�d|fSt|t�r�|s�dS|j�zdd��fdd�|D��fWSty�dd��fdd�|D��fYSwt|t��r|j�zdd��fdd�|D��fWSt�ydd��fdd�|D��fYSwz|��}Wnt�ytdt |�f��wt|ttf��r(|�|�}|S)z"Quote value depending on its type.N�NULL�ascii�'%s'rz'-Infinity'z
'Infinity'z'NaN'z'%s'::timestamptzz'%s'::timestampz
'%s'::datez'%s'::timetzz
'%s'::timez'%s'::intervalz
'%s'::uuidz'{}'z	ARRAY[%s]�,c3��|]	}t�|��VqdSrT�r)r���qrUrXr����z Cursor._quote.<locals>.<genexpr>c3r�rT��unicoder�r�rUrXr��r��(%s)c3r�rTr�r�r�rUrXr��r�c3r�rTr�r�r�rUrXr��r�z Do not know how to adapt type %s)!r(rrr)r8rr��escape_bytea�bytes�decodercrKrGrFr�rHrErrArCr?r@rBrr��_quoter��UnicodeEncodeError�tuple�__pg_repr__�AttributeErrorr/rT)rWr�rUr�rXr��sx


�













 "� "���
z
Cursor._quotec	Csd|sz|dWSttfy|YSwt|t�r&t|�}|j|_||Stt|j|��}||S)z�Quote parameters.

        This function works for both mappings and sequences.

        The function should be used even when there are no parameters,
        so that we have a consistent behavior regarding percent signs.
        rU)	r*rr(�dictryr�rzr��map)rW�stringr�rUrUrX�_quoteparams�s
�
�zCursor._quoteparamsc	Cs�|dd�\}}}}|j|}|dkr|d8}|dkr'|d?|d@}}|}n|s,|j}|dkr2|}d}}t||d|||d�S)	z4Make the description tuple for the given field info.rkNrr�r��i��r�)r��size�CursorDescription)	rW�infor�r.r��modru�	precision�scalerUrUrX�_make_description�s

�zCursor._make_descriptioncs8|j}|jdur|j��fdd�|j��D�}||_|S)z2Read-only attribute describing the result columns.Tcsg|]}�|��qSrUrU)r�r���makerUrXr�r�z&Cursor.description.<locals>.<listcomp>)r�r�rf�listinfo)rW�descrrUr�rX�descriptions
zCursor.descriptioncC�dd�|jD�S)z;Unofficial convenience method for getting the column names.cS�g|]}|d�qS�rrUr�rUrUrXr�r�z#Cursor.colnames.<locals>.<listcomp>�r�rVrUrUrX�colnames�zCursor.colnamescCr�)z;Unofficial convenience method for getting the column types.cSr�)rkrUr�rUrUrXr�r�z#Cursor.coltypes.<locals>.<listcomp>r�rVrUrUrX�coltypesr�zCursor.coltypescCs|j��dS)zClose the cursor object.N)rfr�rVrUrUrXr�szCursor.closeNcsd�r+t�t�r+t��dkr+tdd��D��r+t�fdd��dd�D��r+|�|��S|�|�g�S)z<Prepare and execute a database operation (query or command).rkcss�|]}t|t�VqdSrT)r(r��r��prUrUrXr�(��z!Cursor.execute.<locals>.<genexpr>c3s$�|]
}t|�t�d�kVqdS)rNrmr��r�rUrXr�)r�N)r(r�rn�all�executemany)rW�	operationr�rUr�rXrq s��zCursor.executec
CsT|sdSd|_d|_d}d}zF|jjs6|jjs6z|j�|�Wnty'�ty1t	d��wd|j_|D]}|}|�
||�}|j�|�}|rO||7}q8d|_q8Wn/ty\�typ}z	td||ft
��d}~wty�}zt	d||f��d}~ww|jjtkr�d|_|jj|_d|_|jr�|��|_|S||_|j��|_|S)	z>Prepare operation and execute it against a parameter sequence.Nr�r�BEGIN�Can't start transactionTzError in '%s': '%s' zInternal error in '%s': %s)r�r�r��_tnx�
autocommitrfrqr0�	Exceptionr�r�r-rr/�
resulttype�
RESULT_DQL�ntuplesr�r�r��	oidstatus)rWr��seq_of_parametersr��sqlr��rows�errrUrUrXr�/sZ�
�����

�zCursor.executemanycCs,|�dd�}z|dWStyYdSw)z)Fetch the next row of a query result set.rkFrN)�	fetchmany�
IndexError�rWrerUrUrX�fetchone`s
�zCursor.fetchonecCs|�dd�S)z-Fetch all (remaining) rows of a query result.r�F)r�rVrUrUrX�fetchallhr5zCursor.fetchallFc
sx|dur�j}|r|�_z�j�|�}Wnty�ty-}ztt|���d}~ww�jj���fdd�|D�S)a>Fetch the next set of rows of a query result.

        The number of rows to fetch per call is specified by the
        size parameter. If it is not given, the cursor's arraysize
        determines the number of rows to be fetched. If you set
        the keep parameter to true, this is kept as new arraysize.
        Ncs,g|]}���fdd�t�j|�D���qS)csg|]	\}}�||��qSrUrU)r�r.r�)rwrUrXr�s�z/Cursor.fetchmany.<locals>.<listcomp>.<listcomp>)r��zipr�)r��row�rWrwrUrXr�s
�
�z$Cursor.fetchmany.<locals>.<listcomp>)	r�rfrrr0r-rr)r�rw)rWr��keep�resultr�rUr�rXr�ls ���zCursor.fetchmanycCs8|rt|�pd}d|d�|dg�f}|�||�|S)a�Call a stored database procedure with the given name.

        The sequence of parameters must contain one entry for each input
        argument that the procedure expects. The result of the call is the
        same as this input sequence; replacement of output and input/output
        parameters in the return value is currently not supported.

        The procedure may also provide a result set as output. These can be
        requested through the standard fetch methods of the cursor.
        rzselect * from "%s"(%s)r�z%s)rnr�rq)rW�procnamer�r��queryrUrUrX�callproc�szCursor.callprocc
s�|dk}z�j�Wn^tyg�rtd��|rt�d�nt�d�t�t�rSt���s2td�f��|sLt�t�rC��d�sB�d7�n	��d�sL�d7��fdd	�}	nt�t�ra���fd
d	�}	nt	d��Yn#w�durod
�n	t�t
�sxt	d���dkr���fdd	�}	n�fdd	�}	|r�t|t�s�t	d��|���d�r�td��d|f}d|fg}
g}g}|dur�t|t�s�t	d��|dvr�td��|�
d|f�|dur�t|t�s�t	d��|dkr�td��t|�dkr�td��|�
d�|�
|�|du�rt|t��st	d ��|�
d!�|�
|�|�r)t|t��s!d"�d#d$�|D��}|
�
d%|f�|
�
d&�|�r<|
�
d%d"�|�f�d'�|
�}
|jj}
|�|
|�z
|	�D]}|
|��qOWnt�ys}zd(|_|
|�WYd}~|Sd}~ww|
d�|_|S))a�Copy data from an input stream to the specified table.

        The input stream can be a file-like object with a read() method or
        it can also be an iterable returning a row or multiple rows of input
        on each iteration.

        The format must be text, csv or binary. The sep option sets the
        column separator (delimiter) used in the non binary formats.
        The null option sets the textual representation of NULL in the input.

        The size option sets the size of the buffer used when reading data
        from file-like objects.

        The copy operation can be restricted to a subset of columns. If no
        columns are specified, all of them will be copied.
        �binaryz+Size must only be set for file-like objectszbyte strings�stringszThe input must be %s�
�
c3s��VdSrTrUrU)�streamrUrX�chunks�s�
z Cursor.copy_from.<locals>.chunksc3s^��D])}t|��std�f��t|t�r |�d�s|d7}n	|�d�s)|d7}|VqdS)NzInput stream must consist of %sr�r�)r(rr)r�)�chunk)�
input_typer��	type_namerUrXr��s �
��

�
�z!Need an input stream to copy fromNi z"The size option must be an integerrc3s(�	���}|V|rt|��krdSqrTrm)�buffer)�readr�rUrXr��s��c3s���VdSrTrUrU)r�rUrXr��s��Need a table to copy to�selectz!Must specify a table, not a queryro�copy %sz%The format option must be be a string�r�csvr��Invalid format�	format %s�The sep option must be a string�0The sep option is not allowed with binary formatrk�2The sep option must be a single one-byte character�delimiter %s� The null option must be a string�null %sr�cs��|]}d|fVqdS�roNrU�r��colrUrUrXr�r�z#Cursor.copy_from.<locals>.<genexpr>r�z
from stdinr�r�)r�r�rr�r8r(r)r�rHr*r��lowerr�r�rnr�rf�putdatarq�
BaseExceptionr�)rWr��table�format�sep�nullr��columns�
binary_formatr�r��options�paramsrr�r~rU)r�r�r�r�r�rX�	copy_from�s�




�

��+
	


��







���
zCursor.copy_fromcs6|dk}|durz|j}	Wntytd��w|r t|t�s$td��|���d�r7|r1td��d|f}nd|f}d	|fg}
g}g}|durct|t�sStd
��|dvr[td��|�d
|f�|dur�t|t�sptd��|rvtd��t	|�dkr�td��|�d�|�|�|dur�t|t�s�td��|�d�|�|��dur�|dkr�d�nt
tu�nt�tt
f�s�td���r�|r�td��|r�t|t�s�d�dd�|D��}|
�d|f�|
�d�|r�|
�dd�|�f�d�|
�}
�jj���|
|����fdd�}
|du�r|
�S|
�D]}|	|��q�S)aCopy data from the specified table to an output stream.

        The output stream can be a file-like object with a write() method or
        it can also be None, in which case the method will return a generator
        yielding a row on each iteration.

        Output will be returned as byte strings unless you set decode to true.

        Note that you can also use a select query instead of the table name.

        The format must be text, csv or binary. The sep option sets the
        column separator (delimiter) used in the non binary formats.
        The null option sets the textual representation of NULL in the output.

        The copy operation can be restricted to a subset of columns. If no
        columns are specified, all of them will be copied.
        r�Nz Need an output stream to copy tor�r�z&Columns must be specified in the queryr�ror�z"The format option must be a stringr�r�r�r�r�rkr�rrrFz#The decode option must be a booleanz3The decode option is not allowed with binary formatr�csrrrUrrUrUrXr�cr�z!Cursor.copy_to.<locals>.<genexpr>z	to stdoutr�c3sF�d�_	���}t|t�r�j|kr|�_dS�jd7_|Vq)NrTrk)r�r(r��r��r��getdatarWrUrX�copyns�

�zCursor.copy_to.<locals>.copy)�writer�r*r(r8rr�rr�rnr)r�r�rr�rfrrq)rWr�r
rrr
r�rrrr�rrrr�rUrrX�copy_tos�
�


��





�




zCursor.copy_tocCs|��}|dur
t�|S)z9Return the next row (support for the iteration protocol).N)r��
StopIterationr�rUrUrX�__next__�szCursor.__next__cCstd��)�Not supported.z%The nextset() method is not supported)r5rUrUrUrX�nextset�szCursor.nextsetcC�dS�rNrU)�sizesrUrUrX�
setinputsizes��zCursor.setinputsizesrcCrrrU)r��columnrUrUrX�
setoutputsize�r!zCursor.setoutputsizecCst�)a�Process rows before they are returned.

        You can overwrite this statically with a custom row factory, or
        you can build a row factory dynamically with build_row_factory().

        For example, you can create a Cursor class that returns rows as
        Python dictionaries like this:

            class DictCursor(pgdb.Cursor):

                def row_factory(self, row):
                    return {desc[0]: value
                        for desc, value in zip(self.description, row)}

            cur = DictCursor(con)  # get one DictCursor instance or
            con.cursor_type = DictCursor  # always use DictCursor instances
        )�NotImplementedErrorrrUrUrXr��szCursor.row_factorycCs|j}|rtt|��SdS)aBuild a row factory based on the current description.

        This implementation builds a row factory for creating named tuples.
        You can overwrite this method if you want to dynamically create
        different row factories whenever the column description changes.
        N)r�r�r�)rWr�rUrUrXr��s�zCursor.build_row_factoryrT)NF�NNNNNr�) r_r`rar�r�r�rYr^r�r�r��propertyr�r�r�r�rqr�r�r�r�r�rrrrrrLrr r#r�r�rUrUrUrXr
}sLE
	


1


�
�h	


r
r�)r�ru�display_size�
internal_sizer�r��null_okc@s�eZdZdZeZeZeZeZeZe	Z	e
Z
eZeZe
Z
dd�Zdd�Zdd�Zdd	�Zed
d��Zdd
�Zdd�Zdd�ZerIddd�Zdd�ZdSdS)r	zConnection object.cCsJ||_d|_t|�|_t|_d|_z|j��WdSty$t	d��w)z$Create a database connection object.F�Invalid connectionN)
r�r�rar�r
�cursor_typer�rer�r�rirUrUrXr��s
�zConnection.__init__cCsJ|jr#z
|j���d�Wnty�tytd��wd|_|S)z�Enter the runtime context for the connection object.

        The runtime context can be used for running transactions.

        This also starts a transaction in autocommit mode.
        r�r�T)r�r�rerqr0r�r�r�rVrUrUrXrY�s�zConnection.__enter__cCs0|dur|dur|dur|��dS|��dS)z�Exit the runtime context for the connection object.

        This does not close the connection, but it ends a transaction.
        N)�commit�rollbackr�rUrUrXr^�szConnection.__exit__cCsH|jr |jrz|��Wn	tyYnw|j��d|_dStd��)zClose the connection object.N�Connection has been closed)r�r�r-r0r�r�rVrUrUrXr��s�

zConnection.closecCs,z|jp
|jjdkWStyYdSw)z:Check whether the connection has been closed or is broken.rkT)r��statusr*rVrUrUrX�closed
s
�zConnection.closedcC�Z|jr)|jr'd|_z|j���d�WdSty�ty&td��wdStd��)z/Commit any pending transaction to the database.F�COMMITzCan't commit transactionr.N�r�r�rerqr0r�r�rVrUrUrXr,���	zConnection.commitcCr1)z2Roll back to the start of any pending transaction.F�ROLLBACKzCan't rollback transactionr.Nr3rVrUrUrXr- r4zConnection.rollbackcCs2|jrz|�|�WStytd��wtd��)z0Return a new cursor object using the connection.r*r.)r�r+r�r�rVrUrUrX�cursor.s�zConnection.cursorNcC�|��}|�||�|S)z:Shortcut method to run an operation on an implicit cursor.)r6rq)rWr�rr6rUrUrXrq:�zConnection.executecCr7)z7Shortcut method to run an operation against a sequence.)r6r�)rWr��	param_seqr6rUrUrXr�@r8zConnection.executemanyrT)r_r`rar�r-r.r/r0�
InternalErrorr2r4r3r1r5r�rYr^r�r&r0r,r-r6�shortcutmethodsrqr�rUrUrUrXr	�s2



�r	cKs�d}d}d}d}	d}
d}z|�d�}|d}|d}|d}	|d}
|d}Wntttfy3Ynw|d	ur:|}	|d	ur@|}
|d	urF|}|d	uriz|�d�}|d}t|d�}Wn
ttttfyhYnw|dkrod	}|	dkrud	}	|r�t|���}d
|vr�|g}n
|�dd|f�g}|D]$\}
}t	|�}|r�d|vr�d
|�
dd��
dd�f}|�d|
|f�q�d�|�}t
|||||	|
�}t|�S)zConnect to a database.r�r�r�rrkrlrr�N�=�dbnamer�r��'z\'�\z\\z%s=%s)r�r�r�r*r�rr��items�insertr)r�r�r��_connectr	)�dsn�user�password�host�database�kwargs�dbport�dbhostr=�dbuser�dbpasswd�dboptr�kwr�rjrUrUrXr7Ksh
�
���
r7cs8eZdZdZ�fdd�Z�fdd�Z�fdd�Z�ZS)rz�Type class for a couple of PostgreSQL data types.

    PostgreSQL is object-oriented: types are dynamic.
    We must thus use type names as internal type codes.
    cs$t|t�r	|��}tt|��||�SrT)r(r8r�rbr�__new__)r]�valuesrkrUrXrO�s
zType.__new__cs8t|t�r|�d�r|dd�}||vStt|��|�S�Nr'rk)r(r8r�rbr�__eq__�rW�otherrkrUrXrR��


zType.__eq__cs8t|t�r|�d�r|dd�}||vStt|��|�SrQ)r(r8r�rbr�__ne__rSrkrUrXrV�rUzType.__ne__)r_r`rar�rOrRrVrxrUrUrkrXr�s
rc@� eZdZdZdd�Zdd�ZdS)�	ArrayTypez&Type class for PostgreSQL array types.cCst|t�r
|�d�St|t�S�Nr'�r(r8r�rXrSrUrUrXrR�s


zArrayType.__eq__cCs"t|t�r|�d�St|t�SrYrZrSrUrUrXrV�s
zArrayType.__ne__N�r_r`rar�rRrVrUrUrUrXrX�srXc@rW)�
RecordTypez'Type class for PostgreSQL record types.cCs0t|t�r
|jdkSt|t�r|dkSt|t�S�Nr�r&�r(rYrTr8r\rSrUrUrXrR�s




zRecordType.__eq__cCs2t|t�r
|jdkSt|t�r|dkSt|t�Sr]r^rSrUrUrXrV�s



zRecordType.__ne__Nr[rUrUrUrXr\�sr\zchar bpchar name text varcharrz1int2 int4 serial int8 float4 float8 numeric moneyz?date time timetz timestamp timestamptz interval abstime reltimerrrzint2 int4 int8 serialrz
float4 float8r�rr?ztime timetzztimestamp timestamptzr r$rz
json jsonbcCst|||�S)z)Construct an object holding a date value.)r?)�year�month�dayrUrUrXr�r5rcCst|||||�S)z)Construct an object holding a time value.)r@)�hour�minute�second�microsecondrCrUrUrXr�rvrc	Cst||||||||�S)z/Construct an object holding a time stamp value.)rA)r_r`rarbrcrdrerCrUrUrXr
�sr
cC�tt|�dd��S)zDConstruct an object holding a date value from the given ticks value.Nr)rrD��ticksrUrUrXr�rcCrf)zDConstruct an object holding a time value from the given ticks value.rrp)rrDrgrUrUrXrrircCrf)zDConstruct an object holding a time stamp from the given ticks value.Nrp)r
rDrgrUrUrXr
rirc@seZdZdZdS)rzDConstruct an object capable of holding a binary (long) string value.N)r_r`rar�rUrUrUrXrsrcCst|||||d�S)z2Construct an object holding a time interval value.)r�r�r�r�)rBr�rUrUrXrs
�rc@s4eZdZdZed�Zed�Zedd��Zdd�Z	dS)	rz(Wrapper class for marking hstore values.z^[Nn][Uu][Ll][Ll]$|[ ,=>]z(["\\])cCs@|durdS|s
dS|j�|�}|j�d|�}|rd|f}|S)Nr�z""z\\\1ro)�	_re_quote�search�
_re_escape�sub)r]�srzrUrUrXr�'s
z
Hstore._quotecs"|j�d��fdd�|��D��S)Nr�c3s(�|]\}}d�|��|�fVqdS)z%s=>%sNrU)r��kr�r�rUrXr�5s�&z!Hstore.__str__.<locals>.<genexpr>)r�r�r@rVrUr�rX�__str__3szHstore.__str__N)
r_r`rar��regexrjrlr_r�rprUrUrUrXr!s
rc@s"eZdZdZddd�Zdd�ZdS)rz?Construct a wrapper for holding an object serializable to JSON.NcCs||_|pt|_dSrT)�obj�
jsonencode�encode)rWrrrtrUrUrXr�;sz
Json.__init__cCs|j}t|t�r
|S|�|�SrT)rrr(r8rt)rWrrrUrUrXrp?s

zJson.__str__rT)r_r`rar�r�rprUrUrUrXr8s
rc@s$eZdZdZdd�Zdd�ZeZdS)rz5Construct a wrapper for holding a literal SQL string.cCs
||_dSrT�r�)rWr�rUrUrXr�Ir�zLiteral.__init__cCr�rTrurVrUrUrXrpLr�zLiteral.__str__N)r_r`rar�r�rpr�rUrUrUrXrFs
r�__main__zPyGreSQL versionr�)rbrTr%)rrrN)rrrrN)rrrr)�r��
__future__rr�_pg�ImportError�os�sysr��version_info�environr��pathsep�path�existsr��add_dll_directory�abspathr=r>�__all__rAr?r@rBrCrD�decimalrEr$r(r�mathrFrG�collections.abcrH�collectionsrJ�keywordrK�	functoolsrL�rerMrqrrNrJrOrsrH�	NameErrorr�r�r)r8r�rPrQ�_threadrRr6r9r8r;�inspectr�r�r�r��utcr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r
rrNr:r;r<rSrYr`raryr0rr�r�r�r�r|r
r�r	r7rB�	frozensetrrXr\rrrrrrrrr r!r"r#r$r%r&r'r)r*r+r,rrr
rrrrrrrrr_�printrUrUrUrX�<module>sr
8
�����������U���

%����	;}
	%^
F�
�A

�


�

https://t.me/RX1948 - 2025