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/psycopg2/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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


��a�D�@srdZddlZddlmZmZddlmZmZmZddlm	Z	m
Z
mZGdd�d�Zd/d	d
�Z
Gdd�d�ZGd
d�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zeee�eeedddd�Ze��eeedddd�Ze��eeed d!d"d�Ze��ed#ed$d%d&d�Ze��ed'ed(d)d*d�Ze��ed+ed,d-d.d�Ze��dS)0z1Implementation of the Range type and adaptation

�N)�ProgrammingError�InterfaceError)�	ISQLQuote�adapt�register_adapter)�new_type�new_array_type�
register_typec@s�eZdZdZdZd2dd�Zdd	�Zd
d�Zedd
��Z	edd��Z
edd��Zedd��Zedd��Z
edd��Zedd��Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�ZdS)3�Rangea�Python representation for a PostgreSQL |range|_ type.

    :param lower: lower bound for the range. `!None` means unbound
    :param upper: upper bound for the range. `!None` means unbound
    :param bounds: one of the literal strings ``()``, ``[)``, ``(]``, ``[]``,
        representing whether the lower or upper bounds are included
    :param empty: if `!True`, the range is empty

    ��_lower�_upper�_boundsN�[)FcCsF|s|dvr
td|����||_||_||_dSd|_|_|_dS)N)rz(]z()z[]zbound flags not valid: )�
ValueErrorrr
r)�self�lower�upper�bounds�empty�r�1/usr/lib/python3/dist-packages/psycopg2/_range.py�__init__/s
zRange.__init__cCs2|jdur|jj�d�Sd�|jj|j|j|j�S)Nz(empty=True)z{}({!r}, {!r}, {!r}))r�	__class__�__name__�formatrr
�rrrr�__repr__:s


�zRange.__repr__cCs>|jdurdS|jdt|j�dt|j�|jdg}d�|�S)Nrrz, ��)r�strrr
�join)r�itemsrrr�__str__As
�
z
Range.__str__cC�|jS)z:The lower bound of the range. `!None` if empty or unbound.)rrrrrrN�zRange.lowercCr$)z:The upper bound of the range. `!None` if empty or unbound.)r
rrrrrSr%zRange.uppercCs
|jduS)z`!True` if the range is empty.N�rrrrr�isemptyXs
z
Range.isemptycC�|jdurdS|jduS)z0`!True` if the range doesn't have a lower bound.NF�rrrrrr�	lower_inf]�

zRange.lower_infcCr()z1`!True` if the range doesn't have an upper bound.NF�rr
rrrr�	upper_infdr+zRange.upper_infcC�&|jdus
|jdurdS|jddkS)z4`!True` if the lower bound is included in the range.NFr�[r)rrrr�	lower_inck�zRange.lower_inccCr.)z4`!True` if the upper bound is included in the range.NFr�]r,rrrr�	upper_incrr1zRange.upper_inccCs�|jdurdS|jdur"|jddkr||jkrdSn||jkr"dS|jdur>|jddkr7||jkr5dSdS||jkr>dSdS)NFrr/rr2T)rrr
)r�xrrr�__contains__ys"


�



�zRange.__contains__cCs
|jduS�Nr&rrrr�__bool__��
zRange.__bool__cCst|��|�Sr6)�typer7rrrr�__nonzero__�szRange.__nonzero__cCs2t|t�sdS|j|jko|j|jko|j|jkS)NF)�
isinstancer
rr
r�r�otherrrr�__eq__�s

