remove deprecation warning for html escape

in python 2, (html) escape is part of the cgi module
in python 3, it's part of the html module

we now do a conditional import depending on the version, and name the
function html_escape.
This commit is contained in:
kakwa 2019-02-09 16:29:16 +01:00
parent 79983c078f
commit 90ff69586b
1 changed files with 4 additions and 3 deletions

View File

@ -15,7 +15,6 @@ import logging
import logging.handlers
from operator import itemgetter
from socket import error as socket_error
import cgi
from ldapcherry.exceptions import *
from ldapcherry.lclogging import *
@ -35,8 +34,10 @@ from mako import exceptions
if sys.version < '3':
from sets import Set as set
from urllib import quote_plus
from cgi import escape as html_escape
else:
from urllib.parse import quote_plus
from html import escape as html_escape
SESSION_KEY = '_cp_username'
@ -64,7 +65,7 @@ class LdapCherry(object):
def _escape_list(self, data):
ret = []
for i in data:
ret.append(cgi.escape(i, True))
ret.append(html_escape(i, True))
return ret
def _escape_dict(self, data):
@ -76,7 +77,7 @@ class LdapCherry(object):
elif isinstance(data[d], set):
data[d] = set(self._escape_list(data[d]))
else:
data[d] = cgi.escape(data[d], True)
data[d] = html_escape(data[d], True)
return data
def _escape(self, data, dtype):