
    9h                        S r SSKrSSKrSSKrSSKJrJ	r	  SSK
rSSKrSSKJr  SSKJr  SSKJr  SSKJrJr  SS	KJr  SS
KJrJrJrJrJr  SSK J!r!J"r"J#r#J$r$J%r%  SSK&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  SSK/J0r0   " S S\5      r1 " S S\5      r2 " S S\15      r3 " S S\45      r5 " S S\5      r6 " S S\15      r7 " S S\	5      r8 " S S\5      r9 " S S\5      r:\" S 5      S! 5       r;\<" \;5      \:l;         " S" S#\5      r= " S$ S%\5      r> " S& S'\=5      r? " S( S)\>5      r@ " S* S+\5      rA " S, S-\5      rB " S. S/\C5      rD " S0 S1\5      r " S2 S35      rESGS4 jrF " S5 S65      rGSGS7 jrHS8 rIS9 rJ " S: S;5      rK  SHS< jrL " S= S>5      rMSIS? jrNS@ rOSJSA jrPSKSB jrQSC rR\R                  " SD\R                  " SE5      -   SF-   5      rUg)LzMiscellaneous goodies for psycopg2

This module is a generic place used to hold little helper functions
and classes until a better place in the distribution is found.
    N)
namedtupleOrderedDict)
extensions   )cursor)
connection)adaptquote_ident)	lru_cache)REPLICATION_PHYSICALREPLICATION_LOGICALReplicationConnectionReplicationCursorReplicationMessage)jsonJsonregister_jsonregister_default_jsonregister_default_jsonb)RangeNumericRange	DateRangeDateTimeRangeDateTimeTZRangeregister_rangeRangeAdapterRangeCaster)register_ipaddressc                   `   ^  \ rS rSrSrU 4S jrU 4S jrS	U 4S jjrU 4S jrU 4S jr	Sr
U =r$ )
DictCursorBaseA   z%Base class for all dict-like cursors.c                    > SU;   a	  US   nUS	 O[        S5      e[        TU ]  " U0 UD6  SU l        SU l        X0l        g )Nrow_factoryz;DictCursorBase can't be instantiated without a row factory.F)NotImplementedErrorsuper__init___query_executed	_prefetchr#   )selfargskwargsr#   	__class__s       A/var/www/html/env/lib/python3.13/site-packages/psycopg2/extras.pyr&   DictCursorBase.__init__D   sV    F" /K}%%MO O$)&)$&    c                    > U R                   (       a  [        TU ]	  5       nU R                  (       a  U R	                  5         U R                   (       d  [        TU ]	  5       nW$ N)r(   r%   fetchoner'   _build_indexr)   resr,   s     r-   r2   DictCursorBase.fetchoneP   E    >>'"$C~~'"$C
r/   c                    > U R                   (       a  [        TU ]	  U5      nU R                  (       a  U R	                  5         U R                   (       d  [        TU ]	  U5      nW$ r1   )r(   r%   	fetchmanyr'   r3   )r)   sizer5   r,   s      r-   r9   DictCursorBase.fetchmanyY   sI    >>'#D)C~~'#D)C
r/   c                    > U R                   (       a  [        TU ]	  5       nU R                  (       a  U R	                  5         U R                   (       d  [        TU ]	  5       nW$ r1   )r(   r%   fetchallr'   r3   r4   s     r-   r=   DictCursorBase.fetchallb   r7   r/   c              #   @  >#     U R                   (       a  [        TU ]	  5       n[        U5      nU R                  (       a  U R                  5         U R                   (       d  [        TU ]	  5       n[        U5      nWv    [        W5      v   M  ! [         a     g f = f7fr1   )r(   r%   __iter__nextr'   r3   StopIteration)r)   r5   firstr,   s      r-   r@   DictCursorBase.__iter__k   s     	~~g&(S	##!!#>>g&(S	K3i  		s#   BB	B 
BBBB)r(   r'   r#   r1   )__name__
__module____qualname____firstlineno____doc__r&   r2   r9   r=   r@   __static_attributes____classcell__r,   s   @r-   r    r    A   s$    /
' r/   r    c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )DictConnection}   z2A connection that uses `DictCursor` automatically.c                 v   > UR                  SU R                  =(       d    [        5        [        TU ]  " U0 UD6$ Ncursor_factory)
setdefaultrR   
DictCursorr%   r   r)   r*   r+   r,   s      r-   r   DictConnection.cursor   s3    *D,?,?,M:Nw~t.v..r/    rE   rF   rG   rH   rI   r   rJ   rK   rL   s   @r-   rN   rN   }   s    </ /r/   rN   c                   R   ^  \ rS rSrSrU 4S jrSU 4S jjrSU 4S jjrS rSr	U =r
$ )	rT      zzA cursor that keeps a list of column name -> index mappings__.

.. __: https://docs.python.org/glossary.html#term-mapping
c                 F   > [         US'   [        TU ]  " U0 UD6  SU l        g )Nr#   T)DictRowr%   r&   r(   rU   s      r-   r&   DictCursor.__init__   s&     '}$)&)r/   c                 N   > [        5       U l        SU l        [        TU ]  X5      $ NT)r   indexr'   r%   executer)   queryvarsr,   s      r-   ra   DictCursor.execute   s#     ]
#wu++r/   c                 N   > [        5       U l        SU l        [        TU ]  X5      $ r_   )r   r`   r'   r%   callprocr)   procnamerd   r,   s      r-   rg   DictCursor.callproc   s$     ]
#w//r/   c                     U R                   (       a]  U R                  (       aK  [        [        U R                  5      5       H!  nXR                  U R                  U   S   '   M#     SU l         g g g Nr   F)r'   descriptionrangelenr`   )r)   is     r-   r3   DictCursor._build_index   sY    D$4$43t//0156

4++A.q12 2#(D  %5r/   )r(   r'   r`   r1   rE   rF   rG   rH   rI   r&   ra   rg   r3   rJ   rK   rL   s   @r-   rT   rT      s!    

