From b6362b596390651d244086907702185745c4bc55 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Mon, 18 Jan 2016 13:08:49 +0100 Subject: [PATCH] Flexible default pattern style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A function to parse pattern specifications was introduced in commit 2bafece. Since then it had a hardcoded default style of “fm”, meaning fnmatch. With the forthcoming support for extracting files using patterns this default style must be more flexible. --- borg/helpers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/borg/helpers.py b/borg/helpers.py index eb3231deb..adb75fb4b 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -418,18 +418,18 @@ _PATTERN_STYLES = set([ _PATTERN_STYLE_BY_PREFIX = dict((i.PREFIX, i) for i in _PATTERN_STYLES) -def parse_pattern(pattern): +def parse_pattern(pattern, fallback=FnmatchPattern): """Read pattern from string and return an instance of the appropriate implementation class. """ if len(pattern) > 2 and pattern[2] == ":" and pattern[:2].isalnum(): (style, pattern) = (pattern[:2], pattern[3:]) + + cls = _PATTERN_STYLE_BY_PREFIX.get(style, None) + + if cls is None: + raise ValueError("Unknown pattern style: {}".format(style)) else: - style = FnmatchPattern.PREFIX - - cls = _PATTERN_STYLE_BY_PREFIX.get(style, None) - - if cls is None: - raise ValueError("Unknown pattern style: {}".format(style)) + cls = fallback return cls(pattern)