Skip to content

Commit 02b5cf0

Browse files
nathanbegbiesoftvar
authored andcommitted
use html.escape instead of cgi.escape for python3 (#40)
Based on the following: DeprecationWarning: cgi.escape is deprecated, use html.escape instead
1 parent 7070939 commit 02b5cf0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

json2html/jsonconv.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
--------
1818
"""
1919

20-
import sys, cgi
20+
import sys
2121

2222
if sys.version_info[:2] < (2, 7):
2323
from ordereddict import OrderedDict
@@ -27,12 +27,15 @@
2727
import json as json_parser
2828

2929
if sys.version_info[:2] < (3, 0):
30+
from cgi import escape as html_escape
3031
text = unicode
3132
text_types = (unicode, str)
3233
else:
34+
from html import escape as html_escape
3335
text = str
3436
text_types = (str,)
3537

38+
3639
class Json2Html:
3740
def convert(self, json="", table_attributes='border="1"', clubbing=True, encode=False, escape=True):
3841
"""
@@ -93,7 +96,7 @@ def convert_json_node(self, json_input):
9396
"""
9497
if type(json_input) in text_types:
9598
if self.escape:
96-
return cgi.escape(text(json_input))
99+
return html_escape(text(json_input))
97100
else:
98101
return text(json_input)
99102
if hasattr(json_input, 'items'):

0 commit comments

Comments
 (0)