o
    f|                     @  s   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 d'dd	Z	
d(d)ddZ	
d(d*ddZd+ddZ					d,d-d"d#Z	d.d/d%d&ZdS )0zText Utilities.    )annotationsN)SequenceMatcher)IterableIterator)version_info_t c                   s   d  fdd| D S )z2Escape string for use within a regular expression.r   c                 3  s8    | ]}|  s| v r|n	|d krdnd| V  qdS ) z\000\N)isalnum).0cwhite C/var/www/html/venv/lib/python3.10/site-packages/kombu/utils/text.py	<genexpr>   s
    &
zescape_regex.<locals>.<genexpr>)join)pr   r   r   r   escape_regex   s   r   333333?needlestrhaystackIterable[str]	min_ratiofloatreturnIterator[tuple[float, str]]c                 c  s2    |D ]}t d| | }||kr||fV  qdS )zVFuzzy match: iteratively.

    Yields
    ------
        Tuple: of ratio and key.
    N)r   ratio)r   r   r   keyr   r   r   r   fmatch_iter   s   	
r    
str | Nonec                 C  s4   zt t| ||ddd d W S  ty   Y dS w )z'Fuzzy match - Find best match (scalar).T)reverser      N)sortedr    
IndexError)r   r   r   r   r   r   fmatch_best(   s   
r&   versionr   c                 C  s   d}|d7 }|d7 }|d7 }|d7 }t || }|s!td|  t|d}|dr4t|dnd}|d	rBt|d	nd}|d
rN|d
nd}|drZ|dnd}t|||||S )aa  Parse a version string into its components and return a version_info_t tuple.

    The version string is expected to follow the pattern:
    'major.minor.micro[releaselevel][serial]'. Each component of the version
    is extracted and returned as a tuple in the format (major, minor, micro,
    releaselevel, serial).

    Args
    ----
        version (str): The version string to parse.

    Returns
    -------
        version_info_t: A tuple containing the parsed version components.

    Raises
    ------
        ValueError: If the version string is invalid and does not match the expected pattern.
    z^(\d+)z(?:\.(\d+))?z!(?:\.*([a-zA-Z+-][\da-zA-Z+-]*))?z(?:\.(.*))?zInvalid version string: r#      r         r      )rematch
ValueErrorintgroup_unpack_version)r'   patternr-   majorminormicroreleaselevelserialr   r   r   version_string_as_tuple7   s   r8   r3   	str | intr4   r5   r6   r7   c                 C  s   t t| t|t|||S )N)r   r/   )r3   r4   r5   r6   r7   r   r   r   r1   a   s   r1   tuple[int, str, str]c                 C  sN   t | D ]
\}}| s n
qt| pd||fS t| d | | |d  |fS )Nr   )	enumerateisdigitr/   )r5   r6   r7   indexcharr   r   r   _splitmicrok   s   r?   )r   )r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r!   )r'   r   r   r   )r   r   r   r   r   )r3   r9   r4   r9   r5   r9   r6   r   r7   r   r   r   )r   r   )r5   r   r6   r   r7   r   r   r:   )__doc__
__future__r   r,   difflibr   typingr   r   kombur   r   r    r&   r8   r1   r?   r   r   r   r   <module>   s(    

+