+
    ihJ                     l   R t ^ RIt^ RIHtHt ^ RIHtHtHt ^ RIH	t	H
t
Ht  ! R R4      tR*R lt ! R R	4      t ! R
 R4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t]! ]]4       ]! ]]R^RR7      t]P-                  4        ]! ]]R^RR7      t]P-                  4        ]! ]]RRRR7      t]P-                  4        ]! R]RR R!R7      t]P-                  4        ]! R"]R#R$R%R7      t]P-                  4        ]! R&]R'R(R)R7      t]P-                  4        R# )+z1Implementation of the Range type and adaptation

N)ProgrammingErrorInterfaceError)	ISQLQuoteadaptregister_adapter)new_typenew_array_typeregister_typec                      a  ] tR t^#t o RtRtRR ltR tR t]	R 4       t
]	R 4       t]	R 4       t]	R	 4       t]	R
 4       t]	R 4       t]	R 4       tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )Rangeam  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

Nc                    V'       g+   VR9  d   \        RV: 24      hWn        W n        W0n        R# R;V n        ;V n        V n        R# )[)zbound flags not valid: N)r   z(]z()z[])
ValueError_lower_upper_bounds)selflowerupperboundsemptys   &&&&&iC:\Users\petid\OneDrive\Desktop\Maestro\MAESTRO\maestro-backend\venv\Lib\site-packages\psycopg2/_range.py__init__Range.__init__/   sE    55 #:6*!EFFKK!L7;;DK;$+    c                    V P                   f   V P                  P                   R2# RP                  V P                  P                  V P                  V P
                  V P                   4      # )Nz(empty=True)z{}({!r}, {!r}, {!r}))r   	__class____name__formatr   r   r   s   &r   __repr__Range.__repr__:   sV    <<nn--.l;;)001H1HT[[$,,8 8r   c                    V P                   f   R# V P                   ^ ,          \        V P                  4      R\        V P                  4      V P                   ^,          .pRP	                  V4      # )Nr   z,  )r   strr   r   join)r   itemss   & r   __str__Range.__str__A   sY    << LLOLLO
 wwu~r   c                    V P                   # )z:The lower bound of the range. `!None` if empty or unbound.)r   r   s   &r   r   Range.lowerN        {{r   c                    V P                   # )z:The upper bound of the range. `!None` if empty or unbound.)r   r   s   &r   r   Range.upperS   r+   r   c                    V P                   RJ # )z`!True` if the range is empty.Nr   r   s   &r   isemptyRange.isemptyX   s     ||t##r   c                >    V P                   f   R# V P                  RJ # )z0`!True` if the range doesn't have a lower bound.NFr   r   r   s   &r   	lower_infRange.lower_inf]         <<{{d""r   c                >    V P                   f   R# V P                  RJ # )z1`!True` if the range doesn't have an upper bound.NFr   r   r   s   &r   	upper_infRange.upper_infd   r6   r   c                j    V P                   e   V P                  f   R# V P                   ^ ,          R8H  # )z4`!True` if the lower bound is included in the range.F[r3   r   s   &r   	lower_incRange.lower_inck   -     <<4;;#6||A#%%r   c                j    V P                   e   V P                  f   R# V P                   ^,          R8H  # )z4`!True` if the upper bound is included in the range.F]r8   r   s   &r   	upper_incRange.upper_incr   r?   r   c                V   V P                   f   R# V P                  e>   V P                   ^ ,          R8X  d   WP                  8  d   R# MWP                  8:  d   R# V P                  e@   V P                   ^,          R8X  d   WP                  8  d   R#  R# WP                  8  d   R# R# )NFr<   rA   Tr   r   r   )r   xs   &&r   __contains__Range.__contains__y   s    <<;;"||A#%{{?  # # ;;"||A#%{{?  #  # r   c                    V P                   R J# Nr/   r   s   &r   __bool__Range.__bool__   s    ||4''r   c                    \        V\        4      '       g   R # V P                  VP                  8H  ;'       d;    V P                  VP                  8H  ;'       d    V P                  VP                  8H  # F)
