| diff --git a/cherrypy/lib/covercp.py b/cherrypy/lib/covercp.py |
| index 6c3871f..f22cce7 100644 |
| --- a/cherrypy/lib/covercp.py |
| +++ b/cherrypy/lib/covercp.py |
| @@ -22,7 +22,7 @@ |
| |
| import re |
| import sys |
| -import cgi |
| +import html |
| import os |
| import os.path |
| import urllib.parse |
| @@ -352,9 +352,9 @@ def annotated_file(self, filename, statements, excluded, missing): |
| buffer.append((lineno, line)) |
| if empty_the_buffer: |
| for lno, pastline in buffer: |
| - yield template % (lno, cgi.escape(pastline)) |
| + yield template % (lno, html.escape(pastline)) |
| buffer = [] |
| - yield template % (lineno, cgi.escape(line)) |
| + yield template % (lineno, html.escape(line)) |
| |
| @cherrypy.expose |
| def report(self, name): |
| diff --git a/cherrypy/lib/headers.py b/cherrypy/lib/headers.py |
| new file mode 100644 |
| index 0000000..ddbe515 |
| --- /dev/null |
| +++ b/cherrypy/lib/headers.py |
| @@ -0,0 +1,39 @@ |
| +"""headers.""" |
| + |
| + |
| +def _parse_param(s): |
| + while s[:1] == ';': |
| + s = s[1:] |
| + end = s.find(';') |
| + while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2: |
| + end = s.find(';', end + 1) |
| + if end < 0: |
| + end = len(s) |
| + f = s[:end] |
| + yield f.strip() |
| + s = s[end:] |
| + |
| + |
| +def parse_header(line): |
| + """Parse a Content-type like header. |
| + |
| + Return the main content-type and a dictionary of options. |
| + |
| + Copied from removed stdlib cgi module. See |
| + `cherrypy/cherrypy#2014 (comment) |
| + <https://github.com/cherrypy/cherrypy/issues/2014#issuecomment-1883774891>`_ |
| + for background. |
| + """ |
| + parts = _parse_param(';' + line) |
| + key = parts.__next__() |
| + pdict = {} |
| + for p in parts: |
| + i = p.find('=') |
| + if i >= 0: |
| + name = p[:i].strip().lower() |
| + value = p[i + 1:].strip() |
| + if len(value) >= 2 and value[0] == value[-1] == '"': |
| + value = value[1:-1] |
| + value = value.replace('\\\\', '\\').replace('\\"', '"') |
| + pdict[name] = value |
| + return key, pdict |
| diff --git a/cherrypy/lib/httputil.py b/cherrypy/lib/httputil.py |
| --- a/cherrypy/lib/httputil.py |
| +++ b/cherrypy/lib/httputil.py |
| @@ -20,4 +20,3 @@ |
| import re |
| from binascii import b2a_base64 |
| -from cgi import parse_header |
| from email.header import decode_header |
| @@ -29,5 +28,6 @@ |
| import cherrypy |
| from cherrypy._cpcompat import ntob, ntou |
| from cherrypy._cpcompat import unquote_plus |
| +from .headers import parse_header |
| |
| response_codes = BaseHTTPRequestHandler.responses.copy() |