
    Y j)                        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Jr  SSKJ	r	  SSK
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5      rS\S\4S jrS\S\\\4   4S jr\R8                  " S5      rSrS\S\4S jrS\S\4S jr S\S\4S jr!S\S\4S jr"\4S\S\#S\4S jjr$S\S\4S jr%\" 5       r&g)z"Output framework for the `hf` CLI.    N)Sequence)Enum)Any)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	)
OutputFormatWithAuto    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       l/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/huggingface_hub/cli/_output.pyr   r       s    QEDEDEr   r   c                      \ rS rSr% Sr\\S'   S#S jr\R                  4S\SS4S j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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"rg)%Output*   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returnNc                 $    U R                  5         g N)set_modeselfs    r   __init__Output.__init__3   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_mode6   sK    ',,,19'--AUA[A[D	'---!# .r   c                 <    U R                   [        R                  :H  $ r#   )r    r   r   r%   s    r   is_quietOutput.is_quiet>   s    yy06666r   )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   printr   )r&   r.   r   r   s       r   textOutput.textA   sr    ? E$5 !IJJE$Eii+%++$%L %%++$%L % ,r   )headersid_key
alignmentsitemsr5   r6   r7   c          
      T  ^ 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
Vs/ s H  o Vs/ s H  n[        U5      PM     snPM      nn
nU Vs/ s H  n[        U5      PM     nnU=(       d    0 R                  5        VVs0 s H  u  p[        U5      U_M     nnn[	        [        XUS95        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n
f s  s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r#   )get).0itemcols     r   	<genexpr>Output.table.<locals>.<genexpr>l   s     8e_dW[#d9R_ds   ")r5   r7   	c              3   8   #    U  H  n[        U5      v   M     g 7fr#   )_format_table_cell_agentr<   vs     r   r?   r@   x   s     #MA$<Q$?$?   default )r    r   r   r   r2   r   listkeysanyr;   _format_table_cell_human
_to_headerr8   r   joindumpsstrr   )r&   r8   r5   r6   r7   all_columnsr>   r=   hrowsrowrE   formatted_rowsscreaming_headerskscreaming_alignments	quiet_keys         `          r   tableOutput.tableR   s     ))L/)//2L2F2L2LL-.  *..$K?uQx}}/K&1fksS8e_d8e5eskGf;@A54g.g!g.5Aii+%++os8toshk_b9c_bZ[:RST:U_b9cos8t<C$DGqZ]G!$DFPFVTVE]E]E_'`E_TQ
1q(8E_$'`h~Uijk+%++dii()C$))#M#MMN  *%**djjec:;%++"0gaj	!D$((9b12 " , g.A :d8t$D'`sH   J5J	JJ	%J	JJ2J J3J$	JJ)r6   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.
NrI      )indentrH   )dataclassesis_dataclass
isinstancetype_dataclass_to_dictr    r   r   r2   r;   r   r   rP   rQ   )r&   r]   r6   r`   s       r   dictOutput.dict   s    
 ##D))*T42H2H%d+D99,222v7I$((62&'ii#7#=#==4djjc:;r   messagec                    U R                   =[        R                  :X  ak    [        R                  " 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   ✓ Nz  z: 
= rG   rI   r   )r    r   r   r   greenr8   appendr2   rO   r   r   rP   rQ   r   rJ   values)r&   rh   r]   partsrX   rE   ro   s          r   resultOutput.result   s   ii+%++d7)$456 JJLDA}r!Bqc]3 ) dii&'+%++04

NA3asNchhuoG<*%**tdjjs3D%++dkkm,&)$  ,	 Os   3	E7 E7F)rH   yesrH   rs   c                    U(       a  gU R                   [        R                  :w  a  [        U S35      e[        R
                  " XSS9  g)zF
Ask for confirmation. Raises `ConfirmationError` in non-human modes.
Nz  Use --yes to skip confirmation.T)rH   abort)r    r   r   r   typerconfirm)r&   rh   rH   rs   s       r   rw   Output.confirm   s>     99,222#wi/O$PQQ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&   rh   statuss      r   r|   Output.status   s3    DII1E1K1K$KL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   r2   r   yellowsysstderrr&   rh   s     r   warningOutput.warning   sH    99,222$++	'343::FIgY'cjj9r   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   r2   r   redr   r   r   s     r   errorOutput.error   sH    99,222$((WWI./cjjAGG9%CJJ7r   c                     U R                   [        R                  :X  a0  [        [        R
                  " SU 35      [        R                  S9  g[        SU 3[        R                  S9  g)zEPrint a helpful hint to stderr (human: gray, agent/json: plain text).zHint: r   N)r    r   r   r2   r   grayr   r   r   s     r   hintOutput.hint   sH    99,222$))fWI./cjjAF7)$3::6r   )r    )r!   Nr#   )r   r   r   r   r   r   __annotations__r'   r   r$   boolr,   rQ   r3   r   rf   r   rJ   r[   rq   rw   r   r|   r   r   r   r   r   r   r   r   r   *   s     5I4M4M $1 $RV $7$ 7!$\` !d
 !S4Z !sUYz !ei !* %)!,0,3S#X',3 cT!	,3
 d
,3 cNT),3 
,3\ 7; < <t <t <%c %3 %4 %& 8=% <s < <4 <TX <cDj J :s :t :8S 8T 87C 7D 7r   r   rE   r!   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.)rc   datetime	isoformatrf   r8   _serialize_valuerJ   )rE   keyvalr=   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.)ra   asdictr8   r   )r   rX   rE   s      r   re   re      sC    /:/A/A$/G/M/M/Oa/OtqST"A""/Oaaas
   	A	A	z\033\[[0-9;]*m#   r3   c                 .    [         R                  SU 5      $ )NrI   )_ANSI_REsubr3   s    r   r1   r1      s    <<D!!r   c                 @    SR                  U R                  5       5      $ )Nrl   )rO   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   rN   rN      s!    
 (D1A779r   valuec                 z   U c  g[        U [        5      (       a  U (       a  S$ 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.NrI   u   ✔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r#   )_format_table_value_humanrD   s     r   r?   ,_format_table_value_human.<locals>.<genexpr>   s     Eu!2155urF   r   )rc   r   r   strftimerQ   r   matchr   rJ   rO   rf   r   rP   r   s    r   r   r      s    }%u%2%%**++~~j))%"((+A5"I"ISbz%E""%yyEuEEE	E4	 	 U?E&M 233DJJu-..E
##r   max_lenc                 P    [        U 5      n[        U5      U:  a  USUS-
   S-   nU$ )z/Format a value + truncate it for table display.N   z...)r   len)r   r   cells      r   rM   rM     s2    $U+D
4y7Mgk"U*Kr   c                     [        U [        R                  5      (       a  U R                  5       $ [        [	        U 5      5      $ )zHFormat a cell value for agent TSV output (ISO timestamps, tabs escaped).)rc   r   r   r   rQ   r   s    r   rC   rC   	  s1    %**++  E
##r   )'r   ra   r   r   r   r   collections.abcr   enumr   typingr   rv   huggingface_hub.errorsr   huggingface_hub.utilsr   r   r	   r
   r   rQ   r   r   objectr   rf   re   compiler   _MAX_CELL_LENGTHr1   r   rN   r   intrM   rC   outr   r   r   <module>r      s   )    	 
 $    4 ] ]3 Z7 Z7@ 6 bS bT#s(^ b
 ::'( "c "c ""s "s "S S $S $S $* 9I C # S $C $C $ hr   