瀏覽代碼

Flexible default pattern style

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.
Michael Hanselmann 9 年之前
父節點
當前提交
b6362b5963
共有 1 個文件被更改,包括 6 次插入6 次删除
  1. 6 6
      borg/helpers.py

+ 6 - 6
borg/helpers.py

@@ -418,18 +418,18 @@ _PATTERN_STYLES = set([
 _PATTERN_STYLE_BY_PREFIX = dict((i.PREFIX, i) for i in _PATTERN_STYLES)
 _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.
     """Read pattern from string and return an instance of the appropriate implementation class.
     """
     """
     if len(pattern) > 2 and pattern[2] == ":" and pattern[:2].isalnum():
     if len(pattern) > 2 and pattern[2] == ":" and pattern[:2].isalnum():
         (style, pattern) = (pattern[:2], pattern[3:])
         (style, pattern) = (pattern[:2], pattern[3:])
-    else:
-        style = FnmatchPattern.PREFIX
 
 
-    cls = _PATTERN_STYLE_BY_PREFIX.get(style, None)
+        cls = _PATTERN_STYLE_BY_PREFIX.get(style, None)
 
 
-    if cls is None:
-        raise ValueError("Unknown pattern style: {}".format(style))
+        if cls is None:
+            raise ValueError("Unknown pattern style: {}".format(style))
+    else:
+        cls = fallback
 
 
     return cls(pattern)
     return cls(pattern)