,
0
) )r/   rT   c                      ^  \ rS rSrSrSrS rU 4S jrU 4S jrU 4S jr	S r
U 4S	 jrSS
 jrS rS rU 4S jrS rS rSrU =r$ )r\      z6A row object that allow by-column-name access to data._indexc                 ^    UR                   U l        S /[        UR                  5      -  U S S & g r1   )r`   rv   ro   rm   )r)   r   s     r-   r&   DictRow.__init__   s(    ll&3v1122Qr/   c                 v   > [        U[        [        45      (       d  U R                  U   n[        TU ]  U5      $ r1   )
isinstanceintslicerv   r%   __getitem__)r)   xr,   s     r-   r}   DictRow.__getitem__   s1    !c5\**AAw"1%%r/   c                 x   > [        U[        [        45      (       d  U R                  U   n[        TU ]  X5        g r1   )rz   r{   r|   rv   r%   __setitem__)r)   r~   vr,   s      r-   r   DictRow.__setitem__   s.    !c5\**AAA!r/   c                 J   >^ ^ [         TT ]  mUU 4S jT R                   5       $ )Nc              3   P   >#    U  H  oT" TR                   U   5      4v   M     g 7fr1   ru   .0ngr)   s     r-   	<genexpr> DictRow.items.<locals>.<genexpr>   s!     <1Adkk!n%&s   #&r%   r}   rv   r)   r   r,   s   `@r-   itemsDictRow.items   s    G<<<r/   c                 ,    [        U R                  5      $ r1   )iterrv   r)   s    r-   keysDictRow.keys   s    DKK  r/   c                 J   >^ ^ [         TT ]  mUU 4S jT R                   5       $ )Nc              3   N   >#    U  H  nT" TR                   U   5      v   M     g 7fr1   ru   r   s     r-   r   !DictRow.values.<locals>.<genexpr>   s!     7;a$++a.!!;s   "%r   r   s   `@r-   valuesDictRow.values   s    G74;;77r/   c                 0     X   $ ! [          a    Us $ f = fr1   )	Exception)r)   r~   defaults      r-   getDictRow.get   s"    	7N 	N	s    c                 4    [        U R                  5       5      $ r1   )r   r   r   s    r-   copyDictRow.copy   s    4::<((r/   c                     XR                   ;   $ r1   ru   )r)   r~   s     r-   __contains__DictRow.__contains__   s    KKr/   c                     > [         TU ]  5       $ r1   )r%   
__reduce__)r)   r,   s    r-   r   DictRow.__reduce__   s    w!##r/   c                 @    U S S  U R                   R                  5       4$ r1   )rv   r   r   s    r-   __getstate__DictRow.__getstate__   s    Aw((***r/   c                 (    US   U S S & US   U l         g Nr   r   ru   )r)   datas     r-   __setstate__DictRow.__setstate__   s    q'Q1gr/   r1   )rE   rF   rG   rH   rI   	__slots__r&   r}   r   r   r   r   r   r   r   r   r   r   rJ   rK   rL   s   @r-   r\   r\      sL    @I3&
"
=!8) $+ r/   r\   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )RealDictConnection   z6A connection that uses `RealDictCursor` automatically.c                 v   > UR                  SU R                  =(       d    [        5        [        TU ]  " U0 UD6$ rQ   )rS   rR   RealDictCursorr%   r   rU   s      r-   r   RealDictConnection.cursor   s3    *D,?,?,Q>Rw~t.v..r/   rW   rX   rL   s   @r-   r   r      s    @/ /r/   r   c                   R   ^  \ rS rSrSrU 4S jrSU 4S jjrSU 4S jjrS rSr	U =r
$ )	r      a=  A cursor that uses a real dict as the base type for rows.

Note that this cursor is extremely specialized and does not allow
the normal access (using integer indices) to fetched data. If you need
to access database rows both as a dictionary and a list, then use
the generic `DictCursor` instead of `!RealDictCursor`.
c                 8   > [         US'   [        TU ]  " U0 UD6  g )Nr#   )RealDictRowr%   r&   rU   s      r-   r&   RealDictCursor.__init__   s     +}$)&)r/   c                 >   > / U l         SU l        [        TU ]  X5      $ r_   )column_mappingr'   r%   ra   rb   s      r-   ra   RealDictCursor.execute   s"     #wu++r/   c                 >   > / U l         SU l        [        TU ]  X5      $ r_   )r   r'   r%   rg   rh   s      r-   rg   RealDictCursor.callproc   s#     #w//r/   c                     U R                   (       a>  U R                  (       a,  U R                   Vs/ s H  oS   PM	     snU l        SU l         g g g s  snf rl   )r'   rm   r   )r)   ds     r-   r3   RealDictCursor._build_index   sG    D$4$4151A1A"B1AAQ41A"BD#(D  %5"Bs   A)r'   r   r1   rr   rL   s   @r-   r   r      s!    *,
0
) )r/   r   c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )r      z.A `!dict` subclass representing a data record.c                   > U(       a#  [        US   [        5      (       a  US   nUSS  nOS n[        TU ]  " U0 UD6  UbF  UR                  (       a!  UR
                  (       d  UR                  5         UR
                  U [        '   g g r   )rz   _cursorr%   r&   rm   r   r3   r   )r)   r*   r+   r   r,   s       r-   r&   RealDictRow.__init__   s{    JtAw00!WF8DF$)&)!!&*?*?##%
 !' 5 5D r/   c                    > [         U ;   a5  U [            n[        TU ]	  X1   U5        U[        U5      S-
  :X  a  U [         	 g [        TU ]	  X5        g )Nr   )r   r%   r   ro   )r)   keyvaluemappingr,   s       r-   r   RealDictRow.__setitem__  sO    $;'GGe4c'lQ&&%C'r/   rW   )	rE   rF   rG   rH   rI   r&   r   rJ   rK   rL   s   @r-   r   r      s    86&
