o
    jTte                      @   s   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
dZG dd dZG dd deZd	d
 Zdd Zdd Zdd ZdddZdd Zdd Zdd ZdS )    N)contextmanager)NotSupportedErrorzdjango.db.backendsc                   @   st   e Zd Zdd Zeg dZdd Zdd Zdd	 Zd
d Z	dddZ
dddZdd Zdd Zdd Zdd ZdS )CursorWrapperc                 C   s   || _ || _d S N)cursordb)selfr   r    r	   d/var/www/social.2tendo.club/virtuCedar/venv/lib/python3.10/site-packages/django/db/backends/utils.py__init__   s   
zCursorWrapper.__init__)fetchone	fetchmanyfetchallnextsetc                 C   s&   t | j|}|tjv r| j|S |S r   )getattrr   r   WRAP_ERROR_ATTRSr   wrap_database_errors)r   attrcursor_attrr	   r	   r
   __getattr__   s   
zCursorWrapper.__getattr__c                 c   s<    | j j | jE d H  W d    d S 1 sw   Y  d S r   )r   r   r   r   r	   r	   r
   __iter__   s   
"zCursorWrapper.__iter__c                 C   s   | S r   r	   r   r	   r	   r
   	__enter__    s   zCursorWrapper.__enter__c                 C   s*   z|    W d S  | jjjy   Y d S w r   )closer   DatabaseError)r   typevalue	tracebackr	   r	   r
   __exit__#   s
   zCursorWrapper.__exit__Nc                 C   s   |d ur| j jjstd| j   | j j; |d u r,|d u r,| j|W  d    S |d u r>| j||W  d    S |pAd}| j|||W  d    S 1 sTw   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kparamsr	   r	   r
   r#   /   s   


$zCursorWrapper.callprocc                 C      | j ||d| jdS )NFmanyexecutor)_execute_with_wrappers_executer   sqlr%   r	   r	   r
   executeA      zCursorWrapper.executec                 C   r'   )NTr(   )r+   _executemanyr   r.   
param_listr	   r	   r
   executemanyD   r0   zCursorWrapper.executemanyc                 C   s8   | j | d}t| j jD ]}t||}q|||||S )N)
connectionr   )r   reversedexecute_wrappers	functoolspartial)r   r.   r%   r)   r*   contextwrapperr	   r	   r
   r+   G   s   z$CursorWrapper._execute_with_wrappersc                 G   sf   | j   | j j  |d u r| j|W  d    S | j||W  d    S 1 s,w   Y  d S r   )r   r"   r   r   r/   )r   r.   r%   ignored_wrapper_argsr	   r	   r
   r,   M   s   


$zCursorWrapper._executec                 G   sD   | j   | j j | j||W  d    S 1 sw   Y  d S r   )r   r"   r   r   r4   )r   r.   r3   r<   r	   r	   r
   r1   V   s   

$zCursorWrapper._executemany)NNr   )__name__
__module____qualname__r   	frozensetr   r   r   r   r   r#   r/   r4   r+   r,   r1   r	   r	   r	   r
   r      s    

	r   c                       s8   e Zd Zd	 fdd	Z fddZed
ddZ  ZS )CursorDebugWrapperNc                    B   | j ||dd t ||W  d    S 1 sw   Y  d S )NT)use_last_executed_query)	debug_sqlsuperr/   r-   	__class__r	   r
   r/   `      $zCursorDebugWrapper.executec                    rB   )NT)r)   )rD   rE   r4   r2   rF   r	   r
   r4   d   rH   zCursorDebugWrapper.executemanyFc           	      c   sJ   t  }zRd V  W t  }|| }|r| jj| j||}z
|r%t|nd}W n ty3   d}Y nw | jj	|r@d||f n|d| d t
jd||||||dd d S t  }|| }|rl| jj| j||}z
|rst|nd}W n ty   d}Y nw | jj	|rd||f n|d| d t
jd||||||dd w )	N ?z%s times: %sz%.3f)r.   timez(%.3f) %s; args=%s)durationr.   r%   )extra)rK   	monotonicr   opslast_executed_queryr   len	TypeErrorqueries_logappendloggerdebug)	r   r.   r%   rC   r)   startstoprL   timesr	   r	   r
   rD   h   sX   


zCursorDebugWrapper.debug_sqlr   )NNFF)r=   r>   r?   r/   r4   r   rD   __classcell__r	   r	   rF   r
   rA   \   s
    rA   c                 C   s   | rt jtt| d S d S )N-)datetimedatemapintsplit)sr	   r	   r
   typecast_date   s   rb   c              	   C   s`   | sd S |  d\}}}d|v r| d\}}nd}tt|t|t|t|d d d S )N:.0000000   )r`   r\   rK   r_   )ra   hourminutessecondsmicrosecondsr	   r	   r
   typecast_time   s   ,rl   c                 C   s   | sd S d| vrt | S |  \}}d|v r|dd\}}nd|v r+|dd\}}|d}|d}|d }d|v rE|d\}}nd}tt|d	 t|d t|d t|d	 t|d t|t|d
 d d S )N r[      +rc      rd   re   r   rf   rg   )rb   r`   r\   r_   )ra   dt_datesrY   rj   rk   r	   r	   r
   typecast_timestamp   s(   

ru   c                 C   sD   z	|  d\}}W n ty   d| }}Y n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"."rI   ")r`   
ValueErrorstrip)
identifier	namespacenamer	   r	   r
   split_identifier   s   r|      c                 C   sV   t | \}}|du st||kr| S t||d}d|rd| nd|d||  |f 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%s%sz%s"."rI   )r|   rQ   names_digest)ry   r~   hash_lenrz   r{   digestr	   r	   r
   truncate_name   s
   &r   c                 G   s0   t  }|D ]	}||  q| 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argr	   r	   r
   r      s   r   c                 C   sl   | du rdS t   }|dur||_|dur&| jt d| |d} nd|jt j< |	| } d
| S )zc
    Format a number into a string with the requisite number of digits and
    decimal places.
    Nrn   )r:   z{:f})decimal
getcontextcopyprecquantizeDecimalscalebtrapsRoundedcreate_decimalformat)r   
max_digitsdecimal_placesr:   r	   r	   r
   format_number   s   

r   c                 C   s(   |  do	| 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'.
    rv   rn   )
startswithendswith)
table_name
has_quotesr	   r	   r
   strip_quotes   s   r   )Nr}   )r\   r   r8   r   loggingrK   
contextlibr   	django.dbr   	getLoggerrU   r   rA   rb   rl   ru   r|   r   r   r   r   r	   r	   r	   r
   <module>   s&    
N,
