o
    ߥi(                     @   s  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	m
Z
 d dlZd dlmZ e	eef Zee Zeeef Zee Zeegef ZG dd de jZdeddfdd	Zd
ededefddZdee deee  fddZdededededee defddZdedededee def
ddZdee deddfddZedkrze  W dS  e y Z! ze"ee! W Y dZ![!dS dZ![!w e#y   e"d  Y dS w dS )!    N)CallableIterableListOptionalPatternTupleUnioncast)regex_chooserc                   @   s   e Zd ZU eed< eee  ed< eee  ed< ee ed< eed< e	ed< eed< eed< eed	< eed
< ee	 ed< 					ddeee  deee  deee  dededdfddZ
dS )	TypedArgspathsfilterreverse_filterexcludereversenumber_typenosignsignnoexplocaleentriesNFreturnc                 C   sF   || _ || _|du rg n|| _|| _|| _d| _d| _d| _d| _dS )zUsed by testing onlyNintFT)	r   r   r   r   r   r   signedexpr   )selfr   r   r   r   r    r   D/home/ubuntu/.local/lib/python3.10/site-packages/natsort/__main__.py__init__   s   	
zTypedArgs.__init__)NNNFF)__name__
__module____qualname__bool__annotations__r   r   NumPairNumstrr   r   r   r   r   r      s<   
 


r   	argumentsr   c               
   G   s  ddl m}m} ddlm} ||tttj|d}|j	ddd
tjd |j	d	d
dddd |j	dddtdddd |j	dddtddddd |j	ddtddd |j	dd ddd!d" |j	d#d$d%d&d'd(d)d* |j	d+dd,d-d.d/ |j	d0d1ddd-d2d/ |j	d3d4d,d5d6d/ |j	d7d8ddd9d" |j	d:d;tjd<d= |j| pd>t d?}t|j|_t|j|_d@dA |jD }t|| d>S )Bzn
    Performs a natural sort on entries given on the command-line.

    Arguments are read from sys.argv.
    r   )ArgumentParserRawDescriptionHelpFormatter)dedent)descriptionformatter_classz	--versionversionz%(prog)s {})actionr-   z-pz--pathsF
store_truea  Interpret the input as file paths.  This is not strictly necessary to sort all file paths, but in cases where there are OS-generated file paths like "Folder/" and "Folder (1)/", this option is needed to make the paths sorted in the order you expect ("Folder/" before "Folder (1)/").)defaultr.   helpz-fz--filter   )LOWHIGHappendzPUsed for keeping only the entries that have a number falling in the given range.)nargstypemetavarr.   r1   z-Fz--reverse-filterr   zMUsed for excluding the entries that have a number falling in the given range.)r6   r7   r8   r.   destr1   z-ez	--excludez9Used to exclude an entry that contains a specific number.)r7   r.   r1   z-rz	--reversezReturns in reversed order.)r.   r0   r1   z-tz--number-typez--number_typer   )r   floatrealfirr   a"  Choose the type of number to search for. "float" will search for floating-point numbers.  "int" will only search for integers. "real" is a shortcut for "float" with --sign. "i" is a synonym for "int", "f" is a synonym for "float", and "r" is a synonym for "real".The default is %(default)s.)r9   choicesr0   r1   z--nosignstore_falser   znDo not consider "+" or "-" as part of a number, i.e. do not take sign into consideration. This is the default.)r0   r.   r9   r1   z-sz--signzdConsider "+" or "-" as part of a number, i.e. take sign into consideration. The default is unsigned.z--noexpTr   zDo not consider an exponential as part of a number, i.e. 1e4, would be considered as 1, "e", and 4, not as 10000.  This only effects the --number-type=float.z-lz--localez_Causes natsort to use locale-aware sorting. You will get the best results if you install PyICU.r   *zNThe entries to sort. Taken from stdin if nothing is given on the command line.)r6   r0   r1   N)	namespacec                 S   s   g | ]}|  qS r   )strip).0er   r   r   
<listcomp>       zmain.<locals>.<listcomp>)argparser(   r)   textwrapr*   r	   r&   main__doc__add_argumentformatnatsort__version__r:   sysstdin
parse_argsr   check_filtersr   r   r   sort_and_print_entries)r'   r(   r)   r*   parserargsr   r   r   r   rJ   2   s   

		rJ   lowhighc                 C   s   | |krt d| |fS )a  
    Verify that that given range has a low lower than the high.

    Parameters
    ----------
    low : {float, int}
    high : {float, int}

    Returns
    -------
    tuple : low, high

    Raises
    ------
    ValueError
        Low is greater than or equal to high.

    zlow >= high)