( 
(r/   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )NamedTupleConnectioni  z8A connection that uses `NamedTupleCursor` automatically.c                 v   > UR                  SU R                  =(       d    [        5        [        TU ]  " U0 UD6$ rQ   )rS   rR   NamedTupleCursorr%   r   rU   s      r-   r   NamedTupleConnection.cursor  s4    *D,?,?,SCSTw~t.v..r/   rW   rX   rL   s   @r-   r   r     s    B/ /r/   r   c                      ^  \ rS rSrSrSrSrSU 4S jjrU 4S jrSU 4S jjr	U 4S jr
SU 4S	 jjrU 4S
 jrU 4S jrS r\S 5       rSrU =r$ )r   i#  a  A cursor that generates results as `~collections.namedtuple`.

`!fetch*()` methods will return named tuples instead of regular tuples, so
their elements can be accessed both as regular numeric items as well as
attributes.

    >>> nt_cur = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
    >>> rec = nt_cur.fetchone()
    >>> rec
    Record(id=1, num=100, data="abc'def")
    >>> rec[1]
    100
    >>> rec.data
    "abc'def"
Ni   c                 0   > S U l         [        TU ]	  X5      $ r1   )Recordr%   ra   rb   s      r-   ra   NamedTupleCursor.execute6  s    wu++r/   c                 0   > S U l         [        TU ]	  X5      $ r1   )r   r%   executemanyrb   s      r-   r   NamedTupleCursor.executemany:  s    w"5//r/   c                 0   > S U l         [        TU ]	  X5      $ r1   )r   r%   rg   rh   s      r-   rg   NamedTupleCursor.callproc>  s    w//r/   c                    > [         TU ]  5       nUb6  U R                  nUc  U R                  5       =o l        UR	                  U5      $ g r1   )r%   r2   r   _make_nt_make)r)   tntr,   s      r-   r2   NamedTupleCursor.fetchoneB  sF    G=Bz#'==?2[88A;	 r/   c                    > [         TU ]  U5      nU R                  nUc  U R                  5       =o0l        [	        [        UR                  U5      5      $ r1   )r%   r9   r   r   listmapr   )r)   r:   tsr   r,   s       r-   r9   NamedTupleCursor.fetchmanyJ  sF    Wt$[[:#}}.BC"%&&r/   c                    > [         TU ]  5       nU R                  nUc  U R                  5       =o l        [	        [        UR                  U5      5      $ r1   )r%   r=   r   r   r   r   r   )r)   r   r   r,   s      r-   r=   NamedTupleCursor.fetchallQ  sD    W[[:#}}.BC"%&&r/   c              #     >#     [         TU ]  5       n[        U5      nU R                  nUc  U R	                  5       =o0l        UR                  U5      v    UR                  [        U5      5      v   M  ! [         a     g f = f7fr1   )r%   r@   rA   r   r   r   rB   )r)   itr   r   r,   s       r-   r@   NamedTupleCursor.__iter__X  sy     	!#BRABz#'==?2[((1+hhtBx((  		s#   BA0A5 5
B?BBBc                     U R                   (       a  [        S U R                    5       5      OSnU R                  U5      $ )Nc              3   *   #    U  H	  oS    v   M     g7f)r   NrW   )r   r   s     r-   r   ,NamedTupleCursor._make_nt.<locals>.<genexpr>i  s     3"2QaD"2s   rW   )rm   tuple_cached_make_nt)r)   r   s     r-   r   NamedTupleCursor._make_nth  s3    7;7G7Ge3$"2"233R##C((r/   c                     / nU HK  n[         R                  SU5      nUS   S:X  d  SUS   s=::  a  S::  a  O  OSU-   nUR                  U5        MM     [        SU5      nU$ )N_r   09fr   )	_re_cleansubappendr   )clsr   fieldssr   s        r-   _do_make_ntNamedTupleCursor._do_make_ntl  sf    Ac1%A ts{cQqT0S0!GMM!  &)	r/   )r   r1   )rE   rF   rG   rH   rI   r   	MAX_CACHEra   r   rg   r2   r9   r=   r@   r   classmethodr   rJ   rK   rL   s   @r-   r   r   #  sP     FI,00'' )  r/   r   i   c                 $    U R                  U5      $ r1   )r   )r   r   s     r-   r   r   {  s    ??3r/   c                   J   ^  \ rS rSrSrS rS rS rS rS r	U 4S jr
S	rU =r$ )
LoggingConnectioni  zvA connection that logs all queries to a file or logger__ object.

.. __: https://docs.python.org/library/logging.html
c                     Xl         [        (       aA  [        U[        R                  [        R                  45      (       a  U R
                  U l        gU R                  U l        g)zInitialize the connection to log to `!logobj`.

The `!logobj` parameter can be an open file object or a Logger/LoggerAdapter
instance from the standard logging module.
N)_logobj_loggingrz   LoggerLoggerAdapter_logtologgerlog
_logtofile)r)   logobjs     r-   
initializeLoggingConnection.initialize  sH     8
(*@*@AC C((DHDHr/   c                     U$ )zFilter the query before logging it.

This is the method to overwrite to filter unwanted queries out of the
log or to add some extra data to the output. The default implementation
just does nothing.
rW   r)   msgcurss      r-   filterLoggingConnection.filter  s	     
r/   c                    U R                  X5      nU(       ao  [        U[        5      (       a-  UR                  [        R
                  U R                     S5      nU R                  R                  U[        R                  -   5        g g )Nreplace)r  rz   bytesdecode_ext	encodingsencodingr  write_oslinesepr  s      r-   r  LoggingConnection._logtofile  s]    kk#$#u%%jj!>	JLLsS[[01 r/   c                 l    U R                  X5      nU(       a  U R                  R                  U5        g g r1   )r  r  debugr  s      r-   r	  LoggingConnection._logtologger  s*    kk#$LLs# r/   c                 H    [        U S5      (       d  U R                  S5      eg )Nr  z3LoggingConnection object has not been initialize()d)hasattrProgrammingErrorr   s    r-   _checkLoggingConnection._check  s,    tY''''EG G (r/   c                    > U R                  5         UR                  SU R                  =(       d    [        5        [        TU ]  " U0 UD6$ rQ   )r&  rS   rR   LoggingCursorr%   r   rU   s      r-   r   LoggingConnection.cursor  s<    *D,?,?,P=Qw~t.v..r/   )r  r
  )rE   rF   rG   rH   rI   r  r  r  r	  r&  r   rJ   rK   rL   s   @r-   r  r    s,    
'2$
G
/ /r/   r  c                   @   ^  \ rS rSrSrSU 4S jjrSU 4S jjrSrU =r$ )r)  i  zCA cursor that logs queries using its connection logging facilities.c                    >  [         TU ]  X5      U R                  R                  U R                  U 5        $ ! U R                  R                  U R                  U 5        f = fr1   )r%   ra   r   r
  rc   rb   s      r-   ra   LoggingCursor.execute  sE    	27?5/OO

D1DOO

D1	   8 (A c                    >  [         TU ]  X5      U R                  R                  U R                  U 5        $ ! U R                  R                  U R                  U 5        f = fr1   )r%   rg   r   r
  rc   rh   s      r-   rg   LoggingCursor.callproc  sF    	27#H3OO

D1DOO

D1r.  rW   r1   )	rE   rF   rG   rH   rI   ra   rg   rJ   rK   rL   s   @r-   r)  r)    s    M22 2r/   r)  c                   .    \ rS rSrSrSS jrS rS rSrg)	MinTimeLoggingConnectioni  a  A connection that logs queries based on execution time.

This is just an example of how to sub-class `LoggingConnection` to
provide some extra filtering for the logged queries. Both the
`initialize()` and `filter()` methods are overwritten to make sure
that only queries executing for more than ``mintime`` ms are logged.

