
    EKg]                        d Z ddlZddlmZ ddlmZ ddl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ZddlmZ ddlmZmZmZ dd	lmZmZ  ed
      Z ede      Ze
egef   Ze
egef   Z de!de
e	ge	f   fdZ"de	de	fdZ#de	de	fdZ$dejJ                  fdee
e	gef      dede
e	gef   fdZ& e&       Z'de'_         ddejJ                  fdee   dee
egef      de(dedee   f
dZ)ddejJ                  fdee   dee
egef      de(dedee   f
dZ*ddejJ                  fdee   dee
egef      de(dedee   f
dZ+ddejJ                  fdee   dee
egef      de(dedee,   f
dZ-ddejJ                  fdee   dee
egef      de(dedee,   f
dZ.ddejJ                  fdee   dee
egef      de(dedee,   f
dZ/	 d1dee	   d ee,   d!e(dee	   fd"Z0dede!fd#Z1	 d2d$e	dee
egef      d%e(dee!   fd&Z2 ejf                         d'k(  rtdd(l4m5Z5m6Z6 dd)lm7Z7 e6jp                  jr                  Z:e5jv                  e5jv                  ge:_<        e5jz                  e:_>         e7e:      Z?	 d3dee
e	gef      de
e	gef   fd*Z@n	 ddlAZA	 d3dee
e	gef      de
e	gef   fd+Z@d-e@_          e@       ZCd.eC_         	 	 	 d4dee   dee
egef      de(d/e(dee   f
d0ZDy# eB$ r 	 d3dee
e	gef      de
e	gef   fd,Z@Y Ww xY w)5z
Along with ns_enum.py, this module contains all of the
natsort public API.

The majority of the "work" is defined in utils.py.
    N)partial)
itemgetter)PurePath)
AnyCallableIterableIteratorListOptionalSequenceTupleTypeVarcast)utils)NSTypeNS_DUMBns)NatsortInTypeNatsortOutTypeTNatsortInTypeT)boundencodingreturnc                 8    t        t        j                  |       S )a  
    Return a function that can be used to decode bytes to unicode.

    Parameters
    ----------
    encoding : str
        The codec to use for decoding. This must be a valid unicode codec.

    Returns
    -------
    decode_function
        A function that takes a single argument and attempts to decode
        it using the supplied codec. Any `UnicodeErrors` are raised.
        If the argument was not of `bytes` type, it is simply returned
        as-is.

    See Also
    --------
    as_ascii
    as_utf8

    Examples
    --------

        >>> f = decoder('utf8')
        >>> f(b'bytes') == 'bytes'
        True
        >>> f(12345) == 12345
        True
        >>> # On Python 3, without decoder this would return [b'a10', b'a2']
        >>> natsorted([b'a10', b'a2'], key=decoder('utf8')) == [b'a2', b'a10']
        True
        >>> # On Python 3, without decoder this would raise a TypeError.
        >>> natsorted([b'a10', 'a2'], key=decoder('utf8')) == ['a2', b'a10']
        True

    r   )r   r   do_decodingr   s    S/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/natsort/natsort.pydecoderr   *   s    L 5$$x88    sc                 .    t        j                  | d      S )ap  
    Function to decode an input with the ASCII codec, or return as-is.

    Parameters
    ----------
    s : object

    Returns
    -------
    output
        If the input was of type `bytes`, the return value is a `str` decoded
        with the ASCII codec. Otherwise, the return value is identically the
        input.

    See Also
    --------
    decoder

    asciir   r   r!   s    r   as_asciir&   S       ( Q((r    c                 .    t        j                  | d      S )ap  
    Function to decode an input with the UTF-8 codec, or return as-is.

    Parameters
    ----------
    s : object

    Returns
    -------
    output
        If the input was of type `bytes`, the return value is a `str` decoded
        with the UTF-8 codec. Otherwise, the return value is identically the
        input.

    See Also
    --------
    decoder

    zutf-8r$   r%   s    r   as_utf8r)   j   r'   r    keyalgc           	         	 t         j                  |z   |t         j                  z  r1t        j                  j                  j                         r	|t        z  }|t         j                  z  r|t         j                  z  r%t        j                  j                  j                  }n$t        j                  j                  j                  }t        j                  j                  j                  }n|t         j                  z  r%t        j                  j                  j                  }n$t        j                  j                  j                   }t        j                  j                  j                   }t#        j$                  |      }t#        j&                  |      }t#        j(                  |      }t#        j*                  |||      }t#        j,                  |||j.                  |||      }	|t         j0                  z  rt#        j2                  |	      }	t#        j4                  |      }
t#        j6                  |||      }t9        t"        j:                  | |	|
|      S # t        $ r) d}t        |dj	                  t        |            z         w xY w)aD  
    Generate a key to sort strings and numbers naturally.

    This key is designed for use as the `key` argument to
    functions such as the `sorted` builtin.

    The user may customize the generated function with the
    arguments to `natsort_keygen`, including an optional
    `key` function.

    Parameters
    ----------
    key : callable, optional
        A key used to manipulate the input value before parsing for
        numbers. It is **not** applied recursively.
        It should accept a single argument and return a single value.

    alg : ns enum, optional
        This option is used to control which algorithm `natsort`
        uses when sorting. For details into these options, please see
        the :class:`ns` class documentation. The default is `ns.INT`.

    Returns
    -------
    out : function
        A function that parses input for natural sorting that is
        suitable for passing as the `key` argument to functions
        such as `sorted`.

    See Also
    --------
    natsorted
    natsort_key

    Examples
    --------
    `natsort_keygen` is a convenient way to create a custom key
    to sort lists in-place (for example).::

        >>> a = ['num5.10', 'num-3', 'num5.3', 'num2']
        >>> a.sort(key=natsort_keygen(alg=ns.REAL))
        >>> a
        ['num-3', 'num2', 'num5.10', 'num5.3']

    z9natsort_keygen: 'alg' argument must be from the enum 'ns'z, got {})r*   string_func
