o
    nN)j%                     @   s  d Z ddlZddlZddlZddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ eeeef\ZZZZejZedd	 d
D Zedd	 dD ZedZzer\ddlZneW n eyj   dZY nw zej dd W n e!y   e   Y nw d2ddZ"zddl"m"Z" W n	 e#y   Y nw G dd dZ$G dd dZ%G dd dZ&G dd de&Z'G dd de&Z(G dd de&Z)d d! Z*d"d# Z+d$d% Z,d&d' Z-d(d) Z.d*d+ Z/d,d- Z0d.d/ Z1d0d1 Z2dS )3z*
General helpers required for `tqdm.std`.
    N)partialpartialmethodwraps)	signatureeast_asian_width)warnproxyc                 c       | ]}t |V  qd S NCUR_OS
startswith.0i r   k/var/www/html/finance.cargoinsureonline.com/_shared/backend-venv/lib/python3.10/site-packages/tqdm/utils.py	<genexpr>       r   )win32cygwinc                 c   r   r   r   r   r   r   r   r      r   )aixlinuxdarwinfreebsdz\x1b\[[;\d]*[A-Za-z]F)strip c                    s   du ri | d dkr| dd } t dtdd |r$| |  d| fn| f}i  |D ] d t fddtj D  q+|rLtnt	 fd	d
}|S )z
    Basic (env-only) version of [envwrap](https://github.com/tqdm/envwrap).
    Install `envwrap` for config file support.
    N_z*Trailing underscore in `name` is automatic   
stacklevelc                 3   s2    | ]\}}| r| d   |fV  qd S r   )r   lowerr   kv)r   prefixr   r   r   1   s    
zenvwrap.<locals>.<genexpr>c              
      s   t | j  fdd D }|D ]S} | }|j|jur?t|jd|jfD ]}z
||| ||< W n	 ty<   Y q'w  q|jd urPt|j|| ||< qz| || ||< W q t	ye   Y qw | fi |S )Nc                    s   i | ]\}}| v r||qS r   r   r%   paramsr   r   
<dictcomp>8   s    z)envwrap.<locals>.wrap.<locals>.<dictcomp>__args__)
r   
parametersitems
annotationemptygetattr	ExceptiondefaulttypeKeyError)func	overridesr&   paramtyp)env_overridesparttypesr)   r   wrap5   s*   

zenvwrap.<locals>.wrap)
r   DeprecationWarningupperlenupdateosenvironr.   r   r   )nameappr<   	is_methodprefixesr=   r   )r:   r   r;   r(   r<   r   envwrap"   s    
rH   )rH   c                   @   s"   e Zd ZdZdddZdd ZdS )	FormatReplacezN
    >>> a = FormatReplace('something')
    >>> f"{a:5d}"
    'something'
    r   c                 C   s   || _ d| _d S Nr   )replaceformat_called)selfrK   r   r   r   __init__[   s   
zFormatReplace.__init__c                 C   s   |  j d7  _ | jS )N   )rL   rK   )rM   r    r   r   r   
__format___   s   zFormatReplace.__format__N)r   )__name__
__module____qualname____doc__rN   rP   r   r   r   r   rI   U   s    
rI   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )
Comparablez1Assumes child has self._comparable attr/@propertyc                 C   s   | j |j k S r   _comparablerM   otherr   r   r   __lt__f      zComparable.__lt__c                 C   s   | |k p| |kS r   r   rX   r   r   r   __le__i   s   zComparable.__le__c                 C   s   | j |j kS r   rV   rX   r   r   r   __eq__l   r[   zComparable.__eq__c                 C   s
   | |k S r   r   rX   r   r   r   __ne__o      
zComparable.__ne__c                 C   s
   | |k S r   r   rX   r   r   r   __gt__r   r_   zComparable.__gt__c                 C   s
   | |k  S r   r   rX   r   r   r   __ge__u   r_   zComparable.__ge__N)