Note that this connection uses the specialized cursor
`MinTimeLoggingCursor`.
c                 :    [         R                  X5        X l        g r1   )r  r  _mintime)r)   r  mintimes      r-   r  #MinTimeLoggingConnection.initialize  s    $$T2r/   c                     [         R                  " 5       UR                  -
  S-  nX0R                  :  aZ  [	        U[
        5      (       a-  UR                  [        R                  U R                     S5      nU [        R                   SU S3$ g )Ni  r  z  (execution time: z ms))_timetime	timestampr4  rz   r  r  r  r  r  r  r  )r)   r  r  r   s       r-   r  MinTimeLoggingConnection.filter  sp    ZZ\DNN*d2}}#u%%jj!>	JU3;;-':1#TBB r/   c                     UR                  SU R                  =(       d    [        5        [        R                  " U /UQ70 UD6$ rQ   )rS   rR   MinTimeLoggingCursorr  r   )r)   r*   r+   s      r-   r   MinTimeLoggingConnection.cursor  s=    *7#7	9 ''>t>v>>r/   )r4  N)r   )	rE   rF   rG   rH   rI   r  r  r   rJ   rW   r/   r-   r2  r2    s    	 C?r/   r2  c                   ,    \ rS rSrSrSS jrSS jrSrg)r=  i  z=The cursor sub-class companion to `MinTimeLoggingConnection`.Nc                 b    [         R                  " 5       U l        [        R	                  XU5      $ r1   )r8  r9  r:  r)  ra   )r)   rc   rd   s      r-   ra   MinTimeLoggingCursor.execute  s"    $$T$77r/   c                 b    [         R                  " 5       U l        [        R	                  XU5      $ r1   )r8  r9  r:  r)  rg   )r)   ri   rd   s      r-   rg   MinTimeLoggingCursor.callproc  s"    %%dd;;r/   )r:  r1   )rE   rF   rG   rH   rI   ra   rg   rJ   rW   r/   r-   r=  r=    s    G8<r/   r=  c                   (   ^  \ rS rSrU 4S jrSrU =r$ )LogicalReplicationConnectioni  c                 8   > [         US'   [        TU ]  " U0 UD6  g Nreplication_type)r   r%   r&   rU   s      r-   r&   %LogicalReplicationConnection.__init__  s     %8!"$)&)r/   rW   rE   rF   rG   rH   r&   rJ   rK   rL   s   @r-   rE  rE        * *r/   rE  c                   (   ^  \ rS rSrU 4S jrSrU =r$ )PhysicalReplicationConnectioni  c                 8   > [         US'   [        TU ]  " U0 UD6  g rG  )r   r%   r&   rU   s      r-   r&   &PhysicalReplicationConnection.__init__  s     %9!"$)&)r/   rW   rJ  rL   s   @r-   rM  rM    rK  r/   rM  c                       \ rS rSrSrSrg)StopReplicationi  z
Exception used to break out of the endless loop in
`~ReplicationCursor.consume_stream()`.

Subclass of `~exceptions.Exception`.  Intentionally *not* inherited from
`~psycopg2.Error` as occurrence of this exception does not indicate an
error.
rW   N)rE   rF   rG   rH   rI   rJ   rW   r/   r-   rQ  rQ    s     	r/   rQ  c                   <    \ rS rSrSrS	S jrS r  S
S jrS rSr	g)r   i
  z;A cursor used for communication on replication connections.Nc                 v   S[        X5       S3nUc  U R                  R                  nU[        :X  a+  Uc  [        R
                  " S5      eUS[        X05       3-  nOKU[        :X  a  Ub  [        R
                  " S5      eUS-  nO"[        R
                  " S[        U5       35      eU R                  U5        g)	z"Create streaming replication slot.zCREATE_REPLICATION_SLOT  NzAoutput plugin name is required to create logical replication slotLOGICAL zIcannot specify output plugin name when creating physical replication slotPHYSICALunrecognized replication type: )	r
   r   rH  r   psycopg2r%  r   reprra   )r)   	slot_name	slot_typeoutput_plugincommands        r-   create_replication_slot)ReplicationCursor.create_replication_slot  s     -[-I,J!L88I++$///0 0 +m"B!CDDG..(//01 1 z!G ++1$y/1BCE E 	Wr/   c                 B    S[        X5       3nU R                  U5        g)z Drop streaming replication slot.zDROP_REPLICATION_SLOT N)r
   ra   )r)   rZ  r]  s      r-   drop_replication_slot'ReplicationCursor.drop_replication_slot+  s"     +;y+G*HIWr/   c           	         SnUc  U R                   R                  nU[        :X  a6  U(       a  US[        X5       S3-  nO[        R
                  " S5      eUS-  nOFU[        :X  a  U(       a  US[        X5       S3-  nO"[        R
                  " S[        U5       35      e[        U5      [        L a5  UR                  S5      n	[        U	S	   S
5      S S[        U	S   S
5      S 3n	OUS-	  S-  S SUS-  S 3n	X-  nUS	:w  a(  U[        :X  a  [        R
                  " S5      eUSU 3-  nU(       a  U[        :X  a  [        R
                  " S5      eUS-  nUR                  5        HE  u  pUR                  S5      (       d  US-  nU[        X5       S[        [        U5      5       3-  nMG     US-  nU R                  XUS9  g)zStart replication stream.zSTART_REPLICATION NzSLOT rT  z-slot name is required for logical replicationrU  rW  /r      Xr   08X    l    z/cannot specify timeline for logical replicationz
 TIMELINE z=cannot specify output plugin options for physical replicationz ((z, ))r  status_interval)r   rH  r   r
   rX  r%  r   rY  typestrsplitr{   r   endswith_Astart_replication_expert)r)   rZ  r[  	start_lsntimelineoptionsr  rk  r]  lsnkr   s               r-   start_replication#ReplicationCursor.start_replication1  s   
 '88I++U;y#?"@BB//CE E z!G..U;y#?"@BB ++1$y/1BCE E 	?c!//#&CQ_Q'qSVR(=>C"_z1!4Ai*6LS5QRCq=////EG G H:..G00//SU U tOG'',,tOGk!231RAZLAA ( sNG%%O 	& 	Er/   c                 6    U R                   R                  5       $ r1   )r   filenor   s    r-   rz  ReplicationCursor.filenol  s    %%''r/   rW   NN)NNr   r   NF
   )
rE   rF   rG   rH   rI   r^  ra  rw  rz  rJ   rW   r/   r-   r   r   
  s#    E< =>DF8Ev(r/   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	UUID_adapterir  zAdapt Python's uuid.UUID__ type to PostgreSQL's uuid__.

.. __: https://docs.python.org/library/uuid.html
.. __: https://www.postgresql.org/docs/current/static/datatype-uuid.html
c                     Xl         g r1   _uuid)r)   uuids     r-   r&   UUID_adapter.__init__y      
r/   c                 .    U[         R                  L a  U $ g r1   r  	ISQLQuoter)   protos     r-   __conform__UUID_adapter.__conform__|      DNN"K #r/   c                 @    SU R                    S3R                  S5      $ )N''::uuidutf8)r  encoder   s    r-   	getquotedUUID_adapter.getquoted  s     DJJ<w'//77r/   c                 "    SU R                    S3$ )Nr  r  r  r   s    r-   __str__UUID_adapter.__str__  s    4::,g&&r/   r  N)
rE   rF   rG   rH   rI   r&   r  r  r  rJ   rW   r/   r-   r  r  r  s    8'r/   r  c                   ^ SSK mU (       d  SnSnO$[        U [        [        45      (       a  U u  p#OU nSn[        R
                  " U4SU4S j5      [        l        [        R                  " U4S[        R                  5      [        l        [        R                  " [        R                  U5        [        R                  " [        R                  U5        [        R                  " TR                  [        5        [        R                  $ )a:  Create the UUID type and an uuid.UUID adapter.

:param oids: oid for the PostgreSQL :sql:`uuid` type, or 2-items sequence
    with oids of the type and the array. If not specified, use PostgreSQL
    standard oids.
:param conn_or_curs: where to register the typecaster. If not specified,
    register it globally.
r   Ni  i  UUIDc                 J   > U =(       a    TR                  U 5      =(       d    S $ r1   )r  )r   r   r  s     r-   <lambda>register_uuid.<locals>.<lambda>  s    !9$))D/!AT!Ar/   zUUID[])r  rz   r   r   r  new_typer  new_array_type	UUIDARRAYregister_typeregister_adapterr  )oidsconn_or_cursoid1oid2r  s       @r-   register_uuidr    s     	D4-	(	(
dthACDI(($(DIIFDNtyy,/t~~|4$))\299r/   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)Ineti  a/  Wrap a string to allow for correct SQL-quoting of inet values.

Note that this adapter does NOT check the passed value to make
sure it really is an inet-compatible address but DOES call adapt()
on it to make sure it is impossible to execute an SQL-injection
by passing an evil value to the initializer.
c                     Xl         g r1   )addr)r)   r  s     r-   r&   Inet.__init__  s    	r/   c                 P    U R                   R                   SU R                  < S3$ )Nri  rj  )r,   rE   r  r   s    r-   __repr__Inet.__repr__  s$    ..))*!DII=::r/   c                     Xl         g r1   )_connr)   conns     r-   prepareInet.prepare  r  r/   c                     [        U R                  5      n[        US5      (       a  UR                  U R                  5        UR                  5       S-   $ )Nr  s   ::inet)rp  r  r$  r  r  r  )r)   objs     r-   r  Inet.getquoted  s=    m3	""KK

