
    :"ri,$                        d dl Z d dlZd dlZdZd Z G d de      Z G d de      Z G d	 d
ee      Z	 G d de	      Z
 G d de
      Z G d d      Z G d dee      Z G d dee      Z G d dee      Z G d de      Z G d de      Z G d dee      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Zy)'    N)PostgresErrorFatalPostgresErrorUnknownPostgresErrorInterfaceErrorInterfaceWarningPostgresLogMessageClientConfigurationErrorInternalClientErrorOutdatedSchemaCacheErrorProtocolErrorUnsupportedClientFeatureErrorTargetServerAttributeNotMatchedUnsupportedServerFeatureErrorc                 J    | j                   }|dk(  xs |j                  d      S )Nasyncpgzasyncpg.)
__module__
startswith)clsmodnames     `/var/www/fortnox.pascalinesoft.com/venv/lib/python3.12/site-packages/asyncpg/exceptions/_base.py_is_asyncpg_classr      s&    nnGiA7#5#5j#AA    c                        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%Zed&        Z x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                 $   t         	|   | |||      }|j                  | j                  k(  r1|dk(  r,| j                  j	                         D ]  }t        ||d         t        |      rCt        j                  |j                     }t        ||      rt        dj                  |            |j                  d      }|Q| j                  j                  |      }|%t        dj                  ||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__s
            r   rB   zPostgresMessageMeta.__new__2   s   godD%5>>T__,9J1J__++- &Q%& S!++cnn-CsD!"#E#L#L$   wwz"((,,T2H# !88>$((*;*;9=> > '*Dd#
r   c                 B    | j                   j                  |t              S N)rL   rK   r   )rO   rU   s     r   get_message_class_for_sqlstatez2PostgresMessageMeta.get_message_class_for_sqlstateI   s      $$T+?@@r   )	rN   r   __qualname__rL   rC   rB   classmethodrZ   __classcell__rW   s   @r   r   r      s   LZ] 	Z 	Y	
 	X 	V 	Z 	  	 	Y 	] 	\ 	] 	 	  	%!" 	!#$ 	%%J*. A Ar   r   c                   D    e Zd Zed        Zed        Zedd       Zd Zy)r@   c                 X    |j                  d      }t        |       j                  |      S )Nr   )rK   typerZ   )r   fieldsr    s      r   _get_error_classz PostgresMessage._get_error_classP   s$    ::c?Cy77AAr   c                     d|i}t        |       j                  }|j                         D ]  \  }}|j                  |      }|s|||<     |S )Nquery)ra   rC   itemsrK   )r   rb   re   rR   	field_mapkvfields           r   _get_error_dictzPostgresMessage._get_error_dictU   s[     U
 I((	LLN 	DAqMM!$EE
	
 
r   Nc                    | j                  ||      }| j                  |      }|j                  dd      }|j                  dk(  xr! t	        |      xr |j                  d      dk(  }|r+t
        j                  |j                     }|j                  }d}|j                  dv xr t	        |      }|r/|j                  dd      }	|	t        j                  d	      z  }	|	|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.
            )rk   rc   rK   rN   r   rF   rG   r   InvalidCachedStatementErrortextwrapdedent)
r   rb   re   rR   excclsr"   is_icse
exceptionsis_prepared_stmt_errorr&   s
             r   _make_constructorz!PostgresMessage._make_constructorc   s   !!&%0%%f-'')R( OO99 If%IGG,-1HH 	 V%6%67J;;F8G OO  @ @ &f% 	 "7762&DHOO %  D  CKw##r   c                     i }t        |       j                  j                         D ]  }t        | |      }||||<    |S rY   )ra   rC   rD   getattr)selfrR   rS   vals       r   as_dictzPostgresMessage.as_dict   sJ    d&&--/ 	A$"CA	 
r   rY   )rN   r   r[   r\   rc   rk   ry   r~    r   r   r@   r@   N   sD    B B   6$ 6$pr   r@   )	metaclassc                   (    e Zd ZdZd Zedd       Zy)r   z#Base class for all Postgres errors.c                     | j                   d   }| j                  r|dj                  | j                        z  }| j                  r|dj                  | j                        z  }|S Nr   z
DETAIL:  {}z

HINT:  {}argsr$   rJ   r&   r|   msgs     r   __str__zPostgresError.__str__   T    iil;;?))$++66C99=''		22C
r   Nc                 x    | j                  ||      \  }}} ||      }|j                  j                  |       |S rY   )ry   __dict__update)r   rb   re   ru   r"   rR   exs          r   newzPostgresError.new   s;    "44VUCG_
3	r   rY   )rN   r   r[   __doc__r   r\   r   r   r   r   r   r      s    -  r   r   c                       e Zd ZdZy)r   z9A fatal error that should result in server disconnection.NrN   r   r[   r   r   r   r   r   r      s    Cr   r   c                       e Zd ZdZy)r   z'An error with an unknown SQLSTATE code.Nr   r   r   r   r   r          1r   r   c                        e Zd ZddddZd Zy)InterfaceMessageNr$   r&   c                     || _         || _        y rY   r   )r|   r$   r&   s      r   __init__zInterfaceMessage.__init__   s    	r   c                     | j                   d   }| j                  r|dj                  | j                        z  }| j                  r|dj                  | j                        z  }|S r   r   r   s     r   r   zInterfaceMessage.__str__   r   r   )rN   r   r[   r   r   r   r   r   r   r      s    !%D r   r   c                   $    e Zd ZdZddddZd Zy)r   z/An error caused by improper use of asyncpg API.Nr   c                `    t         j                  | ||       t        j                  | |       y Nr   )r   r   	Exceptionr|   r   r$   r&   s       r   r   zInterfaceError.__init__   s'    !!$vD!A4%r   c                      t        |       || j                  | j                        j                  | j                        S r   )ra   r$   r&   with_traceback__traceback__r   s     r   with_msgzInterfaceError.with_msg   s;    tDz;;
 .
		
r   )rN   r   r[   r   r   r   r   r   r   r   r      s    9&* &
r   r   c                       e Zd ZdZy)r	   z1An error caused by improper client configuration.Nr   r   r   r   r	   r	      s    ;r   r	   c                       e Zd ZdZy)	DataErrorz'An error caused by invalid query input.Nr   r   r   r   r   r      r   r   r   c                       e Zd ZdZy)r   z,Requested feature is unsupported by asyncpg.Nr   r   r   r   r   r      s    6r   r   c                       e Zd ZdZy)r   z6Requested feature is unsupported by PostgreSQL server.Nr   r   r   r   r   r      s    @r   r   c                       e Zd ZdZddddZy)r   z3A warning caused by an improper use of asyncpg API.Nr   c                `    t         j                  | ||       t        j                  | |       y r   )r   r   UserWarningr   s       r   r   zInterfaceWarning.__init__   s'    !!$vD!AT3'r   )rN   r   r[   r   r   r   r   r   r   r      s    =&* (r   r   c                       e Zd ZdZy)r
   z/All unexpected errors not classified otherwise.Nr   r   r   r   r
   r
      s    9r   r
   c                       e Zd ZdZy)r   zBUnexpected condition in the handling of PostgreSQL protocol input.Nr   r   r   r   r   r      s    Lr   r   c                       e Zd ZdZy)r   zECould not find a host that satisfies the target attribute requirementNr   r   r   r   r   r     s    Or   r   c                   ,     e Zd ZdZdddd fd
Z xZS )r   zEA value decoding error caused by a schema change before row fetching.N)schema	data_typer(   c                N    t         |   |       || _        || _        || _        y rY   )rA   r   r0   r6   r(   )r|   r   r   r   r(   rW   s        r   r   z!OutdatedSchemaCacheError.__init__  s'    !' r   )rN   r   r[   r   r   r]   r^   s   @r   r   r     s    O&*dT ! !r   r   c                   .    e Zd ZdZd Zd Zedd       Zy)r   z+A base class for non-error server messages.c                 `    dj                  t        |       j                  | j                        S )Nz{}: {})rJ   ra   rN   r"   )r|   s    r   r   zPostgresLogMessage.__str__  s!    tDz22DLLAAr   c                 \    t        dj                  t        |       j                              )Nzinstances of {} are immutable)rM   rJ   ra   rN   )r|   rP   r}   s      r   __setattr__zPostgresLogMessage.__setattr__  s*    7>>J! " 	"r   Nc                 r   | j                  ||      \  }}}|t        u rt        }|t        u rI|j                  d      xs |j                  d      }|r#|j	                         dk(  rt
        j                  }t        |t        t        f      r	 ||      }n |       }|j                  j                  |       |S )Nr   r   WARNING)ry   r   r   rK   upperr   PostgresWarning
issubclassBaseExceptionWarningr   r   )r   rb   re   ru   message_textrR   r   r   s           r   r   zPostgresLogMessage.new  s    $'$9$9&%$H!c))'F''ww}-D1DHHNN,	9 00f}g67&C(CC 
r   rY   )rN   r   r[   r   r   r   r\   r   r   r   r   r   r     s$    5B"  r   r   )r   rF   rs   __all__r   ra   r   r@   r   r   r   r   r   r   
ValueErrorr	   r   r   r   r   r   r
   r   r   r   r   r   r   r   <module>r      s    
 ,B
1A$ 1AhT 3 TnOY (D D2- 2 
%y 
"<~z <2
 27N 7AN A(' (:) :M' MP&9 P!2 ! r   