Skip to content

Commit

Permalink
Merge pull request #2156 from DanCech/expand-braces-backport
Browse files Browse the repository at this point in the history
backport expand_braces from master
  • Loading branch information
deniszh committed Dec 15, 2017
2 parents 2bb157b + 90d1ab2 commit 9c603a3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
MANIFEST
.vagrant/
.venv/
_trial_temp
build
dist
Expand All @@ -7,6 +9,14 @@ dropin.cache
*.egg-info
docs/_build
*.log
*.pyc
.tox
*.swp
.idea
*.iml
storage
*.pyc
webapp/coverage.xml
webapp/.coverage
webapp/htmlcov
webapp/static
webapp/static/**/*
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ install:
- pip install https://github.com/graphite-project/ceres/tarball/master
- pip install https://github.com/graphite-project/whisper/tarball/master
- pip install $REQUIREMENTS
- pip install pytz pyparsing==1.5.7 http://cairographics.org/releases/py2cairo-1.8.10.tar.gz cairocffi
- pip install coverage pytz pyparsing==1.5.7 http://cairographics.org/releases/py2cairo-1.8.10.tar.gz cairocffi

script:
- PYTHONPATH=. python graphite/manage.py syncdb --noinput
- PYTHONPATH=. python graphite/manage.py test --settings=tests.settings -v2
- PYTHONPATH=. coverage run --branch --source=graphite graphite/manage.py test --settings=tests.settings -v2
- coverage xml
- coverage report

after_success:
- pip install codecov
- codecov
41 changes: 26 additions & 15 deletions webapp/graphite/storage.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


DATASOURCE_DELIMETER = '::RRD_DATASOURCE::'
EXPAND_BRACES_RE = re.compile(r'.*(\{.+?[^\\]\})')
EXPAND_BRACES_RE = re.compile(r'.*(\{.*?[^\\]?\})')


class Store:
Expand Down Expand Up @@ -85,7 +85,7 @@ def _parallel_remote_find(self, query, headers=None):
log.exception("result_queue not empty, but unable to retrieve results")

return results

def find_first(self, query, headers=None):
# Search locally first
for directory in self.directories:
Expand Down Expand Up @@ -266,22 +266,33 @@ def match_entries(entries, pattern):
Brace expanding patch for python3 borrowed from:
https://bugs.python.org/issue9584
"""


def expand_braces(s):
res = list()

m = EXPAND_BRACES_RE.search(s)
if m is not None:
sub = m.group(1)
open_brace, close_brace = m.span(1)
if ',' in sub:
for pat in sub.strip('{}').split(','):
res.extend(expand_braces(s[:open_brace] + pat + s[close_brace:]))
res = list()

# Used instead of s.strip('{}') because strip is greedy.
# We want to remove only ONE leading { and ONE trailing }, if both exist
def remove_outer_braces(s):
if s[0] == '{' and s[-1] == '}':
return s[1:-1]
return s

m = EXPAND_BRACES_RE.search(s)
if m is not None:
sub = m.group(1)
open_brace, close_brace = m.span(1)
if ',' in sub:
for pat in sub.strip('{}').split(','):
res.extend(expand_braces(
s[:open_brace] + pat + s[close_brace:]))
else:
res.extend(expand_braces(
s[:open_brace] + remove_outer_braces(sub) + s[close_brace:]))
else:
res.extend(expand_braces(s[:open_brace] + sub.replace('}', '\\}') + s[close_brace:]))
else:
res.append(s.replace('\\}', '}'))
res.append(s.replace('\\}', '}'))

return list(set(res))
return list(set(res))


# Node classes
Expand Down

0 comments on commit 9c603a3

Please sign in to comment.