
    Ng^&                         d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ dZd Zd	 Z d
 Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(ddZ)dS )aN  
Usage: humanfriendly [OPTIONS]

Human friendly input/output (text formatting) on the command
line based on the Python package with the same name.

Supported options:

  -c, --run-command

    Execute an external command (given as the positional arguments) and render
    a spinner and timer while the command is running. The exit status of the
    command is propagated.

  --format-table

    Read tabular data from standard input (each line is a row and each
    whitespace separated field is a column), format the data as a table and
    print the resulting table to standard output. See also the --delimiter
    option.

  -d, --delimiter=VALUE

    Change the delimiter used by --format-table to VALUE (a string). By default
    all whitespace is treated as a delimiter.

  -l, --format-length=LENGTH

    Convert a length count (given as the integer or float LENGTH) into a human
    readable string and print that string to standard output.

  -n, --format-number=VALUE

    Format a number (given as the integer or floating point number VALUE) with
    thousands separators and two decimal places (if needed) and print the
    formatted number to standard output.

  -s, --format-size=BYTES

    Convert a byte count (given as the integer BYTES) into a human readable
    string and print that string to standard output.

  -b, --binary

    Change the output of -s, --format-size to use binary multiples of bytes
    (base-2) instead of the default decimal multiples of bytes (base-10).

  -t, --format-timespan=SECONDS

    Convert a number of seconds (given as the floating point number SECONDS)
    into a human readable timespan and print that string to standard output.

  --parse-length=VALUE

    Parse a human readable length (given as the string VALUE) and print the
    number of metres to standard output.

  --parse-size=VALUE

    Parse a human readable data size (given as the string VALUE) and print the
    number of bytes to standard output.

  --demo

    Demonstrate changing the style and color of the terminal font using ANSI
    escape sequences.

  -h, --help

    Show this message and exit.
    N)Timerformat_lengthformat_numberformat_sizeformat_timespanparse_length
parse_size)format_pretty_tableformat_smart_table)
ANSI_COLOR_CODESANSI_TEXT_STYLESHIGHLIGHT_COLOR
ansi_strip	ansi_wrapenable_ansi_supportfind_terminal_sizeoutputusagewarning)Spinner)demonstrate_256_colorsdemonstrate_ansi_formattingmainprint_formatted_lengthprint_formatted_numberprint_formatted_sizeprint_formatted_tableprint_formatted_timespanprint_parsed_lengthprint_parsed_sizerun_commandc                  \   t                       	 t          j        t          j        dd         dg d          \  } }n;# t          $ r.}t          d|           t          j        d           Y d}~nd}~ww xY wg }d}d}t          d | D                       }| D ]\  }}|dv r|}|d	k    r.|                    t          j
        t          |                     A|d
k    r.|                    t          j
        t          |                     u|dv r.|                    t          j
        t          |                     |dv r.|                    t          j
        t          |                     |dv r/|                    t          j
        t          |                     |dv r0|                    t          j
        t           ||                     @|dk    rd}J|dv r/|                    t          j
        t"          |                     }|dk    r|                    t$                     |dv rt'          t(                      dS |r-|                    t          j
        t*          |                     |st'          t(                     dS |D ]}	 |	             dS )z9Command line interface for the ``humanfriendly`` program.   Nzcd:l:n:s:bt:h)zrun-commandzformat-tablez
delimiter=zformat-length=zformat-number=zformat-size=binaryzformat-timespan=zparse-length=zparse-size=demohelpz	Error: %sFc              3   $   K   | ]\  }}|d v V  dS ))z-bz--binaryN ).0ovs      M/var/www/html/ai-engine/env/lib/python3.11/site-packages/humanfriendly/cli.py	<genexpr>zmain.<locals>.<genexpr>   s,      ==TQ((======    )z-dz--delimiterz--parse-sizez--parse-length)z-cz--run-command)z-lz--format-length)z-nz--format-number)z-sz--format-sizez--format-tableT)z-tz--format-timespanz--demo)z-hz--help)r   getoptsysargv	Exceptionr   exitanyappend	functoolspartialr    r   r!   r   r   r   r   r   r   __doc__r   )
options	argumentseactions	delimitershould_format_tabler$   optionvaluer7   s
             r,   r   r      s   #]38ABB< K
 K
 K
  
    Q GI==W=====F   ***II~%%NN9,->FFGGGG'''NN9,-@%HHIIII...NN9,[)DDEEEE000NN9,-CUKKLLLL000NN9,-CUKKLLLL...NN9,-A5&QQRRRR'''"&222NN9,-EuMMNNNNxNN67777''''NNNFF (  Ly()>	JJKKK g  				 s   -> 
A6$A11A6c                    t                      }dd                    t          t          j        |                     z  }t          ||          5 }t          j        |           }	 |                                 |	                                 |
                                n>	 ddd           n# 1 swxY w Y   t          j        |j                   dS )zHRun an external command and show a spinner while the command is running.zWaiting for command: %s )labeltimerTN)r   joinmappipesquoter   
