[meld] filters: Significantly simplify filter construction logic



commit 27bb042ec3c5b8d172c2a95dc971d72deecbb980
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Oct 28 07:34:11 2018 +1000

    filters: Significantly simplify filter construction logic
    
    The previous API had tacked on bytes-based filters, and as a result we
    had a weird split that made a fairly simple situation extremely verbose.

 meld/filters.py | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
---
diff --git a/meld/filters.py b/meld/filters.py
index cedf24eb..7ae4fe7d 100644
--- a/meld/filters.py
+++ b/meld/filters.py
@@ -70,31 +70,17 @@ class FilterEntry:
     @classmethod
     def new_from_gsetting(cls, elements, filter_type):
         name, active, filter_string = elements
-        compiled = FilterEntry.compile_filter(filter_string, filter_type)
-        if compiled is None:
-            active = False
-        byte_filt = FilterEntry.compile_byte_filter(filter_string, filter_type)
-        return FilterEntry(name, active, compiled, byte_filt, filter_string)
-
-    @classmethod
-    def compile_filter(cls, filter_string, filter_type):
         if filter_type == cls.REGEX:
-            compiled = cls._compile_regex(filter_string)
+            str_re = cls._compile_regex(filter_string)
+            bytes_re = cls._compile_byte_regex(filter_string)
         elif filter_type == cls.SHELL:
-            compiled = cls._compile_shell_pattern(filter_string)
+            str_re = cls._compile_shell_pattern(filter_string)
+            bytes_re = None
         else:
             raise ValueError("Unknown filter type")
-        return compiled
 
-    @classmethod
-    def compile_byte_filter(cls, filter_string, filter_type):
-        if filter_type == cls.REGEX:
-            compiled = cls._compile_byte_regex(filter_string)
-        elif filter_type == cls.SHELL:
-            compiled = None
-        else:
-            raise ValueError("Unknown filter type")
-        return compiled
+        active = active and bool(str_re)
+        return cls(name, active, str_re, bytes_re, filter_string)
 
     @classmethod
     def check_filter(cls, filter_string, filter_type):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]