From e355a93dc171b6eb4ddc62c92ab636f1086f103a Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Fri, 22 May 2015 14:49:02 +0100 Subject: [PATCH] Use escape utility from html rather than cgi module --- gramps/gen/simple/_simpletable.py | 8 ++--- gramps/gen/utils/libformatting.py | 20 ++++++------ gramps/gui/editors/displaytabs/childmodel.py | 6 ++-- .../gui/editors/displaytabs/eventrefmodel.py | 4 +-- .../gui/views/treemodels/citationbasemodel.py | 4 +-- gramps/gui/views/treemodels/eventmodel.py | 4 +-- gramps/gui/widgets/fanchart.py | 2 +- gramps/gui/widgets/fanchartdesc.py | 2 +- gramps/gui/widgets/labels.py | 4 +-- gramps/plugins/gramplet/pedigreegramplet.py | 10 +++--- gramps/plugins/view/geoclose.py | 10 +++--- gramps/plugins/view/pedigreeview.py | 2 +- gramps/plugins/view/relview.py | 32 +++++++++---------- 13 files changed, 54 insertions(+), 54 deletions(-) diff --git a/gramps/gen/simple/_simpletable.py b/gramps/gen/simple/_simpletable.py index 6ffdc6de9..d8393bee6 100644 --- a/gramps/gen/simple/_simpletable.py +++ b/gramps/gen/simple/_simpletable.py @@ -24,7 +24,7 @@ Provide a simplified table creation interface """ -import cgi +from html import escape from ..const import GRAMPS_LOCALE as glocale _ = glocale.translation.sgettext from ..lib import (Person, Family, Event, Source, Place, Citation, @@ -153,7 +153,7 @@ class SimpleTable(object): if item.get_valid(): if item.format: self.set_cell_markup(col, row, - item.format % cgi.escape(text)) + item.format % escape(text)) self.row_sort_val(col, item.sortval) else: # sort before others: @@ -161,7 +161,7 @@ class SimpleTable(object): # give formatted version: invalid_date_format = config.get('preferences.invalid-date-format') self.set_cell_markup(col, row, - invalid_date_format % cgi.escape(text)) + invalid_date_format % escape(text)) if (self._link_col == col or link is None): link = ('Date', item) elif isinstance(item, Span): @@ -261,7 +261,7 @@ class SimpleTable(object): elif y in self._cell_markup[x]: return self._cell_markup[x][y] else: - return cgi.escape(data) + return escape(data) else: if y is None: return False # no markup for this column diff --git a/gramps/gen/utils/libformatting.py b/gramps/gen/utils/libformatting.py index f5ff00f5f..2f4e29287 100644 --- a/gramps/gen/utils/libformatting.py +++ b/gramps/gen/utils/libformatting.py @@ -28,7 +28,7 @@ recompute # Python modules # #------------------------------------------------------------------------- -from cgi import escape +from html import escape #------------------------------------------------------------------------- # @@ -73,17 +73,17 @@ class FormattingHelper(object): text = "" marriage = get_marriage_or_fallback(self.dbstate.db, family) if marriage and use_markup and marriage.get_type() != EventType.MARRIAGE: - mdate = "%s %s" % (marriage.get_type().get_abbreviation(), + mdate = "%s %s" % (marriage.get_type().get_abbreviation(), escape(get_date(marriage))) mplace = "%s" % escape(self.get_place_name(marriage.get_place_handle())) name = "%s" % str(marriage.get_type()) elif marriage and use_markup: - mdate = "%s %s" % (marriage.get_type().get_abbreviation(), + mdate = "%s %s" % (marriage.get_type().get_abbreviation(), escape(get_date(marriage))) mplace = escape(self.get_place_name(marriage.get_place_handle())) name = str(marriage.get_type()) elif marriage: - mdate = "%s %s" % (marriage.get_type().get_abbreviation(), + mdate = "%s %s" % (marriage.get_type().get_abbreviation(), get_date(marriage)) mplace = self.get_place_name(marriage.get_place_handle()) name = str(marriage.get_type()) @@ -149,28 +149,28 @@ class FormattingHelper(object): if line_count >= 3: birth = get_birth_or_fallback(self.dbstate.db, person) if birth and use_markup and birth.get_type() != EventType.BIRTH: - bdate = "%s" % escape(get_date(birth)) + bdate = "%s" % escape(get_date(birth)) bplace = "%s" % escape(self.get_place_name( birth.get_place_handle())) elif birth and use_markup: - bdate = escape(get_date(birth)) + bdate = escape(get_date(birth)) bplace = escape(self.get_place_name(birth.get_place_handle())) elif birth: - bdate = get_date(birth) + bdate = get_date(birth) bplace = self.get_place_name(birth.get_place_handle()) else: bdate = "" bplace = "" death = get_death_or_fallback(self.dbstate.db, person) if death and use_markup and death.get_type() != EventType.DEATH: - ddate = "%s" % escape(get_date(death)) + ddate = "%s" % escape(get_date(death)) dplace = "%s" % escape(self.get_place_name( death.get_place_handle())) elif death and use_markup: - ddate = escape(get_date(death)) + ddate = escape(get_date(death)) dplace = escape(self.get_place_name(death.get_place_handle())) elif death: - ddate = get_date(death) + ddate = get_date(death) dplace = self.get_place_name(death.get_place_handle()) else: ddate = "" diff --git a/gramps/gui/editors/displaytabs/childmodel.py b/gramps/gui/editors/displaytabs/childmodel.py index b9f2006b5..2458ee71b 100644 --- a/gramps/gui/editors/displaytabs/childmodel.py +++ b/gramps/gui/editors/displaytabs/childmodel.py @@ -24,7 +24,7 @@ # #------------------------------------------------------------------------- from gi.repository import Gtk -import cgi +from html import escape #------------------------------------------------------------------------- # @@ -76,7 +76,7 @@ class ChildModel(Gtk.ListStore): if birth.get_type() == EventType.BIRTH: return get_date(birth) else: - return '%s' % cgi.escape(get_date(birth)) + return '%s' % escape(get_date(birth)) else: return "" @@ -99,7 +99,7 @@ class ChildModel(Gtk.ListStore): if death.get_type() == EventType.DEATH: return get_date(death) else: - return '%s' % cgi.escape(get_date(death)) + return '%s' % escape(get_date(death)) else: return "" diff --git a/gramps/gui/editors/displaytabs/eventrefmodel.py b/gramps/gui/editors/displaytabs/eventrefmodel.py index 16eb72fc0..a03df98b3 100644 --- a/gramps/gui/editors/displaytabs/eventrefmodel.py +++ b/gramps/gui/editors/displaytabs/eventrefmodel.py @@ -38,7 +38,7 @@ from gi.repository import Pango WEIGHT_NORMAL = Pango.Weight.NORMAL WEIGHT_BOLD = Pango.Weight.BOLD -import cgi +from html import escape #------------------------------------------------------------------------- # @@ -145,7 +145,7 @@ class EventRefModel(Gtk.TreeStore): event = self.db.get_event_from_handle(event_ref.ref) retval = get_date(event) if not get_date_valid(event): - return invalid_date_format % cgi.escape(retval) + return invalid_date_format % escape(retval) else: return retval diff --git a/gramps/gui/views/treemodels/citationbasemodel.py b/gramps/gui/views/treemodels/citationbasemodel.py index 6d55dffcc..1c47100ed 100644 --- a/gramps/gui/views/treemodels/citationbasemodel.py +++ b/gramps/gui/views/treemodels/citationbasemodel.py @@ -28,7 +28,7 @@ CitationBaseModel classes for GRAMPS. # python modules # #------------------------------------------------------------------------- -import cgi +from html import escape import logging log = logging.getLogger(".") LOG = logging.getLogger(".citation") @@ -90,7 +90,7 @@ class CitationBaseModel(object): citation.unserialize(data) date_str = get_date(citation) if date_str != "": - retval = cgi.escape(date_str) + retval = escape(date_str) if not get_date_valid(citation): return INVALID_DATE_FORMAT % retval else: diff --git a/gramps/gui/views/treemodels/eventmodel.py b/gramps/gui/views/treemodels/eventmodel.py index 9fe913657..6f57dfb66 100644 --- a/gramps/gui/views/treemodels/eventmodel.py +++ b/gramps/gui/views/treemodels/eventmodel.py @@ -23,7 +23,7 @@ # python modules # #------------------------------------------------------------------------- -import cgi +from html import escape import logging log = logging.getLogger(".") @@ -149,7 +149,7 @@ class EventModel(FlatBaseModel): event.unserialize(data) date_str = get_date(event) if date_str != "": - retval = cgi.escape(date_str) + retval = escape(date_str) if not get_date_valid(event): return INVALID_DATE_FORMAT % retval else: diff --git a/gramps/gui/widgets/fanchart.py b/gramps/gui/widgets/fanchart.py index e03063c17..60c9a4d0c 100644 --- a/gramps/gui/widgets/fanchart.py +++ b/gramps/gui/widgets/fanchart.py @@ -44,7 +44,7 @@ import math import colorsys import sys import pickle -from cgi import escape +from html import escape #------------------------------------------------------------------------- # diff --git a/gramps/gui/widgets/fanchartdesc.py b/gramps/gui/widgets/fanchartdesc.py index 57d6aa86b..ecee93cb1 100644 --- a/gramps/gui/widgets/fanchartdesc.py +++ b/gramps/gui/widgets/fanchartdesc.py @@ -42,7 +42,7 @@ import cairo import math import colorsys import pickle -from cgi import escape +from html import escape #------------------------------------------------------------------------- # diff --git a/gramps/gui/widgets/labels.py b/gramps/gui/widgets/labels.py index 5a0a3f8bd..80553ffa6 100644 --- a/gramps/gui/widgets/labels.py +++ b/gramps/gui/widgets/labels.py @@ -27,7 +27,7 @@ __all__ = ["LinkLabel", "EditLabel", "BasicLabel", "GenderLabel", # #------------------------------------------------------------------------- import os -import cgi +from html import escape from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext import logging @@ -112,7 +112,7 @@ class LinkLabel(Gtk.EventBox): else: raise AttributeError("invalid theme: '%s'" % theme) - self.orig_text = cgi.escape(label[0]) + self.orig_text = escape(label[0]) self.gender = label[1] self.decoration = format text = '%s' % (self.decoration, self.orig_text) diff --git a/gramps/plugins/gramplet/pedigreegramplet.py b/gramps/plugins/gramplet/pedigreegramplet.py index 6d70baa89..e61b06f71 100644 --- a/gramps/plugins/gramplet/pedigreegramplet.py +++ b/gramps/plugins/gramplet/pedigreegramplet.py @@ -22,7 +22,7 @@ # Python modules # #------------------------------------------------------------------------ -import cgi +from html import escape #------------------------------------------------------------------------ # @@ -196,11 +196,11 @@ class PedigreeGramplet(Gramplet): if birth and birth.get_type() != EventType.BIRTH: sdate = get_date(birth) if sdate: - bdate = "%s" % cgi.escape(sdate) + bdate = "%s" % escape(sdate) else: bdate = "" elif birth: - bdate = cgi.escape(get_date(birth)) + bdate = escape(get_date(birth)) else: bdate = "" @@ -208,11 +208,11 @@ class PedigreeGramplet(Gramplet): if death and death.get_type() != EventType.DEATH: sdate = get_date(death) if sdate: - ddate = "%s" % cgi.escape(sdate) + ddate = "%s" % escape(sdate) else: ddate = "" elif death: - ddate = cgi.escape(get_date(death)) + ddate = escape(get_date(death)) else: ddate = "" diff --git a/gramps/plugins/view/geoclose.py b/gramps/plugins/view/geoclose.py index be7d91255..db6b555a9 100644 --- a/gramps/plugins/view/geoclose.py +++ b/gramps/plugins/view/geoclose.py @@ -33,7 +33,7 @@ _ = glocale.translation.gettext import operator from gi.repository import Gtk from math import * -import cgi +from html import escape #------------------------------------------------------------------------- # @@ -249,11 +249,11 @@ class GeoClose(GeoGraphyView): if birth and birth.get_type() != EventType.BIRTH: sdate = get_date(birth) if sdate: - bdate = "%s" % cgi.escape(sdate) + bdate = "%s" % escape(sdate) else: bdate = "" elif birth: - bdate = cgi.escape(get_date(birth)) + bdate = escape(get_date(birth)) else: bdate = "" return bdate @@ -266,11 +266,11 @@ class GeoClose(GeoGraphyView): if death and death.get_type() != EventType.DEATH: sdate = get_date(death) if sdate: - ddate = "%s" % cgi.escape(sdate) + ddate = "%s" % escape(sdate) else: ddate = "" elif death: - ddate = cgi.escape(get_date(death)) + ddate = escape(get_date(death)) else: ddate = "" return ddate diff --git a/gramps/plugins/view/pedigreeview.py b/gramps/plugins/view/pedigreeview.py index a7ffd4b8b..33f40b075 100644 --- a/gramps/plugins/view/pedigreeview.py +++ b/gramps/plugins/view/pedigreeview.py @@ -27,7 +27,7 @@ # Python modules # #------------------------------------------------------------------------- -from cgi import escape +from html import escape import math import os import pickle diff --git a/gramps/plugins/view/relview.py b/gramps/plugins/view/relview.py index 55f817e48..a3499cda8 100644 --- a/gramps/plugins/view/relview.py +++ b/gramps/plugins/view/relview.py @@ -30,7 +30,7 @@ Relationship View from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.sgettext ngettext = glocale.translation.ngettext # else "nearby" comments are ignored -import cgi +from html import escape import pickle #------------------------------------------------------------------------- @@ -206,7 +206,7 @@ class RelationshipView(NavigationView): def person_update(self, handle_list): if self.active: - person = self.get_active() + person = self.get_active() if person: while not self.change_person(person): pass @@ -219,7 +219,7 @@ class RelationshipView(NavigationView): """Large change to person database""" if self.active: self.bookmarks.redraw() - person = self.get_active() + person = self.get_active() if person: while not self.change_person(person): pass @@ -230,7 +230,7 @@ class RelationshipView(NavigationView): def family_update(self, handle_list): if self.active: - person = self.get_active() + person = self.get_active() if person: while not self.change_person(person): pass @@ -241,7 +241,7 @@ class RelationshipView(NavigationView): def family_add(self, handle_list): if self.active: - person = self.get_active() + person = self.get_active() if person: while not self.change_person(person): pass @@ -252,7 +252,7 @@ class RelationshipView(NavigationView): def family_delete(self, handle_list): if self.active: - person = self.get_active() + person = self.get_active() if person: while not self.change_person(person): pass @@ -263,7 +263,7 @@ class RelationshipView(NavigationView): def family_rebuild(self): if self.active: - person = self.get_active() + person = self.get_active() if person: while not self.change_person(person): pass @@ -558,7 +558,7 @@ class RelationshipView(NavigationView): # name and edit button name = name_displayer.display(person) fmt = '%s' - text = fmt % cgi.escape(name) + text = fmt % escape(name) label = widgets.DualMarkupLabel(text, _GenderCode[person.gender], x_align=1) if self._config.get('preferences.releditbtn'): @@ -740,7 +740,7 @@ class RelationshipView(NavigationView): Shows following elements: (collapse/expand arrow, Parents/Family title label, Family gramps_id, and add-choose-edit-delete buttons) """ - msg = '%s' % cgi.escape(title) + msg = '%s' % escape(title) hbox = Gtk.Box() label = widgets.MarkupLabel(msg, x_align=1) # Draw the collapse/expand button: @@ -1012,7 +1012,7 @@ class RelationshipView(NavigationView): else: format = "%s" - label = widgets.MarkupLabel(format % cgi.escape(title), + label = widgets.MarkupLabel(format % escape(title), x_align=1, y_align=0) if self._config.get('preferences.releditbtn'): label.set_padding(0, 5) @@ -1111,7 +1111,7 @@ class RelationshipView(NavigationView): else: format = "%s" - lbl = widgets.MarkupLabel(format % cgi.escape(title), + lbl = widgets.MarkupLabel(format % escape(title), x_align=1, y_align=.5) if self._config.get('preferences.releditbtn'): lbl.set_padding(0, 5) @@ -1201,11 +1201,11 @@ class RelationshipView(NavigationView): if birth and birth.get_type() != EventType.BIRTH: sdate = get_date(birth) if sdate: - bdate = "%s" % cgi.escape(sdate) + bdate = "%s" % escape(sdate) else: bdate = "" elif birth: - bdate = cgi.escape(get_date(birth)) + bdate = escape(get_date(birth)) else: bdate = "" @@ -1213,11 +1213,11 @@ class RelationshipView(NavigationView): if death and death.get_type() != EventType.DEATH: sdate = get_date(death) if sdate: - ddate = "%s" % cgi.escape(sdate) + ddate = "%s" % escape(sdate) else: ddate = "" elif death: - ddate = cgi.escape(get_date(death)) + ddate = escape(get_date(death)) else: ddate = "" @@ -1292,7 +1292,7 @@ class RelationshipView(NavigationView): pass def write_relationship(self, box, family): - msg = _('Relationship type: %s') % cgi.escape(str(family.get_relationship())) + msg = _('Relationship type: %s') % escape(str(family.get_relationship())) box.add(widgets.MarkupLabel(msg)) def write_relationship_events(self, vbox, family):