a
    c	g4v                     @  sn  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.f d)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 )L    )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[]slotsTZkw_onlyfrozenc                   @  s  e Zd ZU dZdZded< dZded< erTej	ddZ
ded	< ej	d
dZded< n8ej	f ddieZ
ded	< ej	f dd
ieZded< esdXdd
ddddddddZddddZeddddZeddddZeddddZeddddZeddddZedddd Zed!dd"d#Zd$dd%d&d'Zd(dd)d*ZdYdd+dd+dd,d-d.d/Zd(dd0d1d2Zd3dd0d4d5Zd6dd%d7d8Zd3dd0d9d:Zd3dd0d;d<ZeZ d3dd0d=d>Z!e!Z"d3dd0d?d@Z#d3dd0dAdBZ$dd+dd+ddCdDdEZ%d3dd0dFdGZ&d3d3d0dHdIZ'd3d3d0dJdKZ(d3d3d0dLdMZ)d3d3d0dNdOZ*d3d3d0dPdQZ+d3d3d0dRdSZ,d+ddTdUZ-d+ddVdWZ.dS )Z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

    NzOptional[_T]lowerupperr%   )default_BoundsTypeboundsFboolemptyr+   )r-   r/   r)   r*   r-   r/   c                C  s   | j ||||d d S )Nr0   )__dict__update)selfr)   r*   r-   r/    r4   h/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/ranges.py__init__^   s    	zRange.__init__)returnc                 C  s   | j  S Nr/   r3   r4   r4   r5   __bool__p   s    zRange.__bool__c                 C  s   | j S z$A synonym for the 'empty' attribute.r9   r:   r4   r4   r5   isemptys   s    zRange.isemptyc                 C  s   | j S r<   r9   r:   r4   r4   r5   is_emptyy   s    zRange.is_emptyc                 C  s   | j d dkS )z,Return True if the lower bound is inclusive.r   [r-   r:   r4   r4   r5   	lower_inc   s    zRange.lower_incc                 C  s   | j  o| jdu S )zKReturn True if this range is non-empty and lower bound is
        infinite.N)r/   r)   r:   r4   r4   r5   	lower_inf   s    zRange.lower_infc                 C  s   | j d dkS )z,Return True if the upper bound is inclusive.r   ]r@   r:   r4   r4   r5   	upper_inc   s    zRange.upper_incc                 C  s   | j  o| jdu S )zOReturn True if this range is non-empty and the upper bound is
        infinite.N)r/   r*   r:   r4   r4   r5   	upper_inf   s    zRange.upper_infzAbstractRange[Range[_T]]c                 C  s   t  S r8   )AbstractRanger:   r4   r4   r5   __sa_type_engine__   s    zRange.__sa_type_engine__r#   valuer7   c                 C  s   | j r
dS | jdu r@| jdu p>| jd dkr6|| jk S || jkS | jdu rl| jd dkrb|| jkS || jkS | jd dkr|| jkn|| jko| jd dkr|| jk S || jkS )z3Return True if this range contains the given value.FNr   )r   ()r/   r)   r*   r-   r3   rI   r4   r4   r5   _contains_value   s*    


zRange._contains_valuer   c                 C  sb   t | jtst | jtrdS t | jts4t | jtr8dS t | jtsPt | jtrZtddS 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:   r4   r4   r5   _get_discrete_step   s    
zRange._get_discrete_stepstrrP   )value1bound1value2bound2only_valuesr7   c                 C  sx  |dv }|dv }||  u r$du rBn n||kr4dS |r<dS dS n(|du rV|rRdS dS |du rj|rfdS dS ||kr~||kr~dS |dv }|dv }	|   }
|
dur|r|s||
7 }d}n|r||
7 }d}|r|	s||
7 }d}	n|	r||
7 }d}	||k rdS ||krdS |rdS |r|	rdS |sH|	sH||kr8dS |rBdS dS n,|s\|rXdS dS |	sp|rldS d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.
        >   rK   r?   Nr   r   >   r?   rC   TF)rQ   )r3   rS   rT   rU   rV   rW   Zvalue1_is_lower_boundZvalue2_is_lower_boundZ
value1_incZ
value2_incstepr4   r4   r5   _compare_edges   s^    

