mirror of
https://github.com/HelloZeroNet/ZeroNet.git
synced 2023-12-14 04:33:03 +01:00
Add r string literal for regexps
This commit is contained in:
parent
43f833e604
commit
62401b24ec
4 changed files with 27 additions and 26 deletions
|
@ -83,7 +83,7 @@ class ContentManager(object):
|
|||
for line in open(content_path):
|
||||
if '"modified"' not in line:
|
||||
continue
|
||||
match = re.search("([0-9\.]+),$", line.strip(" \r\n"))
|
||||
match = re.search(r"([0-9\.]+),$", line.strip(" \r\n"))
|
||||
if match and float(match.group(1)) <= old_content.get("modified", 0):
|
||||
self.log.debug("%s loadContent same json file, skipping" % content_inner_path)
|
||||
return [], []
|
||||
|
@ -352,7 +352,7 @@ class ContentManager(object):
|
|||
|
||||
# Returns if file with the given modification date is archived or not
|
||||
def isArchived(self, inner_path, modified):
|
||||
match = re.match("(.*)/(.*?)/", inner_path)
|
||||
match = re.match(r"(.*)/(.*?)/", inner_path)
|
||||
if not match:
|
||||
return False
|
||||
user_contents_inner_path = match.group(1) + "/content.json"
|
||||
|
@ -430,7 +430,7 @@ class ContentManager(object):
|
|||
back = content["user_contents"]
|
||||
content_inner_path_dir = helper.getDirname(content_inner_path)
|
||||
relative_content_path = inner_path[len(content_inner_path_dir):]
|
||||
user_auth_address_match = re.match("([A-Za-z0-9]+)/.*", relative_content_path)
|
||||
user_auth_address_match = re.match(r"([A-Za-z0-9]+)/.*", relative_content_path)
|
||||
if user_auth_address_match:
|
||||
user_auth_address = user_auth_address_match.group(1)
|
||||
back["content_inner_path"] = "%s%s/content.json" % (content_inner_path_dir, user_auth_address)
|
||||
|
@ -496,9 +496,9 @@ class ContentManager(object):
|
|||
# Delivered for directory
|
||||
if "inner_path" in parent_content:
|
||||
parent_content_dir = helper.getDirname(parent_content["inner_path"])
|
||||
user_address = re.match("([A-Za-z0-9]*?)/", inner_path[len(parent_content_dir):]).group(1)
|
||||
user_address = re.match(r"([A-Za-z0-9]*?)/", inner_path[len(parent_content_dir):]).group(1)
|
||||
else:
|
||||
user_address = re.match(".*/([A-Za-z0-9]*?)/.*?$", inner_path).group(1)
|
||||
user_address = re.match(r".*/([A-Za-z0-9]*?)/.*?$", inner_path).group(1)
|
||||
|
||||
try:
|
||||
if not content:
|
||||
|
@ -600,7 +600,7 @@ class ContentManager(object):
|
|||
elif len(relative_path) > 255:
|
||||
return False
|
||||
else:
|
||||
return re.match("^[a-z\[\]\(\) A-Z0-9~_@=\.\+-/]+$", relative_path)
|
||||
return re.match(r"^[a-z\[\]\(\) A-Z0-9~_@=\.\+-/]+$", relative_path)
|
||||
|
||||
def sanitizePath(self, inner_path):
|
||||
return re.sub("[^a-z\[\]\(\) A-Z0-9_@=\.\+-/]", "", inner_path)
|
||||
|
@ -905,12 +905,12 @@ class ContentManager(object):
|
|||
# Filename limit
|
||||
if rules.get("files_allowed"):
|
||||
for file_inner_path in list(content["files"].keys()):
|
||||
if not SafeRe.match("^%s$" % rules["files_allowed"], file_inner_path):
|
||||
if not SafeRe.match(r"^%s$" % rules["files_allowed"], file_inner_path):
|
||||
raise VerifyError("File not allowed: %s" % file_inner_path)
|
||||
|
||||
if rules.get("files_allowed_optional"):
|
||||
for file_inner_path in list(content.get("files_optional", {}).keys()):
|
||||
if not SafeRe.match("^%s$" % rules["files_allowed_optional"], file_inner_path):
|
||||
if not SafeRe.match(r"^%s$" % rules["files_allowed_optional"], file_inner_path):
|
||||
raise VerifyError("Optional file not allowed: %s" % file_inner_path)
|
||||
|
||||
# Check if content includes allowed
|
||||
|
|
|
@ -67,11 +67,12 @@ class PeerPortchecker(object):
|
|||
return res
|
||||
|
||||
def checkCanyouseeme(self, port):
|
||||
data = urllib.request.urlopen("http://www.canyouseeme.org/", b"port=%s" % str(port).encode("ascii"), timeout=20.0).read().decode("utf8")
|
||||
message = re.match('.*<p style="padding-left:15px">(.*?)</p>', data, re.DOTALL).group(1)
|
||||
message = re.sub("<.*?>", "", message.replace("<br>", " ").replace(" ", " ")) # Strip http tags
|
||||
data = urllib.request.urlopen("https://www.canyouseeme.org/", b"ip=1.1.1.1&port=%s" % str(port).encode("ascii"), timeout=20.0).read().decode("utf8")
|
||||
|
||||
match = re.match(".*service on (.*?) on", message)
|
||||
message = re.match(r'.*<p style="padding-left:15px">(.*?)</p>', data, re.DOTALL).group(1)
|
||||
message = re.sub(r"<.*?>", "", message.replace("<br>", " ").replace(" ", " ")) # Strip http tags
|
||||
|
||||
match = re.match(r".*service on (.*?) on", message)
|
||||
if match:
|
||||
ip = match.group(1)
|
||||
else:
|
||||
|
@ -86,10 +87,10 @@ class PeerPortchecker(object):
|
|||
|
||||
def checkPortchecker(self, port):
|
||||
data = urllib.request.urlopen("https://portchecker.co/check", b"port=%s" % str(port).encode("ascii"), timeout=20.0).read().decode("utf8")
|
||||
message = re.match('.*<div id="results-wrapper">(.*?)</div>', data, re.DOTALL).group(1)
|
||||
message = re.sub("<.*?>", "", message.replace("<br>", " ").replace(" ", " ").strip()) # Strip http tags
|
||||
message = re.match(r'.*<div id="results-wrapper">(.*?)</div>', data, re.DOTALL).group(1)
|
||||
message = re.sub(r"<.*?>", "", message.replace("<br>", " ").replace(" ", " ").strip()) # Strip http tags
|
||||
|
||||
match = re.match(".*targetIP.*?value=\"(.*?)\"", data, re.DOTALL)
|
||||
match = re.match(r".*targetIP.*?value=\"(.*?)\"", data, re.DOTALL)
|
||||
if match:
|
||||
ip = match.group(1)
|
||||
else:
|
||||
|
@ -107,14 +108,14 @@ class PeerPortchecker(object):
|
|||
|
||||
data = self.requestUrl(url).read().decode("utf8")
|
||||
|
||||
ip = re.match('.*Your IP is.*?name="host".*?value="(.*?)"', data, re.DOTALL).group(1)
|
||||
token = re.match('.*name="token".*?value="(.*?)"', data, re.DOTALL).group(1)
|
||||
ip = re.match(r'.*Your IP is.*?name="host".*?value="(.*?)"', data, re.DOTALL).group(1)
|
||||
token = re.match(r'.*name="token".*?value="(.*?)"', data, re.DOTALL).group(1)
|
||||
|
||||
post_data = {"host": ip, "port": port, "allow": "on", "token": token, "submit": "Scanning.."}
|
||||
data = self.requestUrl(url, post_data).read().decode("utf8")
|
||||
|
||||
message = re.match(".*<div class='formfield'>(.*?)</div>", data, re.DOTALL).group(1)
|
||||
message = re.sub("<.*?>", "", message.replace("<br>", " ").replace(" ", " ").strip()) # Strip http tags
|
||||
message = re.match(r".*<div class='formfield'>(.*?)</div>", data, re.DOTALL).group(1)
|
||||
message = re.sub(r"<.*?>", "", message.replace("<br>", " ").replace(" ", " ").strip()) # Strip http tags
|
||||
|
||||
if "online" in message:
|
||||
return {"ip": ip, "opened": True}
|
||||
|
@ -128,12 +129,12 @@ class PeerPortchecker(object):
|
|||
|
||||
data = self.requestUrl(url).read().decode("utf8")
|
||||
|
||||
ip = re.match('.*Your IP address is:[ ]*([0-9\.:a-z]+)', data.replace(" ", ""), re.DOTALL).group(1)
|
||||
ip = re.match(r'.*Your IP address is:[ ]*([0-9\.:a-z]+)', data.replace(" ", ""), re.DOTALL).group(1)
|
||||
|
||||
post_data = {"addr": ip, "ports_selected": "", "ports_list": port}
|
||||
data = self.requestUrl(url, post_data).read().decode("utf8")
|
||||
|
||||
message = re.match(".*<table class='table_font_16'>(.*?)</table>", data, re.DOTALL).group(1)
|
||||
message = re.match(r".*<table class='table_font_16'>(.*?)</table>", data, re.DOTALL).group(1)
|
||||
|
||||
if "ok.png" in message:
|
||||
return {"ip": ip, "opened": True}
|
||||
|
@ -147,12 +148,12 @@ class PeerPortchecker(object):
|
|||
|
||||
data = self.requestUrl(url).read().decode("utf8")
|
||||
|
||||
ip = re.match('.*Your IP address is[ ]*([0-9\.:a-z]+)', data.replace(" ", ""), re.DOTALL).group(1)
|
||||
ip = re.match(r'.*Your IP address is[ ]*([0-9\.:a-z]+)', data.replace(" ", ""), re.DOTALL).group(1)
|
||||
|
||||
post_data = {"host": ip, "scanType": "1", "port": port, "protocol": "tcp", "authorized": "yes"}
|
||||
data = self.requestUrl(url, post_data).read().decode("utf8")
|
||||
|
||||
message = re.match(".*<table id='scantable'>(.*?)</table>", data, re.DOTALL).group(1)
|
||||
message = re.match(r".*<table id='scantable'>(.*?)</table>", data, re.DOTALL).group(1)
|
||||
message_text = re.sub("<.*?>", " ", message.replace("<br>", " ").replace(" ", " ").strip()) # Strip http tags
|
||||
|
||||
if "OPEN" in message_text:
|
||||
|
|
|
@ -163,7 +163,7 @@ class TorManager(object):
|
|||
|
||||
# Version 0.2.7.5 required because ADD_ONION support
|
||||
res_version = self.send("GETINFO version", conn)
|
||||
version = re.search('version=([0-9\.]+)', res_version).group(1)
|
||||
version = re.search(r'version=([0-9\.]+)', res_version).group(1)
|
||||
assert float(version.replace(".", "0", 2)) >= 207.5, "Tor version >=0.2.7.5 required, found: %s" % version
|
||||
|
||||
self.setStatus("Connected (%s)" % res_auth)
|
||||
|
|
|
@ -312,7 +312,7 @@ class UiRequest(object):
|
|||
extra_headers = {}
|
||||
script_nonce = self.getScriptNonce()
|
||||
|
||||
match = re.match("/(?P<address>[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
|
||||
match = re.match(r"/(?P<address>[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
|
||||
just_added = False
|
||||
if match:
|
||||
address = match.group("address")
|
||||
|
@ -525,7 +525,7 @@ class UiRequest(object):
|
|||
if ".." in path or "./" in path:
|
||||
raise SecurityError("Invalid path")
|
||||
|
||||
match = re.match("/media/(?P<address>[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
|
||||
match = re.match(r"/media/(?P<address>[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
|
||||
if match:
|
||||
path_parts = match.groupdict()
|
||||
path_parts["request_address"] = path_parts["address"] # Original request address (for Merger sites)
|
||||
|
|
Loading…
Reference in a new issue