o
    E6dy                     @  sj  d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% erdd l&m'Z' dd!l m(Z( dd"l m)Z) ed#e	d$Z*e%d% Z+e#rd&d'iZ,d(d'iZ-ni Z,i Z-ej.dLd)d'ie,G d*d+ d+ee* Z/G d,d- d-ej!e/e*  Z0G d.d/ d/e0e/e*  Z1G d0d1 d1e0e/e*  Z2G d2d3 d3e1e/e*  e2e/e*  Z3G d4d5 d5e0e/e4  Z5G d6d7 d7e0e/e4  Z6G d8d9 d9e0e/e  Z7G d:d; d;e0e/e  Z8G d<d= d=e0e/e  Z9G d>d? d?e0e/e  Z:G d@dA dAe2e/e4  Z;G dBdC dCe2e/e4  Z<G dDdE dEe2e/e  Z=G dFdG dGe2e/e  Z>G dHdI dIe2e/e  Z?G dJdK dKe2e/e  Z@dS )M    )annotationsN)date)datetime)	timedelta)Decimal)Any)cast)Generic)Optional)overload)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )ADJACENT_TO)CONTAINED_BY)CONTAINS)NOT_EXTEND_LEFT_OF)NOT_EXTEND_RIGHT_OF)OVERLAP)STRICTLY_LEFT_OF)STRICTLY_RIGHT_OF   )types)	operators)
TypeEngine)py310)Literal)ColumnElement)_TE)TypeEngineMixin_T)bound)z()[)z(]z[]slotsTkw_onlyfrozenc                   @  s  e Zd ZU dZdZded< 	 dZded< 	 er,ej	ddZ
ded	< ej	d
dZded< nej	dZddieZ
ded	< ej	dZdd
ieZded< esV		d[dd
dd\ddZd]ddZed]ddZed]ddZed]ddZed]ddZed]ddZed]ddZed^d!d"Zd_d%d&Zd`d(d)Z	
dadbd1d2Zdcd4d5Zddd7d8Zded:d;Zddd<d=Zddd>d?ZeZ ddd@dAZ!e!Z"dddBdCZ#dddDdEZ$dfdFdGZ%dddHdIZ&dgdJdKZ'dgdLdMZ(dgdNdOZ)dgdPdQZ*dgdRdSZ+dgdTdUZ,dhdVdWZ-dhdXdYZ.dS )iRangea_  Represent a PostgreSQL range.

    E.g.::

        r = Range(10, 50, bounds="()")

    The calling style is similar to that of psycopg and psycopg2, in part
    to allow easier migration from previous SQLAlchemy versions that used
    these objects directly.

    :param lower: Lower bound value, or None
    :param upper: Upper bound value, or None
    :param bounds: keyword-only, optional string value that is one of
     ``"()"``, ``"[)"``, ``"(]"``, ``"[]"``.  Defaults to ``"[)"``.
    :param empty: keyword-only, optional bool indicating this is an "empty"
     range

    .. versionadded:: 2.0

    NOptional[_T]lowerupperr%   )default_BoundsTypeboundsFboolemptyr-   )r/   r1   c                C  s   | j ||||d d S )N)r+   r,   r/   r1   )__dict__update)selfr+   r,   r/   r1    r5   |C:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\sqlalchemy/dialects/postgresql/ranges.py__init__^   s   	zRange.__init__returnc                 C  s   | j  S Nr1   r4   r5   r5   r6   __bool__p      zRange.__bool__c                 C     | j S z$A synonym for the 'empty' attribute.r:   r;   r5   r5   r6   isemptys      zRange.isemptyc                 C  r>   r?   r:   r;   r5   r5   r6   is_emptyy   rA   zRange.is_emptyc                 C     | j d dkS )z,Return True if the lower bound is inclusive.r   [r/   r;   r5   r5   r6   	lower_inc      zRange.lower_incc                 C     | j  o| jdu S )zKReturn True if this range is non-empty and lower bound is
        infinite.N)r1   r+   r;   r5   r5   r6   	lower_inf      zRange.lower_infc                 C  rC   )z,Return True if the upper bound is inclusive.r   ]rE   r;   r5   r5   r6   	upper_inc   rG   zRange.upper_incc                 C  rH   )zOReturn True if this range is non-empty and the upper bound is
        infinite.N)r1   r,   r;   r5   r5   r6   	upper_inf   rJ   zRange.upper_infAbstractRange[Range[_T]]c                 C  s   t  S r9   )AbstractRanger;   r5   r5   r6   __sa_type_engine__   s   zRange.__sa_type_engine__valuer#   c                 C  s   | j rdS | jdu r | jdu p| jd dkr|| jk S || jkS | jdu r6| jd dkr1|| jkS || jkS | jd dkrB|| jkn|| jkoW| jd dkrS|| jk S || jkS )z3Return True if this range contains the given value.FNr   )r   ()r1   r+   r,   r/   r4   rQ   r5   r5   r6   _contains_value   s0   