zRange._compare_edgesotherr7   c           
      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o| ||||	dkS )zCompare this range to the `other` taking into account
        bounds inclusivity, returning ``True`` if they are equal.
        TFr   r   )rO   r(   NotImplementedr/   r)   r-   r*   rZ   
r3   r\   slowerslower_bolowerolower_bsuppersupper_boupperoupper_br4   r4   r5   __eq__(  s"    




zRange.__eq__z	Range[_T]c           
      C  s   | j r
dS |j rdS | j}| jd }|j}|jd }| ||||dk rLdS | j}| jd }|j}|jd }	| ||||	dkrdS dS )z7Determine whether this range is a contained by `other`.TFr   r   )r/   r)   r-   rZ   r*   r^   r4   r4   r5   contained_byC  s"    



zRange.contained_byzUnion[_T, Range[_T]]c                 C  s"   t |tr|| S | |S dS )z.Determine whether this range contains `value`.N)rO   r(   rh   rM   rL   r4   r4   r5   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r| ||||dkrdS dS )z3Determine whether this range overlaps with `other`.Fr   r   Tr/   r)   r-   r*   rZ   
r3   r\   r_   r`   rc   rd   ra   rb   re   rf   r4   r4   r5   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   )r/   r*   r-   r)   rZ   )r3   r\   rc   rd   ra   rb   r4   r4   r5   strictly_left_of  s    

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   rj   )r3   r\   r_   r`   re   rf   r4   r4   r5   strictly_right_of  s    

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   )r/   r)   r-   rZ   )r3   r\   r_   r`   ra   rb   r4   r4   r5   not_extend_left_of  s    

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   )r/   r*   r-   rZ   )r3   r\   rc   rd   re   rf   r4   r4   r5   not_extend_right_of  s    

zRange.not_extend_right_of)rS   rT   rU   rV   r7   c                 C  s   |  ||||d}|dkrr|  }|du r.dS |dkrT|dkrJ||| kS ||kS q|dkrd||kS ||| kS n`|dkr|dkr|dks|dkr|d	kr|  }|durdS |dkr|dkp|dko|d	kS dS dS )
zTDetermine whether an upper bound is immediately successive to a
        lower bound.TrX   NFrC   r?   r   rJ   rK   )rZ   rQ   )r3   rS   rT   rU   rV   resrY   r4   r4   r5   _upper_edge_adjacent_to_lower  s>    
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 }	| ||||pn| ||	||S )z8Determine whether this range is adjacent to the `other`.Fr   r   )r/   r)   r-   r*   rr   rk   r4   r4   r5   adjacent_to  s"    



zRange.adjacent_toc                 C  s   | j r
|S |j r| S | |s0| |s0td| j}| jd }| j}| jd }|j}|jd }|j}|jd }	| ||||dk r|}
|}n|}
|}| ||||	dkr|}|}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   r@   )r/   rl   rs   
ValueErrorr)   r-   r*   rZ   r(   r   r,   r3   r\   r_   r`   rc   rd   ra   rb   re   rf   Zrlowerrlower_bZrupperrupper_br4   r4   r5   union  s:    



zRange.unionc                 C  s
   |  |S r8   )rx   r3   r\   r4   r4   r5   __add__;  s    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 r|dkrtd| ||||	}| ||||}|dks|dk r| S |
dkr|dkrtddddS |
dkrZ|dkrZ|dkrZ|dkrdnd	}|dkrB|d	krB| ||||dkrBt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 dsJ d|  d| dS )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 implementedNTr9   r?   rJ   rC   r@   rK   FzUnhandled case computing z - )	r/   r)   r-   r*   rZ   rt   r(   r   r,   )r3   r\   r_   r`   rc   rd   ra   rb   re   rf   Zsl_vs_olZsu_vs_ouZsl_vs_ouZsu_vs_olrw   rv   r4   r4   r5   
difference>  sn    



zRange.differencec                 C  s
   |  |S r8   )r{   ry   r4   r4   r5   __sub__  s    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 r|}
|}n|}
|}| ||||	dkr|}|	}n|}|}t|
|tt|| dS )zdCompute the intersection of this range with the `other`.

        .. versionadded:: 2.0.10

        NTr9   r   r   r@   )	r/   rl   r(   r)   r-   r*   rZ   r   r,   ru   r4   r4   r5   intersection  s2    