bytes_funcnum_func)r   DEFAULT	TypeError
ValueErrorformatstrLOCALEALPHAnatsortcompatlocale	dumb_sortr   NUMAFTERnull_string_locale_maxnull_string_maxnull_string_localenull_stringr   regex_chooserinput_string_transform_factory"string_component_transform_factoryfinal_data_transform_factoryparse_string_factorysplitPATHparse_path_factoryparse_bytes_factoryparse_number_or_none_factoryr   natsort_key)r*   r+   msgseppre_sepregexinput_transformcomponent_transformfinal_transformr-   r.   r/   s               r   natsort_keygenrQ      s   `<


S R^^ 5 5 ? ? Aw R[[..''>>C..''77C..''77..''::C..''33C..''33$E ::3?OBB3G88c7KO ,,S%++0C_K RWW}..{;**3/J11#sGDH  M  <Iz00S::;;<s   I 2Jznatsort_key(val)
The default natural sorting key.

This is the output of :func:`natsort_keygen` with default values.

See Also
--------
natsort_keygen

Fseqreversec                 |    |t         j                  z  rt        | |t              } t        | |t	        ||            S )a  
    Sorts an iterable naturally.

    Parameters
    ----------
    seq : iterable
        The input to sort.

    key : callable, optional
        A key used to determine how to sort each element of the iterable.
        It is **not** applied recursively.
        It should accept a single argument and return a single value.

    reverse : {{True, False}}, optional
        Return the list in reversed sorted order. The default is
        `False`.

    alg : ns enum, optional
        This option is used to control which algorithm `natsort`
        uses when sorting. For details into these options, please see
        the :class:`ns` class documentation. The default is `ns.INT`.

    Returns
    -------
    out: list
        The sorted input.

    See Also
    --------
    natsort_keygen : Generates the key that makes natural sorting possible.
    realsorted : A wrapper for ``natsorted(seq, alg=ns.REAL)``.
    humansorted : A wrapper for ``natsorted(seq, alg=ns.LOCALE)``.
    index_natsorted : Returns the sorted indexes from `natsorted`.
    os_sorted : Sort according to your operating system's rules.

    Examples
    --------
    Use `natsorted` just like the builtin `sorted`::

        >>> a = ['num3', 'num5', 'num2']
        >>> natsorted(a)
        ['num2', 'num3', 'num5']

    rS   r*   )r   PRESORTsortedr4   rQ   rR   r*   rS   r+   s       r   	natsortedrY      s5    d RZZS's3#wN3,DEEr    c                 @    t        | |||t        j                  z        S )a-  
    Convenience function to properly sort non-numeric characters.

    This is a wrapper around ``natsorted(seq, alg=ns.LOCALE)``.

    Parameters
    ----------
    seq : iterable
        The input to sort.

    key : callable, optional
        A key used to determine how to sort each element of the sequence.
        It is **not** applied recursively.
        It should accept a single argument and return a single value.

    reverse : {{True, False}}, optional
        Return the list in reversed sorted order. The default is
        `False`.

    alg : ns enum, optional
        This option is used to control which algorithm `natsort`
        uses when sorting. For details into these options, please see
        the :class:`ns` class documentation. The default is `ns.LOCALE`.

    Returns
    -------
    out : list
        The sorted input.

    See Also
    --------
    index_humansorted : Returns the sorted indexes from `humansorted`.

    Notes
    -----
    Please read :ref:`locale_issues` before using `humansorted`.

    Examples
    --------
    Use `humansorted` just like the builtin `sorted`::

        >>> a = ['Apple', 'Banana', 'apple', 'banana']
        >>> natsorted(a)
        ['Apple', 'Banana', 'apple', 'banana']
        >>> humansorted(a)
        ['apple', 'Apple', 'banana', 'Banana']

    )rY   r   LOCALErX   s       r   humansortedr\   (  s    l S#wbii88r    c                 @    t        | |||t        j                  z        S )a  
    Convenience function to properly sort signed floats.

    A signed float in a string could be "a-5.7". This is a wrapper around
    ``natsorted(seq, alg=ns.REAL)``.

    The behavior of :func:`realsorted` for `natsort` version >= 4.0.0
    was the default behavior of :func:`natsorted` for `natsort`
    version < 4.0.0.

    Parameters
    ----------
    seq : iterable
        The input to sort.

    key : callable, optional
        A key used to determine how to sort each element of the sequence.
        It is **not** applied recursively.
        It should accept a single argument and return a single value.

    reverse : {{True, False}}, optional
        Return the list in reversed sorted order. The default is
        `False`.

    alg : ns enum, optional
        This option is used to control which algorithm `natsort`
        uses when sorting. For details into these options, please see
        the :class:`ns` class documentation. The default is `ns.REAL`.

    Returns
    -------
    out : list
        The sorted input.

    See Also
    --------
    index_realsorted : Returns the sorted indexes from `realsorted`.

    Examples
    --------
    Use `realsorted` just like the builtin `sorted`::

        >>> a = ['num5.10', 'num-3', 'num5.3', 'num2']
        >>> natsorted(a)
        ['num2', 'num5.3', 'num5.10', 'num-3']
        >>> realsorted(a)
        ['num-3', 'num2', 'num5.10', 'num5.3']

    )rY   r   REALrX   s       r   