#}}**r/   c                 .    U[         R                  L a  U $ g r1   r  r  s     r-   r  Inet.__conform__  r  r/   c                 ,    [        U R                  5      $ r1   )rm  r  r   s    r-   r  Inet.__str__  s    499~r/   )r  r  N)rE   rF   rG   rH   rI   r&   r  r  r  r  r  rJ   rW   r/   r-   r  r    s%    ;+r/   r  c                    SSK nUR                  S[        5        U (       d  SnSnO$[        U [        [
        45      (       a  U u  p4OU nSn[        R                  " U4SS 5      [        l        [        R                  " U4S[        R                  5      [        l
        [        R                  " [        R                  U5        [        R                  " [        R                  U5        [        R                  $ )	a4  Create the INET type and an Inet adapter.

:param oid: oid for the PostgreSQL :sql:`inet` type, or 2-items sequence
    with oids of the type and the array. If not specified, use PostgreSQL
    standard oids.
:param conn_or_curs: where to register the typecaster. If not specified,
    register it globally.
r   Nz4the inet adapter is deprecated, it's not very usefulie  i  INETc                 <    U =(       a    [        U 5      =(       d    S $ r1   )r  )r   r   s     r-   r  register_inet.<locals>.<lambda>  s    !4$t*!<!<r/   	INETARRAY)warningswarnDeprecationWarningrz   r   r   r  r  r  r  r  r  )oidr  r  r  r  s        r-   register_inetr    s     MM> 	C$	'	'
dth<>DI(($;		JDNtyy,/t~~|499r/   c                 \   SSK nSSKJnJnJn    U R                  5       nXR:X  a  gXS:X  a#  UR                  U R                  5       // / 5        O<XT:X  a#  UR                  / U R                  5       // 5        OU R                  SU 35      eM}  ! [         a    U R                  5          M  f = f)a>  Wait until a connection or cursor has data available.

The function is an example of a wait callback to be registered with
`~psycopg2.extensions.set_wait_callback()`. This function uses
:py:func:`~select.select()` to wait for data to become available, and
therefore is able to handle/receive SIGINT/KeyboardInterrupt.
r   N)POLL_OK	POLL_READ
POLL_WRITEzbad state from poll: )
selectpsycopg2.extensionsr  r  r  pollrz  OperationalErrorKeyboardInterruptcancel)r  r  r  r  r  states         r-   wait_selectr    s     BB
	IIKE#t{{}or26$b4;;=/26++.CE7,KLL  ! 	KKM	s"   B 'B 'B 7B B+*B+c                     U c  [         R                  " S5      e[        U S5      (       a"  U R                  nUR	                  [
        S9nX4$ U nUR	                  [
        S9nX4$ )zEReturn the connection and a DBAPI cursor from a connection or cursor.z no connection or cursor providedra   )rR   )rX  r%  r$  r   r   r   )r  r  r  s      r-   _solve_conn_cursr    sk    ''(JKK|Y''&&{{'{2
 : {{'{2:r/   c                       \ rS rSrSrS rS rS rS r\r	\
R                  " S\
R                  5      r\\
R                  " S5      4S	 j5       r\S
 5       r\S 5       rSrg)HstoreAdapteri  z)Adapt a Python dict to the hstore syntax.c                     Xl         g r1   )wrapped)r)   r  s     r-   r&   HstoreAdapter.__init__  s    r/   c                 h    Xl         UR                  R                  S:  a  U R                  U l        g g )Ni_ )r  infoserver_version_getquoted_8r  r  s     r-   r  HstoreAdapter.prepare  s-    	 99##e+!..DN ,r/   c                    U R                   (       d  g[        R                  n/ nU R                   R                  5        H  u  p4U" U5      nUR	                  U R
                  5        UR                  5       nUb4  U" U5      nUR	                  U R
                  5        UR                  5       nOSnUR                  SU-   S-   U-   S-   5        M     SSR                  U5      -   S-   $ )z*Use the operators available in PG pre-9.0.
   ''::hstores   NULL   (s    =>    )s   ||)	r  r  r	   r   r  r  r  r   join)r)   r	   rvrv  r   s        r-   r  HstoreAdapter._getquoted_8   s    || 

