o
    h,$                     @   sB  d dl Z d dlZd dlZdZdd ZG dd deZG dd ded	ZG d
d deeZ	G dd de	Z
G dd de
ZG dd dZG dd deeZG dd deeZG dd deeZG dd deZG dd deZG dd deeZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZdS )(    N)PostgresErrorFatalPostgresErrorUnknownPostgresErrorInterfaceErrorInterfaceWarningPostgresLogMessageClientConfigurationErrorInternalClientErrorOutdatedSchemaCacheErrorProtocolErrorUnsupportedClientFeatureErrorTargetServerAttributeNotMatchedUnsupportedServerFeatureErrorc                 C   s   | j }|dkp|dS )Nasyncpgzasyncpg.)
__module__
startswith)clsmodname r   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/asyncpg/exceptions/_base.py_is_asyncpg_class   s   r   c                       s   e Zd Zi Zi ddddddddd	d
dddddddddddddddddddddd d!d"d#d$iZ fd%d&Zed'd( Z  ZS ))PostgresMessageMetaSseverityVseverity_enCsqlstateMmessageDdetailHhintPpositionpinternal_positionqinternal_queryWcontextsschema_namet
table_nameccolumn_nameddata_type_namenconstraint_nameFserver_source_filenameLserver_source_lineRserver_source_functionc           	         s   t  | |||}|j| jkr!|dkr!| j D ]}t||d  qt|r7tj|j }t	||r7t
d||d}|d urX| j|}|d urStd||j|| j|< |S )NPostgresMessagez exception class redefinition: {}r   z={} has duplicate SQLSTATE code, which isalready defined by {})super__new__r   
_field_mapvaluessetattrr   sysmoduleshasattrRuntimeErrorformatget_message_map	TypeError__name__)	mclsnamebasesdctr   fmodcodeexisting	__class__r   r   r>   2   s*   


zPostgresMessageMeta.__new__c                 C   s   | j |tS N)rH   rG   r   )rK   rQ   r   r   r   get_message_class_for_sqlstateI   s   z2PostgresMessageMeta.get_message_class_for_sqlstate)	rJ   r   __qualname__rH   r?   r>   classmethodrV   __classcell__r   r   rS   r   r      sT    	
r   c                   @   s:   e Zd Zedd Zedd Zed
ddZdd	 ZdS )r<   c                 C   s   | d}t| |S )Nr   )rG   typerV   )r   fieldsr   r   r   r   _get_error_classP   s   
z PostgresMessage._get_error_classc                 C   s>   d|i}t | j}| D ]\}}||}|r|||< q|S )Nquery)rZ   r?   itemsrG   )r   r[   r]   rN   	field_mapkvfieldr   r   r   _get_error_dictU   s   

zPostgresMessage._get_error_dictNc           
      C   s   |  ||}| |}|dd}|jdko t|o |ddk}|r.tj|j }|j}d}|jdv o6t|}|rJ|dd}	|	t	
d	7 }	|	|d< |||fS )
Nr    FeatureNotSupportedErrorr;   RevalidateCachedQueryzQcached statement plan is invalid due to a database schema or configuration change)DuplicatePreparedStatementErrorInvalidSQLStatementNameErrorr#   a  
                NOTE: pgbouncer with pool_mode set to "transaction" or
                "statement" does not support prepared statements properly.
                You have two options:

                * if you are using pgbouncer for connection pooling to a
                  single server, switch to the connection pool functionality
                  provided by asyncpg, it is a much better option for this
                  purpose;

                * if you have no option of avoiding the use of pgbouncer,
                  then you can set statement_cache_size to 0 when creating
                  the asyncpg connection object.
            )rc   r\   rG   rJ   r   rB   rC   r   InvalidCachedStatementErrortextwrapdedent)
r   r[   r]   rN   excclsr   is_icse
exceptionsis_prepared_stmt_errorr#   r   r   r   _make_constructorc   s(   



z!PostgresMessage._make_constructorc                 C   s6   i }t | j D ]}t| |}|d ur|||< q	|S rU   )rZ   r?   r@   getattr)selfrN   rO   valr   r   r   as_dict   s   
zPostgresMessage.as_dictrU   )rJ   r   rW   rX   r\   rc   rp   rt   r   r   r   r   r<   N   s    

8r<   )	metaclassc                   @   s&   e Zd ZdZdd ZedddZdS )r   z#Base class for all Postgres errors.c                 C   :   | j d }| jr|d| j7 }| jr|d| j7 }|S Nr   z
DETAIL:  {}z

HINT:  {}argsr!   rF   r#   rr   msgr   r   r   __str__      
zPostgresError.__str__Nc                 C   s*   |  ||\}}}||}|j| |S rU   )rp   __dict__update)r   r[   r]   rl   r   rN   exr   r   r   new   s   zPostgresError.newrU   )rJ   r   rW   __doc__r|   rX   r   r   r   r   r   r      s
    	r   c                   @      e Zd ZdZdS )r   z9A fatal error that should result in server disconnection.NrJ   r   rW   r   r   r   r   r   r          r   c                   @   r   )r   z'An error with an unknown SQLSTATE code.Nr   r   r   r   r   r      r   r   c                   @   s$   e Zd ZdddddZdd ZdS )InterfaceMessageNr!   r#   c                C   s   || _ || _d S rU   r   )rr   r!   r#   r   r   r   __init__   s   
zInterfaceMessage.__init__c                 C   rv   rw   rx   rz   r   r   r   r|      r}   zInterfaceMessage.__str__)rJ   r   rW   r   r|   r   r   r   r   r      s    r   c                   @   s(   e Zd ZdZdddddZdd ZdS )r   z/An error caused by improper use of asyncpg API.Nr   c                C       t j| ||d t| | d S Nr   )r   r   	Exceptionrr   r{   r!   r#   r   r   r   r         zInterfaceError.__init__c                 C   s   t | || j| jd| jS r   )rZ   r!   r#   with_traceback__traceback__rz   r   r   r   with_msg   s   zInterfaceError.with_msg)rJ   r   rW   r   r   r   r   r   r   r   r      s    r   c                   @   r   )r   z1An error caused by improper client configuration.Nr   r   r   r   r   r      r   r   c                   @   r   )	DataErrorz'An error caused by invalid query input.Nr   r   r   r   r   r      r   r   c                   @   r   )r   z,Requested feature is unsupported by asyncpg.Nr   r   r   r   r   r      r   r   c                   @   r   )r   z6Requested feature is unsupported by PostgreSQL server.Nr   r   r   r   r   r      r   r   c                   @   s    e Zd ZdZdddddZdS )r   z3A warning caused by an improper use of asyncpg API.Nr   c                C   r   r   )r   r   UserWarningr   r   r   r   r      r   zInterfaceWarning.__init__)rJ   r   rW   r   r   r   r   r   r   r      s    r   c                   @   r   )r	   z/All unexpected errors not classified otherwise.Nr   r   r   r   r   r	      r   r	   c                   @   r   )r   zBUnexpected condition in the handling of PostgreSQL protocol input.Nr   r   r   r   r   r      r   r   c                   @   r   )r   zECould not find a host that satisfies the target attribute requirementNr   r   r   r   r   r     r   r   c                       s*   e Zd ZdZdddd fdd
Z  ZS )r
   zEA value decoding error caused by a schema change before row fetching.N)schema	data_typer%   c                   s"   t  | || _|| _|| _d S rU   )r=   r   r-   r3   r%   )rr   r{   r   r   r%   rS   r   r   r     s   
z!OutdatedSchemaCacheError.__init__)rJ   r   rW   r   r   rY   r   r   rS   r   r
     s    r
   c                   @   s.   e Zd ZdZdd Zdd Zed	ddZdS )
r   z+A base class for non-error server messages.c                 C   s   d t| j| jS )Nz{}: {})rF   rZ   rJ   r   )rr   r   r   r   r|     s   zPostgresLogMessage.__str__c                 C   s   t dt| j)Nzinstances of {} are immutable)rI   rF   rZ   rJ   )rr   rL   rs   r   r   r   __setattr__  s   zPostgresLogMessage.__setattr__Nc                 C   s~   |  ||\}}}|tu rt}|tu r(|dp|d}|r(| dkr(tj}t|tt	fr4||}n| }|j
| |S )Nr   r   WARNING)rp   r   r   rG   upperr   PostgresWarning
issubclassBaseExceptionWarningr~   r   )r   r[   r]   rl   message_textrN   r   r{   r   r   r   r     s   
zPostgresLogMessage.newrU   )rJ   r   rW   r   r|   r   rX   r   r   r   r   r   r     s    r   )r   rB   rj   __all__r   rZ   r   r<   r   r   r   r   r   r   
ValueErrorr   r   r   r   r   r   r	   r   r   r
   r   r   r   r   r   <module>   s,   4W
