L iVddlmZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZ ddl!mZddl"m#Z#dd l$m%Z%dd!l&m'Z'erdd"l(m)Z)dd#l"m*Z*dd$l"m+Z+ed%e &Z,e'd'Z-e%r d(d)iZ.d*d)iZ/niZ.iZ/ej`dUd+d)ie.Gd,d-e e,Z1Gd.d/e e1e,Z2Gd0d1e jFe,Z3Gd2d3e3e1e,Z4Gd4d5e4e,Z5Gd6d7e3ee1e,Z6Gd8d9e6e,Z7Gd:d;e4e8Z9Gd<d=e4e8Z:Gd>d?e4eZ;Gd@dAe4eZ<GdBdCe4eZ=GdDdEe4eZ>GdFdGe6e8Z?GdHdIe6e8Z@GdJdKe6eZAGdLdMe6eZBGdNdOe6eZCGdPdQe6eZDdRZEdSZFdVdTZGy)W) annotationsN)date)datetime) timedelta)Decimal)Any)cast)Generic)List)Optional)overload)Sequence)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[]slotsTkw_onlyfrozenceZdZUdZdZded< dZded< er1ejdZ ded <ejd Z d ed <n2ejd-d die Z ded <ejd-d d ie Z d ed <e s d.dd d d/dZd0dZed0dZed0dZed0dZed0dZed0dZed0dZed1dZd2dZd3dZ d4 d5dZd6dZd7dZd8dZeZd7dZd7dZ e Z!d7d Z"e"Z#d7d!Z$d7d"Z% d9d#Z&d7d$Z'd:d%Z(d:d&Z)d:d'Z*d:d(Z+d:d)Z,d:d*Z-d;d+Z.d;d,Z/y)<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]lowerupperr()default _BoundsTypeboundsFboolemptyr1)r3r5cD|jj||||dy)N)r/r0r3r5)__dict__update)selfr/r0r3r5s k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/ranges.py__init__zRange.__init__as' MM ""$"  c|j SNr5r9s r:__bool__zRange.__bool__ss::~r<c|jSz$A synonym for the 'empty' attribute.r?r@s r:isemptyz Range.isemptyvzzr<c|jSrCr?r@s r:is_emptyzRange.is_empty|rEr<c&|jddk(S)z,Return True if the lower bound is inclusive.r[r3r@s r: lower_inczRange.lower_inc{{1~$$r<c<|j xr|jduS)zKReturn True if this range is non-empty and lower bound is infinite.N)r5r/r@s r: lower_infzRange.lower_inf ::~4$**"44r<c&|jddk(S)z,Return True if the upper bound is inclusive.r]rJr@s r: upper_inczRange.upper_incrLr<c<|j xr|jduS)zOReturn True if this range is non-empty and the upper bound is infinite.N)r5r0r@s r: upper_infzRange.upper_infrOr<ctSr>)AbstractSingleRanger@s r:__sa_type_engine__zRange.__sa_type_engine__s "$$r<c|jry|j@|jduxs0|jddk(r||jkS||jkS|j0|jddk(r||jkDS||jk\S|jddk(r||jkDn||jk\xr0|jddk(r||jkS||jkS)z3Return True if this range contains the given value.FNr)r()r5r/r0r3r9values r:_contains_valuezRange._contains_values  :: :: ::%;;q>S( " djj(  :: ;;q>S( " djj( {{1~$ DJJ $**$ {{1~$ DJJ   $**$ r<cXt|jtst|jtryt|jtst|jtryt|jt st|jt r t dSy)uADetermine the “step” for this range, if it is a discrete one.rN)days) isinstancer/intr0rrrr@s r:_get_discrete_stepzRange._get_discrete_stepsn djj# &*TZZ*E  H - JJ2   D )Z D-I!$ $r<cf|dv}|dv}||cxurnn ||k(ry|rdSdS||rdSdS||rdSdS||k(r||k(ry|dv}|dv} |j} | *|r |s|| z }d}n |r|| z }d}|r | s|| z }d} n | r|| z }d} ||kry||kDry|ry|r| ry|s| s ||k(ry|rdSdS|s|rdSdS| s|rdSdSy)aCompare 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. >rZrIrr>rIrQTF)rb) r9value1bound1value2bound2 only_valuesvalue1_is_lower_boundvalue2_is_lower_bound value1_inc value2_incsteps r:_compare_edgeszRange._compare_edgessN"!'* 4 &* 4 V #$(==2r99 ^.2 5A 5 ^-1 52 5 V & 0z) z) &&(  %!dNF!%JdNF!&J$!dNF!%JdNF!&J F? f_  j (,AA 51=2=1q9r92r99r<ct|tstS|jr |jry|j|jk7ry|j}|j d}|j}|j d}|j }|j d}|j }|j d} |j||||dk(xr|j|||| dk(S)zCompare this range to the `other` taking into account bounds inclusivity, returning ``True`` if they are equal. TFrr)r`r-NotImplementedr5r/r3r0ro r9otherslowerslower_bolowerolower_bsuppersupper_boupperoupper_bs r:__eq__z Range.__eq__+s %'! ! ::%++ ZZ5;; &;;q><<?;;q><<?   &( Cq H M##FHfhG1L r<cp|jry|jry|j}|jd}|j}|jd}|j||||dkry|j}|jd}|j}|jd} |j|||| dkDryy)z7Determine whether this range is a contained by `other`.TFrr)r5r/r3ror0rrs r: contained_byzRange.contained_byFs :: ;;;;q><<?   vx BQ F;;q><<?   vx BQ Fr<cft|tr|j|S|j|S)z.Determine whether this range contains `value`.)r`r-r~r]r[s r:containszRange.containscs0 eU #%%d+ +''. .r<c|js |jry|j}|jd}|j}|jd}|j}|jd}|j}|jd} |j ||||dk\r|j |||| dkry|j ||||dk\r|j ||||dkryy)z3Determine whether this range overlaps with `other`.FrrTr5r/r3r0ro r9rsrtrurxryrvrwrzr{s r:overlapszRange.overlapsms ::;;q>;;q><<?<<?   &( Cq H##FHfhG1L   &( Cq H##FHfhG1Lr<c|js |jry|j}|jd}|j}|jd}|j ||||dkS)zBDetermine whether this range is completely to the left of `other`.Frr)r5r0r3r/ro)r9rsrxryrvrws r:strictly_left_ofzRange.strictly_left_of^ ::;;q><<?""68VXFJJr<c|js |jry|j}|jd}|j}|jd}|j ||||dkDS)zCDetermine whether this range is completely to the right of `other`.Frrr)r9rsrtrurzr{s r:strictly_right_ofzRange.strictly_right_ofrr<c|js |jry|j}|jd}|j}|jd}|j||||dk\S)z>Determine whether this does not extend to the left of `other`.Fr)r5r/r3ro)r9rsrtrurvrws r:not_extend_left_ofzRange.not_extend_left_of^ ::;;q><<?""68VXF!KKr<c|js |jry|j}|jd}|j}|jd}|j||||dkS)z?Determine whether this does not extend to the right of `other`.Frr)r5r0r3ro)r9rsrxryrzr{s r:not_extend_right_ofzRange.not_extend_right_ofrr<c<|j||||d}|dk(r<|j}|y|dk(r|dk(r|||z k(S||k(S|dk(r||k(S|||z k(S|dk(rA|dk(r|dk(s |dk(r|dk(r|j}|y|dk(xr|dk(xs |dk(xr|dk(Sy) zTDetermine whether an upper bound is immediately successive to a lower bound.TrdFrQrIrrYrZ)rorb)r9rerfrgrhresrns r:_upper_edge_adjacent_to_lowerz#Range._upper_edge_adjacent_to_lowers!!&&&&$G "9**,D|}S=!Vd]22!V++S=!V++!Vd]22 AX# cMS=cM..0## "cM"S="cM  r<c`|js |jry|j}|jd}|j}|jd}|j}|jd}|j}|jd} |j ||||xs|j || ||S)z8Determine whether this range is adjacent to the `other`.Frr)r5r/r3r0rrs r: adjacent_tozRange.adjacent_tos ::;;q>;;q><<?<<?11 Hfh   / / Hfh  r<c *|jr|S|jr|S|j|s|j|s td|j}|j d}|j }|j d}|j}|j d}|j }|j d} |j||||dkr|} |} n|} |} |j|||| dkDr|} |} n|} | } t| | tt| | zS)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 implementedrrrJ) r5rr ValueErrorr/r3r0ror-r r2r9rsrtrurxryrvrwrzr{rlowerrlower_brupperrupper_bs r:unionz Range.unions ::L ;;K}}U#D,<,;;q><<?<<?   vx BQ FFHFH   vx BQ FFHFH F4 X5H#I  r<c$|j|Sr>)rr9rss r:__add__z Range.__add__@szz%  r<c |js |jr|S|j}|jd}|j}|jd}|j}|jd}|j}|jd} |j ||||} |j |||| } | dkr| dkDr t d|j |||| } |j ||||} | dkDs| dkr|S| dk\r| dkrt dddS| dkra| dk\r\| dkrW|dk(rdnd }|dk7r*|d k7r%|j ||||dk(rt dddSt ||tt||z S| dk\ra| dk\r\| dkrW| d k(rd nd}|dk7r*|d k7r%|j ||||dk(rt dddSt ||tt||z SJd |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. rrz5Subtracting a strictly inner range is not implementedNTr?rIrYrQrJrZzUnhandled case computing z - ) r5r/r3r0rorr-r r2)r9rsrtrurxryrvrwrzr{sl_vs_olsu_vs_ousl_vs_ousu_vs_olrrs r: differencezRange.differenceCs0 ::K;;q>;;q><<?<<?&&vxJ&&vxJ a)rrs r:__sub__z Range.__sub__su%%r<c |js|js|j|stdddS|j}|jd}|j }|jd}|j}|jd}|j }|jd} |j ||||dkr|} |} n|} |} |j |||| dkDr|} | } n|} |} t| | tt| | zS)zdCompute the intersection of this range with the `other`. .. versionadded:: 2.0.10 NTr?rrrJ) r5rr-r/r3r0ror r2rs r: intersectionzRange.intersections ::DMM%,@t40 0;;q>;;q><<?<<?   vx BQ FFHFH   vx BQ FFHFH   X%89  r<c$|j|Sr>)rrs r:__mul__z Range.__mul__s  ''r<c"|jSr>) _stringifyr@s r:__str__z Range.__str__s  r<c|jry|j|j}}|dn|}|dn|}td|j\}}||d||S)Nr5zTuple[str, str],)r5r/r0r r3)r9lrb0b1s r:rzRange._stringifysa ::zz4::1)B)B'5BaS!RD!!r<)NN)r/r.r0r.r3r2r5r4)returnr4)rzAbstractSingleRange[_T])r\r&rr4)rr)F) rer.rfstrrgr.rhrrir4rra)rsrrr4)rs Range[_T]rr4)r\zUnion[_T, Range[_T]]rr4) rer.rfrrgr.rhrrr4)rsrrr)rr)0__name__ __module__ __qualname____doc__r/__annotations__r0r dataclassesfieldr3r5 dc_kwonlyr!r;rApropertyrDrGrKrNrRrTrWr]rbror|r~r __contains__rr __lshift__r __rshift__rrrrrrrrrrrrrr<r:r-r-;sf*E<E</k//= ='k''6t6/k//JJ J J'k''CCCtC #'"&  #'           $  %% 55 %% 55 %% <4" WWW W  W  W Wr 6:/L@ K"J K#J L L--- -  -  -^ ,, \!JCX&$ L(! "r<r-c"eZdZdZeddZy) MultiRangea?Represents a multirange sequence. This list subclass is an utility to allow automatic type inference of the proper multi-range SQL type depending on the single range values. This is useful when operating on literal multi-ranges:: import sqlalchemy as sa from sqlalchemy.dialects.postgresql import MultiRange, Range value = literal(MultiRange([Range(2, 4)])) select(tbl).where(tbl.c.value.op("@")(MultiRange([Range(-3, 7)]))) .. versionadded:: 2.0.26 .. seealso:: - :ref:`postgresql_multirange_list_use`. ctSr>)AbstractMultiRanger@s r:rWzMultiRange.__sa_type_engine__s !##r<N)rzAbstractMultiRange[_T])rrrrrrWrr<r:rrs($$r<rceZdZdZdZdZeddZe d dZ d fd ZGddeje e Z xZ S) AbstractRangez0Base class for single and multi Range SQL types.Tc yr>rr9clskws r:adaptzAbstractRange.adapts7:r<c yr>rrs r:rzAbstractRange.adaptsr<c t|ttfr=||jur/|j}t |d||jfd|iSt ||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. RangeImpl__visit_name__) issubclassAbstractSingleRangeImplAbstractMultiRangeImpl __class__rtypesuperr)r9rr visit_namers r:rzAbstractRange.adaptst s46LM N4>>),,J4,i(dnn%!:.  7=% %r<cpeZdZdZddZddZddZddZeZddZ e Z ddZ ddZ dd Z dd Zdd Zdd Zy ) AbstractRange.comparator_factoryz-Define comparison operations for range types.c B|jjt|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. )exproperater)r9rsrs r:rz)AbstractRange.comparator_factory.containss99$$Xu5 5r<cB|jjt|S)zsBoolean expression. Returns true if the column is contained within the right hand operand. )rrrrs r:r~z-AbstractRange.comparator_factory.contained_by#s99$$\59 9r<cB|jjt|S)zBoolean expression. Returns true if the column overlaps (has points in common with) the right hand operand. )rrrrs r:rz)AbstractRange.comparator_factory.overlaps)s99$$We4 4r<cB|jjt|S)zsBoolean expression. Returns true if the column is strictly left of the right hand operand. )rrrrs r:rz1AbstractRange.comparator_factory.strictly_left_of/s99$$%5u= =r<cB|jjt|S)ztBoolean expression. Returns true if the column is strictly right of the right hand operand. )rrrrs r:rz2AbstractRange.comparator_factory.strictly_right_of7s99$$%6> >r<cB|jjt|S)zBoolean expression. Returns true if the range in the column does not extend right of the range in the operand. )rrrrs r:rz4AbstractRange.comparator_factory.not_extend_right_of?s99$$%8%@ @r<cB|jjt|S)zBoolean expression. Returns true if the range in the column does not extend left of the range in the operand. )rrrrs r:rz3AbstractRange.comparator_factory.not_extend_left_ofEs99$$%7? ?r<cB|jjt|S)z}Boolean expression. Returns true if the range in the column is adjacent to the range in the operand. )rrrrs r:rz,AbstractRange.comparator_factory.adjacent_toKs99$$[%8 8r<cV|jjtj|SzRange expression. Returns the union of the two ranges. Will raise an exception if the resulting range is not contiguous. )rrraddrs r:rz&AbstractRange.comparator_factory.unionQ 99$$Y]]E: :r<cV|jjtj|Sr)rrrsubrs r:rz+AbstractRange.comparator_factory.differenceXrr<cV|jjtj|S)zRange expression. Returns the intersection of the two ranges. Will raise an exception if the resulting range is not contiguous. )rrrmulrs r:rz-AbstractRange.comparator_factory.intersection_rr<N)rsrrrrColumnElement[bool])rsrrr)rsrrzColumnElement[Range[_T]])rrrrrr~rrrrrrrrrrrrr<r:comparator_factoryrsL; 6 :  5  > &  ? '  A  @  9  ; ; ;r<r)rz Type[_TE]rrrr$)rzType[TypeEngineMixin]rrrTypeEngine[Any])rz-Type[Union[TypeEngine[Any], TypeEngineMixin]]rrrr)rrrrrender_bind_cast __abstract__r rr Comparatorr-rr __classcell__)rs@r:rrs:L :: (03  & : & &  &DN;Z225:>N;N;r<rceZdZdZdZddZy)rVzBase for PostgreSQL RANGE types. These are types that return a single :class:`_postgresql.Range` object. .. seealso:: `PostgreSQL range functions `_ Tc|j |jn |j}t|trt |r t St St|ttfr tSt|tr |js tStSt|tr tSt j"Sr>)r/r0r`ra _is_int32 INT4RANGE INT8RANGErfloatNUMRANGErtzinfoTSRANGE TSTZRANGEr DATERANGEsqltypesNULLTYPE)r9r\specs r:_resolve_for_literalz(AbstractSingleRange._resolve_for_literalts#kk5u{{5;; dC  {" {" w. /:  h '$(KK79 @Y[ @ d #; $$ $r<N)r\z Range[Any]rrrrrrrrrr<r:rVrVgsL%r<rVceZdZdZy)rzQMarker for AbstractSingleRange that will apply a subclass-specific adaptationNrrrrrr<r:rrr<rceZdZdZdZddZy)rzBase for PostgreSQL MULTIRANGE types. these are types that return a sequence of :class:`_postgresql.Range` objects. Tc|stjS|d}|j |jn |j}t |t r&t d|Dr tStSt |ttfr tSt |tr |js tStSt |t r t#StjS)Nrc32K|]}t|ywr>)r).0rs r: z:AbstractMultiRange._resolve_for_literal..s/A9Q</s)rrr/r0r`raallINT4MULTIRANGEINT8MULTIRANGErr NUMMULTIRANGErr TSMULTIRANGETSTZMULTIRANGErDATEMULTIRANGE)r9r\firstrs r:rz'AbstractMultiRange._resolve_for_literals$$ $a#kk5u{{5;; dC ///%''%'' w. / ? " h ')-<> J.:J J d #!# #$$ $r<N)r\zSequence[Range[Any]]rrrrr<r:rrsL%r<rceZdZdZy)rzPMarker for AbstractMultiRange that will apply a subclass-specific adaptationNrrr<r:rrrr<rceZdZdZdZy)rz(Represent the PostgreSQL INT4RANGE type.Nrrrrrrr<r:rr 2 Nr<rceZdZdZdZy)rz(Represent the PostgreSQL INT8RANGE type.Nrrr<r:rrrr<rceZdZdZdZy)rz'Represent the PostgreSQL NUMRANGE type.Nrrr<r:rrs 1Nr<rceZdZdZdZy)rz(Represent the PostgreSQL DATERANGE type.Nrrr<r:rrrr<rceZdZdZdZy)r&Represent the PostgreSQL TSRANGE type.Nrrr<r:rrs 0Nr<rceZdZdZdZy)r(Represent the PostgreSQL TSTZRANGE type.Nrrr<r:rrrr<rceZdZdZdZy)rz-Represent the PostgreSQL INT4MULTIRANGE type.Nrrr<r:rr 7%Nr<rceZdZdZdZy)rz-Represent the PostgreSQL INT8MULTIRANGE type.Nrrr<r:rrr"r<rceZdZdZdZy)rz,Represent the PostgreSQL NUMMULTIRANGE type.Nrrr<r:rrs 6$Nr<rceZdZdZdZy)rz-Represent the PostgreSQL DATEMULTIRANGE type.Nrrr<r:rrr"r<rceZdZdZdZy)rrNrrr<r:rrs 0#Nr<rceZdZdZdZy)rr Nrrr<r:rrs 2%Nr<riic|jduxs"t|jcxkxr tkncxr2|jduxs"t|jcxkxr tkScSr>)r/ _min_int_32 _max_int_32r0)rs r:rrsP GGtO D{aggDD  4@;!''@[@@r<r)rz Range[int]rr4)H __future__rrrrrdecimalrtypingrr r r r r rrrrrrrrrrrrrrrrrrsql sql.type_apir utilr! util.typingr" sql.elementsr#r$r%r&r2dc_slotsr dataclassr-rrrVrrrrarrrrrrrrrrrrr*r)rrr<r:r5sK# "#)*'(!&"-#/ T,- HD!IHI/d/h/L "GBKL "0L "^$eBi$4;H''+;D %-b 2 %F1"5 !%xb ':;!%H/3 !#C(! !#C(!  "7+ !#D)! !(+ !#H-! &',& &',& %&w/% &'-& $%h/$ &'1&   r<