o
    <‘ðip  ã                   @  s|   d dl mZ d dlmZmZ d dlmZmZ h d£Zd d
d„Z	d!dd„Z
d"dd„Zd#dd„ZeG dd„ dƒƒZd$dd„ZdS )%é    )Úannotations)Ú	dataclassÚfield)ÚListÚOptional>   Ú{Ú}ú(ú)ú[ú]ÚvalueÚstrÚ
field_nameÚreturnÚNonec                 C  s<   | D ]}t |ƒdk st |ƒdks|tv rt|› d�ƒ‚qdS )zÐEnsure 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)r   r   Úch© r   úP/root/parts/websockify/install/lib/python3.10/site-packages/redis/driver_info.pyÚ_validate_no_invalid_chars	   s    ÿÿþr   Únamec                 C  s*   ddl }t| dƒ | d| ¡stdƒ‚dS )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_-]*$zµUpstream 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   )r   r   r   r   r   Ú_validate_driver_name   s   
ÿÿr   Úversionc                 C  s   t | dƒ d S )NzDriver version)r   )r   r   r   r   Ú_validate_driver_version/   ó   r    Údriver_nameÚdriver_versionc                 C  s   | › d|› �S )NÚ_vr   )r"   r#   r   r   r   Ú_format_driver_entry3   r!   r%   c                   @  sj   e Zd ZU dZdZded< dZded< eed�Z	d	ed
< dd„ Z
eddd„ƒZddd„Zeddd„ƒZdS )Ú
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-pyr   r   NúOptional[str]Úlib_version)Údefault_factoryú	List[str]Ú	_upstreamc                 C  s&   | j du rddlm} |ƒ | _ dS dS )z'Initialize lib_version if not provided.Nr   ©Úget_lib_version)r)   Úredis.utilsr.   )Úselfr.   r   r   r   Ú__post_init__]   s   
ýzDriverInfo.__post_init__r   c                 C  s
   t | jƒS )zuReturn a copy of the upstream driver entries.

        Each entry is in the form ``"driver-name_vversion"``.
        )Úlistr,   ©r0   r   r   r   Úupstream_driversd   s   
zDriverInfo.upstream_driversr"   r#   ú'DriverInfo'c                 C  sL   |du rt dƒ‚|du rt dƒ‚t|ƒ t|ƒ t||ƒ}| j d|¡ | S )z”Add an upstream driver to this instance and return self.

        The most recently added driver appears first in :pyattr:`formatted_name`.
        NzDriver name must not be NonezDriver version must not be Noner   )r   r   r    r%   r,   Úinsert)r0   r"   r#   Úentryr   r   r   Úadd_upstream_driverm   s   
zDriverInfo.add_upstream_driverc                 C  s&   | j s| jS | j› dd | j ¡› d�S )z¹Return 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
   )r,   r   Újoinr3   r   r   r   Úformatted_name‚   s   	zDriverInfo.formatted_name)r   r+   )r"   r   r#   r   r   r5   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r)   r   r2   r,   r1   Úpropertyr4   r8   r;   r   r   r   r   r&   7   s   
  
r&   Údriver_infoúOptional[DriverInfo]Úlib_namer(   r)   c                 C  sF   | dur| S ddl m} |dur|nd}|dur|n|ƒ }t||d�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
    Nr   r-   r'   )r   r)   )r/   r.   r&   )rB   rD   r)   r.   r   r   r   r   r   Úresolve_driver_info�   s   rE   N)r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r"   r   r#   r   r   r   )rB   rC   rD   r(   r)   r(   r   r&   )Ú
__future__r   Údataclassesr   r   Útypingr   r   r   r   r   r    r%   r&   rE   r   r   r   r   Ú<module>   s    



X