diff --git a/gramps/plugins/webreport/webcal.py b/gramps/plugins/webreport/webcal.py index d9659e1cc..1956bad4e 100644 --- a/gramps/plugins/webreport/webcal.py +++ b/gramps/plugins/webreport/webcal.py @@ -14,10 +14,10 @@ # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # -# This program is distributed in the hope that it will be useful, +# This program is distributed in the hope that it will be useful, calendar # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU General Public License for more details.calendar # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software @@ -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):