diff --git a/ChangeLog b/ChangeLog index 2433fd4b7..3a30a8282 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-06-21 Alex Roitman + * src/GrampsCfg.py (cb_format_changed): Catch new exception; + escape special chars from displayed span. + * src/NameDisplay.py (_gen_cooked_func): Only replace known + parameters, leave the rest as is; + (_format_str_base): Catch formatting exceptions and raise our own. + * src/Errors.py (NameDisplayError): Add class. + 2007-06-22 Zsolt Foldvari * src/NameDisplay.py: fix indentation (use only spaces). * src/GrampsCfg.py: handle invalid name format: #1025. diff --git a/src/Errors.py b/src/Errors.py index 3e7316793..80d3711b8 100644 --- a/src/Errors.py +++ b/src/Errors.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2003-2006 Donald N. Allingham +# Copyright (C) 2003-2007 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -135,3 +135,13 @@ class MaskError(Exception): class ValidationError(Exception): pass +class NameDisplayError(Exception): + """ + Error used to report that the name display format string is invalid. + """ + def __init__(self,value): + Exception.__init__(self) + self.value = value + + def __str__(self): + return self.value diff --git a/src/GrampsCfg.py b/src/GrampsCfg.py index e0be6821e..f6000be93 100644 --- a/src/GrampsCfg.py +++ b/src/GrampsCfg.py @@ -26,6 +26,7 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +from xml.sax.saxutils import escape #------------------------------------------------------------------------- # @@ -46,6 +47,7 @@ from RelLib import Name import ManagedWindow from GrampsWidgets import * import QuestionDialog +from Errors import NameDisplayError #------------------------------------------------------------------------- # @@ -620,13 +622,13 @@ class NameFormatEditDlg: def cb_format_changed(self, obj): try: - t = (_nd.format_str(self.name, obj.get_text())) + t = (_nd.format_str(self.name, escape(obj.get_text()))) sample = '%s' % t self.valid = True - except ValueError, msg: + except NameDisplayError: t = _("Invalid or incomplete format definition") sample = '%s' % t self.valid = False - + self.examplelabel.set_text(sample) self.examplelabel.set_use_markup(True) diff --git a/src/NameDisplay.py b/src/NameDisplay.py index 6c9652aa9..d8a528df3 100644 --- a/src/NameDisplay.py +++ b/src/NameDisplay.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2006 Donald N. Allingham +# Copyright (C) 2004-2007 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,6 +39,7 @@ import re #------------------------------------------------------------------------- from RelLib import Name import Config +from Errors import NameDisplayError #------------------------------------------------------------------------- # @@ -373,7 +374,7 @@ class NameDisplay: # for each one we find the variable name that is needed to # replace it and add this to a list. This list will be used # generate the replacement tuple. - pat = re.compile("%.") + pat = re.compile('|'.join(d.keys())) param = () mat = pat.search(format_str) @@ -433,10 +434,14 @@ class NameDisplay: func = self._gen_cooked_func(format_str) self.__class__.format_funcs[format_str] = func - s = func(first,surname,prefix,suffix,patronymic,title,call) + try: + s = func(first,surname,prefix,suffix,patronymic,title,call) + except (ValueError,TypeError,): + raise NameDisplayError, "Incomplete format string" + return ' '.join(s.split()) - #------------------------------------------------------------------------- + #------------------------------------------------------------------------- def sort_string(self,name): return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)