Browse Source

Apply changes from legacy-python2 branch

tags/v0.4
Ben Kurtovic 4 months ago
parent
commit
17c156fcb6
2 changed files with 14 additions and 7 deletions
  1. +10
    -4
      earwigbot/wiki/copyvios/exclusions.py
  2. +4
    -3
      earwigbot/wiki/copyvios/workers.py

+ 10
- 4
earwigbot/wiki/copyvios/exclusions.py View File

@@ -191,16 +191,22 @@ class ExclusionsDB:
Return ``True`` if the URL is in the database, or ``False`` otherwise. Return ``True`` if the URL is in the database, or ``False`` otherwise.
""" """
normalized = re.sub(_RE_STRIP_PREFIX, "", url.lower()) normalized = re.sub(_RE_STRIP_PREFIX, "", url.lower())
parsed = urlparse(url.lower())
query = """SELECT exclusion_url FROM exclusions query = """SELECT exclusion_url FROM exclusions
WHERE exclusion_sitename = ? OR exclusion_sitename = ?""" WHERE exclusion_sitename = ? OR exclusion_sitename = ?"""
with self._db_access_lock, sqlite.connect(self._dbfile) as conn: with self._db_access_lock, sqlite.connect(self._dbfile) as conn:
for (excl,) in conn.execute(query, (sitename, "all")): for (excl,) in conn.execute(query, (sitename, "all")):
excl = excl.lower() excl = excl.lower()
if excl.startswith("*."): if excl.startswith("*."):
parsed = urlparse(url.lower())
matches = excl[2:] in parsed.netloc
if matches and "/" in excl:
excl_path = excl[excl.index("/") + 1]
excl = excl[2:]
if "/" in excl:
excl_netloc, excl_path = excl.split("/", 1)
else:
excl_netloc, excl_path = excl, ""
matches = parsed.netloc == excl_netloc or (
parsed.netloc.endswith("." + excl_netloc)
)
if matches and excl_path:
matches = excl_path.startswith(parsed.path) matches = excl_path.startswith(parsed.path)
elif excl.startswith("re:"): elif excl.startswith("re:"):
try: try:


+ 4
- 3
earwigbot/wiki/copyvios/workers.py View File

@@ -138,10 +138,11 @@ class _CopyvioWorker:
continue continue
path = path[len(proxy_info["path"]) :] path = path[len(proxy_info["path"]) :]
url = proxy_info["target"] + path url = proxy_info["target"] + path
if parsed.query:
url += "?" + parsed.query
if "auth" in proxy_info: if "auth" in proxy_info:
extra_headers["Authorization"] = "Basic %s" % (
base64.b64encode(proxy_info["auth"])
)
auth_hash = base64.b64encode(proxy_info["auth"].encode()).decode()
extra_headers["Authorization"] = f"Basic {auth_hash}"
return url, True return url, True
return url, False return url, False




Loading…
Cancel
Save