0006410: Webcal report crashes and freezes alpha4. For python3 simply opening the file works.

svn: r21458
This commit is contained in:
Tim G L Lyons 2013-02-26 17:14:54 +00:00
parent 138bbb047b
commit ed8b6b9edf

View File

@ -34,7 +34,7 @@ Web Calendar generator.
# python modules # python modules
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from functools import partial from functools import partial
import os, codecs, shutil, re import os, codecs, shutil, re, sys
import datetime, calendar import datetime, calendar
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.get_translation().sgettext _ = glocale.get_translation().sgettext
@ -368,7 +368,22 @@ class WebCalReport(Report):
if not os.path.isdir(destdir): if not os.path.isdir(destdir):
os.makedirs(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 return of
def close_file(self, of): def close_file(self, of):