Skip to content

Commit 96c43fc

Browse files
committed
Correct invalid string escapes, that 3.6 now complains about.
https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior
1 parent e12549c commit 96c43fc

14 files changed

+29
-29
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+
'(', r'\(').replace(
663+
')', r'\)')
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(']',r'\]'))).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(']',r'\]'))).match
13531353
_non_attribute_end_matcher = re.compile(r"[^{}]+".format(
1354-
''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\]'))).match
1354+
''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']',r'\]'))).match
13551355
_non_extended_attribute_end_matcher = re.compile(r"[^{}]+".format(
13561356
''.join(EXTENDED_ATTRIBUTE_ENDS).replace(
1357-
'\\','\\\\').replace(']','\]'))).match
1357+
'\\','\\\\').replace(']',r'\]'))).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+
r"""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+
r""" 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\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+
'([^\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(
@@ -286,7 +286,7 @@ def http2time(text):
286286
return _str2time(day, mon, yr, hr, min, sec, tz)
287287

288288
ISO_DATE_RE = re.compile(
289-
"""^
289+
r"""^
290290
(\d{4}) # year
291291
[-\/]?
292292
(\d\d?) # numerical month
@@ -420,7 +420,7 @@ def split_header_words(header_values):
420420
pairs = []
421421
else:
422422
# skip junk
423-
non_junk, nr_junk_chars = re.subn("^[=\s;]*", "", text)
423+
non_junk, nr_junk_chars = re.subn(r"^[=\s;]*", "", text)
424424
assert nr_junk_chars > 0, (
425425
"split_header_words bug: '%s', '%s', %s" %
426426
(orig_text, text, pairs))

src/future/backports/test/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ def can_xattr():
19741974
os.setxattr(fp.fileno(), b"user.test", b"")
19751975
# Kernels < 2.6.39 don't respect setxattr flags.
19761976
kernel_version = platform.release()
1977-
m = re.match("2.6.(\d{1,2})", kernel_version)
1977+
m = re.match(r"2.6.(\d{1,2})", kernel_version)
19781978
can = m is None or int(m.group(1)) >= 39
19791979
except OSError:
19801980
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)

src/past/types/oldstr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def unescape(s):
2626
Example:
2727
>>> s = unescape(r'abc\\def') # i.e. 'abc\\\\def'
2828
>>> print(s)
29-
'abc\def'
29+
'abc\\def'
3030
>>> s2 = unescape('abc\\ndef')
3131
>>> len(s2)
3232
8

tests/test_future/test_builtins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def write(self, line):
264264
('', ValueError),
265265
(' ', ValueError),
266266
(' \t\t ', ValueError),
267-
(str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
267+
(str(br'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
268268
(chr(0x200), ValueError),
269269
]
270270

@@ -286,7 +286,7 @@ def write(self, line):
286286
('', ValueError),
287287
(' ', ValueError),
288288
(' \t\t ', ValueError),
289-
(str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
289+
(str(br'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
290290
(chr(0x200), ValueError),
291291
]
292292

tests/test_future/test_htmlparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ def get_collector(self):
682682

683683
def test_attr_funky_names2(self):
684684
self._run_check(
685-
"<a $><b $=%><c \=/>",
685+
r"<a $><b $=%><c \=/>",
686686
[("starttag", "a", [("$", None)]),
687687
("starttag", "b", [("$", "%")]),
688688
("starttag", "c", [("\\", "/")])])

tests/test_future/test_http_cookiejar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ def test_port_mirror(self):
10311031
url = "http://foo.bar.com/"
10321032
interact_2965(c, url, "spam=eggs; Version=1; Port")
10331033
h = interact_2965(c, url)
1034-
self.assertRegex(h, "\$Port([^=]|$)",
1034+
self.assertRegex(h, r"\$Port([^=]|$)",
10351035
"port with no value not returned with no value")
10361036

10371037
c = CookieJar(pol)
@@ -1370,9 +1370,9 @@ def test_ietf_example_1(self):
13701370

13711371
self.assertRegex(cookie, r'^\$Version="?1"?;')
13721372
self.assertRegex(cookie, r'Part_Number="?Rocket_Launcher_0001"?;'
1373-
'\s*\$Path="\/acme"')
1373+
r'\s*\$Path="\/acme"')
13741374
self.assertRegex(cookie, r'Customer="?WILE_E_COYOTE"?;'
1375-
'\s*\$Path="\/acme"')
1375+
r'\s*\$Path="\/acme"')
13761376

13771377
#
13781378
# 7. User Agent -> Server

tests/test_future/test_urllib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def test_short_content_raises_ContentTooShortError_without_reporthook(self):
533533

534534

535535
class QuotingTests(unittest.TestCase):
536-
"""Tests for urllib.quote() and urllib.quote_plus()
536+
r"""Tests for urllib.quote() and urllib.quote_plus()
537537
538538
According to RFC 2396 (Uniform Resource Identifiers), to escape a
539539
character you write it as '%' + <2 character US-ASCII hex value>.
@@ -608,7 +608,7 @@ def test_default_quoting(self):
608608
# Make sure all characters that should be quoted are by default sans
609609
# space (separate test for that).
610610
should_quote = [chr(num) for num in range(32)] # For 0x00 - 0x1F
611-
should_quote.append('<>#%"{}|\^[]`')
611+
should_quote.append(r'<>#%"{}|\^[]`')
612612
should_quote.append(chr(127)) # For 0x7F
613613
should_quote = ''.join(should_quote)
614614
for char in should_quote:

tests/test_future/test_urllib_toplevel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def test_short_content_raises_ContentTooShortError_without_reporthook(self):
548548

549549

550550
class QuotingTests(unittest.TestCase):
551-
"""Tests for urllib.quote() and urllib.quote_plus()
551+
r"""Tests for urllib.quote() and urllib.quote_plus()
552552
553553
According to RFC 2396 (Uniform Resource Identifiers), to escape a
554554
character you write it as '%' + <2 character US-ASCII hex value>.
@@ -623,7 +623,7 @@ def test_default_quoting(self):
623623
# Make sure all characters that should be quoted are by default sans
624624
# space (separate test for that).
625625
should_quote = [chr(num) for num in range(32)] # For 0x00 - 0x1F
626-
should_quote.append('<>#%"{}|\^[]`')
626+
should_quote.append(r'<>#%"{}|\^[]`')
627627
should_quote.append(chr(127)) # For 0x7F
628628
should_quote = ''.join(should_quote)
629629
for char in should_quote:

0 commit comments

Comments
 (0)