a
    a*j                     @  s  d Z ddlmZ ddlZddlZddlZddl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mZmZmZ d	d
lmZ d	dlmZmZ edZedejejB Zedjej ej dejejB Z!G dd deZ"ej#G dd dZ$edZ%ere	e&e$f Z'ne	Z'G dd de'Z(G dd dZ)dddddZ*dddd d!Z+dd"d#d$d%Z,dd&d#d'd(Z-dd)d*d+d,Z.dS )-     )annotationsN)UserDict)
ModuleType)TYPE_CHECKING)Version)
NamedTupleOptionalTypeUnion   )ConfigurationError)GRANULARITIESRateLimitItemz[,;|]{1}zf
    \s*([0-9]+)
    \s*(/|\s*per\s*)
    \s*([0-9]+)
    *\s*(hour|minute|second|day|month|year)s?\s*z#^{SINGLE}(:?{SEPARATORS}{SINGLE})*$)ZSINGLE
SEPARATORSc                   @  s"   e Zd ZU dZded< ded< dS )WindowStatsz1
    tuple to describe a rate limited window
    floatZ
reset_timeint	remainingN)__name__
__module____qualname____doc____annotations__ r   r   G/var/www/html/assistant/venv/lib/python3.9/site-packages/limits/util.pyr   %   s   
r   c                   @  s.   e Zd ZU ded< ded< ded< ded< dS )	
DependencystrnamezOptional[Version]version_requiredversion_foundr   moduleN)r   r   r   r   r   r   r   r   r   0   s   
r   Missingc                      s$   e Zd Zddd fddZ  ZS )DependencyDictr   r   )keyreturnc                   s   t  |}|jtu rXd|j d}|jrF||jr@d|j dnd7 }|d7 }t|n8|jr|jrp|j|jk rtd|j d|j d	|j |S )
N'z' prerequisite not available.z A minimum version of z is required. z^ See https://limits.readthedocs.io/en/stable/storage.html#supported-versions for more details.zThe minimum version of z for 'z%' could not be found. Found version: )super__getitem__r!   MissingModuler   r   r   r    )selfr$   
dependencymessage	__class__r   r   r)   B   s4    



zDependencyDict.__getitem__)r   r   r   r)   __classcell__r   r   r.   r   r#   A   s   r#   c                   @  s>   e Zd ZU dZg Zded< ddddZeddd	d
ZdS )LazyDependencyz
    Simple utility that provides an :attr:`dependency`
    to the child class to fetch any dependencies
    without having to import them explicitly.
    z.Union[dict[str, Optional[Version]], list[str]]DEPENDENCIESNone)r%   c                 C  s   t  | _d S N)r#   _dependencies)r+   r   r   r   __init__k   s    zLazyDependency.__init__r#   c                 C  sr   t | ddslt }t| jtr0dd | jD }n| j}| D ]&\}}t|\}}t||||||< q>|| _| jS )z
        Cached mapping of the modules this storage depends on.
        This is done so that the module is only imported lazily
        when the storage is instantiated.

        :meta private:
        r5   Nc                 S  s   i | ]
}|d qS r4   r   ).0r,   r   r   r   
<dictcomp>}       z/LazyDependency.dependencies.<locals>.<dictcomp>)	getattrr#   
isinstancer2   listitemsget_dependencyr   r5   )r+   dependenciesmappingr   minimum_versionr,   versionr   r   r   r?   n   s    

zLazyDependency.dependenciesN)	r   r   r   r   r2   r   r6   propertyr?   r   r   r   r   r1   ^   s
   
r1   r   z$tuple[ModuleType, Optional[Version]])module_pathr%   c                 C  sf   zF| t jvrt|  | dd }tt j| dd}t j|  t|fW S  ty`   tdf Y S 0 dS )z5
    safe function to import a module at runtime
    .r   __version__z0.0.0N)sysmodules
__import__splitr:   r   ImportErrorr*   )rD   rootrB   r   r   r   r>      s    
r>   bytes)pathr%   c                 C  s   t jd|  S )Nlimits)	importlib	resourcesfilesjoinpath
read_bytes)rN   r   r   r   get_package_data   s    rU   zlist[RateLimitItem])limit_stringr%   c           	      C  s~   t | trt| s td|  g }t| D ]J}t|}|r.| \}}}}t	|}|
|t||rpt|prd q.|S )z
    parses rate limits in string notation containing multiple rate limits
    (e.g. ``1/second; 5/minute``)

    :param limit_string: rate limit string using :ref:`ratelimit-string`
    :raise ValueError: if the string notation is invalid.

    z%couldn't parse rate limit string '%s'N)r;   r   EXPRmatch
ValueErrorr   rJ   SINGLE_EXPRgroupsgranularity_from_stringappendr   )	rV   rO   limitrX   amount_Z	multiplesgranularity_stringgranularityr   r   r   
parse_many   s    

rc   r   c                 C  s   t t| d S )z
    parses a single rate limit in string notation
    (e.g. ``1/second`` or ``1 per second``)

    :param limit_string: rate limit string using :ref:`ratelimit-string`
    :raise ValueError: if the string notation is invalid.

    r   )r<   rc   )rV   r   r   r   parse   s    
rd   zType[RateLimitItem])ra   r%   c                 C  s0   t  D ]}|| r|  S qtd|  dS )z<

    :param granularity_string:
    :raise ValueError:
    zno granularity matched for %sN)r   valuesZcheck_granularity_stringrY   )ra   rb   r   r   r   r\      s    

r\   )/r   
__future__r   dataclassesimportlib.resourcesrP   rerG   collectionsr   typesr   typingr   Zpackaging.versionr   Zlimits.typingr   r	   r
   r   errorsr   rO   r   r   compiler   
IGNORECASEVERBOSErZ   formatpatternrW   r   	dataclassr   r*   r   Z	_UserDictr#   r1   r>   rU   rc   rd   r\   r   r   r   r   <module>   sJ   


.