U
    ڲg                  )   @  s  U d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZ ddlmZ erndd	lmZ e
jZ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-d.d/d0d1d2(Zi Zd3ed4< ed5d6 e D  ed7d6 e D  d8d9 e D Zd:d;d<d=d>Zd;d;d?d@dAZed;dBdCdDdEZedBd;dCdFdGZdNd;d;d;dIdJdKZedLej ej ej  dMZ!dS )Oz3
Mappings between PostgreSQL and Python encodings.
    )annotationsN)AnyTYPE_CHECKING   )
ConnStatus)NotSupportedError)cache)BaseConnectionbig5gb2312euc_jis_2004euc_jpeuc_krgb18030gbkz	iso8859-5z	iso8859-6z	iso8859-7z	iso8859-8johabzkoi8-rzkoi8-uz	iso8859-1z
iso8859-16z	iso8859-2z	iso8859-3z	iso8859-4z	iso8859-9z
iso8859-10z
iso8859-13z
iso8859-14z
iso8859-15shift_jis_2004	shift_jisasciicp949utf-8cp1250cp1251cp1252cp1253cp1254cp1255cp1256cp1257cp1258cp866cp874)(ZBIG5ZEUC_CNZEUC_JIS_2004ZEUC_JPZEUC_KRZGB18030ZGBKZ
ISO_8859_5Z
ISO_8859_6Z
ISO_8859_7Z
ISO_8859_8ZJOHABZKOI8RZKOI8UZLATIN1ZLATIN10ZLATIN2ZLATIN3ZLATIN4ZLATIN5ZLATIN6ZLATIN7ZLATIN8ZLATIN9ZSHIFT_JIS_2004SJISZ	SQL_ASCIIZUHCUTF8ZWIN1250ZWIN1251ZWIN1252ZWIN1253ZWIN1254ZWIN1255ZWIN1256ZWIN1257ZWIN1258ZWIN866ZWIN874zdict[bytes, str]	py_codecsc                 c  s   | ]\}}|  |fV  qd S )Nencode.0kv r+   6/tmp/pip-unpacked-wheel-b_ea6rx_/psycopg/_encodings.py	<genexpr>H   s     r-   c                 c  s.   | ]&\}}d |kr| d d |fV  qdS )_ N)replacer&   r'   r+   r+   r,   r-   K   s     c                 C  s   i | ]\}}||  qS r+   r%   r'   r+   r+   r,   
<dictcomp>O   s      r1   zBaseConnection[Any] | Nonestr)connreturnc                 C  s   | r| j jS dS )z
    Return the Python encoding name of a psycopg connection.

    Default to utf8 if the connection has no encoding info.
    r   )Zpgconn	_encoding)r3   r+   r+   r,   conn_encodingR   s    r6   )conninfor4   c                 C  sN   ddl m} || }|d}|rJztt| W S  tk
rH   Y nX 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_dictZclient_encodingr   )r7   r8   getpg2pyencr2   r&   r   )r7   r8   paramsZpgencr+   r+   r,   conninfo_encoding[   s    
r<   bytes)namer4   c                 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lookupr>   )r>   r+   r+   r,   py2pgenco   s    rB   c                 C  sR   zt | dddd  W S  tk
rL   | dd}td|Y nX dS )zConvert a PostgreSQL encoding name to Python encoding name.

    Raise NotSupportedError if the PostgreSQL encoding is not supported by
    Python.
       -       _utf8r0   zcodec not available in Python: N)r$   r0   upperKeyErrordecoder   )r>   Zsnamer+   r+   r,   r:   x   s
    r:   f)sprefixr4   c                 C  sH   |   s0| d dkr||  } |   s0td| } | d dkrD||  } | 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   Z
1234567890r.   )isidentifier	_re_cleansub)rK   rL   r+   r+   r,   _as_python_identifier   s    rP   z[^z_])rJ   )"__doc__
__future__r   restringr@   typingr   r   Z	pq._enumsr   errorsr   _compatr   Z_connection_baser	   OKZ
_py_codecsr$   __annotations__updateitemsr?   r6   r<   rB   r:   rP   compileascii_lowercaseascii_uppercasedigitsrN   r+   r+   r+   r,   <module>   s   /
	