HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/psycopg2/__pycache__/_range.cpython-310.pyc
o

we>H�@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�eZdZdZdZd0dd�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/�ZdS)1�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�H/home/arjun/projects/env/lib/python3.10/site-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__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)r9r
�NotImplemented�getattr)rr;�attr�
self_value�other_valuerrr�__lt__�s


zRange.__lt__cC�||krdS|�|�S�NT)rEr:rrr�__le__��
zRange.__le__cCst|t�r
|�|�StSr6)r9r
rEr@r:rrr�__gt__�s

zRange.__gt__cCrFrG)rJr:rrr�__ge__�rIzRange.__ge__cs�fdd��jD�S)Ncs"i|]
}t�|�r|t�|��qSr)�hasattrrA)�.0�slotrrr�
<dictcomp>�s
�z&Range.__getstate__.<locals>.<dictcomp>)�	__slots__rrrr�__getstate__�s
�zRange.__getstate__cCs"|��D]
\}}t|||�qdSr6)r"�setattr)r�staterN�valuerrr�__setstate__�s�zRange.__setstate__)NNrF)r�
__module__�__qualname__�__doc__rPrrr#�propertyrrr'r*r-r0r3r5r7r<r=r?rErHrJrKrQrUrrrrr
#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�srbc@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)rrerrrr�r8zRangeAdapter.__init__cCs|jtur|SdSr6)�_protor)r�protorrr�__conform__�s
�zRangeAdapter.__conform__cCrdr6)�_conn)r�connrrr�prepare�r8zRangeAdapter.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'::�utf8rksNULL�(s, s, 's'))
�name�NotImplementedErrorrer'�encoderrrLrkri�	getquotedrr)r�r�arrrrrrq�s4
�







�
��zRangeAdapter.getquoted)	rrVrWrXrnrrhrkrqrrrrrc�srcc@sZeZdZdZddd�Zdd�Zedd��Ze�	d	ej
�Ze�	d
�Zddd�Z
dd
d�ZdS)rZa	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�adapterrnrrr�parse�
typecasterr�array_typecaster)rr]r^�oidru�	array_oidrnrrrr$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)
rwr9r �typercrn�
issubclass�	TypeError�ranger
)rr]r^rrrrv2s>


��
�
��
��zRangeCaster._create_rangesc	CsVddlm}ddlm}||�\}}|jjdkr td|jj��|j}d|vr0|�dd�\}	}
n|}
d}	|�	d	|
|	f�|�
�}|s�z8zd
}|j|krR|�	d�d}|�	d
|f�Wn	tycYnw|�
�}|rr|dd�\}
}	W|rz|�	d�n	|r�|�	d�ww||kr�|js�|��|s�td|�d���|dd�\}
}}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, typarray
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;
FzSAVEPOINT register_typeTz�SELECT rngtypid, rngsubtype, typarray, typname, nspname
from pg_range r
join pg_type t on t.oid = rngtypid
join pg_namespace ns on ns.oid = typnamespace
WHERE t.oid = %s::regtype
�Nz#ROLLBACK TO SAVEPOINT register_typezPostgreSQL range 'z' not found�r{rur|)�psycopg2.extensionsr��psycopg2.extrasr��info�server_versionr�status�split�execute�fetchone�
autocommit�rollbackrZ)rrnr^r_r�r�rj�curs�conn_status�schema�tname�rec�	savepointr}�subtype�arrayrrrr[Us`��

���
���
��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: '�'r��z\1��r�)	r��	_re_range�matchr�group�_re_undouble�sub�castru)r�s�cur�mrrrrrrrx�s,



zRangeCaster.parsecCs4t|j|�|jdurt|j|�t|j|j�dSr6)r	ryrzrr�rw)r�scoperrrr\�s
zRangeCaster._registerr6)rrVrWrXrrv�classmethodr[�re�compile�VERBOSEr�r�rxr\rrrrrZs
#
L�

rZc@�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�rrVrWrXrrrrr��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)rer'r*rrrq�decoder-rrrp)rrrrrrrrrq�s,zNumberRangeAdapter.getquotedN)rrVrWrXrqrrrrr��sr�i@�iAr�iV�iWiBi�iC�	daterangeiHi:iI�tsrangeiDiZiE�	tstzrangeiFi�iG)F)rXr��psycopg2._psycopgrrr�rrrrrr	r
rbrcrZr�r�r�r�r��int4range_casterr\�int8range_caster�numrange_caster�daterange_caster�tsrange_caster�tstzrange_casterrrrr�<module>sR
,0=	

������