
    Evg+                        d dl Z 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 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)md5)apps)NotSupportedError)
parse_timezdjango.db.backendsc                   r    e Zd Zd Z eg d          Z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      U/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/db/backends/utils.py__init__zCursorWrapper.__init__   s        )fetchone	fetchmanyfetchallnextsetzAccessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.c                     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          t          j        s,t          j        s t          j        | j	        t                     | 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.categoryr!   )r   featuressupports_callproc_kwargsr   r   readystored_app_configswarningswarnAPPS_NOT_READY_WARNING_MSGRuntimeWarningvalidate_no_broken_transactionr   r   callproc)r   procnameparamskparamss       r   r7   zCursorWrapper.callproc8   s    tw'7'P#$   z 	T$"9 	TM$9NSSSS..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    D +D D  DDc                 >    |                      ||d| j                  S )NFmanyexecutor)_execute_with_wrappers_execute)r   sqlr9   s      r   executezCursorWrapper.executeN   s*    **edm + 
 
 	
r   c                 >    |                      ||d| j                  S )NTr<   )r?   _executemany)r   rA   
param_lists      r   executemanyzCursorWrapper.executemanyS   s+    **$1B + 
 
 	
r   c                     | j         | d}t          | j         j                  D ]}t          j        ||          } |||||          S )N)
connectionr   )r   reversedexecute_wrappers	functoolspartial)r   rA   r9   r=   r>   contextwrappers          r   r?   z$CursorWrapper._execute_with_wrappersX   sW    !%D99 899 	< 	<G ((;;HHxVT7333r   c                 v   t           j        s,t           j        s t          j        | j        t                     | 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 Nr,   )r   r0   r1   r2   r3   r4   r5   r   r6   r   r   rB   )r   rA   r9   ignored_wrapper_argss       r   r@   zCursorWrapper._execute^   s    z 	T$"9 	TM$9NSSS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   B.B..B25B2c                 &   t           j        s,t           j        s t          j        | j        t                     | j                                         | j        j	        5  | j
                            ||          cd d d            S # 1 swxY w Y   d S rP   )r   r0   r1   r2   r3   r4   r5   r   r6   r   r   rF   )r   rA   rE   rQ   s       r   rD   zCursorWrapper._executemanyk   s     z 	T$"9 	TM$9NSSSS..000W) 	< 	<;**3
;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   BB
B
)NNr   )__name__
__module____qualname__r   	frozensetr   r4   r   r   r"   r*   r7   rB   rF   r?   r@   rD   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superrB   )r   rA   r9   	__class__s      r   rB   zCursorDebugWrapper.executex   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)r=   )r[   r\   rF   )r   rA   rE   r]   s      r   rF   zCursorDebugWrapper.executemany|   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 	8r^   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rA   time(%.3f) %s; args=%s; alias=%s)durationrA   r9   aliasextra)re   	monotonicr   opslast_executed_queryr   len	TypeErrorqueries_logappendloggerdebugrh   )	r   rA   r9   rZ   r=   startstoprg   timess	            r   r[   zCursorDebugWrapper.debug_sql   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)rS   rT   rU   rB   rF   r   r[   __classcell__)r]   s   @r   rX   rX   u   sy        0 0 0 0 0 08 8 8 8 8 IN" " " ^" " " " "r   rX   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%src   rd   rf   )rg   rA   rh   ri   )re   rk   queries_loggedrp   rq   rr   rs   rh   )rH   rA   rt   ru   rg   s        r   debug_transactionrz      sv     NE$ 	>##De|H"))#:"X-    LL.  ('-       	 	:$ 	>##De|H"))#:"X-    LL.  ('-      	s   B A3Dc                     dD ]@}|| v r:|                      |d          \  }}|rt          |          rd|vr| d}|||fc S A| ddfS )zH
    Split a time zone name into a 3-tuple of (name, sign, offset).
    )+-   :z:00N)rsplitr   )tznamesignnameoffsets       r   split_tzname_deltar      s      * *6>>!==q11LD& **V,, *f$$ &^^^FT6))))4r   c                 r    | r4t          j        t          t          |                     d                     nd S )Nr}   )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 )Nr   .0000000   )r   r   re   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 r}   r~   r|   r      r   r   r   r   r   )r   r   r   r   )r   dt_datesrv   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"."ra   ")r   
ValueErrorstrip)
identifier	namespacer   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"."ra   )r   rn   names_digest)r   r   hash_lenr   r   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   0  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.
    Nr~   )rM   z{:f})decimal
getcontextcopyprecquantizeDecimalscalebtrapsRoundedcreate_decimalformat)r(   
max_digitsdecimal_placesrM   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   r~   )
startswithendswith)
table_name
has_quotess     r   strip_quotesr   O  sC     &&s++H
0C0CC0H0HJ)9:adz9r   )Nr   )r   r   rK   loggingre   r2   
contextlibr   hashlibr   django.appsr   	django.dbr   django.utils.dateparser   	getLoggerrr   r	   rX   rz   r   r   r   r   r   r   r   r   r   r!   r   r   <module>r      s            % % % % % %             ' ' ' ' ' ' - - - - - -		/	0	0a< a< a< a< a< a< a< a<H. . . . . . . .b   8  &  
 
 
  H1 1 1   *" " "     (: : : : :r   