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.
Files changed (56) hide show
  1. {fosslight_util-2.2.19/src/fosslight_util.egg-info → fosslight_util-2.2.20}/PKG-INFO +1 -1
  2. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/pyproject.toml +1 -1
  3. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/download.py +26 -12
  4. {fosslight_util-2.2.19 → fosslight_util-2.2.20/src/fosslight_util.egg-info}/PKG-INFO +1 -1
  5. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/SOURCES.txt +1 -0
  6. fosslight_util-2.2.20/tests/test_download_user_agent.py +141 -0
  7. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/LICENSE +0 -0
  8. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/MANIFEST.in +0 -0
  9. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/README.md +0 -0
  10. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/setup.cfg +0 -0
  11. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/__init__.py +0 -0
  12. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/_get_downloadable_url.py +0 -0
  13. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/compare_yaml.py +0 -0
  14. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/constant.py +0 -0
  15. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/correct.py +0 -0
  16. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/cover.py +0 -0
  17. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/exclude.py +0 -0
  18. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/get_pom_license.py +0 -0
  19. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/help.py +0 -0
  20. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/oss_item.py +0 -0
  21. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/output_format.py +0 -0
  22. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/parsing_yaml.py +0 -0
  23. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/read_excel.py +0 -0
  24. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
  25. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
  26. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/resources/licenses.json +0 -0
  27. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/set_log.py +0 -0
  28. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/spdx_licenses.py +0 -0
  29. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/time.py +0 -0
  30. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/timer_thread.py +0 -0
  31. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_cyclonedx.py +0 -0
  32. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_excel.py +0 -0
  33. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_opossum.py +0 -0
  34. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_scancodejson.py +0 -0
  35. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_spdx.py +0 -0
  36. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_txt.py +0 -0
  37. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util/write_yaml.py +0 -0
  38. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
  39. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/entry_points.txt +0 -0
  40. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/requires.txt +0 -0
  41. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/src/fosslight_util.egg-info/top_level.txt +0 -0
  42. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_cyclonedx.py +0 -0
  43. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_decide_checkout.py +0 -0
  44. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download.py +0 -0
  45. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_maven.py +0 -0
  46. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_packagist.py +0 -0
  47. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_timeout.py +0 -0
  48. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_version_attempts.py +0 -0
  49. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_download_version_hint.py +0 -0
  50. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_opossum.py +0 -0
  51. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_spdx.py +0 -0
  52. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_spdx_licenses.py +0 -0
  53. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_text.py +0 -0
  54. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_write_excel_hidden_sheet.py +0 -0
  55. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_write_output.py +0 -0
  56. {fosslight_util-2.2.19 → fosslight_util-2.2.20}/tests/test_write_yaml.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.2.19
3
+ Version: 2.2.20
4
4
  Summary: FOSSLight Util
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "fosslight_util"
10
- version = "2.2.19"
10
+ version = "2.2.20"
11
11
  description = "FOSSLight Util"
12
12
  readme = "README.md"
13
13
  license = "Apache-2.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. Start with a curl-style UA
65
- # (widely accepted for file downloads), then browser, then default requests as fallback.
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 body for archive URLs."""
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 == 403 and i < last_i:
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, timeout=_download_request_timeout(10), allow_redirects=True
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 archive URLs."""
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
- e.response is not None
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 403; retrying with alternate User-Agent"
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}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.2.19
3
+ Version: 2.2.20
4
4
  Summary: FOSSLight Util
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0
@@ -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