summaryrefslogtreecommitdiffstats
path: root/Lib/difflib.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-03-14 23:18:47 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-03-14 23:18:47 (GMT)
commit102029dfd645123244437dee6fc8c0f72125433b (patch)
tree5afa2e1185862e22b95ea6aa8f5d0b614852a287 /Lib/difflib.py
parentfbd011dd4982b883d18039f494475022fc2d0cc6 (diff)
downloadcpython-102029dfd645123244437dee6fc8c0f72125433b.zip
cpython-102029dfd645123244437dee6fc8c0f72125433b.tar.gz
cpython-102029dfd645123244437dee6fc8c0f72125433b.tar.bz2
Issue #2052: Add charset parameter to HtmlDiff.make_file().
Diffstat (limited to 'Lib/difflib.py')
-rw-r--r--Lib/difflib.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/difflib.py b/Lib/difflib.py
index ae3479d..758f1aa 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -1598,7 +1598,7 @@ _file_template = """
<head>
<meta http-equiv="Content-Type"
- content="text/html; charset=ISO-8859-1" />
+ content="text/html; charset=%(charset)s" />
<title></title>
<style type="text/css">%(styles)s
</style>
@@ -1685,8 +1685,8 @@ class HtmlDiff(object):
self._linejunk = linejunk
self._charjunk = charjunk
- def make_file(self,fromlines,tolines,fromdesc='',todesc='',context=False,
- numlines=5):
+ def make_file(self, fromlines, tolines, fromdesc='', todesc='',
+ context=False, numlines=5, *, charset='utf-8'):
"""Returns HTML file of side by side comparison with change highlights
Arguments:
@@ -1701,13 +1701,16 @@ class HtmlDiff(object):
When context is False, controls the number of lines to place
the "next" link anchors before the next change (so click of
"next" link jumps to just before the change).
+ charset -- charset of the HTML document
"""
- return self._file_template % dict(
- styles = self._styles,
- legend = self._legend,
- table = self.make_table(fromlines,tolines,fromdesc,todesc,
- context=context,numlines=numlines))
+ return (self._file_template % dict(
+ styles=self._styles,
+ legend=self._legend,
+ table=self.make_table(fromlines, tolines, fromdesc, todesc,
+ context=context, numlines=numlines),
+ charset=charset
+ )).encode(charset, 'xmlcharrefreplace').decode(charset)
def _tab_newline_replace(self,fromlines,tolines):
"""Returns from/to line lists with tabs expanded and newlines removed.