zRange._contains_valuer   c                 C  s^   t | jtst | jtrdS t | jtst | jtrdS t | jts(t | jtr-tddS dS )uA   Determine the “step” for this range, if it is a discrete one.r   N)days)
isinstancer+   intr,   r   r   r   r;   r5   r5   r6   _get_discrete_step   s   
zRange._get_discrete_stepvalue1bound1strvalue2bound2only_valuesrX   c                 C  sX  |dv }|dv }||  u rdu r n n||krdS |rdS dS |du r*|r(dS dS |du r4|r2dS dS ||kr>||kr>dS |dv }|dv }	|   }
|
durt|rY|sX||
7 }d}n|ra||
7 }d}|rl|	sk||
7 }d}	n|	rt||
7 }d}	||k rzdS ||krdS |rdS |r|	rdS |s|	s||krdS |rdS dS |s|rdS dS |	s|rdS dS dS )	a  Compare two range bounds.

        Return -1, 0 or 1 respectively when `value1` is less than,
        equal to or greater than `value2`.

        When `only_value` is ``True``, do not consider the *inclusivity*
        of the edges, just their values.
        >   rS   rD   Nr   r   >   rK   rD   TF)rY   )r4   rZ   r[   r]   r^   r_   Zvalue1_is_lower_boundZvalue2_is_lower_boundZ
value1_incZ
value2_incstepr5   r5   r6   _compare_edges   sb   zRange._compare_edgesotherc           
      C  s   t |tstS | jr|jrdS | j|jkrdS | j}| jd }|j}|jd }| j}| jd }|j}|jd }	| ||||dkoJ| ||||	dkS )zCompare this range to the `other` taking into account
        bounds inclusivity, returning ``True`` if they are equal.
        TFr   r   )rW   r)   NotImplementedr1   r+   r/   r,   rb   
r4   rc   slowerslower_bolowerolower_bsuppersupper_boupperoupper_br5   r5   r6   __eq__(  s"   




zRange.__eq__	Range[_T]c           
      C  s   | j rdS |j r
dS | j}| jd }|j}|jd }| ||||dk r&dS | j}| jd }|j}|jd }	| ||||	dkrBdS dS )z7Determine whether this range is a contained by `other`.TFr   r   )r1   r+   r/   rb   r,   re   r5   r5   r6   contained_byC  s"   



zRange.contained_byUnion[_T, Range[_T]]c                 C  s   t |tr
|| S | |S )z.Determine whether this range contains `value`.)rW   r)   rp   rU   rT   r5   r5   r6   contains`  s   


zRange.containsc           
      C  s   | j s|j rdS | j}| jd }| j}| jd }|j}|jd }|j}|jd }	| ||||dkr>| ||||	dkr>dS | ||||dkrT| ||||dkrTdS dS )z3Determine whether this range overlaps with `other`.Fr   r   Tr1   r+   r/   r,   rb   
r4   rc   rf   rg   rj   rk   rh   ri   rl   rm   r5   r5   r6   overlapsh  s"   



zRange.overlapsc                 C  sD   | j s|j rdS | j}| jd }|j}|jd }| ||||dk S )zBDetermine whether this range is completely to the left of `other`.Fr   r   )r1   r,   r/   r+   rb   )r4   rc   rj   rk   rh   ri   r5   r5   r6   strictly_left_of     

zRange.strictly_left_ofc                 C  sD   | j s|j rdS | j}| jd }|j}|jd }| ||||dkS )zCDetermine whether this range is completely to the right of `other`.Fr   r   rs   )r4   rc   rf   rg   rl   rm   r5   r5   r6   strictly_right_of  rw   zRange.strictly_right_ofc                 C  sD   | j s|j rdS | j}| jd }|j}|jd }| ||||dkS )z>Determine whether this does not extend to the left of `other`.Fr   )r1   r+   r/   rb   )r4   rc   rf   rg   rh   ri   r5   r5   r6   not_extend_left_of  rw   zRange.not_extend_left_ofc                 C  sD   | j s|j rdS | j}| jd }|j}|jd }| ||||dkS )z?Determine whether this does not extend to the right of `other`.Fr   r   )r1   r,   r/   rb   )r4   rc   rj   rk   rl   rm   r5   r5   r6   not_extend_right_of  rw   zRange.not_extend_right_ofc                 C  s   |  ||||d}|dkr7|  }|du rdS |dkr)|dkr%||| kS ||kS |dkr1||kS ||| kS |dkre|dkrC|dksK|dkrU|d	krU|  }|durUdS |dkr]|dkpd|dkod|d	kS dS )
zTDetermine whether an upper bound is immediately successive to a
        lower bound.Tr`   NFrK   rD   r   rR   rS   )rb   rY   )r4   rZ   r[   r]   r^   resra   r5   r5   r6   _upper_edge_adjacent_to_lower  s6   z#Range._upper_edge_adjacent_to_lowerc           
      C  sp   | j s|j rdS | j}| jd }| j}| jd }|j}|jd }|j}|jd }	| ||||p7| ||	||S )z8Determine whether this range is adjacent to the `other`.Fr   r   )r1   r+   r/   r,   r|   rt   r5   r5   r6   adjacent_to  s"   



