
     h'                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ  ej        d          Z G d d          Z G d	 d
e          Zed             Zd Zd Zd Zd Zd ZddZd Zd Zd ZdS )    N)contextmanager)NotSupportedError)md5)
parse_timezdjango.db.backendsc                   n    e Zd Zd Z eg d          Zd Zd Zd Zd Z	ddZ
dd	Zd
 Zd Zd Zd ZdS )CursorWrapperc                 "    || _         || _        d S N)cursordb)selfr   r   s      W/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/django/db/backends/utils.py__init__zCursorWrapper.__init__   s        )fetchone	fetchmanyfetchallnextsetc                     t          | j        |          }|t          j        v r| j                            |          S |S r
   )getattrr   r   WRAP_ERROR_ATTRSr   wrap_database_errors)r   attrcursor_attrs      r   __getattr__zCursorWrapper.__getattr__   s=    dk400=1117//<<<r   c              #   n   K   | j         j        5  | j        E d {V  d d d            d S # 1 swxY w Y   d S r
   )r   r   r   r   s    r   __iter__zCursorWrapper.__iter__   s      W) 	# 	#{"""""""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   *..c                     | S r
    r   s    r   	__enter__zCursorWrapper.__enter__!   s    r   c                 f    	 |                                   d S # | j        j        j        $ r Y d S w xY wr
   )closer   DatabaseError)r   typevalue	tracebacks       r   __exit__zCursorWrapper.__exit__$   sB    	JJLLLLLw% 	 	 	DD	s    00Nc                    | | j         j        j        st          d          | j                                          | j         j        5  |(|&| j                            |          cd d d            S |'| j                            ||          cd d d            S |pd}| j                            |||          cd d d            S # 1 swxY w Y   d S )NzKKeyword parameters for callproc are not supported on this database backend.r    )r   featuressupports_callproc_kwargsr   validate_no_broken_transactionr   r   callproc)r   procnameparamskparamss       r   r.   zCursorWrapper.callproc0   s    tw'7'P#$   	..000W) 	G 	G~'/{++H55	G 	G 	G 	G 	G 	G 	G 	G {++Hf==		G 	G 	G 	G 	G 	G 	G 	G  2{++HfgFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   C3CCCCc                 >    |                      ||d| j                  S )NFmanyexecutor)_execute_with_wrappers_execute)r   sqlr0   s      r   executezCursorWrapper.executeB   s*    **edm + 
 
 	
r   c                 >    |                      ||d| j                  S )NTr3   )r6   _executemany)r   r8   
param_lists      r   executemanyzCursorWrapper.executemanyG   s+    **$1B + 
 
 	
r   c                     | j         | d}t          | j         j                  D ]}t          j        ||          } |||||          S )N)
connectionr   )r   reversedexecute_wrappers	functoolspartial)r   r8   r0   r4   r5   contextwrappers          r   r6   z$CursorWrapper._execute_with_wrappersL   sW    !%D99 899 	< 	<G ((;;HHxVT7333r   c                    | j                                          | j         j        5  |&| j                            |          cd d d            S | j                            ||          cd d d            S # 1 swxY w Y   d S r
   )r   r-   r   r   r9   )r   r8   r0   ignored_wrapper_argss       r   r7   zCursorWrapper._executeR   s    ..000W) 	8 	8~{**3//	8 	8 	8 	8 	8 	8 	8 	8
 {**377	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   A6A66A:=A:c                     | j                                          | j         j        5  | j                            ||          cd d d            S # 1 swxY w Y   d S r
   )r   r-   r   r   r=   )r   r8   r<   rG   s       r   r;   zCursorWrapper._executemany[   s    ..000W) 	< 	<;**3
;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   AAA)NNr
   )__name__
__module____qualname__r   	frozensetr   r   r   r!   r)   r.   r9   r=   r6   r7   r;   r    r   r   r   r      s           !y!Q!Q!QRR  # # #    G G G G$
 
 
 


 
 

