fosslight-util 2.2.19__tar.gz → 2.2.20__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fosslight_util-2.2.19/src/fosslight_util.egg-info → fosslight_util-2.2.20}/PKG-INFO +1 -1
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/pyproject.toml +1 -1
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/download.py +26 -12
- {fosslight_util-2.2.19 → fosslight_util-2.2.20/src/fosslight_util.egg-info}/PKG-INFO +1 -1
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/SOURCES.txt +1 -0
- fosslight_util-2.2.20/tests/test_download_user_agent.py +141 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/LICENSE +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/MANIFEST.in +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/README.md +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/setup.cfg +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/__init__.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/_get_downloadable_url.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/compare_yaml.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/constant.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/correct.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/cover.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/exclude.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/get_pom_license.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/help.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/oss_item.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/output_format.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/parsing_yaml.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/read_excel.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/resources/licenses.json +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/set_log.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/spdx_licenses.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/time.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/timer_thread.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_cyclonedx.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_excel.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_opossum.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_scancodejson.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_spdx.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_txt.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_yaml.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/entry_points.txt +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/requires.txt +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/top_level.txt +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_cyclonedx.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_decide_checkout.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_maven.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_packagist.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_timeout.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_version_attempts.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_version_hint.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_opossum.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_spdx.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_spdx_licenses.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_text.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_write_excel_hidden_sheet.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_write_output.py +0 -0
- {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_write_yaml.py +0 -0
|
@@ -61,8 +61,10 @@ _active_download_alarm = ContextVar("active_download_alarm", default=None)
|
|
|
61
61
|
_download_watchdog_owned = ContextVar("download_watchdog_owned", default=False)
|
|
62
62
|
|
|
63
63
|
# Some mirrors (e.g. mirrors.ustc.edu.cn) return 403 for python-requests' default
|
|
64
|
-
# User-Agent, or 200 with a small text/html interstitial.
|
|
65
|
-
#
|
|
64
|
+
# User-Agent, or 200 with a small text/html interstitial. Others (e.g.
|
|
65
|
+
# maven.egovframe.go.kr) return 400 Request Blocked for a non-browser User-Agent.
|
|
66
|
+
# Start with a curl-style UA (widely accepted for file downloads), then browser,
|
|
67
|
+
# then default requests as fallback.
|
|
66
68
|
_HTTP_BROWSER_USER_AGENT = (
|
|
67
69
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
68
70
|
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
@@ -98,6 +100,15 @@ def _download_http_header_attempts():
|
|
|
98
100
|
]
|
|
99
101
|
|
|
100
102
|
|
|
103
|
+
def _status_retries_with_user_agent(status_code) -> bool:
|
|
104
|
+
"""True when another User-Agent may pass a client block.
|
|
105
|
+
|
|
106
|
+
403 is the usual block. Some hosts return 400 Request Blocked for a
|
|
107
|
+
non-browser User-Agent instead of 403.
|
|
108
|
+
"""
|
|
109
|
+
return status_code in (400, 403)
|
|
110
|
+
|
|
111
|
+
|
|
101
112
|
class Alarm(threading.Thread):
|
|
102
113
|
"""Download watchdog; call ``cancel()`` to stop before timeout.
|
|
103
114
|
|
|
@@ -229,7 +240,7 @@ def _shutdown_response_socket(response):
|
|
|
229
240
|
|
|
230
241
|
|
|
231
242
|
def is_downloadable(url):
|
|
232
|
-
"""Probe URL; retry with alternate User-Agents on 403 or HTML
|
|
243
|
+
"""Probe URL; retry with alternate User-Agents on 400/403 or HTML for archives."""
|
|
233
244
|
attempts = _download_http_header_attempts()
|
|
234
245
|
last_i = len(attempts) - 1
|
|
235
246
|
for i, headers in enumerate(attempts):
|
|
@@ -237,7 +248,7 @@ def is_downloadable(url):
|
|
|
237
248
|
with requests.get(
|
|
238
249
|
url, stream=True, allow_redirects=True, timeout=10, headers=headers
|
|
239
250
|
) as r:
|
|
240
|
-
if r.status_code
|
|
251
|
+
if _status_retries_with_user_agent(r.status_code) and i < last_i:
|
|
241
252
|
continue
|
|
242
253
|
if r.status_code >= 400:
|
|
243
254
|
return False
|
|
@@ -1294,7 +1305,10 @@ def _download_with_system_wget(url, target_dir, size_limit_gb=None):
|
|
|
1294
1305
|
# Before download: best-effort Content-Length check
|
|
1295
1306
|
try:
|
|
1296
1307
|
head = requests.head(
|
|
1297
|
-
url,
|
|
1308
|
+
url,
|
|
1309
|
+
timeout=_download_request_timeout(10),
|
|
1310
|
+
allow_redirects=True,
|
|
1311
|
+
headers={"User-Agent": _HTTP_BROWSER_USER_AGENT, "Accept": "*/*"},
|
|
1298
1312
|
)
|
|
1299
1313
|
if head.status_code < 400:
|
|
1300
1314
|
_raise_if_content_length_over_limit(
|
|
@@ -1319,6 +1333,8 @@ def _download_with_system_wget(url, target_dir, size_limit_gb=None):
|
|
|
1319
1333
|
"--tries=20",
|
|
1320
1334
|
"--timeout=60",
|
|
1321
1335
|
"--waitretry=5",
|
|
1336
|
+
"--user-agent",
|
|
1337
|
+
_HTTP_BROWSER_USER_AGENT,
|
|
1322
1338
|
"-c",
|
|
1323
1339
|
"-P", str(target_dir),
|
|
1324
1340
|
url,
|
|
@@ -1608,7 +1624,7 @@ def _download_file_once(url, target_dir, request_headers=None, size_limit_gb=Non
|
|
|
1608
1624
|
|
|
1609
1625
|
|
|
1610
1626
|
def download_file(url, target_dir, size_limit_gb=None):
|
|
1611
|
-
"""Download via HTTP(S); retry on 403 or HTML interstitial for
|
|
1627
|
+
"""Download via HTTP(S); retry on 400/403 or HTML interstitial for archives."""
|
|
1612
1628
|
attempts = _download_http_header_attempts()
|
|
1613
1629
|
last_i = len(attempts) - 1
|
|
1614
1630
|
for i, req_headers in enumerate(attempts):
|
|
@@ -1619,13 +1635,11 @@ def download_file(url, target_dir, size_limit_gb=None):
|
|
|
1619
1635
|
except (SizeLimitExceeded, TimeOutException):
|
|
1620
1636
|
raise
|
|
1621
1637
|
except requests.exceptions.HTTPError as e:
|
|
1622
|
-
if
|
|
1623
|
-
|
|
1624
|
-
and e.response.status_code == 403
|
|
1625
|
-
and i < last_i
|
|
1626
|
-
):
|
|
1638
|
+
status_code = e.response.status_code if e.response is not None else None
|
|
1639
|
+
if _status_retries_with_user_agent(status_code) and i < last_i:
|
|
1627
1640
|
logger.info(
|
|
1628
|
-
"download_file: HTTP
|
|
1641
|
+
"download_file: HTTP %s; retrying with alternate User-Agent",
|
|
1642
|
+
status_code,
|
|
1629
1643
|
)
|
|
1630
1644
|
continue
|
|
1631
1645
|
logger.warning(f"download_file - failed: {e}")
|
|
@@ -42,6 +42,7 @@ tests/test_download.py
|
|
|
42
42
|
tests/test_download_maven.py
|
|
43
43
|
tests/test_download_packagist.py
|
|
44
44
|
tests/test_download_timeout.py
|
|
45
|
+
tests/test_download_user_agent.py
|
|
45
46
|
tests/test_download_version_attempts.py
|
|
46
47
|
tests/test_download_version_hint.py
|
|
47
48
|
tests/test_opossum.py
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Copyright (c) 2026 LG Electronics Inc.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""User-Agent retry when a host blocks non-browser clients with HTTP 400."""
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
import fosslight_util.download as download
|
|
8
|
+
|
|
9
|
+
_JAR_URL = (
|
|
10
|
+
"https://maven.egovframe.go.kr/maven/org/egovframe/rte/"
|
|
11
|
+
"org.egovframe.rte.fdl.cmmn/4.1.0/org.egovframe.rte.fdl.cmmn-4.1.0.jar"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _Response:
|
|
16
|
+
def __init__(self, status_code, body=b"PK\x03\x04", headers=None):
|
|
17
|
+
self.status_code = status_code
|
|
18
|
+
self._body = body
|
|
19
|
+
self.headers = headers or {"content-type": "application/java-archive"}
|
|
20
|
+
self.url = _JAR_URL
|
|
21
|
+
|
|
22
|
+
def raise_for_status(self):
|
|
23
|
+
if self.status_code >= 400:
|
|
24
|
+
raise requests.HTTPError(response=self)
|
|
25
|
+
|
|
26
|
+
def iter_content(self, chunk_size=8192):
|
|
27
|
+
yield self._body
|
|
28
|
+
|
|
29
|
+
def __enter__(self):
|
|
30
|
+
return self
|
|
31
|
+
|
|
32
|
+
def __exit__(self, exc_type, exc, tb):
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _user_agent(kwargs):
|
|
37
|
+
headers = kwargs.get("headers") or {}
|
|
38
|
+
return headers.get("User-Agent")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_download_file_retries_http_400_with_browser_user_agent(tmp_path, monkeypatch):
|
|
42
|
+
seen = []
|
|
43
|
+
|
|
44
|
+
def fake_head(url, **kwargs):
|
|
45
|
+
seen.append(("head", _user_agent(kwargs)))
|
|
46
|
+
status = 400 if _user_agent(kwargs) == download._HTTP_CURL_LIKE_USER_AGENT else 200
|
|
47
|
+
return _Response(status)
|
|
48
|
+
|
|
49
|
+
def fake_get(url, **kwargs):
|
|
50
|
+
seen.append(("get", _user_agent(kwargs)))
|
|
51
|
+
status = 400 if _user_agent(kwargs) == download._HTTP_CURL_LIKE_USER_AGENT else 200
|
|
52
|
+
return _Response(status, body=b"PK\x03\x04jar")
|
|
53
|
+
|
|
54
|
+
monkeypatch.setattr(download.requests, "head", fake_head)
|
|
55
|
+
monkeypatch.setattr(download.requests, "get", fake_get)
|
|
56
|
+
|
|
57
|
+
path = download.download_file(_JAR_URL, str(tmp_path))
|
|
58
|
+
|
|
59
|
+
assert path is not None
|
|
60
|
+
with open(path, "rb") as downloaded:
|
|
61
|
+
assert downloaded.read() == b"PK\x03\x04jar"
|
|
62
|
+
assert seen == [
|
|
63
|
+
("head", download._HTTP_CURL_LIKE_USER_AGENT),
|
|
64
|
+
("get", download._HTTP_CURL_LIKE_USER_AGENT),
|
|
65
|
+
("head", download._HTTP_BROWSER_USER_AGENT),
|
|
66
|
+
("get", download._HTTP_BROWSER_USER_AGENT),
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_download_file_does_not_retry_http_404(tmp_path, monkeypatch):
|
|
71
|
+
seen = []
|
|
72
|
+
|
|
73
|
+
def fake_head(url, **kwargs):
|
|
74
|
+
seen.append("head")
|
|
75
|
+
return _Response(404)
|
|
76
|
+
|
|
77
|
+
def fake_get(url, **kwargs):
|
|
78
|
+
seen.append("get")
|
|
79
|
+
return _Response(404)
|
|
80
|
+
|
|
81
|
+
monkeypatch.setattr(download.requests, "head", fake_head)
|
|
82
|
+
monkeypatch.setattr(download.requests, "get", fake_get)
|
|
83
|
+
|
|
84
|
+
assert download.download_file(_JAR_URL, str(tmp_path)) is None
|
|
85
|
+
assert seen == ["head", "get"]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_is_downloadable_retries_http_400(monkeypatch):
|
|
89
|
+
seen = []
|
|
90
|
+
|
|
91
|
+
def fake_get(url, **kwargs):
|
|
92
|
+
ua = _user_agent(kwargs)
|
|
93
|
+
seen.append(ua)
|
|
94
|
+
status = 400 if ua == download._HTTP_CURL_LIKE_USER_AGENT else 200
|
|
95
|
+
return _Response(status)
|
|
96
|
+
|
|
97
|
+
monkeypatch.setattr(download.requests, "get", fake_get)
|
|
98
|
+
|
|
99
|
+
assert download.is_downloadable(_JAR_URL) is True
|
|
100
|
+
assert seen == [
|
|
101
|
+
download._HTTP_CURL_LIKE_USER_AGENT,
|
|
102
|
+
download._HTTP_BROWSER_USER_AGENT,
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_system_wget_sends_browser_user_agent(tmp_path, monkeypatch):
|
|
107
|
+
captured = {}
|
|
108
|
+
|
|
109
|
+
class _Proc:
|
|
110
|
+
returncode = 0
|
|
111
|
+
|
|
112
|
+
def poll(self):
|
|
113
|
+
return 0
|
|
114
|
+
|
|
115
|
+
def communicate(self):
|
|
116
|
+
return ("", "")
|
|
117
|
+
|
|
118
|
+
def fake_popen(cmd, **kwargs):
|
|
119
|
+
captured["cmd"] = cmd
|
|
120
|
+
(tmp_path / "org.egovframe.rte.fdl.cmmn-4.1.0.jar").write_bytes(b"PK")
|
|
121
|
+
return _Proc()
|
|
122
|
+
|
|
123
|
+
class _Head:
|
|
124
|
+
status_code = 200
|
|
125
|
+
headers = {}
|
|
126
|
+
|
|
127
|
+
def fake_head(url, **kwargs):
|
|
128
|
+
captured["head_headers"] = kwargs.get("headers")
|
|
129
|
+
return _Head()
|
|
130
|
+
|
|
131
|
+
monkeypatch.setattr(download.shutil, "which", lambda name: "/usr/bin/wget")
|
|
132
|
+
monkeypatch.setattr(download.requests, "head", fake_head)
|
|
133
|
+
monkeypatch.setattr(download.subprocess, "Popen", fake_popen)
|
|
134
|
+
|
|
135
|
+
path = download._download_with_system_wget(_JAR_URL, str(tmp_path))
|
|
136
|
+
|
|
137
|
+
assert path.endswith("org.egovframe.rte.fdl.cmmn-4.1.0.jar")
|
|
138
|
+
cmd = captured["cmd"]
|
|
139
|
+
agent_index = cmd.index("--user-agent")
|
|
140
|
+
assert cmd[agent_index + 1] == download._HTTP_BROWSER_USER_AGENT
|
|
141
|
+
assert captured["head_headers"]["User-Agent"] == download._HTTP_BROWSER_USER_AGENT
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|