subprocessPopenstepsleeppollr0   r3   
returncode)command_linerD   spinner_labelspinnerprocesss        r,   r!   r!      s    GGE-U[,9W9W0X0XXM	}E	2	2	2 g"<00	LLNNNMMOOO||~~)		                HW     s   AB11B58B5c                     d| v r+t          t          t          |                                dS t          t          t          |                                dS )zPrint a human readable length..N)r   r   floatintr@   s    r,   r   r      sO    
e||}U5\\**+++++}SZZ(()))))r.   c                 X    t          t          t          |                                dS )z/Print large numbers in a human readable format.N)r   r   rU   rW   s    r,   r   r      s$    
=u&&'''''r.   c                 \    t          t          t          |           |                     dS )zPrint a human readable size.)r$   N)r   r   rV   )r@   r$   s     r,   r   r      s)    
;s5zz&11122222r.   c                     g }t           j        D ]>}|                                }|                    |                    |                      ?t          t          |                     dS )z8Read tabular data from standard input and print a table.N)r0   stdinrstripr5   splitr   r
   )r=   datalines      r,   r   r      sc    D	 + +{{}}DJJy))****
t$$%%%%%r.   c                 X    t          t          t          |                                dS )z Print a human readable timespan.N)r   r   rU   rW   s    r,   r   r      s$    
?5<<(()))))r.   c                 >    t          t          |                      dS )z=Parse a human readable length and print the number of metres.N)r   r   rW   s    r,   r   r      s    
<r.   c                 >    t          t          |                      dS )z?Parse a human readable data size and print the number of bytes.N)r   r	   rW   s    r,   r    r       s    
:er.   c            
         t          dt          dd                     ddg} |                     t          j                               t          |           D ]e}t          t                    }|dk    rd||<   |                    dd	          	                                }t          d
t          |fi |           fdD ]\  }dt                      fdt          d          fgdk    r&
                    ddt          d          f           t          dt          d|z  d          z             t          t          fdt          t          j                              D             dgd D             z                        t          ddd           t          ddd           t          ddd           t          dd d!           d"S )#z-Demonstrate the use of ANSI escape sequences.z%szText styles:Tboldnormalbrightcolor_rB   z - %s))ri   zForeground colors)
backgroundzBackground colors)rg   rk   r   faint)rl   z
%s%s:c                 8    g | ]gfd D             z   S )c                     g | ]L\  }}t          d k    rdndfi t          t          |                                          fgz             MS )rk   XXXXXXz      )r   dictlistitems)r)   rC   kw
color_name
color_types      r,   
<listcomp>z:demonstrate_ansi_formatting.<locals>.<listcomp>.<listcomp>   s|         eR  *l : :HH 4

++
J/G.HHII   r.   r(   )r)   ru   rv   intensitiess    @r,   rw   z/demonstrate_ansi_formatting.<locals>.<listcomp>   s`     #
 #
 #
  L      $/	   #
 #
 #
r.   Colorc                 <    g | ]\  }}|                                 S r(   )
capitalize)r)   rC   rt   s      r,   rw   z/demonstrate_ansi_formatting.<locals>.<listcomp>  s5     %
 %
 %
#,5"E%
 %
 %
r.   )column_names   zstandard colors      zhigh-intensity colors      z
216 colors      zgray scale colorsN)r   r   extendr   keyssortedrq   r   replacer{   insertr   r   r   )styles
style_namer9   style_labelcolor_labelrv   rx   s        @@r,   r   r      sA    4>555666!F
MM"'))***Vnn ; ;
_---!!"&GJ ((c22==??w	+9999::::$I  
K tvvt4((()
 %%q7Dt,<,<,<"=>>>v	%+"5DAAAABBB! #
 #
 #
 #
 #
 !''7'<'>'> ? ?#
 #
 #
 !	 %
 %
0;%
 %
 %
 
	 	 	 		 		 		 		 1a!23331b"9:::2sL1113%899999r.   c                   	
 d}|r|d|z  z  }t          dt          d|z  d          z              d                    d t          | |d	z             D                       }t	                      \  }}|t          t          |                    k    rt          |           dS t          t          |                    d	z   
t          |
z            	
fd
t          | |d	z             D             	fdt          dt                    	          D             }t          d                    d |D                                  dS )z#Demonstrate 256 color mode support.z256 color modez (%s)
rm   Trd    c              3   X   K   | ]%}d t          t          |          |          z   V  &dS )rB   rh   N)r   str)r)   ns     r,   r-   z)demonstrate_256_colors.<locals>.<genexpr>  s:      TTq#	#a&& : : ::TTTTTTr.   r#   c                 r    g | ]3}t          t          |                                        |           4S )rh   )r   r   rjust)r)   r   widths     r,   rw   z*demonstrate_256_colors.<locals>.<listcomp>!  s8    SSSa)CFFLL//q999SSSr.   c                 *    g | ]}||z            S r(   r(   )r)   r   colorscolors_per_lines     r,   rw   z*demonstrate_256_colors.<locals>.<listcomp>"  s(    ```A&1../```r.   r   c              3   @   K   | ]}d                      |          V  dS )r   N)rE   )r)   bs     r,   r-   z)demonstrate_256_colors.<locals>.<genexpr>#  s,      44444444r.   N)	r   r   rE   ranger   lenr   r   rV   )ijgrouprC   single_linelinescolumnsblocksr   r   r   s           @@@r,   r   r     s^    E !5 
4)EEM5555666 ''TTE!QQRUOOTTTTTK'))NE7#j--....{ CFFago..SSSS5APQE??SSS`````q#f++9_9_```tyy44V4444455555r.   )N)*r8   r6   r/   rG   rI   r0   humanfriendlyr   r   r   r   r   r   r	   humanfriendly.tablesr
   r   humanfriendly.terminalr   r   r   r   r   r   r   r   r   r   humanfriendly.terminal.spinnersr   __all__r   r!   r   r   r   r   r   r   r    r   r   r(   r.   r,   <module>r      s  F FR           



                  I H H H H H H H                        4 3 3 3 3 3. . .b! ! !* * *( ( (
3 3 3
& & &* * *
     
  
$: $: $:N6 6 6 6 6 6r.   