瀏覽代碼

Allow regexes in exclusion lists.

tags/v0.2
Ben Kurtovic 12 年之前
父節點
當前提交
3a8349e8ab
共有 1 個檔案被更改,包括 3 行新增 和 1 行删除
  1. +3
    -1
      earwigbot/wiki/copyvios/exclusions.py

+ 3
- 1
earwigbot/wiki/copyvios/exclusions.py 查看文件

@@ -161,13 +161,15 @@ class ExclusionsDB(object):


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(r"https?://(www\.)?", "", url.lower())
normalized = re.sub(r"^https?://(www\.)?", "", 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 sqlite.connect(self._dbfile) as conn, self._db_access_lock: with sqlite.connect(self._dbfile) as conn, self._db_access_lock:
for (excl,) in conn.execute(query, (sitename, "all")): for (excl,) in conn.execute(query, (sitename, "all")):
if excl.startswith("*."): if excl.startswith("*."):
matches = excl[2:] in urlparse(url.lower()).netloc matches = excl[2:] in urlparse(url.lower()).netloc
elif excl.startswith("re:"):
matches = re.match(excl[3:], normalized)
else: else:
matches = normalized.startswith(excl) matches = normalized.startswith(excl)
if matches: if matches:


Loading…
取消
儲存