realsortedr_   a  s    n S#wbgg66r    c                 f   t        d      }ndt        t        t        f   dt        ffd}t        |       D cg c]	  \  }}||f }}}|t        j                  z  r|j                  |d        |j                  |t        ||             |D cg c]  \  }}|	 c}}S c c}}w c c}}w )a  
    Determine the list of the indexes used to sort the input sequence.

    Sorts a sequence naturally, but returns a list of sorted the
    indexes and not the sorted list itself. This list of indexes
    can be used to sort multiple lists by the sorted order of the
    given sequence.

    Parameters
    ----------
    seq : iterable
        The input to sort.

    key : callable, optional
        A key used to determine how to sort each element of the sequence.
        It is **not** applied recursively.
        It should accept a single argument and return a single value.

    reverse : {{True, False}}, optional
        Return the list in reversed sorted order. The default is
        `False`.

    alg : ns enum, optional
        This option is used to control which algorithm `natsort`
        uses when sorting. For details into these options, please see
        the :class:`ns` class documentation. The default is `ns.INT`.

    Returns
    -------
    out : tuple
        The ordered indexes of the input.

    See Also
    --------
    natsorted
    order_by_index

    Examples
    --------

    Use index_natsorted if you want to sort multiple lists by the
    sorted order of one list::

        >>> a = ['num3', 'num5', 'num2']
        >>> b = ['foo', 'bar', 'baz']
        >>> index = index_natsorted(a)
        >>> index
        [2, 0, 1]
        >>> # Sort both lists by the sort order of a
        >>> order_by_index(a, index)
        ['num2', 'num3', 'num5']
        >>> order_by_index(b, index)
        ['baz', 'foo', 'bar']

       xr   c                 j     t        t        t        gt        f          t	        d      |             S Nra   )r   r   r   r   r   rb   r*   s    r   newkeyzindex_natsorted.<locals>.newkey  s.    :4!m!34c:=:a=;KLLr    c                 6    t         t        d      |             S rd   )r4   r   )rb   s    r   <lambda>z!index_natsorted.<locals>.<lambda>  s    3}z!}Q?O;Pr    rU   )
