[meld] filters: Simplify byte/str regex filter compiling
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] filters: Simplify byte/str regex filter compiling
- Date: Sat, 27 Oct 2018 22:07:19 +0000 (UTC)
commit 71ad9c440b12586756f09f297061a3e5de435e43
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Oct 28 07:37:20 2018 +1000
filters: Simplify byte/str regex filter compiling
meld/filters.py | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
---
diff --git a/meld/filters.py b/meld/filters.py
index 7ae4fe7d..94fb5f46 100644
--- a/meld/filters.py
+++ b/meld/filters.py
@@ -32,22 +32,18 @@ class FilterEntry:
self.filter_string = filter_string
@classmethod
- def _compile_regex(cls, regex):
+ def _compile_regex(cls, regex, byte_regex=False):
+ if byte_regex and not isinstance(regex, bytes):
+ # TODO: Register a custom error handling function to replace
+ # encoding errors with '.'?
+ regex = regex.encode('utf8', 'replace')
+
try:
compiled = re.compile(regex, re.M)
except re.error:
compiled = None
return compiled
- @classmethod
- def _compile_byte_regex(cls, regex):
- if not isinstance(regex, bytes):
- # TODO: Register a custom error handling function to replace
- # encoding errors with '.'?
- regex = regex.encode('utf8', 'replace')
-
- return cls._compile_regex(regex)
-
@classmethod
def _compile_shell_pattern(cls, pattern):
bits = pattern.split()
@@ -72,7 +68,7 @@ class FilterEntry:
name, active, filter_string = elements
if filter_type == cls.REGEX:
str_re = cls._compile_regex(filter_string)
- bytes_re = cls._compile_byte_regex(filter_string)
+ bytes_re = cls._compile_regex(filter_string, byte_regex=True)
elif filter_type == cls.SHELL:
str_re = cls._compile_shell_pattern(filter_string)
bytes_re = None
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]