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