improve code quality, remove unused imports, use system randomness etc
This commit is contained in:
parent
d549d31421
commit
40233eb115
@ -95,8 +95,9 @@ def _save_urls_on_file(input_list, live_url_count):
|
||||
if m:
|
||||
domain = m.group(1)
|
||||
|
||||
sys_random = random.SystemRandom()
|
||||
uid = "".join(
|
||||
random.choice(string.ascii_lowercase + string.digits) for _ in range(6)
|
||||
sys_random.choice(string.ascii_lowercase + string.digits) for _ in range(6)
|
||||
)
|
||||
|
||||
file_name = "{domain}-{live_url_count}-urls-{uid}.txt".format(
|
||||
|
@ -123,11 +123,11 @@ def _check_filters(filters):
|
||||
raise WaybackError("filters must be a list.")
|
||||
|
||||
# [!]field:regex
|
||||
for filter in filters:
|
||||
for _filter in filters:
|
||||
try:
|
||||
match = re.search(
|
||||
r"(\!?(?:urlkey|timestamp|original|mimetype|statuscode|digest|length)):(.*)",
|
||||
filter,
|
||||
_filter,
|
||||
)
|
||||
|
||||
key = match.group(1)
|
||||
@ -135,8 +135,8 @@ def _check_filters(filters):
|
||||
|
||||
except Exception:
|
||||
exc_message = (
|
||||
"Filter '{filter}' not following the cdx filter syntax.".format(
|
||||
filter=filter
|
||||
"Filter '{_filter}' not following the cdx filter syntax.".format(
|
||||
_filter=_filter
|
||||
)
|
||||
)
|
||||
raise WaybackError(exc_message)
|
||||
@ -267,7 +267,7 @@ def _archive_url_parser(header, url, latest_version=__version__, instance=None):
|
||||
newest_archive = None
|
||||
try:
|
||||
newest_archive = instance.newest()
|
||||
except Exception as e:
|
||||
except WaybackError:
|
||||
pass # We don't care as this is a save request
|
||||
|
||||
if newest_archive:
|
||||
|
@ -1,5 +1,3 @@
|
||||
import requests
|
||||
import concurrent.futures
|
||||
from datetime import datetime, timedelta
|
||||
from .exceptions import WaybackError
|
||||
from .cdx import Cdx
|
||||
|
Loading…
Reference in New Issue
Block a user