diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-01-09 11:54:25 -0500 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-01-09 11:54:25 -0500 |
commit | 0fc73208b80c1e4a158ea02e31c4fb212b6d0b39 (patch) | |
tree | 13d6986203cc23937ba0f1c2bd49594b6ed76daa /src/lib/Server/Plugins | |
parent | 11767966bd09ddc5b72acc77abe6b296fbb8b8f1 (diff) | |
download | bcfg2-0fc73208b80c1e4a158ea02e31c4fb212b6d0b39.tar.gz bcfg2-0fc73208b80c1e4a158ea02e31c4fb212b6d0b39.tar.bz2 bcfg2-0fc73208b80c1e4a158ea02e31c4fb212b6d0b39.zip |
improved error handling of GroupPatterns
Diffstat (limited to 'src/lib/Server/Plugins')
-rw-r--r-- | src/lib/Server/Plugins/GroupPatterns.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/lib/Server/Plugins/GroupPatterns.py b/src/lib/Server/Plugins/GroupPatterns.py index 76a628931..7733f409f 100644 --- a/src/lib/Server/Plugins/GroupPatterns.py +++ b/src/lib/Server/Plugins/GroupPatterns.py @@ -25,7 +25,7 @@ class PackedDigitRange(object): class PatternMap(object): - range_finder = '\\[\\[[\d\-,]+\\]\\]' + range_finder = r'\[\[[\d\-,]+\]\]' def __init__(self, pattern, rangestr, groups): self.pattern = pattern @@ -35,15 +35,18 @@ class PatternMap(object): self.re = re.compile(pattern) self.process = self.process_re elif rangestr != None: + if '\\' in rangestr: + raise Exception("Backslashes are not allowed in NameRanges") self.process = self.process_range - self.re = re.compile('^' + re.subn(self.range_finder, '(\d+)', - rangestr)[0]) - dmatcher = re.compile(re.subn(self.range_finder, - '\\[\\[([\d\-,]+)\\]\\]', - rangestr)[0]) - self.dranges = [PackedDigitRange(x) for x in dmatcher.match(rangestr).groups()] + self.re = re.compile('^' + re.sub(self.range_finder, '(\d+)', + rangestr)) + dmatcher = re.compile(re.sub(self.range_finder, + r'\[\[([\d\-,]+)\]\]', + rangestr)) + self.dranges = [PackedDigitRange(x) + for x in dmatcher.match(rangestr).groups()] else: - raise Exception + raise Exception("No pattern or range given") def process_range(self, name): match = self.re.match(name) |