ZErBdZddlZddlmZmZddlmZmZmZddlm Z m Z m Z GddZ d.d Z Gd d ZGd d ZGdde ZGdde ZGdde ZGdde ZGddeZeeeeeedddZeeeedddZeeeedd d!Zeed"ed#d$d%Zeed&ed'd(d)Zeed*ed+d,d-ZedS)/z1Implementation of the Range type and adaptation N)ProgrammingErrorInterfaceError) ISQLQuoteadaptregister_adapter)new_typenew_array_type register_typeceZdZdZdZddZdZdZed Z ed Z ed Z ed Z ed Z edZedZdZdZdZdZdZdZdZdZdZdZdZdS)RangeaPython 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)selflowerupperboundsemptys /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/psycopg2/_range.py__init__zRange.__init__/s_ <555 !E6!E!EFFFDKDK!DLLL7; ;DK ;$+ c|j|jjdSd|jj|j|j|jS)Nz (empty=True)z{}({!r}, {!r}, {!r}))r __class____name__formatrrrs r__repr__zRange.__repr__:sJ < n-;;; ;)001H T[$,88 8rc|jdS|jdt|jdt|j|jdg}d|S)Nrrz, )rstrrrjoin)ritemss r__str__z Range.__str__AsY < 7 LO        LO  wwu~~rc|jS)z:The lower bound of the range. `!None` if empty or unbound.)rr s rrz Range.lowerN {rc|jS)z:The upper bound of the range. `!None` if empty or unbound.)rr s rrz Range.upperSr*rc|jduS)z`!True` if the range is empty.Nrr s risemptyz Range.isemptyXs|t##rc&|jdS|jduS)z0`!True` if the range doesn't have a lower bound.NFrrr s r lower_infzRange.lower_inf] < 5{d""rc&|jdS|jduS)z1`!True` if the range doesn't have an upper bound.NFrrr s r upper_infzRange.upper_infdr2rcD|j|jdS|jddkS)z4`!True` if the lower bound is included in the range.NFr[r0r s r lower_inczRange.lower_inck) < 4;#65|A#%%rcD|j|jdS|jddkS)z4`!True` if the upper bound is included in the range.NFr#]r4r s r upper_inczRange.upper_incrr9rc|jdS|j,|jddkr||jkrdSn ||jkrdS|j,|jddkr||jkrdSn ||jkrdSdS)NFrr7r#r;T)rrr)rxs r __contains__zRange.__contains__ys < 5 ; "|A#%%t{?? 5# ## 5 ; "|A#%%t{?? 5# ## 5trc|jduSNr-r s r__bool__zRange.__bool__s|4''rct|tsdS|j|jko|j|jko|j|jkS)NF) isinstancer rrrrothers r__eq__z Range.__eq__sL%'' 5 u|+. u|+.  - /rc.|| SrA)rGrEs r__ne__z Range.__ne__s;;u%%%%rcDt|j|j|jfSrA)hashrrrr s r__hash__zRange.__hash__sT[$+t|<===rct|tstSdD]:}t||}t||}||kr)|dS|dS||kcSdS)Nr TF)rDr NotImplementedgetattr)rrFattr self_value other_values r__lt__z Range.__lt__s%'' "! !3 0 0D t,,J!%..K[((#tt$uu!K////urc<||krdS||SNT)rSrEs r__le__z Range.__le__" 5==4;;u%% %rcdt|tr||StSrA)rDr rSrNrEs r__gt__z Range.__gt__s, eU # # "<<%% %! !rc<||krdS||SrU)rYrEs r__ge__z Range.__ge__rWrc*fdjDS)NcRi|]#}t||t|$S)hasattrrO).0slotrs r z&Range.__getstate__..sC???'$*=*=?gdD))???r) __slots__r s`r __getstate__zRange.__getstate__s0??????? ?rc\|D]\}}t|||dSrA)r'setattr)rstateravalues r __setstate__zRange.__setstate__s< ;;== ' 'KD% D$ & & & & ' 'r)NNrF)r __module__ __qualname____doc__rcrr!r(propertyrrr.r1r5r8r<r?rBrGrIrLrSrVrYr[rdrir^rrr r #s0I < < < <888   XX$$X$##X# ##X# &&X& &&X& ,(((///&&&>>> &&& """ &&& ???'''''rr Fcrt|||}|| r|pd|S)aCreate 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)pgrangepyrange conn_or_cursgloballycasters rregister_rangerws@4 ! !'7L A AF \2l:d;;; Mrc.eZdZdZdZdZdZdZdZdS) 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)rprotos r __conform__zRangeAdapter.__conform__s ;) # #K $ #rc||_dSrA)_conn)rconns rpreparezRangeAdapter.prepares  rc|jtd|j}|jrd|jdzS|jSt |j}t|dr||j | }nd}|j St |j }t|dr||j | }nd}|jddz|zdz|zdz|j dzd zS) NzMRangeAdapter must be subclassed overriding its name or the getquoted() methods 'empty'::utf8rsNULL(s, s, 's')) nameNotImplementedErrorr{r.encoderrr_rr getquotedrr)rrarrs rrzRangeAdapter.getquotedsA 9 %,-- - L 9 ;$)"2"26":":: : 7 agAq)$$ & $*%%%KKMMEEE 7 agAq)$$ & $*%%%KKMMEEEy''$.6>Fy''//0278 8r) rrjrkrlrrrrrr^rrryrysa D88888rryceZdZdZd dZdZedZej dej Z ej dZ d dZ 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)NARRAY) subtype_oid_create_rangesadapterrrrrparse typecasterr array_typecaster)rrrrsoidr array_oidrs rrzRangeCaster.__init__$s& GW---| CDL$:$C"C64<<  $2 dWndo%?%?D ! ! !%)D ! ! !rc4d|_t|tr)t|tfi|_||j_n7 t |tr|tur||_n#t$rYnwxYw|jtdd|_ t|trt|tfi|_t |tr|tur||_n#t$rYnwxYw|jtddS)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) rrDr%typeryr issubclass TypeErrorranger )rrrrss rrzRangeCaster._create_ranges2sN  gs # # ,"==DL 'DL   g|44+#<77#*DL     < LNN N  '3'' 9!'E8R88 '5)) %gU.B.B$     D  : CEE E  s%%A-- A:9A:AC22 C?>C?c6ddlm}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| dn#| r| dwwxYw||kr|j s| | 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#publiczselect 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_typeTzSELECT 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 foundrrr)psycopg2.extensionsrpsycopg2.extrasrinfoserver_versionrstatussplitexecutefetchone autocommitrollbackro)rrrsrtrrrcurs conn_statusschematnamerec savepointrsubtypearrays rrpzRangeCaster._from_dbUsO >=====444444%%l33 d 9 #e + +"#L)*$+,, ,k  $;; JJsA..MFEEEF   V_    mmoo H H! ;"777LL!:;;; $I   X mmoo,$'GME6 $    HLL!FGGGHLL!FGGGGH / / / / MMOOO 8"6T66688 8 #2A2wgu4'U<<< $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|dS|j|}|td|d|d}|2|d}||jd|}|d }|2|d }||jd|}|6||j|}||j|}|d |d z}||||S) NrT)rzfailed to parse range: ''rz\1r#) r _re_rangematchrgroup _re_undoublesubcastr)rscurmrrrs rrzRangeCaster.parsesD 94 <<::D:)) ) N  # # 9 !@A!@!@!@AA A  =GGAJJE )--eU;;  =GGAJJE )--eU;; ?HHT-u55EHHT-u55Eaggajj(zz%///rct|j||jt|j|t|j|jdSrA)r rrrrr)rscopes rrqzRangeCaster._registersJdou---  , $/ 7 7 7T\22222rrA)rrjrkrlrr classmethodrprecompileVERBOSErrrrqr^rrroros ) ) ) )!E!E!EFJ<J<[J333333rroceZdZdZdS) NumericRangezA `Range` suitable to pass Python numeric types to a PostgreSQL range. PostgreSQL types :sql:`int4range`, :sql:`int8range`, :sql:`numrange` are casted into `!NumericRange` instances. Nrrjrkrlr^rrrrs  DrrceZdZdZdS) DateRangez#Represents :sql:`daterange` values.Nrr^rrrr--DrrceZdZdZdS) DateTimeRangez!Represents :sql:`tsrange` values.Nrr^rrrrs++DrrceZdZdZdS)DateTimeTZRangez#Represents :sql:`tstzrange` values.Nrr^rrrrrrrceZdZdZdZdS)NumberRangeAdapterz1Adapt a range if the subtype doesn't need quotes.c|j}|jrdS|js:t|jd}nd}|js:t|jd}nd}d|j d|d||j dd dS)Ns'empty'asciir$rr,r#) r{r.r1rrrdecoder5rrr)rrrrs rrzNumberRangeAdapter.getquoteds L 9 :{  !'NN,,..55g>>EEE{ !'NN,,..55g>>EEE@AIaL@%@@%@1@@@HHQQQrN)rrjrkrlrr^rrrrs.;;RRRRRrri@iAriViWiBiiC daterangeiHi:iItsrangeiDiZiE tstzrangeiFiiG)F)rlrpsycopg2._psycopgrrrrrrrr r r rwryrorrrrrint4range_casterrqint8range_casternumrange_casterdaterange_castertsrange_castertstzrange_casterr^rrrs>6 >>>>>>>>BBBBBBBBBBGGGGGGGGGGh'h'h'h'h'h'h'h'V>-8-8-8-8-8-8-8-8`y3y3y3y3y3y3y3y3x     5                E        e   RRRRRRRR21222 ;1< "...;1< "...+0, $$000;{I $$000Y  $$000;{O $$000r