
    5pj9                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJr  SSKJrJr  SSKrSSKJr  SSKJrJrJrJrJr   " S	 S
\\
5      rS\S\SS4S jr " S S5      r\S\S\S\4S j5       rS\S\4S jrS\S\ \\4   4S jr!\RD                  " S5      r#S\S\4S jr$S\S\4S jr%S\S\4S jr&S\'\   S\'\'\      S\ \\4   4S  jr(S!\S\4S" jr)S\'\   S\'\'\      S#\*S\*4S$ jr+S!\S\4S% jr,\" 5       r-g)&z"Output framework for the `hf` CLI.    N)Sequence)Enum)cache)Anycast)ConfirmationError)ANSI
StatusLinedisable_progress_barsis_agenttabulatec                   ,    \ rS rSrSrSrSrSrSrSr	Sr
g	)
OutputFormat!   zGOutput format for CLI commands with auto detection of agent/human mode.agentautohumanjsonquiet N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   __static_attributes__r       W/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/cli/_output.pyr   r   !   s    QEDEDEr   r   valueskwargsreturnc                  "    [        U 0 UDSS0D6  g)zLike `print`, but always flushed: some CLI flows block on user action right after
printing (e.g. the device-code login), so output must not stay buffered.flushTN)print)r   r    s     r   _print_flushr%   +   s     
6(V(4(r   c                      \ rS rSr% Sr\\S'   \\S'   S(S jr\R                  4S\SS4S jjr
S\SS4S	 jrS\4S
 jrS)SSS.S\S-  S\S-  S\S-  SS4S jjjrSSSS.S\\\\4      S\\   S-  S\S-  S\\\4   S-  SS4
S jjrSS.S\S\S-  SS4S jjrS\S\SS4S jrSSSS.S\S\S\S \SS4
S! jjrS)S\S-  S\4S" jjrS\SS4S# jrS\SS4S$ jrS\SS4S% jrS\SS4S& jrS'rg)*Output1   zOutput sink for the `hf` CLI.

Mode is resolved once at init time based on `is_agent()` auto-detection
and can be overridden per-command via `set_mode()`.
modeno_truncater!   Nc                 2    SU l         U R                  5         g )NF)r*   set_modeselfs    r   __init__Output.__init__;   s     r   c                     U[         R                  :X  a/  [        5       (       a  [         R                  O[         R                  nXl        U[         R                  :w  a  [        5         gg)zPOverride the output mode (called once at startup and again per '--format' flag).N)r   r   r   r   r   r)   r   )r.   r)   s     r   r,   Output.set_mode?   sG    <$$$)1<%%9K9KD	<%%%!# &r   c                     Xl         g)z2Toggle off cell truncation for human table output.Nr*   )r.   r*   s     r   set_no_truncateOutput.set_no_truncateG   s    &r   c                 <    U R                   [        R                  :H  $ N)r)   r   r   r-   s    r   is_quietOutput.is_quietK   s    yyL....r   )r   r   msgr   r   c                    Ub  Uc  Ub  [        S5      eUn[        U5      nU R                  =[        R                  :X  a    Ub  [        U5        gg[        R                  :X  a  Ub  [        U5        ggg)z)Print a free-form text message to stdout.Nz&Cannot mix 'msg' with 'human'/'agent'.)
ValueError_strip_ansir)   r   r   r%   r   )r.   r;   r   r   s       r   textOutput.textN   ss    ? E$5 !IJJE$Eii###$ ' %##$ ' % $r   )headersid_key
alignmentsitemsrA   rB   rC   c          
        ^ U(       df  U R                   ==[        R                  :X  a  O=[        R                  :X  a  O  O    [	        S5        g[        R
                  :X  a  [	        S5        ggUcK  [        US   R                  5       5      nU V^s/ s H!  m[        U4S jU 5       5      (       d  M  TPM#     nnU VVs/ s H#  or Vs/ s H  oR                  U5      PM     snPM%     n	nnU R                   =[        R                  :X  a    U Vs/ s H  n[        U5      PM     n
nU	 VVs/ s H  o Vs/ s H  n[        U5      PM     snPM      nnn[        XU R                  S9n0 [        X)5      EU=(       d    0 EnUR                  5        VVs0 s H  u  nn[        U5      U_M     nnn[	        [!        [#        SU5      U
US95        U(       a  U R%                  S	5        gg=[        R                  :X  aF    [	        S
R'                  U5      5        U	 H$  n[	        S
R'                  S U 5       5      5        M&     g=[        R
                  :X  a-    [	        [
        R(                  " [        U5      [*        S95        g[        R,                  :X  a3  U=(       d    US   nU H  n[	        UR                  US5      5        M      ggs  snf s  snf s  snnf s  snf s  snf s  snnf s  snnf )aw  Print tabular data to stdout.

Args:
    items: List of dicts. Headers are auto-detected from keys if not provided.
    headers: Explicit column names. If None, derived from dict keys (all-None columns filtered).
    id_key: Key to print in quiet mode. If None, uses the first header.
    alignments: Optional mapping of header name to "left" or "right". Defaults to "left".
zNo results found.z[]Nr   c              3   H   >#    U  H  oR                  T5      S Lv   M     g 7fr8   )get).0itemcols     r   	<genexpr>Output.table.<locals>.<genexpr>y   s     8e_dW[#d9R_ds   "r4   zlist[list[str | int]])rA   rC   z>Use `--no-truncate` or `--format json` to display full values.	c              3   8   #    U  H  n[        U5      v   M     g 7fr8   )_format_table_cell_agentrH   vs     r   rK   rL      s     *TPS1+CA+F+FPS   default )r)   r   r   r   r%   r   listkeysanyrG   
_to_header_format_table_value_human_truncate_columnsr*   _infer_alignmentsrD   r   r   hintjoindumpsstrr   )r.   rD   rA   rB   rC   all_columnsrJ   rI   hrowsscreaming_headersrowrQ   formatted_rowsis_truncatedinferredkscreaming_alignments	quiet_keys         `            r   tableOutput.table_   sW     ))<'\''*<,*<*<< !45  "&& &?uQx}}/K&1fksS8e_d8e5eskGf;@A54g.g!g.5Aii###<C$DGqZ]G!$Djn2ojncfZ]3^Z]UV4Ma4PZ]3^jn2o01B`d`p`pqU/>U:CSQSUEM^^EU'VEUTQ
1q(8EU$'V4nE 1#7  II^_  ###TYYw/0C *TPS*T!TU  """TZZUSAB##"0gaj	!D )R!89 " $7 g.A %E3^2o
 (WsH   K5K	KK%KK/	K&8K!K&K,K!K&)rB   datac                |   [         R                  " U5      (       a   [        U[        5      (       d  [	        U5      nU R
                  [        R                  :X  a  Ub  [        UR                  US5      5        gU R
                  [        R                  :X  a  SOSn[        [        R                  " X[        S95        g)ztPrint structured data as JSON in all modes (indented for human, compact otherwise).

Accepts a dict or a dataclass.
NrU      )indentrT   )dataclassesis_dataclass
isinstancetype_dataclass_to_dictr)   r   r   r%   rG   r   r   r_   r`   )r.   rn   rB   rq   s       r   dictOutput.dict   s    
 ##D))*T42H2H%d+D99***v/A&"-.ii<#5#554TZZSABr   messagec                    U R                   =[        R                  :X  aw    [        R                  " [        SS5       SU 35      /nUR                  5        H!  u  pEUc  M
  UR                  SU SU 35        M#     [        SR                  U5      5        g=[        R                  :X  aS    UR                  5        VVs/ s H  u  pEUc  M
  U SU 3PM     nnn[        U(       a  SR                  U5      OU5        g=[        R                  :X  a-    [        U(       a  [        R                  " U[        S	9OS
5        g[        R                  :X  a0  [        UR!                  5       5      nU(       a  [        US   5        gggs  snnf )z"Print a success summary to stdout.u   ✓z[OK] Nz  z: 
=rS   rU   r   )r)   r   r   r	   green_ascii_saferD   appendr%   r^   r   r   r_   r`   r   rV   r   )r.   ry   rn   partsri   rQ   r   s          r   resultOutput.result   s   ii###{5&'A&B!G9$MNO JJLDA}r!Bqc]3 ) TYYu-.###04

NA3asNSXXe_7C"""dTZZc:K##dkkm, +  $	 Os   ?	FFFz--yes)rT   yesconfirm_paramrT   r   r   c                    U(       a  gU R                   [        R                  :w  a  [        U SU S35      e[        R
                  " XSS9  g)zF
Ask for confirmation. Raises `ConfirmationError` in non-human modes.
Nz Use z to skip confirmation.T)rT   abort)r)   r   r   r   clickconfirm)r.   ry   rT   r   r   s        r   r   Output.confirm   sC     99***#wiu]OCY$Z[[gd;r   c                 v    [        U R                  [        R                  :H  S9nUb  UR	                  U5        U$ )zEReturn a status line that emits only in human mode (no-op otherwise).)enabled)r
   r)   r   r   update)r.   ry   statuss      r   r   Output.status   s2    DII1C1C$CDMM'"r   c                     U R                   [        R                  :X  a0  [        [        R
                  " SU 35      [        R                  S9  g[        SU 3[        R                  S9  g)z0Print a non-fatal warning to stderr (all modes).z	Warning: fileN)r)   r   r   r%   r	   yellowsysstderrr.   ry   s     r   warningOutput.warning   sG    99***y	%:;#**M9WI.SZZ@r   c                     U R                   [        R                  :X  a0  [        [        R
                  " SU 35      [        R                  S9  g[        SU 3[        R                  S9  g)z%Print an error to stderr (all modes).zError: r   N)r)   r   r   r%   r	   redr   r   r   s     r   errorOutput.error   sG    99***GG9"56SZZH77),3::>r   c                    U R                   [        R                  :X  a  gU R                   [        R                  :X  a-  [	        [
        R                  " U5      [        R                  S9  g[	        U[        R                  S9  g)zPrint a text message to stderr (human: gray, json/agent: plain text).

Suppressed in quiet mode. Kept in json mode (like agent) since agents
commonly run with ``--format json`` and the message goes to stderr so
it never pollutes the parsed stdout.
Nr   )	r)   r   r   r   r%   r	   grayr   r   r   s     r   log
Output.log   sP     99***99***7+#**=szz2r   c                 ,    U R                  SU 35        g)a  Print a helpful hint to stderr (human: gray, json/agent: plain text).

Suppressed in quiet mode. Kept in json mode (like agent) since agents
commonly run with ``--format json`` and the next-command hints are useful
there; hints go to stderr so they never pollute the parsed stdout.
zHint: N)r   r   s     r   r]   Output.hint   s     	6'#$r   )r)   r*   )r!   Nr8   )r   r   r   r   r   r   __annotations__boolr/   r   r,   r5   r9   r`   r?   r   rw   r   rV   rl   r   r   r
   r   r   r   r   r]   r   r   r   r   r'   r'   1   s     -9,=,= $\ $$ $'4 'D '/$ /($\` (d
 (S4Z (sUYz (ei (* %)!,08:S#X'8: cT!	8:
 d
8: cNT)8: 
8:t 7; C Ct Ct C,c ,3 ,4 ,& 8=%fm <s < <4 <`c <rv <cDj J As At A?S ?T ?33 34 3%C %D %r   r'   charfallbackc                     [        [        R                  SS5      =(       d    Sn U R                  U5        U $ ! [        [
        4 a    Us $ f = f)u  Return `char`, or `fallback` if stdout cannot encode it.

On Windows, `sys.stdout` uses the ANSI code page (e.g. cp1252) instead of the console
encoding whenever it is not attached to a console (output redirected, piped, captured by
a CI step). Printing a decoration like "✓" then raises `UnicodeEncodeError` - a
`ValueError` subclass, so it surfaces as a confusing "Invalid value." error and aborts
the command. Cached since the stream encoding is fixed for the lifetime of the process.
encodingNzutf-8)getattrr   stdoutencodeLookupErrorUnicodeEncodeError)r   r   r   s      r   r   r      sO     szz:t4?HH K +, s   9 AArQ   c                 n   [        U [        R                  5      (       a  U R                  5       $ [        U [        5      (       a4  U R	                  5        VVs0 s H  u  pUc  M
  U[        U5      _M     snn$ [        U [        5      (       a  U  Vs/ s H  n[        U5      PM     sn$ U $ s  snnf s  snf )z4Recursively serialize a value to be JSON-compatible.)rt   datetime	isoformatrw   rD   _serialize_valuerV   )rQ   keyvalrI   s       r   r   r     s    !X&&''{{}	At		;<779X9xs*%c**9XX	At		34514 &155H Y5s   	B,%B,B2infoc                     [         R                  " U 5      R                  5        VVs0 s H  u  pUc  M
  U[        U5      _M     snn$ s  snnf )z0Convert a dataclass to a json-serializable dict.)rr   asdictrD   r   )r   ri   rQ   s      r   rv   rv     sC    /:/A/A$/G/M/M/Oa/OtqST"A""/Oaaas
   	A	A	z\033\[[0-9;]*mr?   c                 .    [         R                  SU 5      $ )NrU   )_ANSI_REsubr?   s    r   r>   r>     s    <<D!!r   c                 @    SR                  U R                  5       5      $ )Nr{   )r^   splitr   s    r   _single_liner     s    88DJJL!!r   namec                 R    [         R                  " SSU 5      nUR                  5       $ )zAConvert a camelCase or PascalCase string to SCREAMING_SNAKE_CASE.z([a-z])([A-Z])z\1_\2)rer   upper)r   ss     r   rY   rY      s!    
 (D1A779r   rA   rc   c                 v   ^ 0 n[        U 5       H&  u  mn[        U4S jU 5       5      (       d  M"  SX#'   M(     U$ )zNReturn ``{"col": "right"}`` for columns where every non-None value is numeric.c              3      >#    U  HJ  oT   S L =(       d8    [        UT   [        [        45      =(       a    [        UT   [        5      (       + v   ML     g 7fr8   )rt   intfloatr   )rH   re   cs     r   rK   $_infer_alignments.<locals>.<genexpr>*  sH     uptil1v~d*SVc5\"B"c:VYZ[V\^bKcGcdpts   AAright)	enumerateall)rA   rc   r   rb   r   s       @r   r\   r\   &  s;    F'"1uptuuuFI # Mr   valuec                    U c  g[        U [        5      (       a  U (       a  [        SS5      $ S$ [        U [        R                  5      (       a  U R	                  S5      $ [        U [
        5      (       a!  [        R                  " SU 5      (       a  U SS $ [        U [
        5      (       a  [        U 5      $ [        U [        5      (       a  SR                  S	 U  5       5      $ [        U [        5      (       a<  S
U ;   a  [        [        U S
   5      5      $ [        [        R                  " U 5      5      $ [        [        U 5      5      $ )z/Convert a value to string for terminal display.NrU   u   ✔r   z%Y-%m-%dz^\d{4}-\d{2}-\d{2}T
   z, c              3   8   #    U  H  n[        U5      v   M     g 7fr8   )rZ   rP   s     r   rK   ,_format_table_value_human.<locals>.<genexpr><  s     Eu!2155urR   r   )rt   r   r   r   strftimer`   r   matchr   rV   r^   rw   r   r_   r   s    r   rZ   rZ   /  s    }%,1{5%(9r9%**++~~j))%"((+A5"I"ISbz%E""%yyEuEEE	E4	 	 U?E&M 233DJJu-..E
##r   r*   c                  ^^^^ U(       d  T(       d  g[        U 5      n[        U5       V^s/ s H8  m[        [        U T   5      /UU4S j[        [        T5      5       5       Q76 PM:     nn[        R                  " 5       R
                  [        SUS-
  5      -
  n[        U5      U::  a  gUR                  5       mU  Vs/ s H  n[        [        U5      S5      PM     snm[        T5      U:  aG  [        U4S j[        T5       5       U4S jSS	9nUS:  a  OTU==   S-  ss'   [        T5      U:  a  MG  Sn	T H?  n
[        U
5       H-  u  mn[        U5      TT   :  d  M  S
n	USTT   S-
   S-   U
T'   M/     MA     U	$ s  snf s  snf )a  Truncate cells in-place to fit the current terminal width.

Returns `True` if any cell was truncated, so the caller can emit a hint.
`shutil.get_terminal_size` is cross-platform: it honors `$COLUMNS`, then
queries the OS-native API, then falls back to `(80, 24)`.
Fc              3   F   >#    U  H  n[        TU   T   5      v   M     g 7fr8   )len)rH   rr   rc   s     r   rK   $_truncate_columns.<locals>.<genexpr>U  s!     %P?O!c$q'!*oo?Os   !r         c              3   B   >#    U  H  u  pUTU   :  d  M  Uv   M     g 7fr8   r   )rH   iw
min_widthss      r   rK   r   c  s      @?41a*Q-.?QQ?s   	c                    > TU    $ r8   r   )r   capss    r   <lambda>#_truncate_columns.<locals>.<lambda>d  s	    $q'r   )r   rT   TN   z...)	r   rangemaxshutilget_terminal_sizecolumnssumcopyr   )rA   rc   r*   nr   naturalbudgetrb   widest	truncatedre   cellr   r   s    `  `       @@r   r[   r[   D  sk    $GA[`ab[cd[cVWs3wqz?Q%PuSY?O%PQ[cGd %%'//#aQ-?F
7|v
 <<>D*12'Q#c!fa.'2J
d)f
@9T?@!

 A:V d)f
 I ~GAt4y47" 	mQ!,u4A & 
 9 e 3s   ?FFc                     [        U [        R                  5      (       a  U R                  5       $ [        [	        U 5      5      $ )zHFormat a cell value for agent TSV output (ISO timestamps, tabs escaped).)rt   r   r   r   r`   r   s    r   rO   rO   t  s1    %**++  E
##r   ).r   rr   r   r   r   r   r   collections.abcr   enumr   	functoolsr   typingr   r   r   huggingface_hub.errorsr   huggingface_hub.utilsr	   r
   r   r   r   r`   r   r%   r'   r   objectr   rw   rv   compiler   r>   r   rY   rV   r\   rZ   r   r[   rO   outr   r   r   <module>r      s   )    	  
 $     4 ] ]3 )# ) ) )|% |%D c S S  " 6 bS bT#s(^ b
 ::'("c "c ""s "s "S S tCy T#Y DcN $S $S $*-#Y-
tCy/- 	-
 
-`$C $C $ hr   