LL&&(DAaAIIdii A}!H		$))$KKM IIdQh(1,t34 ) ejjn$t++r/   c                    U R                   (       d  g[        R                  " [        U R                   R	                  5       5      5      nUR                  U R                  5        [        R                  " [        U R                   R                  5       5      5      nUR                  U R                  5        SUR                  5       -   S-   UR                  5       -   S-   $ )z(Use the hstore(text[], text[]) function.r  s   hstore(s   , r  )	r  r  r	   r   r   r  r  r   r  )r)   rv  r   s      r-   _getquoted_9HstoreAdapter._getquoted_98  s    || JJtDLL--/01			$))JJtDLL//123			$))AKKM)E1AKKMADHHr/   am  
        # hstore key:
        # a string of normal or escaped chars
        "((?: [^"\\] | \\. )*)"
        \s*=>\s* # hstore value
        (?:
            NULL # the value can be null - not catched
            # or a quoted string like the key
            | "((?: [^"\\] | \\. )*)"
        )
        (?:\s*,\s*|$) # pairs separated by comma or end of string.
    z\\(.)c                    Uc  g0 nSnU R                   R                  U5       H  nUb  UR                  5       U:w  a  [        R                  " SU 35      eUR                  SUR                  S5      5      nUR                  S5      nUb  UR                  SU5      nXU'   UR                  5       nM     U[        U5      :  a  [        R                  " SU 35      eU$ )zParse an hstore representation in a Python string.

The hstore is represented as something like::

    "a"=>"1", "b"=>"2"

with backslash-escaped strings.
Nr   z"error parsing hstore pair at char \1r      z/error parsing hstore: unparsed data after char )	
_re_hstorefinditerstartrX  InterfaceErrorr   groupendro   )	r)   r   cur_bsdecr  r  mrv  r   s	            r-   parseHstoreAdapter.parseR  s     9))!,AyAGGI.--8@B B

5!''!*-A
A}JJua(qEEEGE - 3q6>))A%IK K 	r/   c                     Uc  gUR                  [        R                  UR                  R                     5      nU R                  X5      $ )z2Parse an hstore returning unicode keys and values.N)r  r  r  r   r  r  )r)   r   r  s      r-   parse_unicodeHstoreAdapter.parse_unicodes  s<     9HHT^^CNN$;$;<=zz!!!r/   c                    [        U5      u  p#UR                  nUR                  R                  S:  =(       a    S=(       d    Sn/ / pvUR	                  SU S35        U H+  nUR                  US   5        UR                  US   5        M-     U[        R                  :w  a!  UR                  (       d  UR                  5         [        U5      [        U5      4$ )zBReturn the lists of OID of the hstore and hstore[] types.
        9 typarrayNULLzSELECT t.oid, z\
FROM pg_type t JOIN pg_namespace ns
    ON typnamespace = ns.oid
WHERE typname = 'hstore';
r   r   )r  statusr  r  ra   r   r  STATUS_IN_TRANSACTION
autocommitrollbackr   )	r)   r  r  r  conn_statusr  rv0rv1r  s	            r-   get_oidsHstoreAdapter.get_oids|  s     &l3
 kk 99++u4CMvrS 	z 2  	
 DJJtAwJJtAw 
 4555MMOSz5:%%r/   )r  r  r  N)rE   rF   rG   rH   rI   r&   r  r  r  r  _recompileVERBOSEr  r   r  r  r  rJ   rW   r/   r-   r  r    s    3/,0	I I  
