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

svn: r21457
This commit is contained in:
Tim G L Lyons 2013-02-26 17:14:28 +00:00
parent 114a71c13c
commit daae9242bf

View File

@ -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):