ValueError)rW   rX   r   r   r   range_check   s   rZ   filtersc              
   C   sB   | sdS zdd | D W S  t y  } zt dt| d}~ww )a  
    Execute range_check for every element of an iterable.

    Parameters
    ----------
    filters : iterable
        The collection of filters to check. Each element
        must be a two-element tuple of floats or ints.

    Returns
    -------
    The input as-is, or None if it evaluates to False.

    Raises
    ------
    ValueError
        Low is greater than or equal to high for any element.

    Nc                 S   s   g | ]}t |d  |d qS )r      )rZ   rD   r<   r   r   r   rF      s    z!check_filters.<locals>.<listcomp>zError in --filter: )rY   r&   )r[   errr   r   r   rS      s   rS   entrylowshighs	converterregexc                    s    t  fdd|| D S )a  
    Check if an entry falls into a desired range.

    Every number in the entry will be extracted using *regex*,
    if any are within a given low to high range the entry will
    be kept.

    Parameters
    ----------
    entry : str
    lows : iterable
        Collection of low values against which to compare the entry.
    highs : iterable
        Collection of high values against which to compare the entry.
    converter : callable
        Function to convert a string to a number.
    regex : regex object
        Regular expression to locate numbers in a string.

    Returns
    -------
    True if the entry should be kept, False otherwise.

    c                 3   s@    | ]}t D ]\}}| |  ko|kn  V  q	qd S N)zip)rD   numrW   rX   rb   ra   r`   r   r   	<genexpr>  s    z#keep_entry_range.<locals>.<genexpr>anyfindall)r_   r`   ra   rb   rc   r   rg   r   keep_entry_range   s   rl   valuesc                    s    t  fdd|| D  S )a)  
    Check if an entry does not match a given value.

    Every number in the entry will be extracted using *regex*,
    if any match a given value the entry will not be kept.

    Parameters
    ----------
    entry : str
    values : iterable
        Collection of values against which to compare the entry.
    converter : callable
        Function to convert a string to a number.
    regex : regex object
        Regular expression to locate numbers in a string.

    Returns
    -------
    True if the entry should be kept, False otherwise.

    c                 3   s    | ]	} |v V  qd S rd   r   )rD   rf   rb   rm   r   r   rh   +  s    z#keep_entry_value.<locals>.<genexpr>ri   )r_   rm   rb   rc   r   rn   r   keep_entry_value  s    ro   r   rV   c                    sx  |j dv }|jp|j dv }tjj| tjj| B tjj|j  B tjj|j	 B tjj
|j B }|jdup8|jdu}|s>|jrtjj| tjj| B tjj|j  B }t||jdurwdd |jD dd |jD fdd| D } |jdurdd |jD d	d |jD fd
d| D } |jrt|j  fdd| D } tj| |j|dD ]}t| qdS )z:Sort the entries, applying the filters first if necessary.)r:   r;   r<   r>   )r;   r>   Nc                 S      g | ]}|d  qS r   r   r]   r   r   r   rF   H  rG   z*sort_and_print_entries.<locals>.<listcomp>c                 S   rp   r\   r   r]   r   r   r   rF   H  rG   c                    s    g | ]}t | tr|qS r   rl   r:   rD   r_   ra   r`   rc   r   r   rF   I      c                 S   rp   rq   r   r]   r   r   r   rF   P  rG   c                 S   rp   rr   r   r]   r   r   r   rF   Q  rG   c                    s    g | ]}t | ts|qS r   rs   rt   ru   r   r   rF   S  rv   c                    s   g | ]}t | tr|qS r   )ro   r:   rt   )r   rc   r   r   rF   Z  s    )r   alg)r   r   rN   nsFLOATSIGNEDNOEXPr   PATHr   LOCALEr   r   r   r   r
   set	natsortedr   print)r   rV   is_floatr   rw   	do_filterinp_optionsr_   r   )r   ra   r`   rc   r   rT   .  sR   






"


rT   __main__r\   )$rH   rP   typingr   r   r   r   r   r   r   r	   rN   natsort.utilsr
   r:   r   r%   NumIterr$   NumPairIterr&   NumConverter	Namespacer   rJ   rZ   rS   r"   rl   ro   rT   r   rY   aexitKeyboardInterruptr   r   r   r   <module>   sd   (! 
&
7