Skip to content

Commit

Permalink
Merge pull request mitmproxy#3443 from BoboTiG/fix-invalid-seq-warnings
Browse files Browse the repository at this point in the history
Fix several DeprecationWarning: invalid escape sequence
  • Loading branch information
mhils authored Jan 6, 2019
2 parents 889987a + 3a2d7bb commit 4f270b5
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions examples/complex/sslstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def response(flow: http.HTTPFlow) -> None:
flow.response.content = flow.response.content.replace(b'https://', b'http://')

# strip meta tag upgrade-insecure-requests in response body
csp_meta_tag_pattern = b'<meta.*http-equiv=["\']Content-Security-Policy[\'"].*upgrade-insecure-requests.*?>'
csp_meta_tag_pattern = br'<meta.*http-equiv=["\']Content-Security-Policy[\'"].*upgrade-insecure-requests.*?>'
flow.response.content = re.sub(csp_meta_tag_pattern, b'', flow.response.content, flags=re.IGNORECASE)

# strip links in 'Location' header
Expand All @@ -52,7 +52,7 @@ def response(flow: http.HTTPFlow) -> None:
# strip upgrade-insecure-requests in Content-Security-Policy header
if re.search('upgrade-insecure-requests', flow.response.headers.get('Content-Security-Policy', ''), flags=re.IGNORECASE):
csp = flow.response.headers['Content-Security-Policy']
flow.response.headers['Content-Security-Policy'] = re.sub('upgrade-insecure-requests[;\s]*', '', csp, flags=re.IGNORECASE)
flow.response.headers['Content-Security-Policy'] = re.sub(r'upgrade-insecure-requests[;\s]*', '', csp, flags=re.IGNORECASE)

# strip secure flag from 'Set-Cookie' headers
cookies = flow.response.headers.get_all('Set-Cookie')
Expand Down
2 changes: 1 addition & 1 deletion examples/complex/xss_scanner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
__ __ _____ _____ _____
\ \ / // ____/ ____| / ____|
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy/contentviews/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CSS_SPECIAL_AREAS = (
"'" + strutils.SINGLELINE_CONTENT + strutils.NO_ESCAPE + "'",
'"' + strutils.SINGLELINE_CONTENT + strutils.NO_ESCAPE + '"',
r"/\*" + strutils.MULTILINE_CONTENT + "\*/",
r"/\*" + strutils.MULTILINE_CONTENT + r"\*/",
"//" + strutils.SINGLELINE_CONTENT + "$"
)
CSS_SPECIAL_CHARS = "{};:"
Expand Down
4 changes: 2 additions & 2 deletions mitmproxy/contentviews/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
r"'" + strutils.MULTILINE_CONTENT_LINE_CONTINUATION + strutils.NO_ESCAPE + "'",
r'"' + strutils.MULTILINE_CONTENT_LINE_CONTINUATION + strutils.NO_ESCAPE + '"',
r'`' + strutils.MULTILINE_CONTENT + strutils.NO_ESCAPE + '`',
r"/\*" + strutils.MULTILINE_CONTENT + "\*/",
r"/\*" + strutils.MULTILINE_CONTENT + r"\*/",
r"//" + strutils.SINGLELINE_CONTENT + "$",
r"for\(" + strutils.SINGLELINE_CONTENT + "\)",
r"for\(" + strutils.SINGLELINE_CONTENT + r"\)",
)


Expand Down
2 changes: 1 addition & 1 deletion mitmproxy/contentviews/xml_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

