From 209f34e6fa85a79be48220e483344d0911363b78 Mon Sep 17 00:00:00 2001 From: Ahmed Salhin Date: Fri, 17 Jul 2020 16:50:48 +0100 Subject: [PATCH 1/4] address deprication of cgi in python 3.8 --- version_information/version_information.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/version_information/version_information.py b/version_information/version_information.py index 17efeb6..fb1d3e1 100644 --- a/version_information/version_information.py +++ b/version_information/version_information.py @@ -47,7 +47,7 @@ (the ``version`` field from ``setup.py``). """ -import cgi +import html import json import sys import time @@ -122,20 +122,20 @@ def _repr_json_(self): def _repr_html_(self): - html = "" - html += "" + html_table = "
SoftwareVersion
" + html_table += "" for name, version in self.packages: - _version = cgi.escape(version) - html += "" % (name, _version) + _version = html_table.escape(version) + html_table += "" % (name, _version) try: - html += "" % time.strftime(timefmt) + html_table += "" % time.strftime(timefmt) except: - html += "" % \ + html_table += "" % \ time.strftime(timefmt).decode(_date_format_encoding()) - html += "
SoftwareVersion
%s%s
%s%s
%s
%s
%s
%s
" + html_table += "" - return html + return html_table @staticmethod def _latex_escape(str_): From 661667f7592f1fdd8921b336669f4eba44bc4b9b Mon Sep 17 00:00:00 2001 From: Ahmed Salhin Date: Fri, 17 Jul 2020 16:50:48 +0100 Subject: [PATCH 2/4] address deprecation of cgi in python 3.8 --- version_information/version_information.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/version_information/version_information.py b/version_information/version_information.py index 17efeb6..fb1d3e1 100644 --- a/version_information/version_information.py +++ b/version_information/version_information.py @@ -47,7 +47,7 @@ (the ``version`` field from ``setup.py``). """ -import cgi +import html import json import sys import time @@ -122,20 +122,20 @@ def _repr_json_(self): def _repr_html_(self): - html = "" - html += "" + html_table = "
SoftwareVersion
" + html_table += "" for name, version in self.packages: - _version = cgi.escape(version) - html += "" % (name, _version) + _version = html_table.escape(version) + html_table += "" % (name, _version) try: - html += "" % time.strftime(timefmt) + html_table += "" % time.strftime(timefmt) except: - html += "" % \ + html_table += "" % \ time.strftime(timefmt).decode(_date_format_encoding()) - html += "
SoftwareVersion
%s%s
%s%s
%s
%s
%s
%s
" + html_table += "" - return html + return html_table @staticmethod def _latex_escape(str_): From 2917ab9511db49de94c118ed6c20be58a2e26bd0 Mon Sep 17 00:00:00 2001 From: "William J. Capehart" Date: Sun, 2 Aug 2020 16:18:30 -0600 Subject: [PATCH 3/4] Modification to _repr_html_() to accomodate use of a string type varialbe for html The _latex_escape was duplicated and used in place of the cgi.escape() object from previous versions of _repr_html_() --- version_information/version_information.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/version_information/version_information.py b/version_information/version_information.py index fb1d3e1..cdaeb53 100644 --- a/version_information/version_information.py +++ b/version_information/version_information.py @@ -120,12 +120,30 @@ def _repr_json_(self): else: return json.dumps(obj) + @staticmethod + def _htmltable_escape(str_): + CHARS = { + '&': r'\&', + '%': r'\%', + '$': r'\$', + '#': r'\#', + '_': r'\_', + '{': r'\letteropenbrace{}', + '}': r'\letterclosebrace{}', + '~': r'\lettertilde{}', + '^': r'\letterhat{}', + '\\': r'\letterbackslash{}', + '>': r'\textgreater', + '<': r'\textless', + } + return u"".join([CHARS.get(c, c) for c in str_]) + def _repr_html_(self): html_table = "" html_table += "" for name, version in self.packages: - _version = html_table.escape(version) + _version = html_table._htmltable_escape(version) html_table += "" % (name, _version) try: From 87bde0987160feb315137c51b3d69b6e29c8c8cf Mon Sep 17 00:00:00 2001 From: Bill Capehart Date: Fri, 28 Aug 2020 21:39:56 -0600 Subject: [PATCH 4/4] Corrected error in _repr_html_ --- version_information/version_information.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version_information/version_information.py b/version_information/version_information.py index cdaeb53..9f3d57f 100644 --- a/version_information/version_information.py +++ b/version_information/version_information.py @@ -143,7 +143,7 @@ def _repr_html_(self): html_table = "
SoftwareVersion
%s%s
" html_table += "" for name, version in self.packages: - _version = html_table._htmltable_escape(version) + _version = self._htmltable_escape(version) html_table += "" % (name, _version) try:
SoftwareVersion
%s%s