From ed8b6b9edfc40a814f7aa3da312d0b4df70c6ba3 Mon Sep 17 00:00:00 2001 From: Tim G L Lyons Date: Tue, 26 Feb 2013 17:14:54 +0000 Subject: [PATCH] 0006410: Webcal report crashes and freezes alpha4. For python3 simply opening the file works. svn: r21458 --- gramps/plugins/webreport/webcal.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gramps/plugins/webreport/webcal.py b/gramps/plugins/webreport/webcal.py index d9659e1cc..250604278 100644 --- a/gramps/plugins/webreport/webcal.py +++ b/gramps/plugins/webreport/webcal.py @@ -34,7 +34,7 @@ Web Calendar generator. # python modules #------------------------------------------------------------------------ from functools import partial -import os, codecs, shutil, re +import os, codecs, shutil, re, sys import datetime, calendar from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.get_translation().sgettext @@ -368,7 +368,22 @@ class WebCalReport(Report): if not os.path.isdir(destdir): os.makedirs(destdir) - of = codecs.EncodedFile(open(fname, "w"), 'utf-8', self.encoding, 'xmlcharrefreplace') + if sys.version_info[0] < 3: + # In python 2.x, the data written by of.write() is genarally of + # type 'str' (i.e. 8-bit strings), except for cases where (at + # least) one of the objects being converted by a '%' operator is + # unicode (e.g. the "Generated by" line or the _META3 line), in + # which case the data being written is of type 'unicode' (See + # http://docs.python.org/2/library/stdtypes.html#string- + # formatting). The data written to the file is encoded according + # to self.encoding + of = codecs.EncodedFile(open(fname, 'w'), 'utf-8', + self.encoding, 'xmlcharrefreplace') + else: + # In python 3, the data that is written by of.write() is always + # of type 'str' (i.e. unicode text). + of = open(fname, 'w', encoding=self.encoding, + errors='xmlcharrefreplace') return of def close_file(self, of):