# http://www.xml.com/pub/a/2001/07/25/namingparts.html - this is close enough for what we do.
REGEX_TAG = re.compile("[a-zA-Z0-9._:\-]+(?!=)")
REGEX_TAG = re.compile(r"[a-zA-Z0-9._:\-]+(?!=)")
# https://www.w3.org/TR/html5/syntax.html#void-elements
HTML_VOID_ELEMENTS = {
"area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param",
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy/net/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re

# Allow underscore in host name
_label_valid = re.compile(b"(?!-)[A-Z\d\-_]{1,63}(?<!-)$", re.IGNORECASE)
_label_valid = re.compile(br"(?!-)[A-Z\d\-_]{1,63}(?<!-)$", re.IGNORECASE)


def is_valid_host(host: bytes) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy/platform/pf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def lookup(address, port, s):
"""
# We may get an ipv4-mapped ipv6 address here, e.g. ::ffff:127.0.0.1.
# Those still appear as "127.0.0.1" in the table, so we need to strip the prefix.
address = re.sub("^::ffff:(?=\d+.\d+.\d+.\d+$)", "", address)
address = re.sub(r"^::ffff:(?=\d+.\d+.\d+.\d+$)", "", address)
s = s.decode()
spec = "%s:%s" % (address, port)
for i in s.split("\n"):
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy/platform/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _connect(self):

def original_addr(self, csock: socket.socket):
ip, port = csock.getpeername()[:2]
ip = re.sub("^::ffff:(?=\d+.\d+.\d+.\d+$)", "", ip)
ip = re.sub(r"^::ffff:(?=\d+.\d+.\d+.\d+$)", "", ip)
ip = ip.split("%", 1)[0]
with self.lock:
try:
Expand Down
6 changes: 3 additions & 3 deletions mitmproxy/tools/console/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def filtexp(self):
)
)
examples = [
("google\.com", "Url containing \"google.com"),
("~q ~b test", "Requests where body contains \"test\""),
("!(~q & ~t \"text/html\")", "Anything but requests with a text/html content type."),
(r"google\.com", r"Url containing \"google.com"),
("~q ~b test", r"Requests where body contains \"test\""),
(r"!(~q & ~t \"text/html\")", "Anything but requests with a text/html content type."),
]
text.extend(
common.format_keyvals(examples, indent=4)
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy/tools/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def get(self, flow_id, message):
original_cd = message.headers.get("Content-Disposition", None)
filename = None
if original_cd:
filename = re.search('filename=([-\w" .()]+)', original_cd)
filename = re.search(r'filename=([-\w" .()]+)', original_cd)
if filename:
filename = filename.group(1)
if not filename:
Expand Down
4 changes: 2 additions & 2 deletions mitmproxy/utils/strutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def split_special_areas(
>>> split_special_areas(
>>> "test /* don't modify me */ foo",
>>> [r"/\*[\s\S]*?\*/"]) # (regex matching comments)
>>> [r"/\\*[\\s\\S]*?\\*/"]) # (regex matching comments)
["test ", "/* don't modify me */", " foo"]
"".join(split_special_areas(x, ...)) == x always holds true.
Expand Down Expand Up @@ -201,7 +201,7 @@ def escape_special_areas(
>>> x = escape_special_areas(x, "{", ["'" + SINGLELINE_CONTENT + "'"])
>>> print(x)
if (true) { console.log('�}'); }
>>> x = re.sub(r"\s*{\s*", " {\n ", x)
>>> x = re.sub(r"\\s*{\\s*", " {\n ", x)
>>> x = unescape_special_areas(x)
>>> print(x)
if (true) {
Expand Down
2 changes: 1 addition & 1 deletion test/mitmproxy/coretypes/test_basethread.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

def test_basethread():
t = basethread.BaseThread('foobar')
assert re.match('foobar - age: \d+s', t._threadinfo())
assert re.match(r'foobar - age: \d+s', t._threadinfo())
4 changes: 2 additions & 2 deletions test/mitmproxy/net/http/test_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
[["one", "uno"], ["two", "due"]]
],
[
'one="uno"; two="\due"',
'one="uno"; two="\\due"',
[["one", "uno"], ["two", "due"]]
],
[
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_read_key():
def test_read_quoted_string():
tokens = [
[('"foo" x', 0), ("foo", 5)],
[('"f\oo" x', 0), ("foo", 6)],
[('"f\\oo" x', 0), ("foo", 6)],
[(r'"f\\o" x', 0), (r"f\o", 6)],
[(r'"f\\" x', 0), (r"f" + '\\', 5)],
[('"fo\\\"" x', 0), ("fo\"", 6)],
Expand Down
2 changes: 1 addition & 1 deletion test/mitmproxy/net/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def handle(self):
# We may get an ipv4-mapped ipv6 address here, e.g. ::ffff:127.0.0.1.
# Those still appear as "127.0.0.1" in the table, so we need to strip the prefix.
peername = self.connection.getpeername()
address = re.sub("^::ffff:(?=\d+.\d+.\d+.\d+$)", "", peername[0])
address = re.sub(r"^::ffff:(?=\d+.\d+.\d+.\d+$)", "", peername[0])
port = peername[1]

self.wfile.write(str((address, port)).encode())
Expand Down

0 comments on commit 4f270b5

Please sign in to comment.