{f-.VdZddlZddlZddlZddlmZmZmZddlm Z ddl m Z ddl m Z ddlmZeeeef\ZZZZej.Zedd DZed d DZej8d Z erddlZne ej@d d(dZ"Gdde#Z$Gdde#Z%Gdde#Z&Gdde&Z'Gdde&Z(Gdde&Z)dZ*dZ+dZ,dZ-d Z.d!Z/d"Z0d#Z1d$Z2d%Z3d&Z4d'Z5y#e!$rej@YwxYw#e$rdZYwxYw))z* General helpers required for `tqdm.std`. N)partial partialmethodwraps) signatureeast_asian_width)warnproxyc#FK|]}tj|ywNCUR_OS startswith.0is S/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/tqdm/utils.py rs ?aV  q ! ?!)win32cygwinc#FK|]}tj|ywr rrs rrrs QaV  q ! Qr)aixlinuxdarwinfreebsdz\x1b\[[;\d]*[A-Za-z]F)stripc it|}tjjDcic]+\}}|j |s||dj |-c}}|rt ntfd}|Scc}}w)a Override parameter defaults via `os.environ[prefix + param_name]`. Maps UPPER_CASE env vars map to lower_case param names. camelCase isn't supported (because Windows ignores case). Precedence (highest first): - call (`foo(a=3)`) - environ (`FOO_A=2`) - signature (`def foo(a=1)`) Parameters ---------- prefix : str Env var prefix, e.g. "FOO_" types : dict, optional Fallback mappings `{'param_name': type, ...}` if types cannot be inferred from function signature. Consider using `types=collections.defaultdict(lambda: ast.literal_eval)`. is_method : bool, optional Whether to use `functools.partialmethod`. If (default: False) use `functools.partial`. Examples -------- ``` $ cat foo.py from tqdm.utils import envwrap @envwrap("FOO_") def test(a=1, b=2, c=3): print(f"received: a={a}, b={b}, c={c}") $ FOO_A=42 FOO_C=1337 python -c 'import foo; foo.test(c=99)' received: a=42, b=2, c=99 ``` Nct|j}jDcic] \}}||vs ||}}}|D]}||}|j|jur8t |jd|jfD]} |||||<VX|j"t|j||||<  |||||<|fi|Scc}}w#t $rYrwxYw#t$rYwxYw)N__args__) r parametersitems annotationemptygetattr ExceptiondefaulttypeKeyError) funcparamskv overridesparamtyp env_overridesparttypess rwrapzenvwrap..wrapLs%4++&3&9&9&;KdaqF{QTK KA1IEu{{2"5#3#3Z%BRBRATUC'*9Q<'8 !  V*2tEMM29Q<@ ! #+58IaL#9IaL"D&I&&'L% s. C$C$C*C9* C65C69 DD)lenosenvironr#rlowerrr) prefixr4 is_methodrr-r.r5r2r3s ` @@renvwrapr<"srH } F A24**2B2B2D]$!Q U[H\QqrU[[]A%]M%=7D'. K5^s A?A?ceZdZdZddZdZy) FormatReplacezN >>> a = FormatReplace('something') >>> f"{a:5d}" 'something' c ||_d|_yNr)replace format_called)selfrAs r__init__zFormatReplace.__init__ls cD|xjdz c_|jS)N)rBrA)rC_s r __format__zFormatReplace.__format__ps a||rEN))__name__ __module__ __qualname____doc__rDrIrErr>r>fs rEr>c4eZdZdZdZdZdZdZdZdZ y) Comparablez1Assumes child has self._comparable attr/@propertyc4|j|jkSr  _comparablerCothers r__lt__zComparable.__lt__ws%"3"333rEc||kxs||k(Sr rOrUs r__le__zComparable.__le__zsu 0$%-0rEc4|j|jk(Sr rSrUs r__eq__zComparable.__eq__}s5#4#444rEc||k( Sr rOrUs r__ne__zComparable.__ne__5=  rEc||k Sr rOrUs r__gt__zComparable.__gt__r^rEc||k Sr rOrUs r__ge__zComparable.__ge__s%<rEN) rKrLrMrNrWrYr[r]r`rbrOrErrQrQus#;415!! rErQc*eZdZdZdZdZdZdZy) ObjectWrapperc.t|j|Sr )r&_wrappedrCnames r __getattr__zObjectWrapper.__getattr__st}}d++rEc0t|j||Sr )setattrrfrCrhvalues r __setattr__zObjectWrapper.__setattr__st}}dE22rEcf tj||S#t$rt||cYSwxYw)z7Actual `self.getattr` rather than self._wrapped.getattr)objectriAttributeErrorr&rgs rwrapper_getattrzObjectWrapper.wrapper_getattrs6 '%%dD1 1 '4& & 's 00c0tj|||S)z7Actual `self.setattr` rather than self._wrapped.setattr)rprnrls rwrapper_setattrzObjectWrapper.wrapper_setattrs!!$e44rEc(|jd|y)z4 Thin wrapper around a given object rfN)rt)rCwrappeds rrDzObjectWrapper.__init__s Z1rEN)rKrLrMrirnrrrtrDrOrErrdrds,3'52rErdc.eZdZdZfdZdZdZxZS)SimpleTextIOWrapperz Change only `.write()` of the wrapped object by encoding the passed value and passing the result to the wrapped object's `.write()` method. cHt|||jd|y)Nencoding)superrDrt)rCrvrz __class__s rrDzSimpleTextIOWrapper.__init__s  ! Z2rEct|jj|j|jdS)zP Encode `s` and pass to the wrapped object's `.write()` method. rz)rfwriteencoderr)rCss rr~zSimpleTextIOWrapper.writes-}}""188D,@,@,L#MNNrEc6|jt|d|k(SNrfrfr&rUs rr[zSimpleTextIOWrapper.__eq__}}z5 AAArE)rKrLrMrNrDr~r[ __classcell__r|s@rrxrxs 3O BrErxc8eZdZdZedZfdZdZxZS)DisableOnWriteErrorzO Disable the given `tqdm_instance` upon `write()` or `flush()` errors. c,tfd}|S)zV Quietly set `tqdm_instance.miniters=inf` if `func` raises `errno=5`. c8 |i|S#t$r@}|jdk7r td_n#t$rYnwxYwYd}~yYd}~yd}~wt $r>}dt |vr td_n#t$rYnwxYwYd}~yYd}~yd}~wwxYw)Ninfclosed)OSErrorerrnofloatminitersReferenceError ValueErrorstr)argskwargser+ tqdm_instances rinnerz7DisableOnWriteError.disable_on_exception..inners T,V,, 77a<-25\M*%+ 3q6)-25\M*%+  sc BA6A AAAA BB*A;:B; BBBBBr )rr+rs`` rdisable_on_exceptionz(DisableOnWriteError.disable_on_exceptions m,  " rEct||t|dr,|jd|j ||j t|dr-|jd|j ||j yy)Nr~flush)r{rDhasattrrtrr~r)rCrvrr|s rrDzDisableOnWriteError.__init__ss ! 7G $  22='--P R 7G $  22='--P R %rEc6|jt|d|k(SrrrUs rr[zDisableOnWriteError.__eq__rrE) rKrLrMrN staticmethodrrDr[rrs@rrrs(2RBrErc eZdZdfd ZxZS)CallbackIOWrapperct||t|||dk(r'tfd}|j d|y|dk(r'tfd}|j d|yt d)z{ Wrap a given `file`-like object's `read()` or `write()` to report lengths to the given `callback` r~cB|g|i|}t||Sr r6)datarrrescallbackr+s rr~z)CallbackIOWrapper.__init__..writes(41$1&1T# rEreadc:|i|}t||Sr r)rrrrr+s rrz(CallbackIOWrapper.__init__..reads#T,V,T# rEz Can only wrap read/write methodsN)r{rDr&rrtr*)rCrstreammethodr~rr+r|s ` @rrDzCallbackIOWrapper.__init__s  vv& W  4[    % 0 v  4[     .=> >rE)r)rKrLrMrDrrs@rrrs ??rErc dj|y#t$rYyt$r: |jj dxsd|k(cYS#t$rYYywxYwwxYw)Nu█▉TFzutf-U8)rUnicodeEncodeErrorr'r9r)rzs r_is_utfrso x(   >>#..v6L48;K L  s1 A!A!%A A! AA!AA!cL t|jS#t$rYywxYwNF)rrzrq)fps r_supports_unicoder s(r{{## s  ##cht|tr|D]}t|dkDsyyt|S)NFT) isinstancerordr)rcs r _is_asciirs4!SA1v| Q rEcJd}trt}|t}trt}|S)zy Return a function which returns console dimensions (width, height). Supported: linux, osx, windows, cygwin. N)IS_WIN_screen_shape_windows_screen_shape_tputIS_NIX_screen_shape_linux) _screen_shapes r_screen_shape_wrapperrs* M -  .M + rEc V ddl}ddlm}m}ddlm}m}d}||k(rd}n||k(rd}|jj|}|d}|jj||} | r2|jd|j\ } } } } }}}}}}}||z ||z fS y #t$rYy wxYw) Nr)create_string_bufferwindll)stdinstdoutiii hhhhHhhhhhhNN) structctypesrrsysrrkernel32 GetStdHandleGetConsoleScreenBufferInfounpackrawr')rrrrrr io_handlehcsbir_bufx_bufy_curx_cury_wattrlefttoprightbottom_maxx_maxys rrr)s 7% ;I 6\I OO ( ( 3#B'oo88DA #]]=$((C UE5%sE6 E4<#- -      sBB B('B(c  ddl}ddlm}dDcgc](}t||j d|zdz *c}Scc}w#t $rYywxYw)zcygwin xterm (windows)rN) check_call)colslinesztput rGr)shlex subprocessrintsplitr')rHrrrs rrrAs^ )*,Ju{{7Q;789A=, ,,    s!A-AAA AAc0 ddlm}ddlm}ddlm} |d|||ddd\}}||fS#t $rM dDcgc]!}t tj|d z #ncc}wc}cYS#ttf$rYYy wxYwwxYw#t$rYy wxYw) Nr)array)ioctl) TIOCGWINSZrz)COLUMNSLINESrGr) rfcntlrtermiosrr'rr7r8r*r ImportError)rrrrrowsrrs rrrMs"& "sE"j($CDRaHJD$:  " "8LM1BJJqM*Q.MMMj) "! " " sHB 0 BA/&A%$A/,B/B>BBB BBcltdtdtsytfd}|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) stacklevelNc|dSr@rO)rshapes rrz$_environ_cols_wrapper..innerksRy|rE)r DeprecationWarningrr)rrs @r_environ_cols_wrapperr`sC   ,-?AO ! #E  5\ LrEc<tjdk(rtdSdS)NntrJz)r7rhcoloramarOrEr _term_move_uprrs''T/(82GxGrEc8tdt|DS)Nc3>K|]}t|dvrdndyw)FWrrGNr)rchs rrz_text_width..ws"IB$R(D0qa7Is)sumr)rs r _text_widthrvs I#a&I IIrEc@ttjd|S)zp Returns the real on-screen length of a string which may contain ANSI control codes and wide chars. rJ)rRE_ANSIsub)rs rdisp_lenrzs w{{2t, --rEc.t|t|k(r|d|Sttj |}t||kDr|dd}t||kDr|r6ttj |r|j dr|S|dzS|S)zB Trim a string which may contain ANSI control characters. Nz)r6rboolrsearchendswith)rlength ansi_presents r disp_trimrs 4yHTN"GV}t,-L 4.6 !CRy 4.6 !W^^D12}}Y/tETI5EE KrEr)6rNr7rer functoolsrrrinspectr unicodedatarwarningsr weakrefr rangechrr_range_unich_unicode _basestringplatformranyrrcompilerrrinit TypeErrorr<rpr>rQrdrxrrrrrrrrrrrrrrrOrErr sg 33((-sC(<%+  ?+> ? ? Q+P Q Q "**, -     E" AH F   *2F22B-B((B-(BV? ?4   0 "&$HJ. I   Hs$9 DDDDD('D(