From bf309faa3452fd9cc8cb86c8c4b41e7b4ab2b372 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Sat, 26 Aug 2006 19:39:32 +0000 Subject: [PATCH] 2006-08-26 Alex Roitman * src/Filters/Rules/Person/__init__.py (register): Add dictionary for private rules. * src/Filters/_FilterParser.py (startElement): Support parsing for private rules. svn: r7272 --- ChangeLog | 6 ++++++ src/Filters/Rules/Person/__init__.py | 4 ++++ src/Filters/_FilterParser.py | 20 +++++++++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index de8bbb203..660054f79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-08-26 Alex Roitman + * src/Filters/Rules/Person/__init__.py (register): Add dictionary + for private rules. + * src/Filters/_FilterParser.py (startElement): Support parsing for + private rules. + 2006-08-26 Don Allingham * src/GrampsDb/_GrampsDbBase.py (GrampsDbBase.get_name_group_mapping): convert group as name used as a key back to unicode (bug #389) diff --git a/src/Filters/Rules/Person/__init__.py b/src/Filters/Rules/Person/__init__.py index 139614d75..e56104b91 100644 --- a/src/Filters/Rules/Person/__init__.py +++ b/src/Filters/Rules/Person/__init__.py @@ -93,6 +93,9 @@ from _RegExpName import RegExpName from _MatchIdOf import MatchIdOf from _RegExpIdOf import RegExpIdOf +# This is the name->class storage for private rule classes +private = {} + #------------------------------------------------------------------------- # # This is used by Custom Filter Editor tool @@ -156,4 +159,5 @@ editor_rule_list = [ ] def register(rule): + private[rule.__name__] = rule editor_rule_list.append(rule) diff --git a/src/Filters/_FilterParser.py b/src/Filters/_FilterParser.py index 5cebfed37..c452cab1b 100644 --- a/src/Filters/_FilterParser.py +++ b/src/Filters/_FilterParser.py @@ -91,15 +91,21 @@ class FilterParser(handler.ContentHandler): except (ImportError, NameError, AttributeError ): # Now try to use name from Rules.Namespace mc_match = save_name.split('.') + last_name = mc_match[-1] try: exec 'self.r = Rules.%s.%s' % ( - self.namespace,mc_match[-1]) - except (ImportError, NameError ): - print "ERROR: Filter rule '%s' in "\ - "filter '%s' not found!"\ - % (save_name,self.f.get_name()) - self.r = None - return + self.namespace,last_name) + except (ImportError, NameError, AttributeError ): + # Now try the private rule + try: + exec "self.r = Rules.%s.private['%s']" % ( + self.namespace,last_name) + except KeyError: + print "ERROR: Filter rule '%s' in "\ + "filter '%s' not found!"\ + % (save_name,self.f.get_name()) + self.r = None + return self.a = [] elif tag == "arg": self.a.append(attrs['value'])