o
    i                     @   s   U d Z ddlZddlZddlmZ edejZddddd	d
Zee	e
f ed< ddddddddZee	e
f ed< de	de
fddZde	de
fddZde	dee	e
f de
fddZdede	fdd ZdS )!z&Parsing helpers shared across modules.    N)Dictz(\d+)([a-z]+)i  i@B i ʚ;l    J)l     I5 )kmgtp
BYTE_UNITS   <     Q :	  ' 3)sr   hdwmoy
TIME_UNITSvaluereturnc                 C   
   t | tS )zaParse a size expressed as a string with digits and unit (like `"10MB"`) to an integer (in bytes).)_parse_with_unitr   r    r   d/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/huggingface_hub/utils/_parsing.py
parse_size+      
r   c                 C   r   )zfParse a duration expressed as a string with digits and unit (like `"10s"`) to an integer (in seconds).)r   r   r   r   r   r   parse_duration0   r   r    unitsc                 C   s   |   }|s
tdzt| W S  ty   Y nw t|}|s(td|  dt|d}|d }||vrItd| dt|  d|||  S )	z)Parse a numeric value with optional unit.zValue cannot be empty.zInvalid value 'z7'. Must match pattern '\d+[a-z]+' or be a plain number.r	      zUnknown unit 'z'. Must be one of .)	strip
ValueErrorintRE_NUMBER_WITH_UNIT	fullmatchgrouplowerlistkeys)r   r!   strippedmatchnumberunitr   r   r   r   5   s    

r   tsc                 C   sr   d}t   |  }|dk rdS |D ]\}}}t|| }|dur%||kr% nq| d| |dkr4d d	S d d	S )
zFormat timestamp in seconds into a human-readable string, relative to now.

    Vaguely inspired by Django's `timesince` formatter.
    ))secondr	   r
   )minuter
   r
   )hourr      )dayr      )weekr   r7   )monthr      )yearr   N   za few seconds agoN r	   r    z ago)timeround)r1   _TIMESINCE_CHUNKSdeltalabeldivider	max_valuer   r   r   r   format_timesinceL   s   
&rF   )__doc__rer?   typingr   compile
IGNORECASEr'   r   strr&   __annotations__r   r   r    r   floatrF   r   r   r   r   <module>   s.   	