4 4 48 8 8< < < < <r   r   c                   D     e Zd Zd fd	Z fdZe	 dd            Z xZS )CursorDebugWrapperNc                     |                      ||d          5  t                                          ||          cd d d            S # 1 swxY w Y   d S )NT)use_last_executed_query)	debug_sqlsuperr9   )r   r8   r0   	__class__s      r   r9   zCursorDebugWrapper.executed   s    ^^C^FF 	0 	077??3//	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0   "A		AAc                     |                      ||d          5  t                                          ||          cd d d            S # 1 swxY w Y   d S )NT)r4   )rQ   rR   r=   )r   r8   r<   rS   s      r   r=   zCursorDebugWrapper.executemanyh   s    ^^C$^77 	8 	877&&sJ77	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8rT   Fc              #   |  K   t          j                    }	 d V  t          j                    }||z
  }|r&| j        j                            | j        ||          }	 |rt          |          nd}n# t          $ r d}Y nw xY w| j        j        	                    |r|d|n|d|z  d           t                              d|||| j        j        |||| j        j        d           d S # t          j                    }||z
  }|r&| j        j                            | j        ||          }	 |rt          |          nd}n# t          $ r d}Y nw xY w| j        j        	                    |r|d|n|d|z  d           t                              d|||| j        j        |||| j        j        d           w xY w)	N ?z times: %.3fr8   time(%.3f) %s; args=%s; alias=%s)durationr8   r0   aliasextra)r[   	monotonicr   opslast_executed_queryr   len	TypeErrorqueries_logappendloggerdebugr^   )	r   r8   r0   rP   r4   startstopr]   timess	            r   rQ   zCursorDebugWrapper.debug_sqll   sT        	EEE>##De|H& Pgk55dk3OO'+3F    G&&<@IUUUCC88c"X-    LL. ($!W]	        >##De|H& Pgk55dk3OO'+3F    G&&<@IUUUCC88c"X-    LL. ($!W]	      sC   C+ A0 0A?>A?+AF;-E F;EF;EA+F;r
   )NNFF)rI   rJ   rK   r9   r=   r   rQ   __classcell__)rS   s   @r   rN   rN   a   sy        0 0 0 0 0 08 8 8 8 8 IN" " " ^" " " " "r   rN   c              #   
  K   t          j                    }	 d V  | j        rkt          j                    }||z
  }| j                            d|z  d|z  d           t
                              d||d | j        ||| j        d           d S d S # | j        rjt          j                    }||z
  }| j                            d|z  d|z  d           t
                              d||d | j        ||| j        d           w w xY w)Nz%srY   rZ   r\   )r]   r8   r^   r_   )r[   ra   queries_loggedrf   rg   rh   ri   r^   )r?   r8   rj   rk   r]   s        r   debug_transactionrp      sv     NE$ 	>##De|H"))#:"X-    LL.  ('-       	 	:$ 	>##De|H"))#:"X-    LL.  ('-      	s   B A3Dc                     dD ]7}|| v r1|                      |d          \  }}|rt          |          r|||fc S 8| ddfS )zH
    Split a time zone name into a 3-tuple of (name, sign, offset).
    )+-   N)rsplitr   )tznamesignnameoffsets       r   split_tzname_deltarz      sk      * *6>>!==q11LD& **V,, *T6))))4r   c                 r    | r4t          j        t          t          |                     d                     nd S )Nrs   )datetimedatemapintsplit)ss    r   typecast_dater      s/    23=s3--..r   c           
      &   | sd S |                      d          \  }}}d|v r|                     d          \  }}nd}t          j        t          |          t          |          t          |          t          |dz   d d                             S )N:.0000000   )r   r|   r[   r   )r   hourminutessecondsmicrosecondss        r   typecast_timer      s     tWWS\\D'7
g~~ 'c 2 2=D		3w<<WsL84KRaR3P/Q/Q  r   c                    | sd S d| vrt          |           S |                                 \  }}d|v r|                    dd          \  }}nd|v r|                    dd          \  }}|                    d          }|                    d          }|d         }d|v r|                    d          \  }}nd}t          j        t          |d	                   t          |d                   t          |d                   t          |d	                   t          |d                   t          |          t          |d
z   d d                             S )N rs   rt   rr   r      r   r   r   r   r   )r   r   r|   r   )r   dt_datesrl   r   r   s           r   typecast_timestampr      s<     t
!||Q7799DAq
axxwwsA11	wwsA1GGCLLEGGCLLEAhG
g~~ 'c 2 2E!HE!HE!HE!HE!HG\H$bqb)**  r   c                     	 |                      d          \  }}n# t          $ r d| }}Y nw xY w|                    d          |                    d          fS )z
    Split an SQL identifier into a two element tuple of (namespace, name).

    The identifier could be a table, column, or sequence name might be prefixed
    by a namespace.
    z"."rW   ")r   
ValueErrorstrip)
identifier	namespacerx   s      r   split_identifierr      si    )$**511	44 ) ) )j4			)??3C00s    ,,   c                     t          |           \  }}|t          |          |k    r| S t          ||          }|rd|z  nd|d||z
           |S )z
    Shorten an SQL identifier to a repeatable mangled version with the given
    length.

    If a quote stripped name contains a namespace, e.g. USERNAME"."TABLE,
    truncate the table portion only.
    N)lengthz%s"."rW   )r   rd   names_digest)r   r   hash_lenr   rx   digests         r   truncate_namer     s|     'z22OIt~Tf,,$x000F(0)b0 v  !! r   c                     t          d          }|D ])}|                    |                                           *|                                d|          S )zk
    Generate a 32-bit digest of a set of arguments that can be used to shorten
    identifying names.
    F)usedforsecurityN)r   updateencode	hexdigest)r   argshargs       r   r   r     sW    
 	E"""A  	;;==&!!r   c                 b   | dS t          j                                                    }|||_        |>|                     t          j        d                              |           |          } n)d|j        t           j        <   |	                    |           } d
                    |           S )zc
    Format a number into a string with the requisite number of digits and
    decimal places.
    Nrt   )rD   z{:f})decimal
getcontextcopyprecquantizeDecimalscalebtrapsRoundedcreate_decimalformat)r'   
max_digitsdecimal_placesrD   s       r   format_numberr   %  s    
 }t ""''))G!!OA%%~o66  
 
 *+go&&&u--==r   c                 r    |                      d          o|                     d          }|r
| dd         n| S )z
    Strip quotes off of quoted table names to make them safe for use in index
    names, sequence names, etc. For example '"USER"."TABLE"' (an Oracle naming
    scheme) becomes 'USER"."TABLE'.
    r   rt   )
startswithendswith)
table_name
has_quotess     r   strip_quotesr   9  sC     &&s++H
0C0CC0H0HJ)9:adz9r   )Nr   )r|   r   rB   loggingr[   
contextlibr   	django.dbr   django.utils.cryptor   django.utils.dateparser   	getLoggerrh   r   rN   rp   rz   r   r   r   r   r   r   r   r   r    r   r   <module>r      s           % % % % % % ' ' ' ' ' ' # # # # # # - - - - - -		/	0	0O< O< O< O< O< O< O< O<d. . . . . . . .b   8	 	 	"  
 
 
  H1 1 1   *" " "     (: : : : :r   