8000 Add timeout for fetching URL by TG1999 · Pull Request #156 · aboutcode-org/purldb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add timeout for fetching URL #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions packagedb/find_source_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class URLDataReturnType(enum.Enum):
text = "text" # This is the text of the response


non_reachable_urls = []
non_reachable_urls = [
]
CACHE = {
# url: data
}
Expand Down Expand Up @@ -73,7 +74,7 @@ def get_data_from_response(response, data_type=URLDataReturnType.text):
def get_data_from_url(
url,
data_type=URLDataReturnType.text,
timeout=None,
timeout=10,
):
"""
Take a ``url`` as input and return the data from the URL
Expand All @@ -83,6 +84,23 @@ def get_data_from_url(
try:
if not url:
return
if url.startswith("https://github.com/assets"):
return
not_supported_extensions = [
".pdf",
".zip",
".woff2",
".jar",
".js",
".png",
".css",
".svg",
".jpg",
".tgz",
]
for extension in not_supported_extensions:
if url.endswith(extension):
return
if url in non_reachable_urls:
return
if url in CACHE:
Expand Down Expand Up @@ -372,11 +390,11 @@ def get_git_repo_urls(urls):
if url and any(url_hint in url for url_hint in url_hints):
yield url
else:
if url.startswith("git+"):
if url and url.startswith("git+"):
_, _, url = url.partition("git+")
try:
url = get_data_from_url(
url=url, data_type=URLDataReturnType.url, timeout=(10, None)
url=url, data_type=URLDataReturnType.url
)
if not url:
continue
Expand Down
0