././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1620395161.2974768 braceexpand-0.1.7/0000775000175000017500000000000000000000000011634 5ustar00stst././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394765.0 braceexpand-0.1.7/CHANGELOG.md0000664000175000017500000000155600000000000013454 0ustar00stst# Changelog ## 0.1.7 (2021-05-07) - Add type annotations to braceexpand function ## 0.1.6 (2020-10-09) - Fix char range ending with 'A' expanding to empty list - Fix handling of character range with increment '0' - Fix deprecation warnings due to invalid escape sequences. ## 0.1.5 (2019-11-27) - Don't pad int range when start or end is '-0' - Fix handling of range with increment '0' ## 0.1.4 (2019-11-26) - Add support for negative integers in ranges ## 0.1.3 (2019-10-02) - Fix bug where patterns nested inside an extra level of braces were not further expanded. For example, `{{a,b}}` now correctly expands to `{a} {b}`. - Drop support for Python 2.6 ## 0.1.2 (2015-08-31) - Dont pad int range when start or end is '0' ## 0.1.1 (2015-01-10) - Updated list of supported Python versions ## 0.1 (2015-01-06) - Initial release ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1486840254.0 braceexpand-0.1.7/LICENSE0000664000175000017500000000207700000000000012647 0ustar00ststThe MIT License (MIT) Copyright (c) 2015 Stanis Trendelenburg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394260.0 braceexpand-0.1.7/MANIFEST.in0000664000175000017500000000020200000000000013364 0ustar00ststinclude CHANGELOG.md README.* LICENSE Makefile test_braceexpand.py include src/braceexpand/*.pyi include src/braceexpand/py.typed ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394332.0 braceexpand-0.1.7/Makefile0000664000175000017500000000025500000000000013276 0ustar00ststREADME.rst: README.md pandoc --from=markdown --to=rst $< > $@ init: pip install -e . test: python src/braceexpand/__init__.py python test_braceexpand.py .PHONY: test ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1620395161.2974768 braceexpand-0.1.7/PKG-INFO0000664000175000017500000000730700000000000012740 0ustar00ststMetadata-Version: 1.1 Name: braceexpand Version: 0.1.7 Summary: Bash-style brace expansion for Python Home-page: https://github.com/trendels/braceexpand Author: Stanis Trendelenburg Author-email: stanis.trendelenburg@gmail.com License: MIT Description: Bash-style brace expansion for Python ===================================== |build-status-img| |PyPI| 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 :literal:`[]^_\`` between ``Z`` and ``a``. ``braceexpand`` is tested with Python 2.7, and 3.6+ Installation ------------ Install the ``braceexpand`` package from pypi: :: $ pip install braceexpand Examples -------- The ``braceexpand`` function returns an iterator over the expansions generated from a pattern. .. code:: python >>> 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'] License ------- braceexpand is licensed under the MIT License. See the included file ``LICENSE`` for details. .. |build-status-img| image:: https://travis-ci.org/trendels/braceexpand.svg :target: https://travis-ci.org/trendels/braceexpand .. |PyPI| image:: https://img.shields.io/pypi/v/braceexpand :target: https://pypi.python.org/pypi/braceexpand Platform: UNKNOWN Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394935.0 braceexpand-0.1.7/README.md0000664000175000017500000000450500000000000013117 0ustar00stst# Bash-style brace expansion for Python [![build-status-img]][build-status-url] [![PyPI](https://img.shields.io/pypi/v/braceexpand)](https://pypi.python.org/pypi/braceexpand) Implements Brace Expansion as described in [bash(1)][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`. `braceexpand` is tested with Python 2.7, and 3.6+ ## Installation Install the `braceexpand` package from pypi: $ pip install braceexpand ## Examples The `braceexpand` function returns an iterator over the expansions generated from a pattern. ~~~python >>> 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'] ~~~ [1]: http://man7.org/linux/man-pages/man1/bash.1.html#EXPANSION [build-status-url]: https://travis-ci.org/trendels/braceexpand [build-status-img]: https://travis-ci.org/trendels/braceexpand.svg ## License braceexpand is licensed under the MIT License. See the included file `LICENSE` for details. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394939.0 braceexpand-0.1.7/README.rst0000664000175000017500000000501100000000000013320 0ustar00ststBash-style brace expansion for Python ===================================== |build-status-img| |PyPI| 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 :literal:`[]^_\`` between ``Z`` and ``a``. ``braceexpand`` is tested with Python 2.7, and 3.6+ Installation ------------ Install the ``braceexpand`` package from pypi: :: $ pip install braceexpand Examples -------- The ``braceexpand`` function returns an iterator over the expansions generated from a pattern. .. code:: python >>> 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'] License ------- braceexpand is licensed under the MIT License. See the included file ``LICENSE`` for details. .. |build-status-img| image:: https://travis-ci.org/trendels/braceexpand.svg :target: https://travis-ci.org/trendels/braceexpand .. |PyPI| image:: https://img.shields.io/pypi/v/braceexpand :target: https://pypi.python.org/pypi/braceexpand ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1620395161.2974768 braceexpand-0.1.7/setup.cfg0000664000175000017500000000004600000000000013455 0ustar00stst[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394260.0 braceexpand-0.1.7/setup.py0000664000175000017500000000153500000000000013352 0ustar00ststimport os import re from setuptools import setup, find_packages with open(os.path.join('src', 'braceexpand', '__init__.py')) as f: version = re.findall(r"^__version__ = '(.*)'", f.read(), re.M)[0] with open('README.rst') as f: README = f.read() setup( name='braceexpand', version=version, author='Stanis Trendelenburg', author_email='stanis.trendelenburg@gmail.com', url='https://github.com/trendels/braceexpand', license='MIT', description='Bash-style brace expansion for Python', long_description=README, classifiers = [ 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', ], package_dir={'': 'src'}, packages=find_packages('src'), include_package_data=True, ) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1620395161.2934768 braceexpand-0.1.7/src/0000775000175000017500000000000000000000000012423 5ustar00stst././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1620395161.2974768 braceexpand-0.1.7/src/braceexpand/0000775000175000017500000000000000000000000014677 5ustar00stst././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394668.0 braceexpand-0.1.7/src/braceexpand/__init__.py0000664000175000017500000001505400000000000017015 0ustar00stst"""Bash-style brace expansion""" import re import string import sys from itertools import chain, product __version__ = '0.1.7' __all__ = ['braceexpand', 'alphabet', 'UnbalancedBracesError'] class UnbalancedBracesError(ValueError): pass PY3 = sys.version_info[0] >= 3 if PY3: xrange = range alphabet = string.ascii_uppercase + string.ascii_lowercase int_range_re = re.compile(r'^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$') char_range_re = re.compile(r'^([A-Za-z])\.\.([A-Za-z])(?:\.\.-?(\d+))?$') def braceexpand(pattern, escape=True): """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'] """ return (_flatten(t, escape) for t in parse_pattern(pattern, escape)) def parse_pattern(pattern, escape): # pattern -> product(*parts) start = 0 pos = 0 bracketdepth = 0 items = [] #print 'pattern:', pattern while pos < len(pattern): if escape and pattern[pos] == '\\': pos += 2 continue elif pattern[pos] == '{': if bracketdepth == 0 and pos > start: #print 'literal:', pattern[start:pos] items.append([pattern[start:pos]]) start = pos bracketdepth += 1 elif pattern[pos] == '}': bracketdepth -= 1 if bracketdepth == 0: #print 'expression:', pattern[start+1:pos] expr = pattern[start+1:pos] item = parse_expression(expr, escape) if item is None: # not a range or sequence items.extend([['{'], parse_pattern(expr, escape), ['}']]) else: items.append(item) start = pos + 1 # skip the closing brace pos += 1 if bracketdepth != 0: # unbalanced braces raise UnbalancedBracesError("Unbalanced braces: '%s'" % pattern) if start < pos: #print 'literal:', pattern[start:] items.append([pattern[start:]]) return product(*items) def parse_expression(expr, escape): int_range_match = int_range_re.match(expr) if int_range_match: return make_int_range(*int_range_match.groups()) char_range_match = char_range_re.match(expr) if char_range_match: return make_char_range(*char_range_match.groups()) return parse_sequence(expr, escape) def parse_sequence(seq, escape): # sequence -> chain(*sequence_items) start = 0 pos = 0 bracketdepth = 0 items = [] #print 'sequence:', seq while pos < len(seq): if escape and seq[pos] == '\\': pos += 2 continue elif seq[pos] == '{': bracketdepth += 1 elif seq[pos] == '}': bracketdepth -= 1 elif seq[pos] == ',' and bracketdepth == 0: items.append(parse_pattern(seq[start:pos], escape)) start = pos + 1 # skip the comma pos += 1 if bracketdepth != 0 or not items: # unbalanced braces or not a sequence return None # part after the last comma (may be the empty string) items.append(parse_pattern(seq[start:], escape)) return chain(*items) def make_int_range(start, end, step=None): if any([s.startswith(('0', '-0')) for s in (start, end) if s not in ('0', '-0')]): padding = max(len(start), len(end)) else: padding = 0 step = (int(step) or 1) if step else 1 start = int(start) end = int(end) r = xrange(start, end+1, step) if start < end else \ xrange(start, end-1, -step) fmt = '%0{}d'.format(padding) return (fmt % i for i in r) def make_char_range(start, end, step=None): step = (int(step) or 1) if step else 1 start = alphabet.index(start) end = alphabet.index(end) if start < end: return alphabet[start:end+1:step] else: end = end or -len(alphabet) return alphabet[start:end-1:-step] escape_re = re.compile(r'\\(.)') def _flatten(t, escape): l = [] for item in t: if isinstance(item, tuple): l.extend(_flatten(item, escape)) else: l.append(item) s = ''.join(l) # Strip escape characters from generated strings after expansion. return escape_re.sub(r'\1', s) if escape else s if __name__ == '__main__': import doctest import sys failed, _ = doctest.testmod(optionflags=doctest.IGNORE_EXCEPTION_DETAIL) if failed: sys.exit(1) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394260.0 braceexpand-0.1.7/src/braceexpand/__init__.pyi0000664000175000017500000000016500000000000017163 0ustar00ststfrom typing import Iterator alphabet: str def braceexpand(pattern: str, escape: bool = ...) -> Iterator[str]: ... ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620394260.0 braceexpand-0.1.7/src/braceexpand/py.typed0000664000175000017500000000000000000000000016364 0ustar00stst././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1620395161.2974768 braceexpand-0.1.7/src/braceexpand.egg-info/0000775000175000017500000000000000000000000016371 5ustar00stst././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620395161.0 braceexpand-0.1.7/src/braceexpand.egg-info/PKG-INFO0000664000175000017500000000730700000000000017475 0ustar00ststMetadata-Version: 1.1 Name: braceexpand Version: 0.1.7 Summary: Bash-style brace expansion for Python Home-page: https://github.com/trendels/braceexpand Author: Stanis Trendelenburg Author-email: stanis.trendelenburg@gmail.com License: MIT Description: Bash-style brace expansion for Python ===================================== |build-status-img| |PyPI| 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 :literal:`[]^_\`` between ``Z`` and ``a``. ``braceexpand`` is tested with Python 2.7, and 3.6+ Installation ------------ Install the ``braceexpand`` package from pypi: :: $ pip install braceexpand Examples -------- The ``braceexpand`` function returns an iterator over the expansions generated from a pattern. .. code:: python >>> 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'] License ------- braceexpand is licensed under the MIT License. See the included file ``LICENSE`` for details. .. |build-status-img| image:: https://travis-ci.org/trendels/braceexpand.svg :target: https://travis-ci.org/trendels/braceexpand .. |PyPI| image:: https://img.shields.io/pypi/v/braceexpand :target: https://pypi.python.org/pypi/braceexpand Platform: UNKNOWN Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620395161.0 braceexpand-0.1.7/src/braceexpand.egg-info/SOURCES.txt0000664000175000017500000000051100000000000020252 0ustar00ststCHANGELOG.md LICENSE MANIFEST.in Makefile README.md README.rst setup.py test_braceexpand.py src/braceexpand/__init__.py src/braceexpand/__init__.pyi src/braceexpand/py.typed src/braceexpand.egg-info/PKG-INFO src/braceexpand.egg-info/SOURCES.txt src/braceexpand.egg-info/dependency_links.txt src/braceexpand.egg-info/top_level.txt././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620395161.0 braceexpand-0.1.7/src/braceexpand.egg-info/dependency_links.txt0000664000175000017500000000000100000000000022437 0ustar00stst ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1620395161.0 braceexpand-0.1.7/src/braceexpand.egg-info/top_level.txt0000664000175000017500000000001400000000000021116 0ustar00ststbraceexpand ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1602251914.0 braceexpand-0.1.7/test_braceexpand.py0000664000175000017500000001144100000000000015522 0ustar00ststimport unittest from braceexpand import braceexpand, UnbalancedBracesError class BraceExpand(unittest.TestCase): tests = [ ('{1,2}', ['1', '2']), ('{1}', ['{1}']), ('{1,2{}}', ['1', '2{}']), ('}{', ['}{']), ('a{b,c}d{e,f}', ['abde', 'abdf', 'acde', 'acdf']), ('a{b,c{d,e,}}', ['ab', 'acd', 'ace', 'ac']), ('a{b,{c,{d,e}}}', ['ab', 'ac', 'ad', 'ae']), ('{{a,b},{c,d}}', ['a', 'b', 'c', 'd']), ('{7..10}', ['7', '8', '9', '10']), ('{10..7}', ['10', '9', '8', '7']), ('{1..5..2}', ['1', '3', '5']), ('{5..1..2}', ['5', '3', '1']), ('{1..3..0}', ['1', '2', '3']), ('{1..3..-0}', ['1', '2', '3']), ('{a..b..0}', ['a', 'b']), ('{a..b..-0}', ['a', 'b']), ('{07..10}', ['07', '08', '09', '10']), ('{7..010}', ['007', '008', '009', '010']), ('{1..-2}', ['1', '0', '-1', '-2']), ('{01..-2}', ['01', '00', '-1', '-2']), ('{1..-02}', ['001', '000', '-01', '-02']), ('{-01..3..2}', ['-01', '001', '003']), ('{a..e}', ['a', 'b', 'c', 'd', 'e']), ('{a..e..2}', ['a', 'c', 'e']), ('{e..a}', ['e', 'd', 'c', 'b', 'a']), ('{e..a..2}', ['e', 'c', 'a']), ('{1..a}', ['{1..a}']), ('{a..1}', ['{a..1}']), ('{1..1}', ['1']), ('{a..a}', ['a']), ('{,}', ['', '']), ('{Z..a}', ['Z', 'a']), ('{a..Z}', ['a', 'Z']), ('{A..z}', list('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')), ('{z..A}', list('zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA')), ('{a.{b,c}}', ['{a.b}', '{a.c}']), ('{a.{1..2}}', ['{a.1}', '{a.2}']), ('{{{,}}}', ['{{}}', '{{}}']), ] unbalanced_tests = [ # Unbalanced braces '{{1,2}', # Bash: {1 {2 '{1,2}}', # Bash: 1} 2} '{1},2}', # Bash: 1} 2 '{1,{2}', # Bash: {1,{2} '{}1,2}', # Bash: }1 2 '{1,2{}', # Bash: {1,2{} '}{1,2}', # Bash: }1 }2 '{1,2}{', # Bash: 1{ 2{ ] escape_tests = [ ('\\{1,2\\}', ['{1,2}']), ('{1\\,2}', ['{1,2}']), ('\\}{1,2}', ['}1', '}2']), ('\\{{1,2}', ['{1', '{2']), ('{1,2}\\}', ['1}', '2}']), ('{1,2}\\{', ['1{', '2{']), ('{\\,1,2}', [',1', '2']), ('{1\\,,2}', ['1,', '2']), ('{1,\\,2}', ['1', ',2']), ('{1,2\\,}', ['1', '2,']), ('\\\\{1,2}', ['\\1', '\\2']), ('\\{1..2\\}', ['{1..2}']), ] no_escape_tests = [ ('\\{1,2}', ['\\1', '\\2']), ('{1,2\\}', ['1', '2\\']), ('{1\\,2}', ['1\\', '2']), ('{\\,1,2}', ['\\', '1', '2']), ('{1\\,,2}', ['1\\', '', '2']), ('{1,\\,2}', ['1', '\\', '2']), ('{1,2\\,}', ['1', '2\\', '']), ('\\{1..2\\}', ['\\{1..2\\}']), ] def test_braceexpand(self): for pattern, expected in self.tests: result = list(braceexpand(pattern)) self.assertEqual(expected, result) def test_braceexpand_unbalanced(self): for pattern in self.unbalanced_tests: self.assertRaises(UnbalancedBracesError, braceexpand, pattern) def test_braceexpand_escape(self): for pattern, expected in self.escape_tests: result = list(braceexpand(pattern, escape=True)) self.assertEqual(expected, result) def test_braceexpand_no_escape(self): for pattern, expected in self.no_escape_tests: result = list(braceexpand(pattern, escape=False)) self.assertEqual(expected, result) def test_zero_padding(self): result = list(braceexpand('{00..10}')) self.assertEqual(result[:2], ['00', '01']) result = list(braceexpand('{10..00}')) self.assertEqual(result[-2:], ['01', '00']) result = list(braceexpand('{0..010}')) self.assertEqual(result[:2], ['000', '001']) result = braceexpand('{01..1000}') self.assertEqual(next(result), '0001') def test_zero_single_digit(self): result = list(braceexpand('{0..10}')) self.assertEqual(result[:2], ['0', '1']) result = list(braceexpand('{10..0}')) self.assertEqual(result[-2:], ['1', '0']) def test_negative_zero(self): result = list(braceexpand('{-0..1}')) self.assertEqual(result, ['0', '1']) result = list(braceexpand('{1..-0}')) self.assertEqual(result, ['1', '0']) result = list(braceexpand('{0..-0}')) self.assertEqual(result, ['0']) if __name__ == '__main__': unittest.main()