o
    DDi                     @  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   )errors)pq)
get_tzinfo)make_conninfoc                   @  s8  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dAd d!ZedBd#d$ZedCd&d'ZdDd*d+Zed?d,d-Zed?d.d/Zed?d0d1Zed>d2d3ZedEd5d6Zed>d7d8ZdFd:d;Zd<S )GConnectionInfoz1Allow access to information about the connection.psycopgpgconnpq.abc.PGconnc                 C  s
   || _ d S N)r   )selfr    r   Q/var/www/Datamplify/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  s6   |  d }rt|S tj  }rt|S td)z6The port of the active connection. See :pq:`PQport()`.portz!couldn't find the connection port)r   r   r   miscget_compiled_porteInternalError)r   r   r   r   r   r   )   s
   
zConnectionInfo.portc                 C  r   )z6The database name of the connection. See :pq:`PQdb()`.dbr   r   r   r   r   dbname7   r   zConnectionInfo.dbnamec                 C  r   )z4The user name of the connection. See :pq:`PQuser()`.userr   r   r   r   r   r&   <   r   zConnectionInfo.userc                 C  r   )z3The password of the connection. See :pq:`PQpass()`.passwordr   r   r   r   r   r'   A   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(   F      
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>Y   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   r0   b   s    

)encodingr   Conninfoget_defaults
setdefaultr   r   homeencoder   infor   r   r4   r   get_parametersN   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   dsnj   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   rC   v   s   zConnectionInfo.statuspq.TransactionStatusc                 C  rA   )zl
        The current in-transaction status of the session.
        See :pq:`PQtransactionStatus()`.
        )r   TransactionStatusr   transaction_statusr   r   r   r   rF   {      z!ConnectionInfo.transaction_statuspq.PipelineStatusc                 C  rA   )zb
        The current pipeline status of the client.
        See :pq:`PQpipelineStatus()`.
        )r   PipelineStatusr   pipeline_statusr   r   r   r   rJ      rG   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_statusr<   r7   r3   )r   rK   resr   r   r   rM      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   rP      s   zConnectionInfo.server_versionc                 C  s,   z| j jW S  tjy   | j jd  Y S w )a  
        An integer representing the server full protocol version.

        Return a value in the format described in :pq:`PQfullProtocolVersion()`.

        Only meaningful if the libpq used is version 18 or greater. If the
        version is lesser than that, return the value reported by
        :pq:`PQprotocolVersion()` (but in the same format as above, e.g. 30000
        for version 3). You can use `Capabilities.has_full_protocol_version()`
        to verify if the value can be considered reliable.
        i'  )r   full_protocol_versionr"   NotSupportedErrorprotocol_versionr   r   r   r   rQ      s
   
z$ConnectionInfo.full_protocol_versionc                 C  rO   )zy
        The process ID (PID) of the backend process handling this connection.
        See :pq:`PQbackendPID()`.
        )r   backend_pidr   r   r   r   rT      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   rU      r)   zConnectionInfo.error_messager   c                 C  s
   t | jS )z6The Python timezone info of the connection's timezone.)r   r   r   r   r   r   timezone   r   zConnectionInfo.timezonec                 C  rO   )z:The Python codec name of the connection's client encoding.)r   	_encodingr   r   r   r   r7      s   zConnectionInfo.encodingnamec                 C  s   t | j|}|| jS r   )getattrr   r3   r7   )r   rX   valuer   r   r   r      s   zConnectionInfo._get_pgconn_attrN)r   r   )r   r   )r   r   )r   r*   )r   r@   )r   rD   )r   rH   )rK   r   r   rL   )r   r   )rX   r   r   r   )__name__
__module____qualname____doc__r   propertyr   r   r   r   r%   r&   r'   r(   r>   r?   rC   rF   rJ   rM   rP   rQ   rT   rU   rV   r7   r   r   r   r   r   r
      sV    


	r
   N)r^   
__future__r   pathlibr   datetimer    r   r"   r   _tzr   conninfor	   r
   r   r   r   r   <module>   s    