o
    6	f                     @  sj   d 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ZdS )z>
Objects to return information about a PostgreSQL connection.
    )annotations)Path)tzinfo   )pq)
get_tzinfo)pgconn_encoding)make_conninfoc                   @  s*  e Zd ZdZdZd;ddZed<d	d
Zed<ddZed<ddZed=ddZ	ed<ddZ
ed<ddZed<ddZed<ddZd>ddZed<ddZed?d d!Zed@d#d$ZedAd&d'ZdBd*d+Zed=d,d-Zed=d.d/Zed<d0d1ZedCd3d4Zed<d5d6ZdDd8d9Zd:S )EConnectionInfoz1Allow access to information about the connection.psycopgpgconnpq.abc.PGconnc                 C  s
   || _ d S N)r   )selfr    r   Q/home/ertert/spirit/venv/lib/python3.10/site-packages/psycopg/_connection_info.py__init__   s   
zConnectionInfo.__init__returnstrc                 C  s   dS )z7A string representing the database vendor connected to.
PostgreSQLr   r   r   r   r   vendor   s   zConnectionInfo.vendorc                 C  
   |  dS )zBThe server host name of the active connection. See :pq:`PQhost()`.host_get_pgconn_attrr   r   r   r   r         
zConnectionInfo.hostc                 C  r   )z@The server IP address of the connection. See :pq:`PQhostaddr()`.hostaddrr   r   r   r   r   r   $   r   zConnectionInfo.hostaddrintc                 C  s   t | dS )z6The port of the active connection. See :pq:`PQport()`.port)r   r   r   r   r   r   r   )      zConnectionInfo.portc                 C  r   )z6The database name of the connection. See :pq:`PQdb()`.dbr   r   r   r   r   dbname.   r   zConnectionInfo.dbnamec                 C  r   )z4The user name of the connection. See :pq:`PQuser()`.userr   r   r   r   r   r#   3   r   zConnectionInfo.userc                 C  r   )z3The password of the connection. See :pq:`PQpass()`.passwordr   r   r   r   r   r$   8   r   zConnectionInfo.passwordc                 C  r   )zi
        The command-line options passed in the connection request.
        See :pq:`PQoptions`.
        optionsr   r   r   r   r   r%   =      
zConnectionInfo.optionsdict[str, str]c                   sV   | j dd tj D   dd tt d   d<  fdd| j	j
D S )a\  Return the connection parameters values.

        Return all the parameters set to a non-default value, which might come
        either from the connection string and parameters passed to
        `~Connection.connect()` or from environment variables. The password
        is never returned (you can read it using the `password` attribute).
        c                 S  s    i | ]}|j d ur|j|j qS r   )compiledkeyword.0ir   r   r   
<dictcomp>P   s
    
z1ConnectionInfo.get_parameters.<locals>.<dictcomp>s   channel_bindings   preferz.pgpasss   passfilec                   sH   i | ] }|j d ur"|jdkr"|j  |jkr|j|j qS )Ns   password)valr)   getdecoder*   defaultspyencr   r   r-   Y   s    

)encodingr   Conninfoget_defaults
setdefaultr   r   homeencoder   infor   r   r1   r   get_parametersE   s   zConnectionInfo.get_parametersc                 C  s   t di |  S )a  Return the connection string to connect to the database.

        The string contains all the parameters set to a non-default value,
        which might come either from the connection string and parameters
        passed to `~Connection.connect()` or from environment variables. The
        password is never returned (you can read it using the `password`
        attribute).
        Nr   )r	   r;   r   r   r   r   dsna   s   
zConnectionInfo.dsnpq.ConnStatusc                 C     t | jjS )z3The status of the connection. See :pq:`PQstatus()`.)r   
ConnStatusr   statusr   r   r   r   r@   m   r    zConnectionInfo.statuspq.TransactionStatusc                 C  r>   )zl
        The current in-transaction status of the session.
        See :pq:`PQtransactionStatus()`.
        )r   TransactionStatusr   transaction_statusr   r   r   r   rC   r      z!ConnectionInfo.transaction_statuspq.PipelineStatusc                 C  r>   )zb
        The current pipeline status of the client.
        See :pq:`PQpipelineStatus()`.
        )r   PipelineStatusr   pipeline_statusr   r   r   r   rG   z   rD   zConnectionInfo.pipeline_status
param_name
str | Nonec                 C  s,   | j || j}|dur|| jS dS )zs
        Return a parameter setting of the connection.

        Return `None` is the parameter is unknown.
        N)r   parameter_statusr9   r4   r0   )r   rH   resr   r   r   rJ      s   zConnectionInfo.parameter_statusc                 C     | j jS )zZ
        An integer representing the server version. See :pq:`PQserverVersion()`.
        )r   server_versionr   r   r   r   rM      s   zConnectionInfo.server_versionc                 C  rL   )zy
        The process ID (PID) of the backend process handling this connection.
        See :pq:`PQbackendPID()`.
        )r   backend_pidr   r   r   r   rN      s   zConnectionInfo.backend_pidc                 C  r   )z
        The error message most recently generated by an operation on the connection.
        See :pq:`PQerrorMessage()`.
        error_messager   r   r   r   r   rO      r&   zConnectionInfo.error_messager   c                 C  
   t | jS )z6The Python timezone info of the connection's timezone.)r   r   r   r   r   r   timezone   r   zConnectionInfo.timezonec                 C  rP   )z:The Python codec name of the connection's client encoding.)r   r   r   r   r   r   r4      r   zConnectionInfo.encodingnamec                 C  s   t | j|}|| jS r   )getattrr   r0   r4   )r   rR   valuer   r   r   r      s   zConnectionInfo._get_pgconn_attrN)r   r   )r   r   )r   r   )r   r'   )r   r=   )r   rA   )r   rE   )rH   r   r   rI   )r   r   )rR   r   r   r   )__name__
__module____qualname____doc__r   propertyr   r   r   r   r"   r#   r$   r%   r;   r<   r@   rC   rG   rJ   rM   rN   rO   rQ   r4   r   r   r   r   r   r
      sR    


	r
   N)rX   
__future__r   pathlibr   datetimer    r   _tzr   
_encodingsr   conninfor	   r
   r   r   r   r   <module>   s    