zRange.intersectionc                 C  s
   |  |S r8   )r}   ry   r4   r4   r5   __mul__  s    zRange.__mul__c                 C  s   |   S r8   )
_stringifyr:   r4   r4   r5   __str__  s    zRange.__str__c                 C  s^   | j r
dS | j| j }}|d u r$dn|}|d u r4dn|}td| j\}}| | d| | S )Nr/    zTuple[str, str],)r/   r)   r*   r   r-   )r3   lrZb0b1r4   r4   r5   r     s    zRange._stringify)NN)F)/__name__
__module____qualname____doc__r)   __annotations__r*   r   dataclassesfieldr-   r/   	dc_kwonlyr   r6   r;   propertyr=   r>   rA   rB   rD   rE   rG   rM   rQ   rZ   rg   rh   ri   rl   rm   
__lshift__rn   
__rshift__ro   rp   rr   rs   rx   rz   r{   r|   r}   r~   r   r   r4   r4   r4   r5   r(   8   sl   
   Y /.L&r(   c                      s   e Zd ZdZdZdZeddddddZed	dd
dddZddd
d fddZdddddZG dd de	j
ee  Z  ZS )rF   z
    Base for PostgreSQL RANGE types.

    .. seealso::

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

    Tz	Type[_TE]r   r!   )clskwr7   c                 K  s   d S r8   r4   r3   r   r   r4   r4   r5   adapt  s    zAbstractRange.adaptzType[TypeEngineMixin]zTypeEngine[Any]c                 K  s   d S r8   r4   r   r4   r4   r5   r     s    z-Type[Union[TypeEngine[Any], TypeEngineMixin]]c                   sH   t |tr8|| jur8| j}t| d|| jfd|i S t |S d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__N)
issubclassAbstractRangeImpl	__class__r   typesuperr   )r3   r   r   Z
visit_namer   r4   r5   r     s    
rH   c                 C  sp   |j d ur|j n|j}t|tr&t S t|ttfr:t S t|trV|j	sPt
 S t S t|trft S tjS d S r8   )r)   r*   rO   rP   	INT8RANGEr   floatNUMRANGEr   tzinfoTSRANGE	TSTZRANGEr   	DATERANGEsqltypesZNULLTYPE)r3   rI   specr4   r4   r5   _resolve_for_literal  s    


z"AbstractRange._resolve_for_literalc                   @  s   e Zd ZdZddddddZddddd	Zdddd
dZdddddZeZdddddZ	e	Z
dddddZdddddZdddddZdddddZdddddZdddddZdS )z AbstractRange.comparator_factoryz-Define comparison operations for range types.r   zColumnElement[bool])r\   r   r7   c                 K  s   | 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   )r3   r\   r   r4   r4   r5   ri     s    z)AbstractRange.comparator_factory.containsr[   c                 C  s   | j t|S )zsBoolean expression. Returns true if the column is contained
            within the right hand operand.
            )r   r   r   ry   r4   r4   r5   rh     s    z-AbstractRange.comparator_factory.contained_byc                 C  s   | j t|S )zBoolean expression. Returns true if the column overlaps
            (has points in common with) the right hand operand.
            )r   r   r   ry   r4   r4   r5   rl     s    z)AbstractRange.comparator_factory.overlapsc                 C  s   | j t|S )zsBoolean expression. Returns true if the column is strictly
            left of the right hand operand.
            )r   r   r   ry   r4   r4   r5   rm   #  s    z1AbstractRange.comparator_factory.strictly_left_ofc                 C  s   | j t|S )ztBoolean expression. Returns true if the column is strictly
            right of the right hand operand.
            )r   r   r   ry   r4   r4   r5   rn   +  s    z2AbstractRange.comparator_factory.strictly_right_ofc                 C  s   | j t|S )zBoolean expression. Returns true if the range in the column
            does not extend right of the range in the operand.
            )r   r   r   ry   r4   r4   r5   rp   3  s    z4AbstractRange.comparator_factory.not_extend_right_ofc                 C  s   | j t|S )zBoolean expression. Returns true if the range in the column
            does not extend left of the range in the operand.
            )r   r   r   ry   r4   r4   r5   ro   9  s    z3AbstractRange.comparator_factory.not_extend_left_ofc                 C  s   | j t|S )z}Boolean expression. Returns true if the range in the column
            is adjacent to the range in the operand.
            )r   r   r   ry   r4   r4   r5   rs   ?  s    z,AbstractRange.comparator_factory.adjacent_toc                 C  s   | 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   addry   r4   r4   r5   rx   E  s    z&AbstractRange.comparator_factory.unionc                 C  s   | j tj|S r   )r   r   r   subry   r4   r4   r5   r{   L  s    z+AbstractRange.comparator_factory.differencezColumnElement[Range[_T]]c                 C  s   | j tj|S )zRange expression. Returns the intersection of the two ranges.
            Will raise an exception if the resulting range is not
            contiguous.
            )r   r   r   mulry   r4   r4   r5   r}   S  s    z-AbstractRange.comparator_factory.intersectionN)r   r   r   r   ri   rh   rl   rm   r   rn   r   rp   ro   rs   rx   r{   r}   r4   r4   r4   r5   comparator_factory
  s   
