o
    GRhV+                     @   s   d 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
mZmZ ddlmZ dgZeeZd	d
 Zdddd dfddZedZedZdZdZejdfddZdS )zI
Module version for monitoring CLI pipes (`... | python -m tqdm | ...`).
    N)literal_eval)indent   )TqdmKeyErrorTqdmTypeErrortqdm)__version__mainc              
   C   s~  t | |f d|v r-|dD ]}zt| |W   S  ty#   Y qw t|  d| |dkrI| dks9| dkr;dS | dkrAdS t| d | |d	krpt| d
krW|  S td| rgt	d|  d S t|  d| |dkrv| S |dkrzt
| W S  ty } z
t|  d| |d }~ww |dkrzt| W S  ty } z
t|  d| |d }~ww t|  d| )Nz or z : boolTrue TFalseFchrr   z^\\\w+$"strintfloat)logdebugsplitcastr   lenencoderematchevalr   
ValueErrorr   )valtyptexc r!   J/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/tqdm/cli.pyr      sL   

r      \n   c                 C      d S Nr!   )r   r!   r!   r"   <lambda>8       r'   Tc                 C   s"  |j }|s#	 | |}|st|ddd   dS || |t| qd}t|}		 | |}|sZ|rO|| |rC|d||  n||D ]}
||
 qHt|ddd   dS 	 ||}
|
d	k ri||7 }n'|||d|
t|    ||r|dn||d|
   d}||
|	 d }q[q*)
aZ  
    Params
    ------
    fin  : binary file with `read(buf_size : int)` method
    fout  : binary file with `write` (and optionally `flush`) methods.
    callback  : function(float), e.g.: `tqdm.update`
    callback_len  : If (default: True) do `callback(len(buffer))`.
      Otherwise, do `callback(data) for data in buffer.split(delim)`.
    Tflushc                   S   r%   r&   r!   r!   r!   r!   r"   r'   J   r(   zposix_pipe.<locals>.<lambda>N    r   c                   S   r%   r&   r!   r!   r!   r!   r"   r'   a   r(   r   )writereadgetattrr   countr   find)finfoutdelimbuf_sizecallbackcallback_lenfp_writetmpbuf	len_delimir!   r!   r"   
posix_pipe7   sD   



r;   z\n {4}(\S+)\s{2,}:\s*([^,]+)z\s*(?<!\S)--?([^\s=]+)(\s+|=|$))iterableguioutfilea  
    Extra CLI Options
    -----------------
    name  : type, optional
        TODO: find out why this is needed.
    delim  : chr, optional
        Delimiting character [default: '\n']. Use '\0' for null.
        N.B.: on Windows systems, Python converts '\n' to '\r\n'.
    buf_size  : int, optional
        String buffer size in bytes [default: 256]
        used when `delim` is specified.
    bytes  : bool, optional
        If true, will count bytes, ignore `delim`, and default
        `unit_scale` to True, `unit_divisor` to 1024, and `unit` to 'B'.
    tee  : bool, optional
        If true, passes `stdin` to both `stderr` and `stdout`.
    update  : bool, optional
        If true, will treat input as newly elapsed iterations,
        i.e. numbers to pass to `update()`. Note that this is slow
        (~2e5 it/s) since every input must be decoded as a number.
    update_to  : bool, optional
        If true, will treat input as total elapsed iterations,
        i.e. numbers to assign to `self.n`. Note that this is slow
        (~2e5 it/s) since every input must be decoded as a number.
    null  : bool, optional
        If true, will discard input (no stdout).
    manpath  : str, optional
        Directory in which to install tqdm man pages.
    comppath  : str, optional
        Directory in which to place tqdm completion.
    log  : str, optional
        CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.
c                    s   du rt jdd  z d}W n ty1    D ]}|dr,|tdd } nqd}Y nw  |d  }tjtt|dd t j	dk rJt
jntt
jd	t }tt|}tD ]}|| q[tt|  t|}t|ddd
 |ddd
 |d
dd
 }	ddd |	D }d}
|
d |d d }t fdddD rt jtd  t d n3t fdddD rt j|d  t d n r d dd dkrt j d d  d|
  t!ddg   tt ddd
  d
dd
 }t| |dd di}zY| D ])\}}|"dd}zt#||| ||< W q t$yB } zt%t&|d}~ww td t&|  |d!d"}|d#d"}|d$d"}t'|||fdkrlt%d%W n" t(y   d&|
  t j)t jj}|D ]}| q w |d'd(}|d)d*}|d+d"}|d,d}|d-d}|d.d"rG d/d0 d0t*}n	t j}t|d1|}tt j)d1t j)}|s|rdd2l+m, dd3l-m.} dd4l/m0 fd5d6}|dur|d7||d7 |dur
