From 9df661af87160a2eb39d7c01d8813b24a8126b92 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 11 Dec 2006 21:09:25 +0000 Subject: [PATCH] 2006-12-11 Don Allingham * src/GrampsDb/_WriteXML.py: handle XML escapes * src/DisplayModels/_BaseModel.py: handle ignored values in filtering svn: r7782 --- ChangeLog | 4 ++++ src/DisplayModels/_BaseModel.py | 13 +++++++++---- src/GrampsDb/_WriteXML.py | 29 ++++++++++++++++------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8944d4db9..5ad1640d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-12-11 Don Allingham + * src/GrampsDb/_WriteXML.py: handle XML escapes + * src/DisplayModels/_BaseModel.py: handle ignored values in filtering + 2006-12-10 Martin Hawlisch * src/DataViews/_RelationView.py (change_person): Break endless loop by passing the return values from _change_person. diff --git a/src/DisplayModels/_BaseModel.py b/src/DisplayModels/_BaseModel.py index b0cdeabfd..d7b7b067b 100644 --- a/src/DisplayModels/_BaseModel.py +++ b/src/DisplayModels/_BaseModel.py @@ -114,9 +114,11 @@ class BaseModel(gtk.GenericTreeModel): if self.db.is_open(): if self.search: self.datalist = [h for h in self.sort_keys()\ - if self.search.match(h) and h not in self.skip and h != ignore] + if self.search.match(h) and \ + h not in self.skip and h != ignore] else: - self.datalist = [h for h in self.sort_keys() if h not in self.skip and h != ignore] + self.datalist = [h for h in self.sort_keys() \ + if h not in self.skip and h != ignore] i = 0 self.indexlist = {} for key in self.datalist: @@ -130,9 +132,12 @@ class BaseModel(gtk.GenericTreeModel): def _rebuild_filter(self, ignore=None): if self.db.is_open(): if self.search: - self.datalist = self.search.apply(self.db, [ k for k in self.sort_keys() if k != ignore]) + self.datalist = self.search.apply(self.db, + [ k for k in self.sort_keys()\ + if k != ignore]) else: - self.datalist = self.sort_keys() + self.datalist = [ k for k in self.sort_keys() \ + if k != ignore ] i = 0 self.indexlist = {} diff --git a/src/GrampsDb/_WriteXML.py b/src/GrampsDb/_WriteXML.py index 1be65f639..2a782771a 100644 --- a/src/GrampsDb/_WriteXML.py +++ b/src/GrampsDb/_WriteXML.py @@ -34,6 +34,7 @@ import time import shutil import os import codecs +from xml.sax.saxutils import escape from gettext import gettext as _ #------------------------------------------------------------------------ @@ -75,6 +76,11 @@ _xml_version = "1.1.3" # table for skipping control chars from XML strip_dict = dict.fromkeys(range(9)+range(12,20)) + +def escxml(d): + return esacpe(d, { '"' : '"' } ) + + #------------------------------------------------------------------------- # # @@ -372,10 +378,7 @@ class XmlWriter(UpdateCallback): except: l = unicode(str(line),errors='replace') l = l.strip().translate(strip_dict) - l = l.replace('&','&') - l = l.replace('>','>') - l = l.replace('<','<') - return l.replace('"','"') + return escxml(l) def write_note(self,val,noteobj,indent=0): if not noteobj: @@ -546,11 +549,11 @@ class XmlWriter(UpdateCallback): if childref.frel.is_default(): frel_text = '' else: - frel_text = ' frel="%s"' % childref.frel.xml_str() + frel_text = ' frel="%s"' % escxml(childref.frel.xml_str()) if childref.mrel.is_default(): mrel_text = '' else: - mrel_text = ' mrel="%s"' % childref.mrel.xml_str() + mrel_text = ' mrel="%s"' % escxml(childref.mrel.xml_str()) sreflist = childref.get_source_references() if (len(sreflist) == 0) and childref.get_note() =="": self.write_ref('childref',childref.ref,index,close=True, @@ -568,7 +571,7 @@ class XmlWriter(UpdateCallback): return sp = " "*index priv_text = conf_priv(eventref) - role = eventref.role.xml_str() + role = escxml(eventref.role.xml_str()) if role: role_text = ' role="%s"' % role else: @@ -670,7 +673,7 @@ class XmlWriter(UpdateCallback): sp = " "*index marker = obj.get_marker().xml_str() if marker: - marker_text = ' marker="%s"' % marker + marker_text = ' marker="%s"' % escxml(marker) else: marker_text = '' priv_text = conf_priv(obj) @@ -685,7 +688,7 @@ class XmlWriter(UpdateCallback): sp = " "*index self.write_primary_tag('family',family,index) if family: - rel = family.get_relationship().xml_str() + rel = escxml(family.get_relationship().xml_str()) if rel != "": self.g.write(' %s\n' % (sp,rel) ) @@ -785,7 +788,7 @@ class XmlWriter(UpdateCallback): if alternative: self.g.write(' alt="1"') if name_type: - self.g.write(' type="%s"' % name_type) + self.g.write(' type="%s"' % escxml(name_type)) if name.get_privacy() != 0: self.g.write(' priv="%d"' % name.get_privacy()) if name.get_sort_as() != 0: @@ -875,7 +878,7 @@ class XmlWriter(UpdateCallback): sp = ' ' * indent for attr in list: self.g.write('%s