
    h                          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	  ej                  d      Z G d d      Z G d de      Zd	 Zd
 Zd Zd ZddZd Zd Zd Zy)    N)contextmanager)NotSupportedErrorz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      [/var/www/html/ranktracker/api/venv/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.callproc/   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   sqlr.   s      r   executezCursorWrapper.executeA   s     **3UT]]*[[r   c                 @    | j                  ||d| j                        S )NTr1   )r4   _executemany)r   r6   
param_lists      r   executemanyzCursorWrapper.executemanyD   s#    **3
PTPaPa*bbr   c                     | j                   | d}t        | j                   j                        D ]  }t        j                  ||      }  |||||      S )N)
connectionr	   )r
   reversedexecute_wrappers	functoolspartial)r   r6   r.   r2   r3   contextwrappers          r   r4   z$CursorWrapper._execute_with_wrappersG   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	   r7   )r   r6   r.   ignored_wrapper_argss       r   r5   zCursorWrapper._executeM   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   r6   r:   rE   s       r   r9   zCursorWrapper._executemanyV   sH    ..0WW)) 	<;;**3
;	< 	< 	<s   AA )NNr   )__name__
__module____qualname__r   	frozensetr   r   r   r   r'   r,   r7   r;   r4   r5   r9   r   r   r   r   r      sJ     !!QR#G$\c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superr7   )r   r6   r.   	__class__s      r   r7   zCursorDebugWrapper.execute`   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)r2   )rO   rP   r;   )r   r6   r:   rQ   s      r   r;   zCursorDebugWrapper.executemanyd   s9    ^^C$^7 	87&sJ7	8 	8 	8rR   c              #   F  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||||||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||||||d       w xY ww)	N ?z times: z%.3f)r6   timez(%.3f) %s; args=%s)durationr6   r.   )extra)rW   	monotonicr
   opslast_executed_queryr	   len	TypeErrorqueries_logappendloggerdebug)	r   r6   r.   rN   r2   startstoprX   timess	            r   rO   zCursorDebugWrapper.debug_sqlh   s     	>>#De|H&ggkk55dkk3O'+F GG&&8<4#)(  LL$#+C6J     >>#De|H&ggkk55dkk3O'+F  GG&&8<4#)(  LL$#+C6J  sg   F!C AF!)C 8AF!CF!CF!AF*D:9F:EFEAFF!r   )NNFF)rG   rH   rI   r7   r;   r   rO   __classcell__)rQ   s   @r   rL   rL   \   s!    08  r   rL   c                 h    | r/t        j                  t        t        | j	                  d             S d S )N-)datetimedatemapintsplit)ss    r   typecast_datero      s'    568==#c1773<01@D@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   )rm   ri   rW   rl   )rn   hourminutessecondsmicrosecondss        r   typecast_timerz      sp    WWS\D'7
g~ 'c 2==TCL#g,\T\E\^`_`Da@bccr   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 rh      +rq      rr   rs   r   rt   ru   )ro   rm   ri   rl   )rn   dt_datesre   rx   ry   s           r   typecast_timestampr      s    
!|Q779DAq
axwwsA1	wwsA1GGCLEGGCLEAhG
g~ 'c 2E!Hs58}c%(mE!Hs58}c'l\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"."rU   ")rm   
ValueErrorstrip)
identifier	namespacenames      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"."rU   )r   r]   names_digest)r   r   hash_lenr   r   digests         r   truncate_namer      s\     'z2OIt~Tf,$x0F.7w*R?FXvPXGXAY[abbr   c                     t        j                         }|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.
    N)hashlibmd5updateencode	hexdigest)r   argshargs       r   r   r      sC    
 	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}   )rB   z{:f})decimal
getcontextcopyprecquantizeDecimalscalebtrapsRoundedcreate_decimalformat)r%   
max_digitsdecimal_placesrB   s       r   format_numberr      s    
 }  "'')G!!wq188.ISZ[)*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      s8     &&s+H
0C0CC0HJ):a9z9r   )N   )ri   r   r@   r   loggingrW   
contextlibr   	django.dbr   	getLoggerra   r   rL   ro   rz   r   r   r   r   r   r   r   r   r   <module>r      su          % '			/	0K< K<\% %XAd>1c"" $:r   