r   r   intr   r   	enumerater   rV   sortrQ   )	rR   r*   rS   r+   rf   rb   yindex_seq_pair_s	    `       r   index_natsortedro     s    | {A	MeCFm 	M 	M *338Aq!fN8
RZZG1PQ^FC-HI().$!QA.))	 9 *s   B'B-c                 @    t        | |||t        j                  z        S )a  
    This is a wrapper around ``index_natsorted(seq, alg=ns.LOCALE)``.

    Parameters
    ----------
    seq: iterable
        The input to sort.

    key: callable, optional
        A key used to determine how to sort each element of the sequence.
        It is **not** applied recursively.
        It should accept a single argument and return a single value.

    reverse : {{True, False}}, optional
        Return the list in reversed sorted order. The default is
        `False`.

    alg : ns enum, optional
        This option is used to control which algorithm `natsort`
        uses when sorting. For details into these options, please see
        the :class:`ns` class documentation. The default is `ns.LOCALE`.

    Returns
    -------
    out : tuple
        The ordered indexes of the input.

    See Also
    --------
    humansorted
    order_by_index

    Notes
    -----
    Please read :ref:`locale_issues` before using `humansorted`.

    Examples
    --------
    Use `index_humansorted` just like the builtin `sorted`::

        >>> a = ['Apple', 'Banana', 'apple', 'banana']
        >>> index_humansorted(a)
        [2, 0, 3, 1]

    )ro   r   r[   rX   s       r   index_humansortedrq     s    f 3WcBIIo>>r    c                 @    t        | |||t        j                  z        S )a(  
    This is a wrapper around ``index_natsorted(seq, alg=ns.REAL)``.

    Parameters
    ----------
    seq: iterable
        The input to sort.

    key: callable, optional
        A key used to determine how to sort each element of the sequence.
        It is **not** applied recursively.
        It should accept a single argument and return a single value.

    reverse : {{True, False}}, optional
        Return the list in reversed sorted order. The default is
        `False`.

    alg : ns enum, optional
        This option is used to control which algorithm `natsort`
        uses when sorting. For details into these options, please see
        the :class:`ns` class documentation. The default is `ns.REAL`.

    Returns
    -------
    out : tuple
        The ordered indexes of the input.

    See Also
    --------
    realsorted
    order_by_index

    Examples
    --------
    Use `index_realsorted` just like the builtin `sorted`::

        >>> a = ['num5.10', 'num-3', 'num5.3', 'num2']
        >>> index_realsorted(a)
        [1, 3, 0, 2]

    )ro   r   r^   rX   s       r   index_realsortedrs     s    ^ 3WcBGGm<<r    indexiterc                 N     |r fd|D        S |D cg c]  } |   	 c}S c c}w )a  
    Order a given sequence by an index sequence.

    The output of `index_natsorted` is a
    sequence of integers (index) that correspond to how its input
    sequence **would** be sorted. The idea is that this index can
    be used to reorder multiple sequences by the sorted order of the
    first sequence. This function is a convenient wrapper to
    apply this ordering to a sequence.

    Parameters
    ----------
    seq : sequence
        The sequence to order.

    index : iterable
        The iterable that indicates how to order `seq`.
        It should be the same length as `seq` and consist
        of integers only.

    iter : {{True, False}}, optional
        If `True`, the ordered sequence is returned as a
        iterator; otherwise it is returned as a
        list. The default is `False`.

    Returns
    -------
    out : {{list, iterator}}
        The sequence ordered by `index`, as a `list` or as an
        iterator (depending on the value of `iter`).

    See Also
    --------
    index_natsorted
    index_humansorted
    index_realsorted

    Examples
    --------

    `order_by_index` is a convenience function that helps you apply
    the result of `index_natsorted`::

        >>> a = ['num3', 'num5', 'num2']
        >>> b = ['foo', 'bar', 'baz']
        >>> index = index_natsorted(a)
        >>> index
        [2, 0, 1]
        >>> # Sort both lists by the sort order of a
        >>> order_by_index(a, index)
        ['num2', 'num3', 'num5']
        >>> order_by_index(b, index)
        ['baz', 'foo', 'bar']

    c              3   (   K   | ]	  }|     y wN ).0irR   s     r   	<genexpr>z!order_by_index.<locals>.<genexpr>  s     "EqCFEs   ry   )rR   rt   ru   r{   s   `   r   order_by_indexr}   P  s/    t '+"E"G0GAQ0GG0Gs   "c                 F    t        j                  |       j                  dd S )a'  
    Select an appropriate regex for the type of number of interest.

    Parameters
    ----------
    alg : ns enum
        Used to indicate the regular expression to select.

    Returns
    -------
    regex : str
        Regular expression string that matches the desired number type.

    ra   )r   r?   pattern)r+   s    r   numeric_regex_chooserr     s"      s#++Ab11r    v
