
    g+                        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y)    N)contextmanager)md5)apps)NotSupportedError)
parse_timezdjango.db.backendsc                   j    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y)CursorWrapperc                      || _         || _        y N)cursordb)selfr   r   s      p/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/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                  j                  |      S |S r   )getattrr   r	   WRAP_ERROR_ATTRSr   wrap_database_errors)r   attrcursor_attrs      r   __getattr__zCursorWrapper.__getattr__   s;    dkk40=11177//<<r   c              #      K   | j                   j                  5  | j                  E d {    d d d        y 7 # 1 sw Y   y xY wwr   )r   r   r   r   s    r   __iter__zCursorWrapper.__iter__%   s4     WW)){{"" *)" *)s$   A979	A9AAc                     | S r    r   s    r   	__enter__zCursorWrapper.__enter__)   s    r   c                 x    	 | j                          y # | j                  j                  j                  $ r Y y w xY wr   )closer   DatabaseError)r   typevalue	tracebacks       r   __exit__zCursorWrapper.__exit__,   s2    	JJLww%% 		s    #99Nc                 V   |+| j                   j                  j                  st        d      t        j
                  s5t        j                  s%t        j                  | j                  t               | j                   j                          | j                   j                  5  |&|$| j                  j                  |      cd d d        S |%| j                  j                  ||      cd d d        S |xs d}| j                  j                  |||      cd d d        S # 1 sw Y   y xY w)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     tww'7'7'P'P#$  zz$"9"9MM$99NS..0WW))~'/{{++H5 *) {{++Hf=	 *)  2{{++HfgF *))s   #DD3"DD(c                 @    | j                  ||d| j                        S )NFmanyexecutor)_execute_with_wrappers_execute)r   sqlr9   s      r   executezCursorWrapper.executeN   s'    **edmm + 
 	
r   c                 @    | j                  ||d| j                        S )NTr<   )r?   _executemany)r   rA   
param_lists      r   executemanyzCursorWrapper.executemanyS   s)    **$1B1B + 
 	
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   sL    !%D9 8 89G (((;H :VT733r   c                    t         j                  s5t         j                  s%t        j                  | j
                  t               | j                  j                          | j                  j                  5  |$| j                  j                  |      cd d d        S | j                  j                  ||      cd d d        S # 1 sw Y   y xY w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     zz$"9"9MM$99NS..0WW))~{{**3/ *)
 {{**37 *))s   6CCCc                 P   t         j                  s5t         j                  s%t        j                  | j
                  t               | j                  j                          | j                  j                  5  | j                  j                  ||      cd d d        S # 1 sw Y   y xY wrP   )r   r0   r1   r2   r3   r4   r5   r   r6   r   r   rF   )r   rA   rE   rQ   s       r   rD   zCursorWrapper._executemanyk   sd     zz$"9"9MM$99NS..0WW));;**3
; *))s   6BB%)NNr   )__name__
__module____qualname__r   	frozensetr   r4   r   r   r"   r*   r7   rB   rF   r?   r@   rD   r!   r   r   r	   r	      sR     !!QR	  #G,



48<r   r	   c                   >     e Zd Zd fd	Z fdZe	 dd       Z xZS )CursorDebugWrapperc                 x    | j                  ||d      5  t        | 	  ||      cd d d        S # 1 sw Y   y xY w)NT)use_last_executed_query)	debug_sqlsuperrB   )r   rA   r9   	__class__s      r   rB   zCursorDebugWrapper.executex   s0    ^^C^F7?3/ GFF   09c                 x    | j                  ||d      5  t        | 	  ||      cd d d        S # 1 sw Y   y xY w)NT)r=   )r[   r\   rF   )r   rA   rE   r]   s      r   rF   zCursorDebugWrapper.executemany|   s0    ^^C$^77&sJ7 877r^   c              #     K   t        j                         }	 d  t        j                         }||z
  }|r1| j                  j                  j	                  | j
                  ||      }	 |rt        |      nd}| j                  j                  j                  |r|d|n|d|z  d       t        j                  d|||| j                  j                  |||| j                  j                  d       y # t        $ r d}Y w xY w# t        j                         }||z
  }|r1| j                  j                  j	                  | j
                  ||      }	 |rt        |      nd}n# t        $ r d}Y nw xY w| j                  j                  j                  |r|d|n|d|z  d       t        j                  d|||| j                  j                  |||| j                  j                  d       w xY w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   s      	>>#De|H&ggkk55dkk3O'+F GG&&<@UC8c"X- LL. ($!WW]]	     >>#De|H&ggkk55dkk3O'+F  GG&&<@UC8c"X- LL. ($!WW]]	  sg   G5D AG5)C5 8A=G55D G5DG5AG2E$#G2$E2/G21E22B G22G5r   )NNFF)rS   rT   rU   rB   rF   r   r[   __classcell__)r]   s   @r   rX   rX   u   s$    08 IN" "r   rX   c              #   <  K   t        j                         }	 d  | j                  rqt        j                         }||z
  }| j                  j	                  d|z  d|z  d       t
        j                  d||d | j                  ||| j                  d       y y # | j                  rqt        j                         }||z
  }| j                  j	                  d|z  d|z  d       t
        j                  d||d | j                  ||| j                  d       w w xY w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      s(    NNE$$>>#De|H""))#:"X- LL.   ('--   %:$$>>#De|H""))#:"X- LL.   ('--   %s   DB A>DA?DDc                     dD ]:  }|| v s| j                  |d      \  }}|s t        |      s,d|vr| d}|||fc S  | 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      sb     6>!==q1LD&*V,f$ &xs^FT6))  4r   c                 h    | r/t        j                  t        t        | j	                  d             S d S )Nr}   )datetimedatemapintsplit)ss    r   typecast_dater      s,    23s3-.9=r   c           
          | sy | j                  d      \  }}}d|v r|j                  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      sr    WWS\D'7
g~ 'c 2==D	3w<WsL84KRa3P/Q r   c                    | sy d| vrt        |       S | j                         \  }}d|v r|j                  dd      \  }}nd|v r|j                  dd      \  }}|j                  d      }|j                  d      }|d   }d|v r|j                  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    
!|Q779DAq
axwwsA1	wwsA1GGCLEGGCLEAhG
g~ 'c 2E!HE!HE!HE!HE!HG\H$bq)* r   c                     	 | j                  d      \  }}|j                  d      |j                  d      fS # t        $ r d| }}Y 1w xY w)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     sS    )$**51	4 ??3C00  )j4	)s   8 AA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2OIt~Tf,$x0F()b0 v ! r   c                     t        d      }|D ]!  }|j                  |j                                # |j                         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  s=    
 	E"A	 ;;=&!!r   c                 N   | yt        j                         j                         }|||_        |7| j	                  t        j
                  d      j                  |       |      } n.d|j                  t         j                  <   |j                  |       } dj                  |       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    
 }  "'')G!!OOA%%~o6  
 *+goo&&&u-==r   c                 \    | j                  d      xr | j                  d      }|r| dd S | 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  s8     &&s+H
0C0CC0HJ):a9z9r   )N   )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a< a<H. .b  8&
H1*" (:r   