o
    Si,                     @   s
  d Z ddlZddlZddlZddlmZmZ dZg dZG dd de	Z
ejd dkZer/eZejej Zed	Zed
ZdddZdd Zdd Zdd ZdddZdddZedZ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    N)chainproductz0.1.7)braceexpandalphabetUnbalancedBracesErrorc                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r
   r
   H/home/ubuntu/.local/lib/python3.10/site-packages/braceexpand/__init__.pyr      s    r      z$^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$z*^([A-Za-z])\.\.([A-Za-z])(?:\.\.-?(\d+))?$Tc                    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    | ]}t | V  qd S N)_flatten).0tescaper
   r   	<genexpr>b   s    zbraceexpand.<locals>.<genexpr>)parse_pattern)patternr   r
   r   r   r      s   Jr   c                 C   s,  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 t| S )Nr   \   {   }zUnbalanced braces: '%s')lenappendparse_expressionextendr   r   r   )r   r   startposbracketdepthitemsexpritemr
   r
   r   r   e   s:   


r   c                 C   s>   t | }|rt|  S t| }|rt|  S t| |S r   )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   c                 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s[|s]d S |t| |d  | t| S )Nr   r   r   r   r   r   ,)r   r   r   r   )seqr   r   r    r!   r"   r
   r
   r   r+      s*   

r+   c                    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)
startswith)r   sr
   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xrangeformat)r   endsteppaddingrr
   r5   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   )r9   r   indexr   )r   r<   r=   r
   r
   r   r*      s    

r*   z\\(.)c                 C   sR   g }| D ]}t |tr|t|| q|| qd|}|r'td|S |S )N z\1)
isinstancetupler   r   r   join	escape_resub)r   r   lr$   r2   r
   r
   r   r      s   
r   __main__)optionflagsr   )Tr   )$__doc__restringsys	itertoolsr   r   __version____all__
ValueErrorr   version_infoPY3ranger:   ascii_uppercaseascii_lowercaser   compiler%   r)   r   r   r   r+   r'   r*   rE   r   r   doctesttestmodIGNORE_EXCEPTION_DETAILfailed_exitr
   r
   r
   r   <module>   s<    


M)



