Your IP : 3.12.71.166


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

�

��bg>H����dZddlZddlmZmZddlmZmZmZddlm	Z	m
Z
mZGd�d��Zd.d	�Z
Gd
�d��ZGd�d
��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��Zeee��eeeddd���Ze���eeeddd���Ze���eeedd d!���Ze���ed"ed#d$d%���Ze���ed&ed'd(d)���Ze���ed*ed+d,d-���Ze���dS)/z1Implementation of the Range type and adaptation

�N)�ProgrammingError�InterfaceError)�	ISQLQuote�adapt�register_adapter)�new_type�new_array_type�
register_typec��eZdZdZdZdd�Zd�Zd�Zed	���Z	ed
���Z
ed���Zed���Zed
���Z
ed���Zed���Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�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�[)Fc��|s-|dvrtd|�����||_||_||_dSdx|_x|_|_dS)N)rz(]z()z[]zbound flags not valid: )�
ValueErrorrrr)�self�lower�upper�bounds�emptys     �b/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib64/python3.11/site-packages/psycopg2/_range.py�__init__zRange.__init__/s_���	<��5�5�5� �!E�6�!E�!E�F�F�F��D�K��D�K�!�D�L�L�L�7;�;�D�K�;�$�+�����c��|j�|jj�d�Sd�|jj|j|j|j��S)Nz(empty=True)z{}({!r}, {!r}, {!r}))r�	__class__�__name__�formatrr�rs r�__repr__zRange.__repr__:sJ���<���n�-�;�;�;�;�)�0�0���1H���T�[�$�,�8�8�
8rc��|j�dS|jdt|j��dt|j��|jdg}d�|��S)Nrrz, ��)r�strrr�join)r�itemss  r�__str__z
Range.__str__AsY���<���7�
�L��O�������������L��O�
���w�w�u�~�~�rc��|jS)z:The lower bound of the range. `!None` if empty or unbound.)rr s rrzRange.lowerN����{�rc��|jS)z:The upper bound of the range. `!None` if empty or unbound.)rr s rrzRange.upperSr*rc��|jduS)z`!True` if the range is empty.N�rr s r�isemptyz
Range.isemptyXs���|�t�#�#rc�&�|j�dS|jduS)z0`!True` if the range doesn't have a lower bound.NF�rrr s r�	lower_infzRange.lower_inf]����<���5��{�d�"�"rc�&�|j�dS|jduS)z1`!True` if the range doesn't have an upper bound.NF�rrr s r�	upper_infzRange.upper_infdr2rc�D�|j�|j�dS|jddkS)z4`!True` if the lower bound is included in the range.NFr�[r0r s r�	lower_inczRange.lower_inck�)���<��4�;�#6��5��|�A��#�%�%rc�D�|j�|j�dS|jddkS)z4`!True` if the upper bound is included in the range.NFr#�]r4r s r�	upper_inczRange.upper_incrr9rc���|j�dS|j�,|jddkr||jkrdSn
||jkrdS|j�,|jddkr||jkrdSn
||jkrdSdS)NFrr7r#r;T)rrr)r�xs  r�__contains__zRange.__contains__ys����<���5��;�"��|�A��#�%�%��t�{�?�?� �5�#����#�#� �5��;�"��|�A��#�%�%��t�{�?�?� �5�#����#�#� �5��trc��|jduS�Nr-r s r�__bool__zRange.__bool__�s���|�4�'�'rc��t|t��sdS|j|jko|j|jko|j|jkS)NF)�
isinstancerrrr�r�others  r�__eq__zRange.__eq__�sL���%��'�'�	��5���u�|�+�.���u�|�+�.����
�-�	/rc�.�|�|��SrA)rGrEs  r�__ne__zRange.__ne__�s���;�;�u�%�%�%�%rc�D�t|j|j|jf��SrA)�hashrrrr s r�__hash__zRange.__hash__�s���T�[�$�+�t�|�<�=�=�=rc��t|t��stSdD]:}t||��}t||��}||kr�)|�dS|�dS||kcSdS)Nr
TF)rDr�NotImplemented�getattr)rrF�attr�
self_value�other_values     r�__lt__zRange.__lt__�s����%��'�'�	"�!�!�3�
	0�
	0�D� ��t�,�,�J�!�%��.�.�K��[�(�(���#��t�t��$��u�u�!�K�/�/�/�/��urc�<�||krdS|�|��S�NT)rSrEs  r�__le__zRange.__le__��"���5�=�=��4��;�;�u�%�%�%rc�d�t|t��r|�|��StSrA)rDrrSrNrEs  r�__gt__zRange.__gt__�s,���e�U�#�#�	"��<�<��%�%�%�!�!rc�<�||krdS|�|��SrU)rYrEs  r�__ge__zRange.__ge__�rWrc�*���fd��jD��S)Nc�R��i|]#}t�|���|t�|����$S�)�hasattrrO)�.0�slotrs  �r�
<dictcomp>z&Range.__getstate__.<locals>.<dictcomp>�sC���?�?�?��'�$��*=�*=�?��g�d�D�)�)�?�?�?r)�	__slots__r s`r�__getstate__zRange.__getstate__�s0���?�?�?�?���?�?�?�	?rc�\�|���D]\}}t|||���dSrA)r'�setattr)r�statera�values    r�__setstate__zRange.__setstate__�s<�� �;�;�=�=�	'�	'�K�D�%��D�$��&�&�&�&�	'�	'r)NNrF)r�
__module__�__qualname__�__doc__rcrr!r(�propertyrrr.r1r5r8r<r?rBrGrIrLrSrVrYr[rdrir^rrrr#s���������0�I�	<�	<�	<�	<�8�8�8��������X������X���$�$��X�$��#�#��X�#��#�#��X�#��&�&��X�&��&�&��X�&����,(�(�(�/�/�/�&�&�&�>�>�>���� &�&�&�"�"�"�&�&�&�?�?�?�'�'�'�'�'rrFc�r�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�casters     r�register_rangerw�s@��4�
!�
!�'�7�L�
A�
A�F�
����\�2�l�:�d�;�;�;��Mrc�.�eZdZdZdZd�Zd�Zd�Zd�ZdS)�RangeAdapterz�`ISQLQuote` adapter for `Range` subclasses.

    This is an abstract class: concrete classes must set a `name` class
    attribute or override `getquoted()`.
    Nc��||_dSrA)�adapted)rr{s  rrzRangeAdapter.__init__�s
������rc�&�|jtur|SdSrA)�_protor)r�protos  r�__conform__zRangeAdapter.__conform__�s���;�)�#�#��K�$�#rc��||_dSrA)�_conn)r�conns  r�preparezRangeAdapter.prepare�s
����
�
�
rc��|j�td���|j}|jrd|j�d��zS|j�St
|j��}t|d��r|�|j	��|�
��}nd}|j�St
|j��}t|d��r|�|j	��|�
��}nd}|j�d��dz|zdz|zdz|j�d��zd	zS)
NzMRangeAdapter must be subclassed overriding its name or the getquoted() methods	'empty'::�utf8r�sNULL�(s, s, 's'))
�name�NotImplementedErrorr{r.�encoderrr_r�r��	getquotedrr)r�r�arrs     rr�zRangeAdapter.getquoted�sA���9��%�,�-�-�
-�
�L���9�	;��$�)�"2�"2�6�":�":�:�:��7���a�g���A��q�)�$�$�
&��	�	�$�*�%�%�%��K�K�M�M�E�E��E��7���a�g���A��q�)�$�$�
&��	�	�$�*�%�%�%��K�K�M�M�E�E��E��y����'�'�$�.��6��>��F����y�'�'��/�/�0�27�8�	8r)	rrjrkrlr�rrr�r�r^rrryry�sa��������
�D����������8�8�8�8�8rryc��eZdZdZd
d�Zd�Zed���Zej	dej
��Zej	d��Zd
d�Z
d
d	�ZdS)roa	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.
    Nc��||_|�||��|jjp|jjj}t
