U
    ڲgQ                     @  sL   d 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e Z	d	S )
z
psycopg capabilities objects
    )annotations   )pq)_cmodule)NotSupportedErrorc                   @  s   e Zd ZdZddddZd"dddd	d
Zd#dddddZd$dddddZd%dddddZd&dddddZ	d'dddddZ
d(dddddZdddddddZddddddZdddd Zd!S ))Capabilitiesz\
    An object to check if a feature is supported by the libpq available on the client.
    None)returnc                 C  s
   i | _ d S )N)_cache)self r   9/tmp/pip-unpacked-wheel-b_ea6rx_/psycopg/_capabilities.py__init__   s    zCapabilities.__init__Fbool)checkr	   c                 C  s   | j dd|dS )z~Check if the `PGconn.encrypt_password()` method is implemented.

        The feature requires libpq 10.0 and greater.
        zpq.PGconn.encrypt_password()i r   _has_featurer   r   r   r   r   has_encrypt_password   s    z!Capabilities.has_encrypt_passwordc                 C  s   | j dd|dS )zCheck if the `ConnectionInfo.hostaddr` attribute is implemented.

        The feature requires libpq 12.0 and greater.
        zConnection.info.hostaddri r   r   r   r   r   r   has_hostaddr   s    zCapabilities.has_hostaddrc                 C  s   | j dd|dS )z~Check if the :ref:`pipeline mode <pipeline-mode>` is supported.

        The feature requires libpq 14.0 and greater.
        zConnection.pipeline()" r   r   r   r   r   r   has_pipeline$   s    zCapabilities.has_pipelinec                 C  s   | j dd|dS )zCheck if the `pq.PGconn.set_trace_flags()` method is implemented.

        The feature requires libpq 14.0 and greater.
        zPGconn.set_trace_flags()r   r   r   r   r   r   r   has_set_trace_flags+   s    z Capabilities.has_set_trace_flagsc                 C  s   | j dd|dS )z}Check if the `Connection.cancel_safe()` method is implemented.

        The feature requires libpq 17.0 and greater.
        zConnection.cancel_safe() r   r   r   r   r   r   has_cancel_safe2   s    zCapabilities.has_cancel_safec                 C  s   | j dd|dS )zCheck if `Cursor.stream()` can handle a `size` parameter value
        greater than 1 to retrieve results by chunks.

        The feature requires libpq 17.0 and greater.
        z4Cursor.stream() with 'size' parameter greater than 1r   r   r   r   r   r   r   has_stream_chunked9   s
      zCapabilities.has_stream_chunkedc                 C  s   | j dd|dS )zCheck if the `pq.PGconn.send_closed_prepared()` method is implemented.

        The feature requires libpq 17.0 and greater.
        zPGconn.send_close_prepared()r   r   r   r   r   r   r   has_send_close_preparedC   s    z$Capabilities.has_send_close_preparedstrint)featurewant_versionr   r	   c                 C  sJ   || j kr| j | }n| ||}|| j |< |s4dS |rBt|ndS dS )z
        Check is a version is supported.

        If `check` is true, raise an exception with an explicative message
        explaining why the feature is not supported.

        The expletive messages, are left to the user.
        TFN)r
   _get_unsupported_messager   )r   r    r!   r   msgr   r   r   r   J   s    	


zCapabilities._has_feature)r    r!   r	   c              
   C  s~   t  |k r>d| d|   dt t   dt | d	S t j|k rvd| dt j dt t j dt | d	S dS d	S )
z
        Return a descriptinve message to describe why a feature is unsupported.

        Return an empty string if the feature is supported.
        zthe feature 'z<' is not available: the client libpq version (imported from z) is z%; the feature requires libpq version z	 or newerz,' is not available: you are using a psycopg[z)] libpq wrapper built with libpq version  N)r   version_libpq_sourceZversion_prettyZ__build_version____impl__)r   r    r!   r   r   r   r"   `   s    0
,z%Capabilities._get_unsupported_messagec                 C  s&   t jdkrtjpd}d| S dS dS )z5Return a string reporting where the libpq comes from.binaryunknownz$the psycopg[binary] package version zsystem librariesN)r   r'   r   __version__)r   r%   r   r   r   r&   z   s    


zCapabilities._libpq_sourceN)F)F)F)F)F)F)F)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r"   r&   r   r   r   r   r      s   
r   N)
r.   
__future__r   r$   r   r   errorsr   r   Zcapabilitiesr   r   r   r   <module>   s   v