�
�zRange.__eq__cCs|�|�Sr6)r>r<rrr�__ne__�szRange.__ne__cCst|j|j|jf�Sr6)�hashrr
rrrrr�__hash__�szRange.__hash__cCs`t|t�stSdD]$}t||�}t||�}||krq	|dur!dS|dur(dS||kSdS)NrTF)r;r
�NotImplemented�getattr)rr=�attr�
self_value�other_valuerrr�__lt__�s


zRange.__lt__cC�||krdS|�|�S�NT)rGr<rrr�__le__��
zRange.__le__cCst|t�r
|�|�StSr6)r;r
rGrBr<rrr�__gt__�s

zRange.__gt__cCrHrI)rLr<rrr�__ge__�rKzRange.__ge__cs�fdd��jD�S)Ncs"i|]
}t�|�r|t�|��qSr)�hasattrrC)�.0�slotrrr�
<dictcomp>�s
�z&Range.__getstate__.<locals>.<dictcomp>)�	__slots__rrrr�__getstate__�s
�zRange.__getstate__cCs"|��D]
\}}t|||�qdSr6)r"�setattr)r�staterP�valuerrr�__setstate__�s�zRange.__setstate__)NNrF)r�
__module__�__qualname__�__doc__rRrrr#�propertyrrr'r*r-r0r3r5r7r:r>r?rArGrJrLrMrSrWrrrrr
#s@	







r
FcCs&t�|||�}|�|r|pd�|S)a�Create and register an adapter and the typecasters to convert between
    a PostgreSQL |range|_ type and a PostgreSQL `Range` subclass.

    :param pgrange: the name of the PostgreSQL |range| type. Can be
        schema-qualified
    :param pyrange: a `Range` strict subclass, or just a name to give to a new
        class
    :param conn_or_curs: a connection or cursor used to find the oid of the
        range and its subtype; 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
    :return: `RangeCaster` instance responsible for the conversion

    If a string is passed to *pyrange*, a new `Range` subclass is created
    with such name and will be available as the `~RangeCaster.range` attribute
    of the returned `RangeCaster` object.

    The function queries the database on *conn_or_curs* to inspect the
    *pgrange* type and raises `~psycopg2.ProgrammingError` if the type is not
    found.  If querying the database is not advisable, use directly the
    `RangeCaster` class and register the adapter and typecasters using the
    provided functions.

    N)�RangeCaster�_from_db�	_register)�pgrange�pyrange�conn_or_curs�globally�casterrrr�register_range�srdc@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�RangeAdapterz�`ISQLQuote` adapter for `Range` subclasses.

    This is an abstract class: concrete classes must set a `name` class
    attribute or override `getquoted()`.
    NcC�
||_dSr6)�adapted)rrgrrrr�r8zRangeAdapter.__init__cCs|jtur|SdSr6)�_protor)r�protorrr�__conform__�s
�zRangeAdapter.__conform__cCrfr6)�_conn)r�connrrr�preparer8zRangeAdapter.preparecCs�|jdur	td��|j}|jrd|j�d�S|jdur1t|j�}t|d�r,|�|j	�|�
�}nd}|jdurMt|j�}t|d�rH|�|j	�|�
�}nd}|j�d�d|d|d|j�d�d	S)
NzMRangeAdapter must be subclassed overriding its name or the getquoted() methods	'empty'::�utf8rmsNULL�(s, s, 's'))
�name�NotImplementedErrorrgr'�encoderrrNrmrk�	getquotedrr)r�r�arrrrrrss4
�







�
��zRangeAdapter.getquoted)	rrXrYrZrprrjrmrsrrrrre�srec@sZeZdZdZddd�Zdd�Zedd��Ze�	d	ej
�Ze�	d
�Zddd�Z
dd
d�ZdS)r\a	Helper class to convert between `Range` and PostgreSQL range types.

    Objects of this class are usually created by `register_range()`. Manual
    creation could be useful if querying the database is not advisable: in
    this case the oids must be provided.
    NcCsb||_|�||�|jjp|jjj}t|f||j�|_|dur,t	|f|d|j�|_
dSd|_
dS)N�ARRAY)�subtype_oid�_create_ranges�adapterrprrr�parse�
typecasterr�array_typecaster)rr_r`�oidrw�	array_oidrprrrr(s
�
zRangeCaster.__init__cCs�d|_t|t�rt|tfi�|_||j_nzt|t�r"|tur"||_Wn	ty,Ynw|jdur6td��d|_zt|t�rGt|t	fi�|_t|t	�rS|t	urS||_Wn	ty]Ynw|jdurgtd��dS)z0Create Range and RangeAdapter classes if needed.Nz:pgrange must be a string or a RangeAdapter strict subclassz1pyrange must be a type or a Range strict subclass)
ryr;r r9rerp�
issubclass�	TypeError�ranger
)rr_r`rrrrx6s>


��
�
��
��zRangeCaster._create_rangescCs�ddlm}ddlm}||�\}}|jjdkr td|jj��|j}d|vr0|�dd�\}	}
n|}
d}	z
|�	d	|
|	f�WntyM|j
sL|���w|��}||kr]|j
s]|��|sgtd
|�d���|\}}
}t
||||
|d�S)
z|Return a `RangeCaster` instance for the type *pgrange*.

        Raise `ProgrammingError` if the type is not found.
        r)�STATUS_IN_TRANSACTION)�_solve_conn_cursiX`z'range types not available in version %s�.r�publicz�select rngtypid, rngsubtype,
    (select typarray from pg_type where oid = rngtypid)
