
    Hwg'                         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y)    N)contextmanager)NotSupportedError)md5)
parse_timezdjango.db.backendsc                   f    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y)CursorWrapperc                      || _         || _        y N)cursordb)selfr   r   s      O/var/www/horilla/myenv/lib/python3.12/site-packages/django/db/backends/utils.py__init__zCursorWrapper.__init__   s        )fetchone	fetchmanyfetchallnextsetc                     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__   s=     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                    |+| j                   j                  j                  st        d      | 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.r    )r   featuressupports_callproc_kwargsr   validate_no_broken_transactionr   r   callproc)r   procnameparamskparamss       r   r.   zCursorWrapper.callproc0   s     tww'7'7'P'P#$  	..0WW)) 	G~'/{{++H5	G 	G {{++Hf=		G 	G  2{{++HfgF	G 	G 	Gs   CC."CC#c                 @    | j                  ||d| j                        S )NFmanyexecutor)_execute_with_wrappers_execute)r   sqlr0   s      r   executezCursorWrapper.executeB   s'    **edmm + 
 	
r   c                 @    | j                  ||d| j                        S )NTr3   )r6   _executemany)r   r8   
param_lists      r   executemanyzCursorWrapper.executemanyG   s)    **$1B1B + 
 	
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   sQ    !%D9 8 89 	<G (((;H	<VT733r   c                    | 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r
   )r   r-   r   r   r9   )r   r8   r0   ignored_wrapper_argss       r   r7   zCursorWrapper._executeR   sk    ..0WW)) 	8~{{**3/	8 	8
 {{**37	8 	8 	8s   A=A==Bc                     | j                   j                          | j                   j                  5  | j                  j	                  ||      cd d d        S # 1 sw Y   y xY wr
   )r   r-   r   r   r=   )r   r8   r<   rG   s       r   r;   zCursorWrapper._executemany[   sH    ..0WW)) 	<;;**3
;	< 	< 	<s   AA )NNr
   )__name__
__module____qualname__r   	frozensetr   r   r   r!   r)   r.   r9   r=   r6   r7   r;   r    r   r   r   r      sH     !!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superr9   )r   r8   r0   	__class__s      r   r9   zCursorDebugWrapper.executed   s8    ^^C^F 	07?3/	0 	0 	0   09c                 x    | j                  ||d      5  t        | 	  ||      cd d d        S # 1 sw Y   y xY w)NT)r4   )rQ   rR   r=   )r   r8   r<   rS   s      r   r=   zCursorDebugWrapper.executemanyh   s9    ^^C$^7 	87&sJ7	8 	8 	8rT   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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   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)rI   rJ   rK   r9   r=   r   rQ   __classcell__)rS   s   @r   rN   rN   a   s$    08 IN" "r   rN   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%srY   rZ   r\   )r]   r8   r^   r_   )r[   ra   queries_loggedrf   rg   rh   ri   r^   )r?   r8   rj   rk   r]   s        r   debug_transactionrp      s(    NNE$$>>#De|H""))#:"X- LL.   ('--   %:$$>>#De|H""))#:"X- LL.   ('--   %s   DB A>DA?DDc                 x    dD ]1  }|| v s| j                  |d      \  }}|s t        |      s,|||fc S  | 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      sT      *6>!==q1LD&*V,T6))	*
 4r   c                 h    | r/t        j                  t        t        | j	                  d             S d S )Nrs   )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 )N:.0000000   )r   r|   r[   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 rs   rt   rr   r      r   r   r   r   r   )r   r   r|   r   )r   dt_datesrl   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"."rW   ")r   
ValueErrorstrip)
identifier	namespacerx   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"."rW   )r   rd   names_digest)r   r   hash_lenr   rx   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     sB    
 	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.
    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    
 }  "'')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   rt   )
startswithendswith)
table_name
has_quotess     r   strip_quotesr   9  s8     &&s+H
0C0CC0HJ):a9z9r   )N   )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O< O<d. .b  8	"
H1*" (:r   