treat_basec                     | ||       } t        | t        t        f      st        |       } t        j                  | |      S )Nr   )
isinstancer4   r   r   path_splitter)r   r*   r   s      r   _split_applyr     s<     Fa#x)FqZ88r    Windows)wintypeswindll)
cmp_to_keyc                 F     t        t        t        gt        f    fd      S )Nc           
      N    t        t        t        t        | d                  S )NFr   )tuplemap_winsort_keyr   re   s    r   rh   z os_sort_keygen.<locals>.<lambda>  s    eCl1ce.TUVr    )r   r   r   r   r*   s   `r   os_sort_keygenr     s$     cUN*+V
 	
r    c                 $    t         j                  j                  j                         }t        j
                  j                  |      j                  t        j                  j                  t        j                  j                          fdS )Nc           	      V    t        t        j                  t        |                   S rx   )r   r   
getSortKeyr   )rb   collatorr*   s    r   rh   z os_sort_keygen.<locals>.<lambda>  s    U3x':':LC<P#QRr    )r6   r7   r8   get_icu_localeicuCollatorcreateInstancesetAttributeUCollAttributeNUMERIC_COLLATIONUCollAttributeValueON)r*   locr   s   ` @r   r   r     se     ..''668C||2237H!!""44c6M6M6P6P SRr    c                 |    t        | t        j                  t        j                  z  t        j                  z        S )N)r*   r+   )rQ   r   r[   rE   
IGNORECASEr   s    r   r   r     s'     "cryy277/BR]]/RSSr    a  
Generate a sorting key to replicate your file browser's sort order

See :func:`os_sorted` for description and caveats.

Returns
-------
out : function
    A function that parses input for OS path sorting that is
    suitable for passing as the `key` argument to functions
    such as `sorted`.

See Also
--------
os_sort_key
os_sorted

Notes
-----
On Windows, this will implicitly coerce all inputs to str before
collating.

z
os_sort_key(val)
The default key to replicate your file browser's sort order

This is the output of :func:`os_sort_keygen` with default values.

See Also
--------
os_sort_keygen

presortc                 X    |rt        | |t              } t        | |t        |            S )a  
    Sort elements in the same order as your operating system's file browser

    .. warning::

        The resulting function will generate results that will be
        different depending on your platform. This is intentional.

    On Windows, this will sort with the same order as Windows Explorer.

    On MacOS/Linux, you will get different results depending on whether
    or not you have :mod:`pyicu` installed.

    - If you have :mod:`pyicu` installed, you will get results that are
      the same as (or very close to) the same order as your operating
      system's file browser.
    - If you do not have :mod:`pyicu` installed, then this will give
      the same results as if you used ``ns.LOCALE``, ``ns.PATH``,
      and ``ns.IGNORECASE`` with :func:`natsorted`. If you do not have
      special characters this will give correct results, but once
      special characters are added you should lower your expectations.

    It is *strongly* recommended to have :mod:`pyicu` installed on
    MacOS/Linux if you want correct sort results.

    It does *not* take into account if a path is a directory or a file
    when sorting.

    Parameters
    ----------
    seq : iterable
        The input to sort. Each element must be of type str.

    key : callable, optional
        A key used to determine how to sort each element of the sequence.
        It should accept a single argument and return a single value.

    reverse : {{True, False}}, optional
        Return the list in reversed sorted order. The default is
        `False`.

    presort : {{True, False}}, optional
        Equivalent to adding ``ns.PRESORT``, see :class:`ns` for
        documentation. The default is `False`.

    Returns
    -------
    out : list
        The sorted input.

    See Also
    --------
    natsorted
    os_sort_keygen

    Notes
    -----
    This will implicitly coerce all inputs to str before collating.

    rU   )rW   r4   r   )rR   r*   rS   r   s       r   	os_sortedr     s*    D S's3#wN3,?@@r    )F)NTrx   )NFF)E__doc__platform	functoolsr   operatorr   pathlibr   typingr   r   r   r	   r
   r   r   r   r   r   natsort.compat.localer6   r   natsort.ns_enumr   r   r   natsort.utilsr   r   r   r   NatsortKeyTypeOSSortKeyTyper4   r   r&   r)   r0   rQ   rI   boolrY   r\   r_   ri   ro   rq   rs   r}   r   r   systemctypesr   r   r   ShlwapiStrCmpLogicalW_windows_sort_cmpLPWSTRargtypesINTrestyper   r   r   ImportErroros_sort_keyr   ry   r    r   <module>r      s           / / 7 CL)? =/>9: -.89&9c &9hucz2 &9R) ) ).)s )s )0 59

^	(C5-/0	1^?E^se^#$^D 
  37**	4F	!4F	(A3-.	/4F 4F 
	4F
 
!W4Fr 37**	69	!69	(A3-.	/69 69 
	69
 
!W69v 37**	77	!77	(A3-.	/77 77 
	77
 
!W77x 37**	J*	!J*	(A3-.	/J* J* 
	J*
 
#YJ*^ 37**	3?	!3?	(A3-.	/3? 3? 
	3?
 
#Y3?p 37**	/=	!/=	(A3-.	//= /= 
	/=
 
#Y/=f <A:H	#:H'}:H48:Hc]:Hz2v 2# 2( TX9
9(A3#5679LP9c]9 8??	!'$55"*//8??!C (/0L 9=
hum345
	3%'	(
$S =A	S(C5-#789	Sse^+,	S 0 
  37	DA	!DA	(A3-.	/DA DA 	DA
 
!WDAu  T =A	T(C5-#789	Tse^+,	TTs   K K:9K: