Преглед на файлове

path normalization: rather use function than decorator

less and less complex code, more flexible usage.
Thomas Waldmann преди 8 години
родител
ревизия
126e782998
променени са 1 файла, в които са добавени 7 реда и са изтрити 23 реда
  1. 7 23
      src/borg/helpers.py

+ 7 - 23
src/borg/helpers.py

@@ -474,22 +474,11 @@ class PatternMatcher:
         return self.fallback
         return self.fallback
 
 
 
 
-def normalized(func):
-    """ Decorator for the Pattern match methods, returning a wrapper that
-    normalizes OSX paths to match the normalized pattern on OSX, and
-    returning the original method on other platforms"""
-    @wraps(func)
-    def normalize_wrapper(self, path):
-        return func(self, unicodedata.normalize("NFD", path))
-
-    if sys.platform in ('darwin',):
-        # HFS+ converts paths to a canonical form, so users shouldn't be
-        # required to enter an exact match
-        return normalize_wrapper
-    else:
-        # Windows and Unix filesystems allow different forms, so users
-        # always have to enter an exact match
-        return func
+def normalize_path(path):
+    """normalize paths for MacOS (but do nothing on other platforms)"""
+    # HFS+ converts paths to a canonical form, so users shouldn't be required to enter an exact match.
+    # Windows and Unix filesystems allow different forms, so users always have to enter an exact match.
+    return unicodedata.normalize('NFD', path) if sys.platform == 'darwin' else path
 
 
 
 
 class PatternBase:
 class PatternBase:
@@ -500,19 +489,14 @@ class PatternBase:
     def __init__(self, pattern):
     def __init__(self, pattern):
         self.pattern_orig = pattern
         self.pattern_orig = pattern
         self.match_count = 0
         self.match_count = 0
-
-        if sys.platform in ('darwin',):
-            pattern = unicodedata.normalize("NFD", pattern)
-
+        pattern = normalize_path(pattern)
         self._prepare(pattern)
         self._prepare(pattern)
 
 
-    @normalized
     def match(self, path):
     def match(self, path):
+        path = normalize_path(path)
         matches = self._match(path)
         matches = self._match(path)
-
         if matches:
         if matches:
             self.match_count += 1
             self.match_count += 1
-
         return matches
         return matches
 
 
     def __repr__(self):
     def __repr__(self):