Narrative web: fix tar file output and HTML encoding output support.
svn: r21258
This commit is contained in:
parent
ef9464006e
commit
adb94b1974
@ -202,7 +202,7 @@ class Html(list):
|
||||
if title is not None:
|
||||
head += (Html('title', title, inline=True, indent=True))
|
||||
if html5:
|
||||
head += Html('meta', charset="utf-8", indent=True)
|
||||
head += Html('meta', charset=encoding, indent=True)
|
||||
else:
|
||||
meta1 = 'http-equiv="content-type" content="text/html;charset=%s"'
|
||||
meta2 = 'http-equiv="Content-Style-Type" content="text/css"'
|
||||
|
@ -82,12 +82,13 @@ import time, datetime
|
||||
import locale
|
||||
import shutil
|
||||
import io
|
||||
import codecs
|
||||
import tarfile
|
||||
import tempfile
|
||||
if sys.version_info[0] < 3:
|
||||
from cStringIO import StringIO
|
||||
else:
|
||||
from io import StringIO
|
||||
from io import StringIO, BytesIO, TextIOWrapper, BufferedWriter
|
||||
from textwrap import TextWrapper
|
||||
from unicodedata import normalize
|
||||
from collections import defaultdict
|
||||
@ -7828,9 +7829,14 @@ class NavWebReport(Report):
|
||||
else:
|
||||
self.cur_fname = fname + ext
|
||||
if self.archive:
|
||||
string_io = StringIO()
|
||||
of = io.open(fname, "w", encoding = self.encoding,
|
||||
errors = 'xmlcharrefreplace')
|
||||
if sys.version_info[0] < 3:
|
||||
string_io = StringIO()
|
||||
of = codecs.EncodedFile(string_io, 'utf-8', self.encoding,
|
||||
'xmlcharrefreplace')
|
||||
else:
|
||||
string_io = BytesIO()
|
||||
of = TextIOWrapper(string_io, encoding=self.encoding,
|
||||
errors='xmlcharrefreplace')
|
||||
else:
|
||||
string_io = None
|
||||
if subdir:
|
||||
@ -7838,8 +7844,22 @@ class NavWebReport(Report):
|
||||
if not os.path.isdir(subdir):
|
||||
os.makedirs(subdir)
|
||||
fname = os.path.join(self.html_dir, self.cur_fname)
|
||||
of = io.open(fname, "w", encoding = self.encoding,
|
||||
errors = '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, string_io)
|
||||
|
||||
def close_file(self, of, string_io):
|
||||
@ -7848,6 +7868,8 @@ class NavWebReport(Report):
|
||||
"""
|
||||
|
||||
if self.archive:
|
||||
if sys.version_info[0] >= 3:
|
||||
of.flush()
|
||||
tarinfo = tarfile.TarInfo(self.cur_fname)
|
||||
tarinfo.size = len(string_io.getvalue())
|
||||
tarinfo.mtime = time.time()
|
||||
|
Loading…
Reference in New Issue
Block a user