|f||j��|_|�!t|f|dz|j��|_
dSd|_
dS)N�ARRAY)�subtype_oid�_create_ranges�adapterr�rrr�parse�
typecasterr	�array_typecaster)rrrrs�oidr��	array_oidr�s       rrzRangeCaster.__init__$s���&������G�W�-�-�-��|� �C�D�L�$:�$C��"�C�6�4���<�<���� �$2���d�W�n�d�o�%?�%?�D�!�!�!�%)�D�!�!�!rc�4�d|_t|t��r)t|tfi��|_||j_n7	t
|t��r|tur||_n#t$rYnwxYw|j�td���d|_	t|t��rt|tfi��|_t
|t��r|tur||_n#t$rYnwxYw|j�td���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)
r�rDr%�typeryr��
issubclass�	TypeError�ranger)rrrrss   rr�zRangeCaster._create_ranges2sN������g�s�#�#�		���,��"�=�=�D�L� '�D�L���
��g�|�4�4�+�#�<�7�7�#*�D�L����
�
�
���
�����<���L�N�N�
N���
�	��'�3�'�'�
9�!�'�E�8�R�8�8��
��'�5�)�)�
%�g�U�.B�.B�$��
����	�	�	��D�	�����:���C�E�E�
E��s%�%A-�-
A:�9A:�AC2�2
C?�>C?c�6�ddlm}ddlm}||��\}}|jjdkrt
d|jjz���|j}d|vr|�dd��\}	}
n|}
d}	|�	d	|
|	f��|�
��}|s�	d
}|j|kr|�	d��d}|�	d
|f��|�
��}|r
|dd�\}
}	n#t$rYnwxYw|r|�	d��n#|r|�	d��wwxYw||kr|js|���|st
d|�d����|dd�\}
}}t|||
||���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�r�r�)�psycopg2.extensionsr��psycopg2.extrasr��info�server_versionr�status�split�execute�fetchone�
autocommit�rollbackro)rr�rsrtr�r�r��curs�conn_status�schema�tname�rec�	savepointr��subtype�arrays                rrpzRangeCaster._from_dbUsO��	>�=�=�=�=�=�4�4�4�4�4�4�%�%�l�3�3�
��d��9�#�e�+�+�"�#L��)�*�$+�,�,�
,��k���$�;�;� �J�J�s�A�.�.�M�F�E�E��E��F�	
�����V�_�
	�	�	��m�m�o�o���	H�
H�!�	��;�"7�7�7��L�L�!:�;�;�;� $�I������X�
����m�m�o�o���,�$'����G�M�E�6���$�
�
�
���
�����H��L�L�!F�G�G�G����H��L�L�!F�G�G�G�G�H�����/�/�/���/��M�M�O�O�O��	8�"�6�T�6�6�6�8�8�
8� #�2�A�2�w���g�u��4���'�U�<�<�<�	<s*�;C>�$D&�>
D�D&�
D�D&�&Ea]
        ( \(|\[ )                   # 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	(["\\])\1c��|�dS|dkr|�d���S|j�|��}|�td|�d����|�d��}|�2|�d��}|�|j�d|��}|�d	��}|�2|�d
��}|�|j�d|��}|�6|�|j|��}|�|j|��}|�d��|�d��z}|�|||��S)
NrT)rzfailed to parse range: '�'r��z\1��r#�)	r��	_re_range�matchr�group�_re_undouble�sub�castr�)r�s�cur�mrrrs       rr�zRangeCaster.parse�sD���9��4���<�<��:�:�D�:�)�)�)��N� � ��#�#���9� �!@�A�!@�!@�!@�A�A�A�����
�
���=��G�G�A�J�J�E�� ��)�-�-�e�U�;�;������
�
���=��G�G�A�J�J�E�� ��)�-�-�e�U�;�;���?��H�H�T�-�u�5�5�E��H�H�T�-�u�5�5�E�������a�g�g�a�j�j�(���z�z�%���/�/�/rc��t|j|��|j�t|j|��t|j|j��dSrA)r
r�r�rr�r�)r�scopes  rrqzRangeCaster._register�sJ���d�o�u�-�-�-�� �,��$�/��7�7�7����T�\�2�2�2�2�2rrA)rrjrkrlrr��classmethodrp�re�compile�VERBOSEr�r�r�rqr^rrroros���������)�)�)�)�!E�!E�!E�F�J<�J<��[�J<�X��
���Z���I��2�:�l�+�+�L�0�0�0�0�>3�3�3�3�3�3rroc��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�rrjrkrlr^rrr�r��s��������
	�Drr�c��eZdZdZdS)�	DateRangez#Represents :sql:`daterange` values.Nr�r^rrr�r���������-�-��Drr�c��eZdZdZdS)�
DateTimeRangez!Represents :sql:`tsrange` values.Nr�r^rrr�r��s������+�+��Drr�c��eZdZdZdS)�DateTimeTZRangez#Represents :sql:`tstzrange` values.Nr�r^rrr�r��r�rr�c��eZdZdZd�ZdS)�NumberRangeAdapterz1Adapt a range if the subtype doesn't need quotes.c��|j}|jrdS|js:t|j������d��}nd}|js:t|j������d��}nd}d|j	d�|�d|�|j	d�d��
d��S)Ns'empty'�asciir$r�r�,r#)r{r.r1rrr��decoder5rrr�)rr�rrs    rr�zNumberRangeAdapter.getquoted�s����L���9�	��:��{�	�
�!�'�N�N�,�,�.�.�5�5�g�>�>�E�E��E��{�	��!�'�N�N�,�,�.�.�5�5�g�>�>�E�E��E�@�A�I�a�L�@�%�@�@�%�@���1��@�@�@�H�H��Q�Q�QrN)rrjrkrlr�r^rrr�r��s.������;�;�R�R�R�R�Rrr�i@�iAr�iV�iWiBi�iC�	daterangeiHi:iI�tsrangeiDiZiE�	tstzrangeiFi�iG)F)rlr��psycopg2._psycopgrrr�rrrrr	r
rrwryror�r�r�r�r��int4range_casterrq�int8range_caster�numrange_caster�daterange_caster�tsrange_caster�tstzrange_casterr^rr�<module>r�s>����6
�	�	�	�>�>�>�>�>�>�>�>�B�B�B�B�B�B�B�B�B�B�G�G�G�G�G�G�G�G�G�G�h'�h'�h'�h'�h'�h'�h'�h'�V����>-8�-8�-8�-8�-8�-8�-8�-8�`y3�y3�y3�y3�y3�y3�y3�y3�x	�	�	�	�	�5�	�	�	�	�	�	�	�	��	�	�	�
	�	�	�	�	�E�	�	�	�
	�	�	�	�	�e�	�	�	�R�R�R�R�R��R�R�R�2���1�2�2�2�
�;�1�<��"��.�.�.���������;�1�<��"��.�.�.���������+�0�,��$�$�0�0�0���������;�{�I��$�$�0�0�0����������Y�
��$�$�0�0�0���������;�{�O��$�$�0�0�0���������r

?>