J #&;;x#8  @ " " & &r/   r  c                    UcB  [         R                  U 5      nUb
  US   (       d  [        R                  " S5      eUS   nUS   n[	        U[
        5      (       a  U4nUb=  [	        U[
        5      (       a  U4nO$[        U Vs/ s H  oU(       d  M  UPM     sn5      n[        R                  " US[         R                  5      n[        R                  " Xa(       + =(       a    U =(       d    S5        [        R                  " [        [         5        U(       aF  [        R                  " USU5      n[        R                  " Xq(       + =(       a    U =(       d    S5        ggs  snf )a  Register adapter and typecaster for `!dict`\-\ |hstore| conversions.

:param conn_or_curs: a connection or cursor: the typecaster will be
    registered only on this object unless *globally* is set to `!True`
:param globally: register the adapter globally, not only on *conn_or_curs*
:param unicode: if `!True`, keys and values returned from the database
    will be `!unicode` instead of `!str`. The option is not available on
    Python 3
:param oid: the OID of the |hstore| type if known. If not, it will be
    queried on *conn_or_curs*.
:param array_oid: the OID of the |hstore| array type if known. If not, it
    will be queried on *conn_or_curs*.

The connection or cursor passed to the function will be used to query the
database and look for the OID of the |hstore| type (which may be different
across databases). If querying is not desirable (e.g. with
:ref:`asynchronous connections <async-support>`) you may specify it in the
*oid* parameter, which can be found using a query such as :sql:`SELECT
'hstore'::regtype::oid`. Analogously you can obtain a value for *array_oid*
using a query such as :sql:`SELECT 'hstore[]'::regtype::oid`.

Note that, when passing a dictionary from Python to the database, both
strings and unicode keys and values are supported. Dictionaries returned
from the database have keys/values according to the *unicode* parameter.

The |hstore| contrib module must be already installed in the database
(executing the ``hstore.sql`` script in your ``contrib`` directory).
Raise `~psycopg2.ProgrammingError` if the type is not found.
Nr   z\hstore type not found in the database. please install it from your 'contrib/hstore.sql' filer   HSTOREHSTOREARRAY)r  r  rX  r%  rz   r{   r   r  r  r  r  r  dictr  )r  globallyunicoder  	array_oidr~   r
  r  s           r-   register_hstorer    s   > {$$\2;c!f++HI I AIa&C#sfi%%"I)9)Qqq)9:I ]]3-*=*=>Fv|<DE$.)))]FK;(E(MN  :s   
EEc                       \ rS rSrSrSS jrS rS r\R                  " S\R                  5      r\R                  " S5      r\S	 5       rS
 r\S 5       rSrg)CompositeCasteri  aY  Helps conversion of a PostgreSQL composite type into a Python object.

The class is usually created by the `register_composite()` function.
You may want to create and register manually instances of the class if
querying the database at registration time is not desirable (such as when
using an :ref:`asynchronous connections <async-support>`).

Nc                    Xl         XPl        X l        X@l        U Vs/ s H  ofS   PM	     snU l        U Vs/ s H  ofS   PM	     snU l        U R                  XR                  5        [        R                  " U4XR                  5      U l
        U(       a,  [        R                  " U4U S3U R                  5      U l        g S U l        g s  snf s  snf )Nr   r   ARRAY)nameschemar  r  attnamesatttypes_create_typer  r  r  
typecasterr  array_typecaster)r)   r  r  attrsr  r  as          r-   r&   CompositeCaster.__init__  s    	"',-u!1u-',-u!1u-$.--jjA$($7$7endoo%?D! %)D! .-s
   C
Cc                    Uc  g U R                  U5      n[        U5      [        U R                  5      :w  aB  [        R                  " S[        U R                  5      U R
                  [        U5      4-  5      e[        U R                  U5       VVs/ s H  u  pEUR                  XE5      PM     nnnU R                  U5      $ s  snnf )Nz9expecting %d components for the type %s, %d found instead)	tokenizero   r  rX  	DataErrorr  zipcastmake)r)   r   r  tokensr  tokenr   s          r-   r  CompositeCaster.parse  s    9q!v;#dmm,,$$KT]]#TYYF<=> >
 "$--8:8
 ))C'8 	 : yy  :s   Cc                 $    U R                  U5      $ )zReturn a new Python object representing the data being casted.

*values* is the list of attributes, already casted into their Python
representation.

You can subclass this method to :ref:`customize the composite cast
<custom-composite>`.
)_ctor)r)   r   s     r-   r$  CompositeCaster.make   s     zz&!!r/   z
  \(? ([,)])                        # an empty token, representing NULL
| \(? " ((?: [^"] | "")*) " [,)]    # or a quoted string
| \(? ([^",)]+) [,)]                # or an unquoted string
    z	(["\\])\1c           	         / nU R                   R                  U5       H  nUc  [        R                  " SU< 35      eUR	                  S5      b  UR                  S 5        ME  UR	                  S5      b<  UR                  U R                  R                  SUR	                  S5      5      5        M  UR                  UR	                  S5      5        M     U$ )Nzcan't parse type: r   r  r     )_re_tokenizer  rX  r  r  r   _re_undoubler   )r)   r   r  r  s       r-   r   CompositeCaster.tokenize  s    ""++A.Ay--0B1%.HIIwwqz%		$'		$++//qwwqzBC		!''!*% / 	r/   c                     [         R                  SU5      n[        X5      U l        U R                  R                  U l        g )Nr   )r   r   r   rl  r   r)  )r)   r  r  s      r-   r  CompositeCaster._create_type#  s-    }}S$'t.	YY__
r/   c                    [        U5      u  p4UR                  nSU;   a  UR                  SS5      u  pgOUnSnUR                  R                  S:  =(       a    S=(       d    SnUR                  SU-  Xv45        UR                  5       n	U	(       d   Sn
UR                  [        R                  :X  a  UR                  S	5        S
n
UR                  SU-  U45        UR                  5       n	U	(       a  U	S   S   nU	S   S   nW
(       a  UR                  S5        U[        R                  :w  a!  UR                  (       d  UR                  5         U	(       d  [        R                  " SU S35      eU	S   S   nU	S   S   nU	 Vs/ s H  oS   US   4PM     nnU " X{UXS9$ ! [        R                   a     Nf = f! W
(       a  UR                  S5        f f = fs  snf )zmReturn a `CompositeCaster` instance for the type *name*.

Raise `ProgrammingError` if the type is not found.
.r   publicr  r  r  zSELECT t.oid, %s, attname, atttypid
FROM pg_type t
JOIN pg_namespace ns ON typnamespace = ns.oid
JOIN pg_attribute a ON attrelid = typrelid
WHERE typname = %%s AND nspname = %%s
    AND attnum > 0 AND NOT attisdropped
ORDER BY attnum;
FzSAVEPOINT register_typeTzSELECT t.oid, %s, attname, atttypid, typname, nspname
FROM pg_type t
JOIN pg_namespace ns ON typnamespace = ns.oid
JOIN pg_attribute a ON attrelid = typrelid
WHERE t.oid = %%s::regtype
    AND attnum > 0 AND NOT attisdropped
ORDER BY attnum;
r         z#ROLLBACK TO SAVEPOINT register_typezPostgreSQL type 'z' not foundr  r,  )r  r  )r  r  rn  r  r  ra   r=   r  r  rX  r%  r  r   )r)   r  r  r  r  r  r  tnamer  recs	savepointtype_oidr  r
type_attrss                  r-   _from_dbCompositeCaster._from_db(  s    &l3
 kk $; JJsA.MFEEF 99++u4CMv 	   	! }}H!	 ;;$"<"<<LL!:; $I    }} GAJE!!WQZFLL!FG $444T__MMO++#D657 7 71:GAJ	,01DqtQqTlD
1EZ0 	0/ ,,  LL!FG  2s1   A	F! 'F; G!F85F; 7F88F; ;G)
r)  r  r  r  r  r  r  r  rl  r  r|  )rE   rF   rG   rH   rI   r&   r  r$  r  r  r  r-  r.  r   r   r  r=  rJ   rW   r/   r-   r  r    sq    ) !
" ;;   
	L ;;|,L %
 O0 O0r/   r  c                 4   Uc  [         nUR                  X5      n[        R                  " UR                  U(       + =(       a    U=(       d    S5        UR
                  b8  [        R                  " UR
                  U(       + =(       a    U=(       d    S5        U$ )a  Register a typecaster to convert a composite type into a tuple.

:param name: the name of a PostgreSQL composite type, e.g. created using
    the |CREATE TYPE|_ command
:param conn_or_curs: a connection or cursor used to find the type oid and
    components; 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
:param factory: if specified it should be a `CompositeCaster` subclass: use
    it to :ref:`customize how to cast composite types <custom-composite>`
:return: the registered `CompositeCaster` or *factory* instance
    responsible for the conversion
N)r  r=  r  r  r  r  )r  r  r  factorycasters        r-   register_compositerB  {  sy     !d1Fv((h,*G<*O4P*##\%Bl%Jd	L Mr/   c              #      #    / n[        U 5      n  [        U5       H  nUR                  [        U5      5        M     Uv   / nM5  ! [         a    U(       a  Uv    gf = f7f)zoConsume an iterable and return it in chunks.

Every chunk is at most `page_size`. Never return an empty chunk.
N)r   rn   r   rA   rB   )seq	page_sizepager   rp   s        r-   	_paginaterG    sf     
 D	cB
	9%DH% &JD   	
	s(   A!2A A!AA!AA!c                     [        X#S9 HC  nU Vs/ s H  oPR                  X5      PM     nnU R                  SR                  U5      5        ME     gs  snf )aY  Execute groups of statements in fewer server roundtrips.

Execute *sql* several times, against all parameters set (sequences or
mappings) found in *argslist*.

The function is semantically similar to

.. parsed-literal::

    *cur*\.\ `~cursor.executemany`\ (\ *sql*\ , *argslist*\ )

but has a different implementation: Psycopg will join the statements into
fewer multi-statement commands, each one containing at most *page_size*
statements, resulting in a reduced number of server roundtrips.

After the execution of the function the `cursor.rowcount` property will
**not** contain a total result.

rE     ;N)rG  mogrifyra   r  )r  sqlargslistrE  rF  r*   sqlss          r-   execute_batchrO    sE    ( (837844C&48DIIdO$ 98s   Ac           	         SSK Jn  [        X5      (       a  UR                  U 5      n[        U[        5      (       d6  UR                  [        R                  U R                  R                     5      n[        U5      u  pxU(       a  / OSn	[        X$S9 H  n
Uc'  SSR                  S/[        U
S   5      -  5      -   S-   nUSS nU
 H4  nUR                  U R                  X<5      5        UR                  S5        M6     XS	S& U R!                  S
R                  U5      5        U(       d  M  U	R#                  U R%                  5       5        M     U	$ )a  Execute a statement using :sql:`VALUES` with a sequence of parameters.

:param cur: the cursor to use to execute the query.

:param sql: the query to execute. It must contain a single ``%s``
    placeholder, which will be replaced by a `VALUES list`__.
    Example: ``"INSERT INTO mytable (id, f1, f2) VALUES %s"``.

:param argslist: sequence of sequences or dictionaries with the arguments
    to send to the query. The type and content must be consistent with
    *template*.

:param template: the snippet to merge to every item in *argslist* to
    compose the query.

    - If the *argslist* items are sequences it should contain positional
      placeholders (e.g. ``"(%s, %s, %s)"``, or ``"(%s, %s, 42)``" if there
      are constants value...).

    - If the *argslist* items are mappings it should contain named
      placeholders (e.g. ``"(%(id)s, %(f1)s, 42)"``).

    If not specified, assume the arguments are sequence and use a simple
    positional template (i.e.  ``(%s, %s, ...)``), with the number of
    placeholders sniffed by the first element in *argslist*.

:param page_size: maximum number of *argslist* items to include in every
    statement. If there are more items the function will execute more than
    one statement.

:param fetch: if `!True` return the query results into a list (like in a
    `~cursor.fetchall()`).  Useful for queries with :sql:`RETURNING`
    clause.

.. __: https://www.postgresql.org/docs/current/static/queries-values.html

After the execution of the function the `cursor.rowcount` property will
**not** contain a total result.

While :sql:`INSERT` is an obvious candidate for this function it is
possible to use it with other statements, for example::

    >>> cur.execute(
    ... "create table test (id int primary key, v1 int, v2 int)")

    >>> execute_values(cur,
    ... "INSERT INTO test (id, v1, v2) VALUES %s",
    ... [(1, 2, 3), (4, 5, 6), (7, 8, 9)])

    >>> execute_values(cur,
    ... """UPDATE test SET v1 = data.v1 FROM (VALUES %s) AS data (id, v1)
    ... WHERE test.id = data.id""",
    ... [(1, 20), (4, 50)])

    >>> cur.execute("select * from test order by id")
    >>> cur.fetchall()
    [(1, 20, 3), (4, 50, 6), (7, 8, 9)])

r   )
ComposableNrI  r     ,s   %sr  r/   )psycopg2.sqlrQ  rz   	as_stringr  r  r  r  r   r  
_split_sqlrG  r  ro   r   rK  ra   extendr=   )r  rL  rM  templaterE  fetchrQ  prepostresultrF  partsr*   s                r-   execute_valuesr^    s   x (#""mmC 
 c5!!jj(?(?@A3ICRdF(8dii#d1g,(>??$FHADLLX45LL  bc
CHHUO$5MM#,,.) 9 Mr/   c                 t   / =p/ n[         R                  " SU 5      nU H  n[        U5      S:w  d	  USS S:w  a  UR                  U5        M.  USS S:X  a  XL a  UnM?  [	        S5      eUSS S:X  a  UR                  S5        Mf  [	        SUSS R                  S	S
5      -  5      e   XL a  [	        S5      eX#4$ )z}Split *sql* on a single ``%s`` placeholder.

Split on the %s, perform %% replacement and return pre, post lists of
snippets.
s   (%.)r  Nr      %   sz1the query contains more than one '%s' placeholderz"unsupported format character: '%s'asciir  z.the query doesn't contain any '%s' placeholder)r  rn  ro   r   
ValueErrorr  )rL  currrZ  r[  r%  r&  s         r-   rV  rV    s     ODDYYx%Fu:?eBQi4/KK9{ GI I12Y$KKA)""7I67 8 8 " {IJJ9r/   [z  !"#$%&'()*+,-./:;<=>?@[\]^`{|}~]r|  )FFNN)FN)d   )Nrg  F)VrI   osr  r9  r8  rer  collectionsr   r   loggingr  rX  r   r  r   r   r   _connectionr	   rp  r
   	functoolsr   psycopg2._psycopgr   r   r   _replicationConnectionr   _replicationCursorr   psycopg2._jsonr   r   r   r   r   psycopg2._ranger   r   r   r   r   r   r   r   psycopg2._ipaddressr   r    rN   rT   r   r\   r   r   r   r   r   r   r   r  r)  r2  r=  rE  rM  r   rQ  r  r  r  r  r  r  r  r  r  rB  rG  rO  r^  rV  r  escaper   rW   r/   r-   <module>ru     s  8    /   ' ) 1 0  N N
/ / / 39W 9x/[ /) )83d 3l/ /)^ )8 (+  (F/; /Uw Up 3    $/#?   0/ 0/f2G 2 ?0 ?8	<= 	<*#9 **$: *		i 		c(* c(P' '*D >B8E& E&P ;@(,9Ox`0 `0F8&%2TnB KK#**9
::S@B	r/   