from pg_range r
join pg_type t on t.oid = rngtypid
join pg_namespace ns on ns.oid = typnamespace
where typname = %s and ns.nspname = %s;
zPostgreSQL type 'z' not found�r}rwr~)�psycopg2.extensionsr��psycopg2.extrasr��info�server_versionr�status�split�execute�
autocommit�rollback�fetchoner\)rrpr`rar�r�rl�curs�conn_status�schema�tname�recr9�subtype�arrayrrrr]YsD��	��
�
�zRangeCaster._from_dba]
        ( \(|\[ )                   # lower bound flag
        (?:                         # lower bound:
          " ( (?: [^"] | "")* ) "   #   - a quoted string
          | ( [^",]+ )              #   - or an unquoted string
        )?                          #   - or empty (not catched)
        ,
        (?:                         # upper bound:
          " ( (?: [^"] | "")* ) "   #   - a quoted string
          | ( [^"\)\]]+ )           #   - or an unquoted string
        )?                          #   - or empty (not catched)
        ( \)|\] )                   # upper bound flag
        z	(["\\])\1cCs�|durdS|dkr|jdd�S|j�|�}|dur"td|�d���|�d�}|dur;|�d�}|dur;|j�d|�}|�d	�}|durT|�d
�}|durT|j�d|�}|durf|�|j|�}|�|j|�}|�d�|�d�}|�|||�S)
NrT)rzfailed to parse range: '�'��z\1��r�)	r��	_re_range�matchr�group�_re_undouble�sub�castrw)r�s�cur�mrrrrrrrz�s,



zRangeCaster.parsecCs4t|j|�|jdurt|j|�t|j|j�dSr6)r	r{r|rr�ry)r�scoperrrr^�s
zRangeCaster._registerr6)rrXrYrZrrx�classmethodr]�re�compile�VERBOSEr�r�rzr^rrrrr\!s
#
7�

r\c@�eZdZdZdS)�NumericRangez�A `Range` suitable to pass Python numeric types to a PostgreSQL range.

    PostgreSQL types :sql:`int4range`, :sql:`int8range`, :sql:`numrange` are
    casted into `!NumericRange` instances.
    N�rrXrYrZrrrrr��sr�c@r�)�	DateRangez#Represents :sql:`daterange` values.Nr�rrrrr���r�c@r�)�
DateTimeRangez!Represents :sql:`tsrange` values.Nr�rrrrr��r�r�c@r�)�DateTimeTZRangez#Represents :sql:`tstzrange` values.Nr�rrrrr��r�r�c@seZdZdZdd�ZdS)�NumberRangeAdapterz1Adapt a range if the subtype doesn't need quotes.cCs||j}|jrdS|jst|j����d�}nd}|js&t|j����d�}nd}d|j	d�|�d|�|j	d�d��
d�S)Ns'empty'�asciirr�r�,r)rgr'r*rrrs�decoder-rrrr)rrtrrrrrrs�s,zNumberRangeAdapter.getquotedN)rrXrYrZrsrrrrr��sr�i@�iAr�iV�iWiBi�iC�	daterangeiHi:iI�tsrangeiDiZiE�	tstzrangeiFi�iG)F)rZr��psycopg2._psycopgrrr�rrrrrr	r
rdrer\r�r�r�r�r��int4range_casterr^�int8range_caster�numrange_caster�daterange_caster�tsrange_caster�tstzrange_casterrrrr�<module>sR
00(	

������

https://t.me/RX1948 - 2025