braceexpand-0.1.5/0000775000175000017500000000000013567454030013100 5ustar stst00000000000000braceexpand-0.1.5/CHANGELOG.md0000664000175000017500000000113713567453020014711 0ustar stst00000000000000# Changelog ## 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 braceexpand-0.1.5/LICENSE0000664000175000017500000000207713047660676014123 0ustar stst00000000000000The 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. braceexpand-0.1.5/MANIFEST.in0000664000175000017500000000010313545337264014635 0ustar stst00000000000000include CHANGELOG.md README.* LICENSE Makefile test_braceexpand.py braceexpand-0.1.5/Makefile0000664000175000017500000000020713545337275014546 0ustar stst00000000000000README.rst: README.md pandoc --from=markdown --to=rst $< > $@ test: python braceexpand.py python test_braceexpand.py .PHONY: test braceexpand-0.1.5/PKG-INFO0000664000175000017500000000740713567454030014205 0ustar stst00000000000000Metadata-Version: 1.1 Name: braceexpand Version: 0.1.5 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| 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.5+ 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 unter 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 Platform: UNKNOWN Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 braceexpand-0.1.5/README.md0000664000175000017500000000434613567172572014376 0ustar stst00000000000000# Bash-style brace expansion for Python [![build-status-img]][build-status-url] 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.5+ ## 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 unter the MIT License. See the included file `LICENSE` for details. braceexpand-0.1.5/README.rst0000664000175000017500000000462113567172615014600 0ustar stst00000000000000Bash-style brace expansion for Python ===================================== |build-status-img| 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.5+ 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 unter 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 braceexpand-0.1.5/braceexpand.egg-info/0000775000175000017500000000000013567454030017046 5ustar stst00000000000000braceexpand-0.1.5/braceexpand.egg-info/PKG-INFO0000664000175000017500000000740713567454030020153 0ustar stst00000000000000Metadata-Version: 1.1 Name: braceexpand Version: 0.1.5 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| 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.5+ 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 unter 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 Platform: UNKNOWN Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 braceexpand-0.1.5/braceexpand.egg-info/SOURCES.txt0000664000175000017500000000036613567454030020737 0ustar stst00000000000000CHANGELOG.md LICENSE MANIFEST.in Makefile README.md README.rst braceexpand.py setup.py test_braceexpand.py braceexpand.egg-info/PKG-INFO braceexpand.egg-info/SOURCES.txt braceexpand.egg-info/dependency_links.txt braceexpand.egg-info/top_level.txtbraceexpand-0.1.5/braceexpand.egg-info/dependency_links.txt0000664000175000017500000000000113567454030023114 0ustar stst00000000000000 braceexpand-0.1.5/braceexpand.egg-info/top_level.txt0000664000175000017500000000001413567454030021573 0ustar stst00000000000000braceexpand braceexpand-0.1.5/braceexpand.py0000664000175000017500000001475713567453035015750 0ustar stst00000000000000"""Bash-style brace expansion""" import re import string import sys from itertools import chain, product __version__ = '0.1.5' __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) if step else 1 start = alphabet.index(start) end = alphabet.index(end) return alphabet[start:end+1:step] if start < end else \ 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) braceexpand-0.1.5/setup.cfg0000664000175000017500000000007313567454030014721 0ustar stst00000000000000[egg_info] tag_svn_revision = 0 tag_date = 0 tag_build = braceexpand-0.1.5/setup.py0000664000175000017500000000165013545174403014613 0ustar stst00000000000000import re from setuptools import setup with open('braceexpand.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', py_modules=['braceexpand'], 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 :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', ], ) braceexpand-0.1.5/test_braceexpand.py0000664000175000017500000001104613567447351016777 0ustar stst00000000000000import 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']), ('{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.{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()