
    Oǻip                        d dl mZ d dlmZmZ d dlmZmZ h dZddZ	ddZ
ddZddZe G d	 d
             Z	 	 	 	 	 	 	 	 ddZy)    )annotations)	dataclassfield)ListOptional>   ()[]{}c                v    | D ]4  }t        |      dk  st        |      dkD  s	|t        v s(t        | d       y)zEnsure value contains only printable ASCII without spaces or braces.

    This mirrors the constraints enforced by other Redis clients for values that
    will appear in CLIENT LIST / CLIENT INFO output.
    !   ~   zG must not contain spaces, newlines, non-printable characters, or bracesN)ord_BRACES
ValueError)value
field_namechs      O/opt/lhia/marcimex/agent/venv/lib/python3.12/site-packages/redis/driver_info.py_validate_no_invalid_charsr   	   sF      r7T>SWt^rW},ef     c                ^    ddl }t        | d       |j                  d|       st        d      y)ao  Validate an upstream driver name.

    The name should look like a typical Python distribution or package name,
    following a simplified form of PEP 503 normalisation rules:

    * start with a lowercase ASCII letter
    * contain only lowercase letters, digits, hyphens and underscores

    Examples of valid names: ``"django-redis"``, ``"celery"``, ``"rq"``.
    r   NzDriver namez^[a-z][a-z0-9_-]*$zUpstream driver name must use a Python package-style name: start with a lowercase letter and contain only lowercase letters, digits, hyphens, and underscores (e.g., 'django-redis').)rer   matchr   )namer   s     r   _validate_driver_namer      s8     t]388)40G
 	
 1r   c                    t        | d       y )NzDriver version)r   )versions    r   _validate_driver_versionr!   /   s    w(89r   c                    |  d| S )N_v )driver_namedriver_versions     r   _format_driver_entryr'   3   s    ]"^,--r   c                      e Zd ZU dZdZded<   dZded<    ee      Z	d	ed
<   d Z
edd       Z	 	 	 	 	 	 ddZedd       Zy)
DriverInfoa  Driver information used to build the CLIENT SETINFO LIB-NAME and LIB-VER values.

    This class consolidates all driver metadata (redis-py version and upstream drivers)
    into a single object that is propagated through connection pools and connections.

    The formatted name follows the pattern::

        name(driver1_vVersion1;driver2_vVersion2)

    Parameters
    ----------
    name : str, optional
        The base library name (default: "redis-py")
    lib_version : str, optional
        The redis-py library version. If None, the version will be determined
        automatically from the installed package.

    Examples
    --------
    >>> info = DriverInfo()
    >>> info.formatted_name
    'redis-py'

    >>> info = DriverInfo().add_upstream_driver("django-redis", "5.4.0")
    >>> info.formatted_name
    'redis-py(django-redis_v5.4.0)'

    >>> info = DriverInfo(lib_version="5.0.0")
    >>> info.lib_version
    '5.0.0'
    redis-pystrr   NOptional[str]lib_version)default_factory	List[str]	_upstreamc                B    | j                   ddlm}  |       | _         yy)z'Initialize lib_version if not provided.Nr   get_lib_version)r-   redis.utilsr3   )selfr3   s     r   __post_init__zDriverInfo.__post_init__]   s!    #3.0D $r   c                ,    t        | j                        S )zuReturn a copy of the upstream driver entries.

        Each entry is in the form ``"driver-name_vversion"``.
        )listr0   r5   s    r   upstream_driverszDriverInfo.upstream_driversd   s     DNN##r   c                    |t        d      |t        d      t        |       t        |       t        ||      }| j                  j                  d|       | S )zAdd an upstream driver to this instance and return self.

        The most recently added driver appears first in :pyattr:`formatted_name`.
        zDriver name must not be NonezDriver version must not be Noner   )r   r   r!   r'   r0   insert)r5   r%   r&   entrys       r   add_upstream_driverzDriverInfo.add_upstream_driverm   s]     ;<<!>??k* 0$[.Aa'r   c                    | j                   s| j                  S | j                   ddj                  | j                          dS )zReturn the base name with upstream drivers encoded, if any.

        With no upstream drivers, this is just :pyattr:`name`. Otherwise::

            name(driver1_vX;driver2_vY)
        r   ;r	   )r0   r   joinr9   s    r   formatted_namezDriverInfo.formatted_name   s:     ~~99))Achht~~67q99r   )returnr/   )r%   r+   r&   r+   rC   z'DriverInfo')rC   r+   )__name__
__module____qualname____doc__r   __annotations__r-   r   r8   r0   r6   propertyr:   r>   rB   r$   r   r   r)   r)   7   sw    @ D#!%K% 6Iy61 $ $03	* 
: 
:r   r)   c                R    | | S ddl m} ||nd}||n |       }t        ||      S )a  Resolve driver_info from parameters.

    If driver_info is provided, use it. Otherwise, create DriverInfo from
    lib_name and lib_version (using defaults if not provided).

    Parameters
    ----------
    driver_info : DriverInfo, optional
        The DriverInfo instance to use
    lib_name : str, optional
        The library name (default: "redis-py")
    lib_version : str, optional
        The library version (default: auto-detected)

    Returns
    -------
    DriverInfo
        The resolved DriverInfo instance
    r   r2   r*   )r   r-   )r4   r3   r)   )driver_infolib_namer-   r3   r   r    s         r   resolve_driver_inforM      s=    0  ,+8D(4k/:KG4W55r   N)r   r+   r   r+   rC   None)r   r+   rC   rN   )r    r+   rC   rN   )r%   r+   r&   r+   rC   r+   )rK   zOptional[DriverInfo]rL   r,   r-   r,   rC   r)   )
__future__r   dataclassesr   r   typingr   r   r   r   r   r!   r'   r)   rM   r$   r   r   <module>rR      sm    " ( !
(
.:. U: U: U:p 6% 6 6  6 	 6r   