o
    6	f                     @   sV  U d Z ddlZddlZddlZddlmZmZmZmZ ddl	m
Z
 ddlmZ ddlmZ er;ddlmZ dd	lmZ e
j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+i d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTZi Zeeef edU< edVdW e D  edXdW e D  dYdZ e D Zd[d\d]efd^d_Zd`dad]efdbdcZdded]efdedfZedged]efdhdiZedged]efdjdkZ dsdmedned]efdodpZ!e"dqej# ej$ ej% drZ&dS )tz3
Mappings between PostgreSQL and Python encodings.
    N)AnyDictOptionalTYPE_CHECKING   )
ConnStatus)NotSupportedError)cache)PGconn)BaseConnectionBIG5big5EUC_CNgb2312EUC_JIS_2004euc_jis_2004EUC_JPeuc_jpEUC_KReuc_krGB18030gb18030GBKgbk
ISO_8859_5z	iso8859-5
ISO_8859_6z	iso8859-6
ISO_8859_7z	iso8859-7
ISO_8859_8z	iso8859-8JOHABjohabKOI8Rzkoi8-rKOI8Uzkoi8-uLATIN1z	iso8859-1LATIN10z
iso8859-16LATIN2z	iso8859-2LATIN3z	iso8859-3LATIN4z	iso8859-4LATIN5z	iso8859-9LATIN6z
iso8859-10LATIN7z
iso8859-13LATIN8z
iso8859-14LATIN9z
iso8859-15SHIFT_JIS_2004shift_jis_2004SJIS	shift_jis	SQL_ASCIIasciiUHCcp949UTF8utf-8WIN1250cp1250WIN1251cp1251WIN1252cp1252WIN1253cp1253WIN1254cp1254cp1255cp1256cp1257cp1258cp866cp874)WIN1255WIN1256WIN1257WIN1258WIN866WIN874	py_codecsc                 c   s     | ]\}}|  |fV  qd S )Nencode.0kv rS   K/home/ertert/spirit/venv/lib/python3.10/site-packages/psycopg/_encodings.py	<genexpr>G   s    rU   c                 c   s0    | ]\}}d |v r| d d |fV  qdS )_ N)replacerN   rO   rS   rS   rT   rU   J   s    &c                 C   s   i | ]	\}}||  qS rS   rM   rO   rS   rS   rT   
<dictcomp>N   s    rY   connzOptional[BaseConnection[Any]]returnc                 C   s&   | r| j rdS | jdpd}t|S )z
    Return the Python encoding name of a psycopg connection.

    Default to utf8 if the connection has no encoding info.
    r5      client_encoding   UTF8)closedpgconnparameter_statuspg2pyenc)rZ   pgencrS   rS   rT   conn_encodingQ   s   
rc   r_   r
   c                 C   s$   | j tkrdS | dpd}t|S )z}
    Return the Python encoding name of a libpq connection.

    Default to utf8 if the connection has no encoding info.
    r5   r\   r]   )statusOKr`   ra   )r_   rb   rS   rS   rT   pgconn_encoding^   s   
rf   conninfoc                 C   sJ   ddl m} || }|d}|r#zt| W S  ty"   Y dS w dS )z
    Return the Python encoding name passed in a conninfo string. Default to utf8.

    Because the input is likely to come from the user and not normalised by the
    server, be somewhat lenient (non-case-sensitive lookup, ignore noise chars).
    r   )conninfo_to_dictclient_encodingr5   )rg   rh   getra   rN   r   )rg   rh   paramsrb   rS   rS   rT   conninfo_encodingk   s   
rl   namec                 C   s   t t| j S )zzConvert a Python encoding name to PostgreSQL encoding name.

    Raise LookupError if the Python encoding is unknown.
    )	pg_codecscodecslookuprm   )rm   rS   rS   rT   py2pgenc   s   rq   c                 C   sH   zt | dddd  W S  ty#   | dd}td|w )zConvert a PostgreSQL encoding name to Python encoding name.

    Raise NotSupportedError if the PostgreSQL encoding is not supported by
    Python.
       -       _utf8rX   zcodec not available in Python: )rL   rX   upperKeyErrordecoder   )rm   snamerS   rS   rT   ra      s   ra   fsprefixc                 C   sH   |   s| d dv r||  } |   std| } | d dkr"||  } | S )z
    Reduce a string to a valid Python identifier.

    Replace all non-valid chars with '_' and prefix the value with `!prefix` if
    the first letter is an '_'.
    r   
1234567890rV   )isidentifier	_re_cleansub)r{   r|   rS   rS   rT   _as_python_identifier   s   r   z[^z_])rz   )'__doc__restringro   typingr   r   r   r   	pq._enumsr   errorsr   _compatr	   pq.abcr
   
connectionr   re   
_py_codecsrL   bytesstr__annotations__updateitemsrn   rc   rf   rl   rq   ra   r   compileascii_lowercaseascii_uppercasedigitsr   rS   rS   rS   rT   <module>   s    	
 !"#$%&'/
