From 7b08b70edbb09bc9afaad951d57f7d4cbe6a5893 Mon Sep 17 00:00:00 2001 From: meator Date: Sat, 13 Apr 2024 10:49:01 +0200 Subject: [PATCH] Fix invalid escape sequences --- .../backports/email/_header_value_parser.py | 16 ++++++++-------- src/future/backports/email/feedparser.py | 2 +- src/future/backports/email/utils.py | 2 +- src/future/backports/html/parser.py | 4 ++-- src/future/backports/http/client.py | 2 +- src/future/backports/http/cookiejar.py | 6 +++--- src/future/backports/test/support.py | 2 +- src/future/backports/urllib/parse.py | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/future/backports/email/_header_value_parser.py b/src/future/backports/email/_header_value_parser.py index 59b1b318..2e851d82 100644 --- a/src/future/backports/email/_header_value_parser.py +++ b/src/future/backports/email/_header_value_parser.py @@ -659,8 +659,8 @@ def quote(self, value): if value.token_type == 'comment': return str(value) return str(value).replace('\\', '\\\\').replace( - '(', '\(').replace( - ')', '\)') + '(', '\\(').replace( + ')', '\\)') @property def content(self): @@ -1346,15 +1346,15 @@ def __str__(self): _wsp_splitter = re.compile(r'([{}]+)'.format(''.join(WSP))).split _non_atom_end_matcher = re.compile(r"[^{}]+".format( - ''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\]'))).match + ''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\\]'))).match _non_printable_finder = re.compile(r"[\x00-\x20\x7F]").findall _non_token_end_matcher = re.compile(r"[^{}]+".format( - ''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\]'))).match + ''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\\]'))).match _non_attribute_end_matcher = re.compile(r"[^{}]+".format( - ''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\]'))).match + ''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\\]'))).match _non_extended_attribute_end_matcher = re.compile(r"[^{}]+".format( ''.join(EXTENDED_ATTRIBUTE_ENDS).replace( - '\\','\\\\').replace(']','\]'))).match + '\\','\\\\').replace(']','\\]'))).match def _validate_xtext(xtext): """If input token contains ASCII non-printables, register a defect.""" @@ -1538,7 +1538,7 @@ def get_unstructured(value): return unstructured def get_qp_ctext(value): - """ctext = + """ctext = This is not the RFC ctext, since we are handling nested comments in comment and unquoting quoted-pairs here. We allow anything except the '()' @@ -1873,7 +1873,7 @@ def get_obs_local_part(value): return obs_local_part, value def get_dtext(value): - """ dtext = / obs-dtext + """ dtext = / obs-dtext obs-dtext = obs-NO-WS-CTL / quoted-pair We allow anything except the excluded characters, but if we find any diff --git a/src/future/backports/email/feedparser.py b/src/future/backports/email/feedparser.py index 935c26e3..4cc347a2 100644 --- a/src/future/backports/email/feedparser.py +++ b/src/future/backports/email/feedparser.py @@ -34,7 +34,7 @@ NLCRE = re.compile('\r\n|\r|\n') NLCRE_bol = re.compile('(\r\n|\r|\n)') -NLCRE_eol = re.compile('(\r\n|\r|\n)\Z') +NLCRE_eol = re.compile(r'(\r\n|\r|\n)\Z') NLCRE_crack = re.compile('(\r\n|\r|\n)') # RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character # except controls, SP, and ":". diff --git a/src/future/backports/email/utils.py b/src/future/backports/email/utils.py index 4abebf7c..b18f9a34 100644 --- a/src/future/backports/email/utils.py +++ b/src/future/backports/email/utils.py @@ -65,7 +65,7 @@ # How to figure out if we are processing strings that come from a byte # source with undecodable characters. _has_surrogates = re.compile( - '([^\ud800-\udbff]|\A)[\udc00-\udfff]([^\udc00-\udfff]|\Z)').search + r'([^\ud800-\udbff]|\A)[\udc00-\udfff]([^\udc00-\udfff]|\Z)').search # How to deal with a string containing bytes before handing it to the # application through the 'normal' interface. diff --git a/src/future/backports/html/parser.py b/src/future/backports/html/parser.py index fb652636..59df5c4d 100644 --- a/src/future/backports/html/parser.py +++ b/src/future/backports/html/parser.py @@ -28,7 +28,7 @@ starttagopen = re.compile('<[a-zA-Z]') piclose = re.compile('>') commentclose = re.compile(r'--\s*>') -tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*') +tagfind = re.compile(r'([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*') # see http://www.w3.org/TR/html5/tokenization.html#tag-open-state # and http://www.w3.org/TR/html5/tokenization.html#tag-name-state tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*') @@ -76,7 +76,7 @@ endendtag = re.compile('>') # the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between # ') +endtagfind = re.compile(r'') class HTMLParseError(Exception): diff --git a/src/future/backports/http/client.py b/src/future/backports/http/client.py index e663d125..dd5adeb5 100644 --- a/src/future/backports/http/client.py +++ b/src/future/backports/http/client.py @@ -1,4 +1,4 @@ -"""HTTP/1.1 client library +r"""HTTP/1.1 client library A backport of the Python 3.3 http/client.py module for python-future. diff --git a/src/future/backports/http/cookiejar.py b/src/future/backports/http/cookiejar.py index a39242c0..4e2a38aa 100644 --- a/src/future/backports/http/cookiejar.py +++ b/src/future/backports/http/cookiejar.py @@ -209,7 +209,7 @@ def _str2time(day, mon, yr, hr, min, sec, tz): STRICT_DATE_RE = re.compile( r"^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) " - "(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII) + r"(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII) WEEKDAY_RE = re.compile( r"^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*", re.I | re.ASCII) LOOSE_HTTP_DATE_RE = re.compile( @@ -290,7 +290,7 @@ def http2time(text): return _str2time(day, mon, yr, hr, min, sec, tz) ISO_DATE_RE = re.compile( - """^ + r"""^ (\d{4}) # year [-\/]? (\d\d?) # numerical month @@ -426,7 +426,7 @@ def split_header_words(header_values): pairs = [] else: # skip junk - non_junk, nr_junk_chars = re.subn("^[=\s;]*", "", text) + non_junk, nr_junk_chars = re.subn(r"^[=\s;]*", "", text) assert nr_junk_chars > 0, ( "split_header_words bug: '%s', '%s', %s" % (orig_text, text, pairs)) diff --git a/src/future/backports/test/support.py b/src/future/backports/test/support.py index 6639372b..0ab81fff 100644 --- a/src/future/backports/test/support.py +++ b/src/future/backports/test/support.py @@ -1942,7 +1942,7 @@ def can_xattr(): os.setxattr(fp.fileno(), b"user.test", b"") # Kernels < 2.6.39 don't respect setxattr flags. kernel_version = platform.release() - m = re.match("2.6.(\d{1,2})", kernel_version) + m = re.match(r"2.6.(\d{1,2})", kernel_version) can = m is None or int(m.group(1)) >= 39 except OSError: can = False diff --git a/src/future/backports/urllib/parse.py b/src/future/backports/urllib/parse.py index 04e52d49..2062b552 100644 --- a/src/future/backports/urllib/parse.py +++ b/src/future/backports/urllib/parse.py @@ -954,7 +954,7 @@ def splitquery(url): global _queryprog if _queryprog is None: import re - _queryprog = re.compile('^(.*)\?([^?]*)$') + _queryprog = re.compile(r'^(.*)\?([^?]*)$') match = _queryprog.match(url) if match: return match.group(1, 2)