r   )r   r   r   r   Zrender_bind_cast__abstract__r   r   r   r   Z
Comparatorr(   r   r   __classcell__r4   r4   r   r5   rF     s   	rF   c                   @  s   e Zd ZdZdS )r   KMarker for AbstractRange that will apply a subclass-specific
    adaptationNr   r   r   r   r4   r4   r4   r5   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   r4   r4   r4   r5   r   `  s   r   c                   @  s   e Zd ZdZdS )AbstractMultiRangeImplr   Nr   r4   r4   r4   r5   r   f  s   r   c                   @  s   e Zd ZdZd ZdS )	INT4RANGEz(Represent the PostgreSQL INT4RANGE type.Nr   r   r   r   r   r4   r4   r4   r5   r   m  s   r   c                   @  s   e Zd ZdZd ZdS )r   z(Represent the PostgreSQL INT8RANGE type.Nr   r4   r4   r4   r5   r   s  s   r   c                   @  s   e Zd ZdZd ZdS )r   z'Represent the PostgreSQL NUMRANGE type.Nr   r4   r4   r4   r5   r   y  s   r   c                   @  s   e Zd ZdZd ZdS )r   z(Represent the PostgreSQL DATERANGE type.Nr   r4   r4   r4   r5   r     s   r   c                   @  s   e Zd ZdZd ZdS )r   &Represent the PostgreSQL TSRANGE type.Nr   r4   r4   r4   r5   r     s   r   c                   @  s   e Zd ZdZd ZdS )r   (Represent the PostgreSQL TSTZRANGE type.Nr   r4   r4   r4   r5   r     s   r   c                   @  s   e Zd ZdZd ZdS )INT4MULTIRANGEz-Represent the PostgreSQL INT4MULTIRANGE type.Nr   r4   r4   r4   r5   r     s   r   c                   @  s   e Zd ZdZd ZdS )INT8MULTIRANGEz-Represent the PostgreSQL INT8MULTIRANGE type.Nr   r4   r4   r4   r5   r     s   r   c                   @  s   e Zd ZdZd ZdS )NUMMULTIRANGEz,Represent the PostgreSQL NUMMULTIRANGE type.Nr   r4   r4   r4   r5   r     s   r   c                   @  s   e Zd ZdZd ZdS )DATEMULTIRANGEz-Represent the PostgreSQL DATEMULTIRANGE type.Nr   r4   r4   r4   r5   r     s   r   c                   @  s   e Zd ZdZd ZdS )TSMULTIRANGEr   Nr   r4   r4   r4   r5   r     s   r   c                   @  s   e Zd ZdZd ZdS )TSTZMULTIRANGEr   Nr   r4   r4   r4   r5   r     s   r   )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   ZsqlZsql.type_apir   utilr   Zutil.typingr   Zsql.elementsr    r!   r"   r#   r,   Zdc_slotsr   Z	dataclassr(   rF   r   r   r   rP   r   r   r   r   r   r   r   r   r   r   r   r   r4   r4   r4   r5   <module>   s   
      
