1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-25 02:34:31 +01:00

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

View File

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