zRange.adjacent_toc                 C  s   | j r|S |j r
| S | |s| |std| j}| jd }| j}| jd }|j}|jd }|j}|jd }	| ||||dk rG|}
|}n|}
|}| ||||	dkrZ|}|}n|}|	}t|
|t	t
|| dS )zCompute the union of this range with the `other`.

        This raises a ``ValueError`` exception if the two ranges are
        "disjunct", that is neither adjacent nor overlapping.
        zAAdding non-overlapping and non-adjacent ranges is not implementedr   r   rE   )r1   ru   r}   
ValueErrorr+   r/   r,   rb   r)   r   r.   r4   rc   rf   rg   rj   rk   rh   ri   rl   rm   Zrlowerrlower_bZrupperrupper_br5   r5   r6   union  s:   



zRange.unionc                 C  
   |  |S r9   )r   r4   rc   r5   r5   r6   __add__;     
zRange.__add__c                 C  s  | j s|j r| S | j}| jd }| j}| jd }|j}|jd }|j}|jd }	| ||||}
| ||||	}|
dk rD|dkrDtd| ||||	}| ||||}|dks\|dk r^| S |
dkrm|dkrmtddddS |
dkr|dkr|dkr|dkrdnd	}|dkr|d	kr| ||||dkrtddddS t||tt|| d
S |
dkr|dkr|dkr|	d	krdnd}|dkr|d	kr| ||||dkrtddddS t||tt|| d
S J d|  d| )zCompute the difference between this range and the `other`.

        This raises a ``ValueError`` exception if the two ranges are
        "disjunct", that is neither adjacent nor overlapping.
        r   r   z5Subtracting a strictly inner range is not implementedNTr:   rD   rR   rK   rE   rS   FzUnhandled case computing z - )	r1   r+   r/   r,   rb   r~   r)   r   r.   )r4   rc   rf   rg   rj   rk   rh   ri   rl   rm   Zsl_vs_olZsu_vs_ouZsl_vs_ouZsu_vs_olr   r   r5   r5   r6   
difference>  sb   



zRange.differencec                 C  r   r9   )r   r   r5   r5   r6   __sub__  r   zRange.__sub__c                 C  s   | j s|j s| |stddddS | j}| jd }| j}| jd }|j}|jd }|j}|jd }	| ||||dk rA|}
|}n|}
|}| ||||	dkrT|}|	}n|}|}t|
|tt|| dS )zdCompute the intersection of this range with the `other`.

        .. versionadded:: 2.0.10

        NTr:   r   r   rE   )	r1   ru   r)   r+   r/   r,   rb   r   r.   r   r5   r5   r6   intersection  s2   



zRange.intersectionc                 C  r   r9   )r   r   r5   r5   r6   __mul__  r   zRange.__mul__c                 C  s   |   S r9   )
_stringifyr;   r5   r5   r6   __str__  r=   zRange.__str__c                 C  s^   | j rdS | j| j}}|d u rdn|}|d u rdn|}td| j\}}| | d| | S )Nr1    zTuple[str, str],)r1   r+   r,   r   r/   )r4   lrZb0b1r5   r5   r6   r     s   zRange._stringifyr5   )NN)r+   r*   r,   r*   r/   r.   r1   r0   )r8   r0   )r8   rN   )rQ   r#   r8   r0   )r8   r   )F)rZ   r*   r[   r\   r]   r*   r^   r\   r_   r0   r8   rX   )rc   r   r8   r0   )rc   ro   r8   r0   )rQ   rq   r8   r0   )
rZ   r*   r[   r\   r]   r*   r^   r\   r8   r0   )rc   ro   r8   ro   )r8   r\   )/__name__
__module____qualname____doc__r+   __annotations__r,   r   dataclassesfieldr/   r1   	dc_kwonlyr   r7   r<   propertyr@   rB   rF   rI   rL   rM   rP   rU   rY   rb   rn   rp   rr   ru   rv   
__lshift__rx   
__rshift__ry   rz   r|   r}   r   r   r   r   r   r   r   r   r5   r5   r5   r6   r)   8   sr   
 



Y



 




/

.

L

&
r)   c                      sj   e Zd ZdZdZdZedd	d
Zeddd
Zd fdd
ZdddZG dd de	j
ee  Z  ZS )rO   z
    Base for PostgreSQL RANGE types.

    .. seealso::

        `PostgreSQL range functions <https://www.postgresql.org/docs/current/static/functions-range.html>`_

    Tcls	Type[_TE]kwr   r8   r!   c                 K     d S r9   r5   r4   r   r   r5   r5   r6   adapt     zAbstractRange.adaptType[TypeEngineMixin]TypeEngine[Any]c                 K  r   r9   r5   r   r5   r5   r6   r     r   -Type[Union[TypeEngine[Any], TypeEngineMixin]]c                   sD   t |tr|| jur| j}t| d|| jfd|i S t |S )a	  Dynamically adapt a range type to an abstract impl.

        For example ``INT4RANGE().adapt(_Psycopg2NumericRange)`` should
        produce a type that will have ``_Psycopg2NumericRange`` behaviors
        and also render as ``INT4RANGE`` in SQL and DDL.

        Z	RangeImpl__visit_name__)
issubclassAbstractRangeImpl	__class__r   typesuperr   )r4   r   r   Z
visit_namer   r5   r6   r     s   
rQ   c                 C  sl   |j d ur|j n|j}t|trt S t|ttfrt S t|tr+|j	s(t
 S t S t|tr3t S tjS r9   )r+   r,   rW   rX   	INT8RANGEr   floatNUMRANGEr   tzinfoTSRANGE	TSTZRANGEr   	DATERANGEsqltypesZNULLTYPE)r4   rQ   specr5   r5   r6   _resolve_for_literal  s   


z"AbstractRange._resolve_for_literalc                   @  s   e Zd ZdZdddZd d	d
Zd ddZd ddZeZd ddZ	e	Z
d ddZd ddZd ddZd ddZd ddZd!ddZdS )"z AbstractRange.comparator_factoryz-Define comparison operations for range types.rc   r   r   r8   ColumnElement[bool]c                 K     | j t|S )a
  Boolean expression. Returns true if the right hand operand,
            which can be an element or a range, is contained within the
            column.

            kwargs may be ignored by this operator but are required for API
            conformance.
            )exproperater   )r4   rc   r   r5   r5   r6   rr     s   z)AbstractRange.comparator_factory.containsc                 C  r   )zsBoolean expression. Returns true if the column is contained
            within the right hand operand.
            )r   r   r   r   r5   r5   r6   rp     rG   z-AbstractRange.comparator_factory.contained_byc                 C  r   )zBoolean expression. Returns true if the column overlaps
            (has points in common with) the right hand operand.
            )r   r   r   r   r5   r5   r6   ru     rG   z)AbstractRange.comparator_factory.overlapsc                 C  r   )zsBoolean expression. Returns true if the column is strictly
            left of the right hand operand.
            )r   r   r   r   r5   r5   r6   rv   #  rG   z1AbstractRange.comparator_factory.strictly_left_ofc                 C  r   )ztBoolean expression. Returns true if the column is strictly
            right of the right hand operand.
            )r   r   r   r   r5   r5   r6   rx   +  rG   z2AbstractRange.comparator_factory.strictly_right_ofc                 C  r   )zBoolean expression. Returns true if the range in the column
            does not extend right of the range in the operand.
            )r   r   r   r   r5   r5   r6   rz   3  rG   z4AbstractRange.comparator_factory.not_extend_right_ofc                 C  r   )zBoolean expression. Returns true if the range in the column
            does not extend left of the range in the operand.
            )r   r   r   r   r5   r5   r6   ry   9  rG   z3AbstractRange.comparator_factory.not_extend_left_ofc                 C  r   )z}Boolean expression. Returns true if the range in the column
            is adjacent to the range in the operand.
            )r   r   r   r   r5   r5   r6   r}   ?  rG   z,AbstractRange.comparator_factory.adjacent_toc                 C     | j tj|S zRange expression. Returns the union of the two ranges.
            Will raise an exception if the resulting range is not
            contiguous.
            )r   r   r   addr   r5   r5   r6   r   E     z&AbstractRange.comparator_factory.unionc                 C  r   r   )r   r   r   subr   r5   r5   r6   r   L  r   z+AbstractRange.comparator_factory.differenceColumnElement[Range[_T]]c                 C  r   )zRange expression. Returns the intersection of the two ranges.
            Will raise an exception if the resulting range is not
            contiguous.
            )r   r   r   mulr   r5   r5   r6   r   S  r   z-AbstractRange.comparator_factory.intersectionN)rc   r   r   r   r8   r   )rc   r   r8   r   )rc   r   r8   r   )r   r   r   r   rr   rp   ru   rv   r   rx   r   rz   ry   r}   r   r   r   r5   r5   r5   r6   comparator_factory
  s    










r   )r   r   r   r   r8   r!   )r   r   r   r   r8   r   )r   r   r   r   r8   r   )rQ   r   r8   r   )r   r   r   r   Zrender_bind_cast__abstract__r   r   r   r   Z
Comparatorr)   r   r   __classcell__r5   r5   r   r6   rO     s    	
"rO   c                   @     e Zd ZdZdS )r   KMarker for AbstractRange that will apply a subclass-specific
    adaptationNr   r   r   r   r5   r5   r5   r6   r   [  s    r   c                   @  s   e Zd ZdZdZdS )AbstractMultiRangez$base for PostgreSQL MULTIRANGE typesTN)r   r   r   r   r   r5   r5   r5   r6   r   `      r   c                   @  r   )AbstractMultiRangeImplr   Nr   r5   r5   r5   r6   r   f  s    r   c                   @     e Zd ZdZd ZdS )	INT4RANGEz(Represent the PostgreSQL INT4RANGE type.Nr   r   r   r   r   r5   r5   r5   r6   r   m  r   r   c                   @  r   )r   z(Represent the PostgreSQL INT8RANGE type.Nr   r5   r5   r5   r6   r   s  r   r   c                   @  r   )r   z'Represent the PostgreSQL NUMRANGE type.Nr   r5   r5   r5   r6   r   y  r   r   c                   @  r   )r   z(Represent the PostgreSQL DATERANGE type.Nr   r5   r5   r5   r6   r     r   r   c                   @  r   )r   &Represent the PostgreSQL TSRANGE type.Nr   r5   r5   r5   r6   r     r   r   c                   @  r   )r   (Represent the PostgreSQL TSTZRANGE type.Nr   r5   r5   r5   r6   r     r   r   c                   @  r   )INT4MULTIRANGEz-Represent the PostgreSQL INT4MULTIRANGE type.Nr   r5   r5   r5   r6   r     r   r   c                   @  r   )INT8MULTIRANGEz-Represent the PostgreSQL INT8MULTIRANGE type.Nr   r5   r5   r5   r6   r     r   r   c                   @  r   )NUMMULTIRANGEz,Represent the PostgreSQL NUMMULTIRANGE type.Nr   r5   r5   r5   r6   r     r   r   c                   @  r   )DATEMULTIRANGEz-Represent the PostgreSQL DATEMULTIRANGE type.Nr   r5   r5   r5   r6   r     r   r   c                   @  r   )TSMULTIRANGEr   Nr   r5   r5   r5   r6   r     r   r   c                   @  r   )TSTZMULTIRANGEr   Nr   r5   r5   r5   r6   r     r   r   r5   )A
__future__r   r   r   r   r   decimalr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   sqlZsql.type_apir   utilr   Zutil.typingr   Zsql.elementsr    r!   r"   r#   r.   Zdc_slotsr   	dataclassr)   rO   r   r   r   rX   r   r   r   r   r   r   r   r   r   r   r   r   r5   r5   r5   r6   <module>   s   
      
