From 102029dfd645123244437dee6fc8c0f72125433b Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sun, 15 Mar 2015 01:18:47 +0200 Subject: Issue #2052: Add charset parameter to HtmlDiff.make_file(). --- Lib/difflib.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'Lib/difflib.py') diff --git a/Lib/difflib.py b/Lib/difflib.py index ae3479d3d8..758f1aad0a 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1598,7 +1598,7 @@ _file_template = """ + content="text/html; charset=%(charset)s" /> @@ -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. -- cgit v1.2.1