|d8||d9 t d |r(|jtd1jG fd:d0d0t*}|rf|1d;d< |1d=d |1d>d? t| t
dEi |t2||d|j3 W d   dS 1 s_w   Y  dS |d*krt| |j}|sy|rt
dEi |&|rfd@dA}nfdBdA}|D ]}|| || qW d   n1 sw   Y  dS dS t
|fi |D ]}|| qdS t| t
dEi |-d"}|rއfdCdA}n|rfdDdA}nj3}d}t2|||||| W d   dS 1 sw   Y  dS )Fz
    Parameters (internal use only)
    ---------
    fp  : file-like object for tqdm
    argv  : list (default: sys.argv[1:])
    Nr   z--logz--log=INFOz/%(levelname)s:%(module)s:%(lineno)d:%(message)s)levelformat)      z    rC      r   c                 s   sX    | ]'}|d  t vr|d dkrdndj|d  dd|d  g|dd R  V  qdS )r   r   r
   z
  --{0}  : {2}{3}z
  --{0}=<{1}>  : {2}{3}_-N)UNSUPPORTED_OPTSrB   replace).0otdr!   r!   r"   	<genexpr>   s    
zmain.<locals>.<genexpr>z!Usage:
  tqdm [--help | options]
z^
Options:
  -h, --help     Print this help and exit.
  -v, --version  Print version and exit.

c                 3       | ]}| v V  qd S r&   r!   rJ   vargvr!   r"   rL          )z-vz	--versionr   c                 3   rN   r&   r!   rO   rQ   r!   r"   rL      rS   )z-hz--helpz--zError:Unknown argument: r   r   Tr?   rG   rF   zargs:bytesFupdate	update_toz1Can only have one of --bytes --update --update_toz
Error:
r3   r$   r2   r#   teemanpathcomppathnullc                   @   s   e Zd Zedd ZdS )main.<locals>.stdoutc                 S   r%   r&   r!   )rF   r!   r!   r"   r+      s   main.<locals>.stdout.writeN__name__
__module____qualname__staticmethodr+   r!   r!   r!   r"   stdout   s    rc   buffer)	resources)path)copyfilec                    sn   t dr td|  | nd| } t|| W d   n1 s*w   Y  td| dS )zcopy resource `name` to `dst`filesr   Nz
written:%s)hasattrr   rh   rf   r   info)namedstsrc)rg   re   r!   r"   cp	  s   
zmain.<locals>.cpztqdm.1zcompletion.shztqdm_completion.shc                       s    e Zd Ze fddZdS )r\   c                    s@   t j d |  W d    n1 sw   Y  |  d S )N)r?   )r   external_write_mode)xfpr6   stdout_writer!   r"   r+     s   
r]   Nr^   r!   rq   r!   r"   rc     s    unitB
unit_scaleunit_divisori   c                         t|   d S r&   rV   numericdecoder:   r   r!   r"   r4   -     zmain.<locals>.callbackc                         t|   j  d S r&   rV   rz   r{   nr|   r}   r!   r"   r4   0     c                    rx   r&   ry   r|   r}   r!   r"   r4   =  r~   c                    r   r&   r   r|   r}   r!   r"   r4   @  r   r!   )4sysrR   indexr   
startswithr   loggingbasicConfigr-   version_infor   __doc__r   CLI_EXTRA_DOCdictRE_OPTSfindallrH   popr   r   sorteditemsr   zipjoinstripanyrc   r+   r   exitstderrRE_SHLEXrI   r   KeyErrorr   r   sum	Exceptionstdinobject	importlibre   osrf   shutilrg   
setdefaultr;   rV   )rr   rR   log_idxr:   logLeveld	opt_typesor   opt_types_desc
help_shortopts	tqdm_argsrP   edelim_per_charrV   rW   r   r3   r2   rX   rY   rZ   rc   rf   rn   r+   r4   r5   r!   )rR   rg   rr   r6   re   rs   r   r"   r	      s  


*
"




$

&
$)r   r   r   r   astr   rz   textwrapr   stdr   r   r   versionr   __all__	getLoggerr_   r   r   r;   compiler   r   rH   r   r   r	   r!   r!   r!   r"   <module>   s&    
&

:
#