o
    㥵iD                  
   @   st  d Z ddlZddlZddlmZmZ ddlmZmZm	Z	 g dZ
G dd deZejej ZedZed	Zed
Zd#dededee fddZdededee fddZdedede	ee  fddZdedede	ee  fddZd$dedede	e dee fddZd$dedede	e defddZed krddlZddlZejej d!\Z!Z"e!re#d" dS dS dS )%z
Bash-style brace expansion
Copied from: https://github.com/trendels/braceexpand/blob/main/src/braceexpand/__init__.py
License: MIT
    N)chainproduct)IterableIteratorOptional)braceexpandalphabetUnbalancedBracesErrorc                   @   s   e Zd ZdS )r	   N)__name__
__module____qualname__ r   r   Q/home/ubuntu/.local/lib/python3.10/site-packages/fish_speech/utils/braceexpand.pyr	      s    r	   z$^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$z*^([A-Za-z])\.\.([A-Za-z])(?:\.\.-?(\d+))?$z\\(.)Tpatternescapereturnc                    s    fddt |  D S )a"	  braceexpand(pattern) -> iterator over generated strings

    Returns an iterator over the strings resulting from brace expansion
    of pattern. This function implements Brace Expansion as described in
    bash(1), with the following limitations:

    * A pattern containing unbalanced braces will raise an
      UnbalancedBracesError exception. In bash, unbalanced braces will either
      be partly expanded or ignored.

    * A mixed-case character range like '{Z..a}' or '{a..Z}' will not
      include the characters '[]^_`' between 'Z' and 'a'.

    When escape is True (the default), characters in pattern can be
    prefixed with a backslash to cause them not to be interpreted as
    special characters for brace expansion (such as '{', '}', ',').
    To pass through a a literal backslash, double it ('\\').

    When escape is False, backslashes in pattern have no special
    meaning and will be preserved in the output.

    Examples:

    >>> from braceexpand import braceexpand

    # Integer range
    >>> list(braceexpand('item{1..3}'))
    ['item1', 'item2', 'item3']

    # Character range
    >>> list(braceexpand('{a..c}'))
    ['a', 'b', 'c']

    # Sequence
    >>> list(braceexpand('index.html{,.backup}'))
    ['index.html', 'index.html.backup']

    # Nested patterns
    >>> list(braceexpand('python{2.{5..7},3.{2,3}}'))
    ['python2.5', 'python2.6', 'python2.7', 'python3.2', 'python3.3']

    # Prefixing an integer with zero causes all numbers to be padded to
    # the same width.
    >>> list(braceexpand('{07..10}'))
    ['07', '08', '09', '10']

    # An optional increment can be specified for ranges.
    >>> list(braceexpand('{a..g..2}'))
    ['a', 'c', 'e', 'g']

    # Ranges can go in both directions.
    >>> list(braceexpand('{4..1}'))
    ['4', '3', '2', '1']

    # Numbers can be negative
    >>> list(braceexpand('{2..-1}'))
    ['2', '1', '0', '-1']

    # Unbalanced braces raise an exception.
    >>> list(braceexpand('{1{2,3}'))
    Traceback (most recent call last):
        ...
    UnbalancedBracesError: Unbalanced braces: '{1{2,3}'

    # By default, the backslash is the escape character.
    >>> list(braceexpand(r'{1\{2,3}'))
    ['1{2', '3']

    # Setting 'escape' to False disables backslash escaping.
    >>> list(braceexpand(r'\{1,2}', escape=False))
    ['\\1', '\\2']

    c                 3   s$    | ]} rt d |n|V  qdS )z\1N)	escape_resub.0sr   r   r   	<genexpr>d   s    
zbraceexpand.<locals>.<genexpr>)parse_pattern)r   r   r   r   r   r      s   
Jr   c                 C   s6  d}d}d}g }|t | k rz|r| | dkr|d7 }q| | dkr:|dkr5||kr5|| || g |}|d7 }n6| | dkrp|d8 }|dkrp| |d | }t||}|d u rg|dgt||dgg n|| |d }|d7 }|t | k s|dkrtd|  ||k r|| |d  g dd	 t| D S )
Nr   \   {   }zUnbalanced braces: '%s'c                 s   s    | ]}d  |V  qdS ) N)join)r   itemr   r   r   r      s    z parse_pattern.<locals>.<genexpr>)lenappendparse_expressionextendr   r	   r   )r   r   startposbracketdepthitemsexprr!   r   r   r   r   i   s:   


r   r*   c                 C   s>   t | }|rt|  S t| }|rt|  S t| |S N)int_range_rematchmake_int_rangegroupschar_range_remake_char_rangeparse_sequence)r*   r   int_range_matchchar_range_matchr   r   r   r$      s   


r$   seqc                 C   s   d}d}d}g }|t | k rU|r| | dkr|d7 }q| | dkr&|d7 }n%| | dkr1|d8 }n| | dkrK|dkrK|t| || | |d }|d7 }|t | k s|dkr[t|s_d S |t| |d  | t| S )Nr   r   r   r   r   r   ,)r"   r#   r   r	   r   )r5   r   r&   r'   r(   r)   r   r   r   r2      s.   

r2   leftrightincrc                    s   t dd | |fD rtt| t|}nd}|rt|pdnd}t| }t|}||k r5t||d |nt||d | }d|  fdd|D S )Nc                 S   s   g | ]}|d vr| d qS ))0z-0)
startswithr   r   r   r   
<listcomp>   s    z"make_int_range.<locals>.<listcomp>r   r   z%0{}dc                 3   s    | ]} | V  qd S r+   r   )r   ifmtr   r   r      s    z!make_int_range.<locals>.<genexpr>)anymaxr"   intrangeformat)r7   r8   r9   paddingstepr&   endrr   r>   r   r.      s    *
r.   c                 C   sd   |rt |pdnd}t| }t|}||k r!t||d | S |p'tt }t||d |  S )Nr   )rB   r   indexr"   )r7   r8   r9   rF   r&   rG   r   r   r   r1      s    

r1   __main__)optionflagsr   )Tr+   )$__doc__restring	itertoolsr   r   typingr   r   r   __all__
ValueErrorr	   ascii_uppercaseascii_lowercaser   compiler,   r0   r   strboolr   r   r$   r2   r.   r1   r
   doctestsystestmodIGNORE_EXCEPTION_DETAILfailed_exitr   r   r   r   <module>   s2    


O'$ 