o
    =a!                     @   s\  d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lm	Z	 dd
lm
Z
 ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm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G dd deZG d d! d!e	ZG d"d# d#eZ e Z!dS )$a3  
.. dialect:: postgresql+pygresql
    :name: pygresql
    :dbapi: pgdb
    :connectstring: postgresql+pygresql://user:password@host:port/dbname[?key=value&key=value...]
    :url: https://www.pygresql.org/

.. note::

    The pygresql dialect is **not tested as part of SQLAlchemy's continuous
    integration** and may have unresolved issues.  The recommended PostgreSQL
    dialect is psycopg2.

.. deprecated:: 1.4 The pygresql DBAPI is deprecated and will be removed
   in a future version. Please use one of the supported DBAPIs to
   connect to PostgreSQL.

    N   )_DECIMAL_TYPES)_FLOAT_TYPES)
_INT_TYPES)
PGCompiler)	PGDialect)PGIdentifierPreparer)UUID)HSTORE)JSON)JSONB   )exc)
processors)util)Null)Numericc                   @      e Zd Zdd Zdd ZdS )
_PGNumericc                 C   s   d S N )selfdialectr   r   ]/var/www/html/gps/gps/lib/python3.10/site-packages/sqlalchemy/dialects/postgresql/pygresql.pybind_processor0   s   z_PGNumeric.bind_processorc                 C   s   t |ts|j}| jr(|tv rttj| j	S |t
v s|tv r!d S td| |tv r.d S |t
v s6|tv r9tjS td| )NzUnknown PG numeric type: %d)
isinstanceintoid	asdecimalr   r   to_decimal_processor_factorydecimalDecimal_effective_decimal_return_scaler   r   r   InvalidRequestErrorto_floatr   r   coltyper   r   r   result_processor3   s&   
z_PGNumeric.result_processorN)__name__
__module____qualname__r   r'   r   r   r   r   r   /   s    r   c                       (   e Zd Z fddZ fddZ  ZS )	_PGHStorec                    .   |j stt| |S |jj  fdd}|S )Nc                    s   t | tr	 | S | S r   )r   dictvaluehstorer   r   processT   s   
z)_PGHStore.bind_processor.<locals>.process)has_native_hstoresuperr,   r   dbapiHstorer   r   r3   	__class__r1   r   r   O   s
   z_PGHStore.bind_processorc                       |j stt| ||S d S r   )r4   r5   r,   r'   r%   r9   r   r   r'   [      z_PGHStore.result_processorr(   r)   r*   r   r'   __classcell__r   r   r9   r   r,   N   s    r,   c                       r+   )_PGJSONc                    0   |j stt|S |jj  fdd}|S )Nc                    N   | j u rd } nt| ts| d u rjrd S | d u s!t| ttfr% | S | S r   NULLr   r   none_as_nullr.   listr/   jsonr   r   r   r3   f      

z'_PGJSON.bind_processor.<locals>.process)has_native_jsonr5   r?   r   r6   Jsonr8   r9   rF   r   r   a   
   z_PGJSON.bind_processorc                    r;   r   )rI   r5   r?   r'   r%   r9   r   r   r'   s   r<   z_PGJSON.result_processorr=   r   r   r9   r   r?   `       r?   c                       r+   )_PGJSONBc                    r@   )Nc                    rA   r   rB   r/   rF   r   r   r3   ~   rH   z(_PGJSONB.bind_processor.<locals>.process)rI   r5   rM   r   r6   rJ   r8   r9   rF   r   r   y   rK   z_PGJSONB.bind_processorc                    r;   r   )rI   r5   rM   r'   r%   r9   r   r   r'      r<   z_PGJSONB.result_processorr=   r   r   r9   r   rM   x   rL   rM   c                       r+   )_PGUUIDc                    r-   )Nc                    sP   | d u rd S t | ttfrt| dkr | dS  | S t | tr& | dS | S )N   )bytes)r   )r   strrP   lenr   r/   uuidr   r   r3      s   


z'_PGUUID.bind_processor.<locals>.process)has_native_uuidr5   rN   r   r6   Uuidr8   r9   rS   r   r      s
   z_PGUUID.bind_processorc                    s.   |j stt| ||S | jsdd }|S d S )Nc                 S   s   | d urt | S d S r   )rQ   r/   r   r   r   r3      s   z)_PGUUID.result_processor.<locals>.process)rU   r5   rN   r'   as_uuid)r   r   r&   r3   r9   r   r   r'      s   z_PGUUID.result_processorr=   r   r   r9   r   rN      rL   rN   c                   @   r   )_PGCompilerc                 K   s,   | j |jfi |d | j |jfi | S )Nz %% )r3   leftright)r   binaryoperatorkwr   r   r   visit_mod_binary   s   z_PGCompiler.visit_mod_binaryc                 C   s   | ddS N%z%%)replace)r   textr   r   r   post_process_text   s   z_PGCompiler.post_process_textN)r(   r)   r*   r^   rc   r   r   r   r   rX      s    rX   c                   @   s   e Zd Zdd ZdS )_PGIdentifierPreparerc                 C   s   | | j| j}| ddS r_   )ra   escape_quoteescape_to_quote)r   r0   r   r   r   _escape_identifier   s   z(_PGIdentifierPreparer._escape_identifierN)r(   r)   r*   rg   r   r   r   r   rd      s    rd   c                       sn   e Zd ZdZdZeZeZe	dd Z
eejeeeeeeeeeeeeiZ fddZdd Zd	d
 Z  ZS )PGDialect_pygresqlpygresqlTc                 C   s   dd l }tjddd |S )Nr   zThe pygresql DBAPI is deprecated and will be removed in a future version. Please use one of the supported DBAPIs to connect to PostgreSQL.z1.4)version)pgdbr   warn_deprecated)clsrk   r   r   r   r6      s   zPGDialect_pygresql.dbapic              
      s   t t| jd	i | z| jj}td|}t|dt|df}W n t	t
tfy3   d}Y nw || _|dk rKd } }}|dkrJtd nd| _d| _d } }}|| _|| _|| _d S )
Nz(\d+)\.(\d+)r      )r   r   )   r   FzAPyGreSQL is only fully supported by SQLAlchemy since version 5.0.Tr   )r5   rh   __init__r6   rj   rematchr   groupAttributeError
ValueError	TypeErrordbapi_versionr   warnsupports_unicode_statementssupports_unicode_bindsr4   rI   rU   )r   kwargsrj   mr4   rI   rU   r9   r   r   rp      s,    
zPGDialect_pygresql.__init__c                 C   sR   |j dd}d|v rd|ddddd	 |df |d< ||j g |fS )
Nuser)usernameportz%s:%shost :r   r   )translate_connect_argsgetrsplitpopupdatequery)r   urloptsr   r   r   create_connect_args   s   
z&PGDialect_pygresql.create_connect_argsc                 C   sf   t || jjr1|sdS z|j}W n	 ty   Y nw |sdS z|jW S  ty0   |jd u  Y S w dS )NF)r   r6   Error
connectionrt   closed_cnx)r   er   cursorr   r   r   is_disconnect  s    
z PGDialect_pygresql.is_disconnect)r(   r)   r*   driversupports_statement_cacherX   statement_compilerrd   preparerclassmethodr6   r   update_copyr   colspecsr   r   r
   r,   rJ   r?   r   r   rM   r	   rN   rp   r   r   r>   r   r   r9   r   rh      s(    

rh   )"__doc__r    rq   baser   r   r   r   r   r   r	   r2   r
   rG   r   r   r   r   r   r   sql.elementsr   typesrJ   r   r   r,   r?   rM   rN   rX   rd   rh   r   r   r   r   r   <module>   s8   U