isinstancer   r   r   r   r   others   &&r   __eq__Range.__eq__   s[    %''u||+ . .u||+. .-	/r   c                .    V P                  V4      '       * # rJ   )rR   rP   s   &&r   __ne__Range.__ne__   s    ;;u%%%r   c                Z    \        V P                  V P                  V P                  34      # rJ   )hashr   r   r   r   s   &r   __hash__Range.__hash__   s     T[[$++t||<==r   c                    \        V\        4      '       g   \        # R F3  p\        W4      p\        W4      pW48X  d   K!  Vf    R# Vf    R# W48  u # 	  R# )r   TFr   r   r   )rO   r   NotImplementedgetattr)r   rQ   attr
self_valueother_values   &&   r   __lt__Range.__lt__   s\    %''!!3D ,J!%.K(#$!// 4 r   c                4    W8X  d   R # V P                  V4      # T)rb   rP   s   &&r   __le__Range.__le__       =;;u%%r   c                \    \        V\        4      '       d   VP                  V 4      # \        # rJ   )rO   r   rb   r]   rP   s   &&r   __gt__Range.__gt__   s$    eU##<<%%!!r   c                4    W8X  d   R # V P                  V4      # re   )rj   rP   s   &&r   __ge__Range.__ge__   rh   r   c                ~    V P                    Uu/ uF"  p\        W4      '       g   K  V\        W4      bK$  	  up# u upi rJ   )	__slots__hasattrr^   )r   slots   & r   __getstate__Range.__getstate__   s>    ?&'$*= *gd))&? 	? ?s   ::c                P    VP                  4        F  w  r#\        WV4       K  	  R # rJ   )r&   setattr)r   staterr   values   &&  r   __setstate__Range.__setstate__   s     ;;=KDD& )r   rE   r\   )NNr   F)r   
__module____qualname____firstlineno____doc__rp   r   r    r'   propertyr   r   r0   r4   r9   r=   rB   rG   rK   rR   rU   rY   rb   rf   rj   rm   rs   ry   __static_attributes____classdictcell____classdict__s   @r   r   r   #   s      0I	<8     $ $ # # # # & & & &,(/&> &"&?' 'r   r   c                    \         P                  WV4      pTP                  V'       * ;'       d    T;'       g    R4       V# )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_ranger      s;    4 !!'LAF
\22l::d;Mr   c                   @   a  ] tR t^t o RtRtR tR tR tR t	Rt
V tR# )RangeAdapterz`ISQLQuote` adapter for `Range` subclasses.

This is an abstract class: concrete classes must set a `name` class
attribute or override `getquoted()`.
Nc                    Wn         R # rJ   )adapted)r   r   s   &&r   r   RangeAdapter.__init__   s    r   c                2    V P                   \        J d   V # R # rJ   )_protor   )r   protos   &&r   __conform__RangeAdapter.__conform__   s    ;;)#K $r   c                    Wn         R # rJ   )_conn)r   conns   &&r   prepareRangeAdapter.prepare   s    
r   c                
   V P                   f   \        R4      hV P                  pVP                  '       d#   RV P                   P	                  R4      ,           # VP
                  eT   \        VP
                  4      p\        VR4      '       d   VP                  V P                  4       VP                  4       pMRpVP                  eT   \        VP                  4      p\        VR4      '       d   VP                  V P                  4       VP                  4       pMRpV P                   P	                  R4      R,           V,           R,           V,           R,           VP                  P	                  R4      ,           R	,           # )
NzMRangeAdapter must be subclassed overriding its name or the getquoted() methods	   'empty'::utf8r   s   NULL   (s   , s   , 's   '))nameNotImplementedErrorr   r0   encoder   r   rq   r   r   	getquotedr   r   )r   rar   r   s   &    r   r   RangeAdapter.getquoted   s&   99%,- - LL999$))"2"26":::77aggAq)$$		$**%KKMEE77aggAq)$$		$**%KKMEEyy'$.6>Fyy''/0278 	8r   )r   r   )r   r{   r|   r}   r~   r   r   r   r   r   r   r   r   s   @r   r   r      s*     
 D8 8r   r   c                      a  ] tR tRt o RtRR ltR t]R 4       t]	P                  ! R]	P                  4      t]	P                  ! R4      tRR	 ltRR
 ltRtV tR# )r   i  zHelper 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                J   W@n         V P                  W4       V P                  P                  ;'       g!    V P                  P                  P
                  p\        V3W`P                  4      V n        Ve'   \        V3VR,           V P                  4      V n
        R # R V n
        R # )NARRAY)subtype_oid_create_rangesadapterr   r   r   r   parse
typecasterr   array_typecaster)r   r   r   oidr   	array_oidr   s   &&&&&& r   r   RangeCaster.__init__$  s    &G-||  CCDLL$:$:$C$C"C64< $2dWndoo%?D! %)D!r   c                <   RV n         \        V\        4      '       d)   \        V\        3/ 4      V n         WP                   n        M' \        V\        4      '       d   V\        Jd   Wn         V P                   f   \        R4      hRV n         \        V\        4      '       d   \        V\        3/ 4      V n        \        V\        4      '       d   V\        Jd   W n        T P                  f   \        R4      hR#   \         d     Li ; i  \         d     L9i ; i)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   rO   r$   typer   r   
issubclass	TypeErrorranger   )r   r   r   s   &&&r   r   RangeCaster._create_ranges2  s    gs##,"=DL 'LLg|44#<7#*L <<LN N 
	'3''!'E8R8
'5))gU.B$
 ::CE E !    		s%   &C< AD <D
	D
DDc                \   ^ RI Hp ^ RIHp V! V4      w  rgVP                  P
                  R8  d'   \        RVP                  P
                  ,          4      hVP                  pRV9   d   VP                  R^4      w  rMTp
Rp	VP                  RW34       VP                  4       pV'       gw    RpVP                  V8X  d   VP                  R	4       R
pVP                  RV34       VP                  4       pV'       d   VR,          w  rX'       d   TP                  R4       W8w  d#   VP                  '       g   VP                  4        V'       g   \        RV R24      hVR,          w  rp\        WWVR7      #   \         d     Li ; i  X'       d   TP                  R4       i i ; i)zlReturn a `RangeCaster` instance for the type *pgrange*.

Raise `ProgrammingError` if the type is not found.
)STATUS_IN_TRANSACTION)_solve_conn_cursiX` z'range types not available in version %s.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;
FzSAVEPOINT 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
:   NNz#ROLLBACK TO SAVEPOINT register_typezPostgreSQL range 'z' not found:Nr   Nr   r   r   )psycopg2.extensionsr   psycopg2.extrasr   infoserver_versionr   statussplitexecutefetchone
autocommitrollbackr   )r   r   r   r   r   r   r   cursconn_statusschematnamerec	savepointr   subtypearrays   &&&&            r   r   RangeCaster._from_dbU  s    	>4%l3
99##e+"#L))**$+ , , kk $; JJsA.MFEEF 	  _	 mmoH!	 ;;"77LL!:; $I  X mmo$'GMELL!FG /MMO"$TF+68 8  #2wu4U< 	<) $  LL!FG s*   09E> )#F >F	F FF F+a]  
        ( \(|\[ )                   # 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                   Vf   R # VR8X  d   V P                  RR7      # V P                  P                  V4      pVf   \        RV R24      hVP	                  ^4      pVf2   VP	                  ^4      pVe   V P
                  P                  RV4      pVP	                  ^4      pVf2   VP	                  ^4      pVe   V P
                  P                  RV4      pVe9   VP                  V P                  V4      pVP                  V P                  V4      pVP	                  ^4      VP	                  ^4      ,           pV P                  WEV4      # )Nr   T)r   zfailed to parse range: ''z\1)	r   	_re_rangematchr   group_re_undoublesubcastr   )r   scurmr   r   r   s   &&&    r   r   RangeCaster.parse  s&   9<::D:))NN  #9 #;A3a!@AA
=GGAJE ))--eU;
=GGAJE ))--eU;?HHT--u5EHHT--u5Eaggaj(zz%//r   c                    \        V P                  V4       V P                  e   \        V P                  V4       \        V P                  V P
                  4       R # rJ   )r	   r   r   r   r   r   )r   scopes   &&r   r   RangeCaster._register  s>    doou-  ,$//7T\\2r   )r   r   r   r   r   rJ   )r   r{   r|   r}   r~   r   r   classmethodr   recompileVERBOSEr   r   r   r   r   r   r   s   @r   r   r     sj     )!EF J< J<X 

  ZZI ::l+L0>3 3r   r   c                       ] tR tRtRtRtR# )NumericRangei  zA `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r   r{   r|   r}   r~   r   r   r   r   r   r     s    
 	r   r   c                       ] tR tRtRtRtR# )	DateRangei  z#Represents :sql:`daterange` values.r   Nr   r   r   r   r   r         -r   r   c                       ] tR tRtRtRtR# )DateTimeRangei  z!Represents :sql:`tsrange` values.r   Nr   r   r   r   r   r     s    +r   r   c                       ] tR tRtRtRtR# )DateTimeTZRangei  z#Represents :sql:`tstzrange` values.r   Nr   r   r   r   r   r     r   r   r   c                   *   a  ] tR tRt o RtR tRtV tR# )NumberRangeAdapteri  z1Adapt a range if the subtype doesn't need quotes.c                   V P                   pVP                  '       d   R # VP                  '       g4   \        VP                  4      P                  4       P                  R4      pMRpVP                  '       g4   \        VP                  4      P                  4       P                  R4      pMRpRVP                  ^ ,           V RV VP                  ^,           R2P                  R4      # )s   'empty'asciir#   r   ,)r   r0   r4   r   r   r   decoder9   r   r   r   )r   r   r   r   s   &   r   r   NumberRangeAdapter.getquoted  s    LL999{{{
 !''N,,.55g>EE{{{!''N,,.55g>EEAIIaL>%%1a@HHQQr   r   N)r   r{   r|   r}   r~   r   r   r   r   s   @r   r   r     s     ;R Rr   r   i@  iA  r   iV  iW  iB  i  iC  	daterangeiH  i:  iI  tsrangeiD  iZ  iE  	tstzrangeiF  i  iG  rN   )r~   r   psycopg2._psycopgr   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   int4range_casterr   int8range_casternumrange_casterdaterange_castertsrange_castertstzrange_casterr   r   r   <module>r     sb  6 
 > B B G Gh' h'V>-8 -8`y3 y3x	5 		 	
	E 	
	e 	R R2 1 2
 1<".     1<".     0,$$0    {I$$0     Y$$0    {O$$0     r   