rQ   rR   rS   rT   rZ   r\   r]   r^   r`   ra   r   r   r   r   rU   d   s    rU   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )ObjectWrapperc                 C   s   t | j|S r   )r1   _wrappedrM   rD   r   r   r   __getattr__z   r[   zObjectWrapper.__getattr__c                 C   s   t | j||S r   )setattrrc   rM   rD   valuer   r   r   __setattr__}   s   zObjectWrapper.__setattr__c                 C   s,   zt | |W S  ty   t| | Y S w )z7Actual `self.getattr` rather than self._wrapped.getattr)objectre   AttributeErrorr1   rd   r   r   r   wrapper_getattr   s
   zObjectWrapper.wrapper_getattrc                 C   s   t | ||S )z7Actual `self.setattr` rather than self._wrapped.setattr)rj   ri   rg   r   r   r   wrapper_setattr   s   zObjectWrapper.wrapper_setattrc                 C   s   |  d| dS )z4
        Thin wrapper around a given object
        rc   N)rm   )rM   wrappedr   r   r   rN      s   zObjectWrapper.__init__N)rQ   rR   rS   re   ri   rl   rm   rN   r   r   r   r   rb   y   s    rb   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )SimpleTextIOWrapperz
    Change only `.write()` of the wrapped object by encoding the passed
    value and passing the result to the wrapped object's `.write()` method.
    c                    s   t  | | d| d S )Nencoding)superrN   rm   )rM   rn   rp   	__class__r   r   rN      s   zSimpleTextIOWrapper.__init__c                 C   s   | j || dS )zP
        Encode `s` and pass to the wrapped object's `.write()` method.
        rp   )rc   writeencoderl   )rM   sr   r   r   rt      s   zSimpleTextIOWrapper.writec                 C      | j t|d|kS Nrc   rc   r1   rX   r   r   r   r]         zSimpleTextIOWrapper.__eq__)rQ   rR   rS   rT   rN   rt   r]   __classcell__r   r   rr   r   ro      s
    ro   c                       s4   e Zd ZdZedd Z fddZdd Z  ZS )DisableOnWriteErrorzO
    Disable the given `tqdm_instance` upon `write()` or `flush()` errors.
    c                    s   t  fdd}|S )zV
        Quietly set `tqdm_instance.miniters=inf` if `func` raises `errno=5`.
        c                     s   z | i |W S  t y9 } z%|jdkr ztd_W n	 ty&   Y nw W Y d }~d S W Y d }~d S d }~w tyj } z&dt|vrG ztd_W n	 tyW   Y nw W Y d }~d S W Y d }~d S d }~ww )N   infclosed)OSErrorerrnofloatminitersReferenceError
ValueErrorstr)argskwargser6   tqdm_instancer   r   inner   s2   
z7DisableOnWriteError.disable_on_exception.<locals>.innerr	   )r   r6   r   r   r   r   disable_on_exception   s   z(DisableOnWriteError.disable_on_exceptionc                    sT   t  | t|dr| d| ||j t|dr(| d| ||j d S d S )Nrt   flush)rq   rN   hasattrrm   r   rt   r   )rM   rn   r   rr   r   r   rN      s   

zDisableOnWriteError.__init__c                 C   rw   rx   ry   rX   r   r   r   r]      rz   zDisableOnWriteError.__eq__)	rQ   rR   rS   rT   staticmethodr   rN   r]   r{   r   r   rr   r   r|      s    
	r|   c                       s   e Zd Zd fdd	Z  ZS )CallbackIOWrapperreadc                    sz   t  | t|||dkr"t fdd}| d| dS |dkr9t fdd}| d| dS td)	z{
        Wrap a given `file`-like object's `read()` or `write()` to report
        lengths to the given `callback`
        rt   c                    s&   | g|R i |} t |  |S r   r@   )datar   r   rescallbackr6   r   r   rt      s   z)CallbackIOWrapper.__init__.<locals>.writer   c                     s   | i |} t | |S r   r   )r   r   r   r   r   r   r      s   z(CallbackIOWrapper.__init__.<locals>.readz Can only wrap read/write methodsN)rq   rN   r1   r   rm   r5   )rM   r   streammethodrt   r   rr   r   r   rN      s   
zCallbackIOWrapper.__init__)r   )rQ   rR   rS   rN   r{   r   r   rr   r   r      s    r   c                 C   sf   zd |  W dS  ty   Y dS  ty2   z|  dp#d| kW  Y S  ty1   Y Y dS w w )Nu   █▉Fzutf-U8T)ru   UnicodeEncodeErrorr2   r$   r   )rp   r   r   r   _is_utf   s   	r   c                 C   s"   zt | jW S  ty   Y dS w )NF)r   rp   rk   fpr   r   r   _supports_unicode   s
   r   c                 C   s2   t | tr| D ]}t|dkr dS qdS t| S )N   FT)
isinstancer   ordr   )rv   cr   r   r   	_is_ascii   s   
r   c                     s   ddl m   fdd} | S )zy
    Return a function which returns console dimensions (width, height).
    Supported: linux, osx, windows, cygwin.
    r   get_terminal_sizec                    sB   z t | ddd  \}}|d |d fW S  ty    Y dS w )Nfilenoc                   S   s   d S r   r   r   r   r   r   <lambda>  s    z6_screen_shape_wrapper.<locals>.inner.<locals>.<lambda>rO   )NN)r1   r2   )r   colslinesr   r   r   r     s   z$_screen_shape_wrapper.<locals>.inner)rB   r   r   r   r   r   _screen_shape_wrapper	  s   r   c                     s4   t dtdd t   sdS t  fdd} | S )zd
    Return a function which returns console width.
    Supported: linux, osx, windows, cygwin.
    zQUse `_screen_shape_wrapper()(file)[0]` instead of `_environ_cols_wrapper()(file)`r!   r"   Nc                    s    | d S rJ   r   r   shaper   r   r   %  s   z$_environ_cols_wrapper.<locals>.inner)r   r>   r   r   r   r   r   r   _environ_cols_wrapper  s   r   c                   C   s   t jdkrtd u rdS dS )Nntr   z[A)rB   rD   coloramar   r   r   r   _term_move_up,  s   r   c                 C   s   t dd t| D S )Nc                 s   s$    | ]}t |d v rdndV  qdS )FWr!   rO   Nr   )r   chr   r   r   r   1  s   " z_text_width.<locals>.<genexpr>)sumr   )rv   r   r   r   _text_width0  s   r   c                 C   s   t td| S )zp
    Returns the real on-screen length of a string which may contain
    ANSI control codes and wide chars.
    r   )r   RE_ANSIsub)r   r   r   r   disp_len4  s   r   c                 C   sz   t | t| kr| d| S tt| }t| |kr'| dd } t| |ks|r;tt| r;| dr7| S | d S | S )zB
    Trim a string which may contain ANSI control characters.
    Nr   z[0m)r@   r   boolr   searchendswith)r   lengthansi_presentr   r   r   	disp_trim<  s   r   )r   NF)3rT   rB   resys	functoolsr   r   r   inspectr   unicodedatar   warningsr   weakrefr
   rangechrr   _range_unich_unicode_basestringplatformr   anyIS_WINIS_NIXcompiler   r   ImportErrorinit	TypeErrorrH   ModuleNotFoundErrorrI   rU   rb   ro   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s`    


-+	