
    bi                     l    d dl Z d dlZd dlZd dlZd dlmZmZ d Zd Zd Zd Z	d Z
edk(  r e
        yy)	    N)FileStrc                     t        j                  d      } | j                  dddgd       | j                  dd	d
d       | j                  ddd
d       | j                  ddd
d       | j                  ddd
d       | j                  ddd
d       | j                  ddd       | j                  ddt        j                         | j                         S ) NzPrint newline, word, and byte counts for each FILE, and a total line if more than one FILE is         specified. A word is a non-zero-length sequence of acters delimited by white space.)descriptionfiles*-zFiles to process)nargsdefaulthelpz-cz--bytes
store_truezprint the byte counts)actionr   z-mz--charszprint the character countsz-lz--lineszprint the newline countsz-Lz--max-line-lengthzprint the maximum display widthz-wz--wordszprint the word countsz--files0-fromfilenameztRead input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input)metavarr   z	--versionversion)r   r   )argparseArgumentParseradd_argumentstringzilla__version__
parse_args)parsers    A/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cli/wc.pyparse_argumentsr   	   s   $$]F sSE@RS
i3J   i3O   i3M   .	   i3J   9   I{?V?VW    c                 \   | dk(  r*t         j                  j                         }t        |      }n	 t	        |       }t        |      }i }|j                  r|j                  d      |d<   |j                  r|j                  d      dz   |d<   |j                  r|j                         |d	<   |j                  r&t        d
 |j                  d      D              }||d<   |j                  r+|j                  r|d	   |d<   |dfS |j                         |d<   |dfS # t
        $ r
 d|  dfcY S w xY w)Nr	   zNo such file: F

line_count    
word_count
char_countc              3   2   K   | ]  }t        |        y wN)len).0lines     r   	<genexpr>zwc.<locals>.<genexpr>@   s     MDc$iMs   max_line_length
byte_countT)sysstdinreadr   r   RuntimeErrorlinescountwordschars__len__r)   maxsplitbytes)	file_pathargscontentmapped_bytesmapped_filecountsr)   s          r   wcr=   ,   s3   C)).."7|	7y/K{+L Fzz+11$7|zz+11#6:|zz+335|ML4F4Ft4LMM$3 !zz::#),#7F<  4< $0#7#7#9F< 4<+  	7#I;/66	7s   D D+*D+c                    g }|j                   r|j                  | d          |j                  r|j                  | d          |j                  r|j                  | d          |j                  r|j                  | d          |j
                  r!|j                  | j                  dd             dj                  fd|D              S )	Nr   r!   r"   r*   r)   r   r   c              3   R   K   | ]  }t        |      j                           y wr$   )strrjust)r&   r0   justs     r   r(   z format_output.<locals>.<genexpr>Y   s      HuCJ$$T*Hs   $')r/   appendr1   r2   r6   r)   getjoin)r<   r8   rB   selected_countss     ` r   format_outputrG   L   s    Ozzvl34zzvl34zzvl34zzvl34vzz*;Q?@88HHHHr   c                     t        | d      }|j                         }|j                          |j                  d      D cg c]$  }t        j
                  j                  |      s#|& c}S c c}w )Nr )openr-   closer5   ospathisfile)fnfsxs       r   get_files_fromrT   \   sL    RA	AGGIwwt}:!q(9A:::s    $A,%A,c            	      (   t               } dddddd}t        | j                  | j                  | j                  | j
                  | j                  g      sd| _        d| _        d| _        | j                  rO| j                  d   dk(  r=t        | j                        | _        t        | j                        dk(  rt        d       t        d | j                  D              }| j                  D ]o  }t        ||       \  }}|rQ|j                         D ]  }||xx   |j                  |d      z  cc<   ! t!        || |      d| z   }t#        |       et#        |       q t        | j                        dkD  rt!        || |      dz   }t#        |       y y )Nr   )r   r!   r"   r)   r*   r    r	   c              3   ~   K   | ]5  }t        t        t        j                  |      j                               7 y wr$   )r%   r@   rM   statst_size)r&   rP   s     r   r(   zmain.<locals>.<genexpr>y   s(     Bs3rwwr{**+,Bs   ;=r   z total)r   anyr/   r1   r2   r6   r)   files0_fromr   rT   r%   exitr4   r=   keysrD   rG   print)	r8   total_countsrB   r7   r<   successkeyoutputtotal_outputs	            r   mainrc   c   sj   DL 

DJJ

DJJ@T@TUV


 ::a=C'(8(89DJ4::!#QBtzzBBDZZ 	Y-#((* 8S!VZZQ%77!8"6461YKHF&M&M 4::$\4>Il r   __main__)r+   rM   r   r   r   r   r   r=   rG   rT   rc   __name__ r   r   <module>rg      sD       ! F@I ;$N zF r   