From f389df59c488319f9e9c4233705c157d35a1e6f9 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Mon, 29 Aug 2016 20:21:56 -0700 Subject: [PATCH] improve pylint score (to over 9.00) --- gramps/gen/filters/_filterlist.py | 54 +++++++++++++++++-------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/gramps/gen/filters/_filterlist.py b/gramps/gen/filters/_filterlist.py index 9baca57c0..5270b508c 100644 --- a/gramps/gen/filters/_filterlist.py +++ b/gramps/gen/filters/_filterlist.py @@ -18,6 +18,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # +""" Container class for managing the generic filters """ + #------------------------------------------------------------------------- # # Standard Python modules @@ -25,7 +27,6 @@ #------------------------------------------------------------------------- from xml.sax import make_parser, SAXParseException import os -import sys import collections #------------------------------------------------------------------------- @@ -35,7 +36,6 @@ import collections #------------------------------------------------------------------------- from ._filterparser import FilterParser from ..plug import BasePluginManager -from ..const import GRAMPS_LOCALE as glocale PLUGMAN = BasePluginManager.get_instance() #------------------------------------------------------------------------- @@ -92,13 +92,15 @@ class FilterList: return filters def add(self, namespace, filt): - assert(isinstance(namespace, str)) + """ add a custom filter """ + assert isinstance(namespace, str) if namespace not in self.filter_namespaces: self.filter_namespaces[namespace] = [] self.filter_namespaces[namespace].append(filt) def load(self): + """ load a custom filter """ try: if os.path.isfile(self.file): parser = make_parser() @@ -111,36 +113,40 @@ class FilterList: print("Parser error") def fix(self, line): - l = line.strip() - l = l.replace('&', '&') - l = l.replace('>', '>') - l = l.replace('<', '<') - return l.replace('"', '"') + """ sanitize the custom filter name, if needed """ + new_line = line.strip() + new_line = new_line.replace('&', '&') + new_line = new_line.replace('>', '>') + new_line = new_line.replace('<', '<') + return new_line.replace('"', '"') def save(self): - with open(self.file, 'w', encoding='utf8') as f: - f.write("\n") - f.write('\n') + """ save the list of custom filters """ + with open(self.file, 'w', encoding='utf8') as file: + file.write("\n") + file.write('\n') for namespace in self.filter_namespaces: - f.write('\n' % namespace) + file.write(' \n' % namespace) filter_list = self.filter_namespaces[namespace] sorted_filters = sorted([(filter.get_name(), filter) for filter in filter_list]) for (name, the_filter) in sorted_filters: # enable a diff - f.write(' \n') + file.write(' comment="%s"' % self.fix(comment)) + file.write('>\n') for rule in the_filter.get_rules(): - f.write(' \n' - % (rule.__class__.__name__, rule.use_regex)) + file.write(' ' + '\n' % (rule.__class__.__name__, + rule.use_regex)) for value in list(rule.values()): - f.write(' \n' % self.fix(value)) - f.write(' \n') - f.write(' \n') - f.write('\n') - f.write('\n') + file.write(' ' + '\n' % self.fix(value)) + file.write(' \n') + file.write(' \n') + file.write(' \n') + file.write('\n')