Skip to content

Commit 7b08b70

Browse files
committed
Fix invalid escape sequences
1 parent 2bdbfa5 commit 7b08b70

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

src/future/backports/email/_header_value_parser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ def quote(self, value):
659659
if value.token_type == 'comment':
660660
return str(value)
661661
return str(value).replace('\\', '\\\\').replace(
662-
'(', '\(').replace(
663-
')', '\)')
662+
'(', '\\(').replace(
663+
')', '\\)')
664664

665665
@property
666666
def content(self):
@@ -1346,15 +1346,15 @@ def __str__(self):
13461346

13471347
_wsp_splitter = re.compile(r'([{}]+)'.format(''.join(WSP))).split
13481348
_non_atom_end_matcher = re.compile(r"[^{}]+".format(
1349-
''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\]'))).match
1349+
''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\\]'))).match
13501350
_non_printable_finder = re.compile(r"[\x00-\x20\x7F]").findall
13511351
_non_token_end_matcher = re.compile(r"[^{}]+".format(
1352-
''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\]'))).match
1352+
''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\\]'))).match
13531353
_non_attribute_end_matcher = re.compile(r"[^{}]+".format(
1354-
''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\]'))).match
1354+
''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\\]'))).match
13551355
_non_extended_attribute_end_matcher = re.compile(r"[^{}]+".format(
13561356
''.join(EXTENDED_ATTRIBUTE_ENDS).replace(
1357-
'\\','\\\\').replace(']','\]'))).match
1357+
'\\','\\\\').replace(']','\\]'))).match
13581358

13591359
def _validate_xtext(xtext):
13601360
"""If input token contains ASCII non-printables, register a defect."""
@@ -1538,7 +1538,7 @@ def get_unstructured(value):
15381538
return unstructured
15391539

15401540
def get_qp_ctext(value):
1541-
"""ctext = <printable ascii except \ ( )>
1541+
"""ctext = <printable ascii except \\ ( )>
15421542
15431543
This is not the RFC ctext, since we are handling nested comments in comment
15441544
and unquoting quoted-pairs here. We allow anything except the '()'
@@ -1873,7 +1873,7 @@ def get_obs_local_part(value):
18731873
return obs_local_part, value
18741874

18751875
def get_dtext(value):
1876-
""" dtext = <printable ascii except \ [ ]> / obs-dtext
1876+
""" dtext = <printable ascii except \\ [ ]> / obs-dtext
18771877
obs-dtext = obs-NO-WS-CTL / quoted-pair
18781878
18791879
We allow anything except the excluded characters, but if we find any

src/future/backports/email/feedparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
NLCRE = re.compile('\r\n|\r|\n')
3636
NLCRE_bol = re.compile('(\r\n|\r|\n)')
37-
NLCRE_eol = re.compile('(\r\n|\r|\n)\Z')
37+
NLCRE_eol = re.compile(r'(\r\n|\r|\n)\Z')
3838
NLCRE_crack = re.compile('(\r\n|\r|\n)')
3939
# RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character
4040
# except controls, SP, and ":".

src/future/backports/email/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
# How to figure out if we are processing strings that come from a byte
6666
# source with undecodable characters.
6767
_has_surrogates = re.compile(
68-
'([^\ud800-\udbff]|\A)[\udc00-\udfff]([^\udc00-\udfff]|\Z)').search
68+
r'([^\ud800-\udbff]|\A)[\udc00-\udfff]([^\udc00-\udfff]|\Z)').search
6969

7070
# How to deal with a string containing bytes before handing it to the
7171
# application through the 'normal' interface.

src/future/backports/html/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
starttagopen = re.compile('<[a-zA-Z]')
2929
piclose = re.compile('>')
3030
commentclose = re.compile(r'--\s*>')
31-
tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')
31+
tagfind = re.compile(r'([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')
3232
# see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
3333
# and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
3434
tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*')
@@ -76,7 +76,7 @@
7676
endendtag = re.compile('>')
7777
# the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between
7878
# </ and the tag name, so maybe this should be fixed
79-
endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
79+
endtagfind = re.compile(r'</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
8080

8181

8282
class HTMLParseError(Exception):

src/future/backports/http/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""HTTP/1.1 client library
1+
r"""HTTP/1.1 client library
22
33
A backport of the Python 3.3 http/client.py module for python-future.
44

src/future/backports/http/cookiejar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _str2time(day, mon, yr, hr, min, sec, tz):
209209

210210
STRICT_DATE_RE = re.compile(
211211
r"^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) "
212-
"(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
212+
r"(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
213213
WEEKDAY_RE = re.compile(
214214
r"^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*", re.I | re.ASCII)
215215
LOOSE_HTTP_DATE_RE = re.compile(
@@ -290,7 +290,7 @@ def http2time(text):
290290
return _str2time(day, mon, yr, hr, min, sec, tz)
291291

292292
ISO_DATE_RE = re.compile(
293-
"""^
293+
r"""^
294294
(\d{4}) # year
295295
[-\/]?
296296
(\d\d?) # numerical month
@@ -426,7 +426,7 @@ def split_header_words(header_values):
426426
pairs = []
427427
else:
428428
# skip junk
429-
non_junk, nr_junk_chars = re.subn("^[=\s;]*", "", text)
429+
non_junk, nr_junk_chars = re.subn(r"^[=\s;]*", "", text)
430430
assert nr_junk_chars > 0, (
431431
"split_header_words bug: '%s', '%s', %s" %
432432
(orig_text, text, pairs))

src/future/backports/test/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ def can_xattr():
19421942
os.setxattr(fp.fileno(), b"user.test", b"")
19431943
# Kernels < 2.6.39 don't respect setxattr flags.
19441944
kernel_version = platform.release()
1945-
m = re.match("2.6.(\d{1,2})", kernel_version)
1945+
m = re.match(r"2.6.(\d{1,2})", kernel_version)
19461946
can = m is None or int(m.group(1)) >= 39
19471947
except OSError:
19481948
can = False

src/future/backports/urllib/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ def splitquery(url):
954954
global _queryprog
955955
if _queryprog is None:
956956
import re
957-
_queryprog = re.compile('^(.*)\?([^?]*)$')
957+
_queryprog = re.compile(r'^(.*)\?([^?]*)$')
958958

959959
match = _queryprog.match(url)
960960
if match: return match.group(1, 2)

0 commit comments

Comments
 (0)