-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from zalando-incubator/optimize-blacklist
Read the blacklist once
- Loading branch information
Showing
10 changed files
with
113 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
import os | ||
import logging | ||
import os | ||
from typing import Set | ||
|
||
Blacklist = Set[str] | ||
|
||
def on_blacklist(url): | ||
""" | ||
Checks for matching URLs in an ignore file (blacklist) | ||
from user's current directory. | ||
""" | ||
blacklist_file = f"{os.getcwd()}/.urlignore" | ||
try: | ||
with open(blacklist_file) as file: | ||
blacklist = [line.rstrip("\n") for line in file if len(line) > 1] | ||
|
||
for blacklist_item in blacklist: | ||
if blacklist_item in url: | ||
return True | ||
def get_empty() -> Blacklist: | ||
return set() | ||
|
||
return False | ||
|
||
def from_file() -> Blacklist: | ||
blacklist_file = f"{os.getcwd()}/.urlignore" | ||
try: | ||
with open(blacklist_file) as file: | ||
return set(filter(None, [line.rstrip() for line in file])) | ||
except OSError as err: | ||
logging.debug( | ||
"Could not read blacklist file %s. Reason: %s", blacklist_file, err | ||
) | ||
return False | ||
return get_empty() | ||
|
||
|
||
def on_blacklist(blacklist: Blacklist, url: str) -> bool: | ||
""" | ||
Checks for matching URLs in an ignore file (blacklist) | ||
from user's current directory. | ||
""" | ||
for blacklist_item in blacklist: | ||
if blacklist_item in url: | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters