fosslight-util 2.1.35__py3-none-any.whl → 2.1.36__py3-none-any.whl

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.
@@ -8,6 +8,12 @@ import logging
8
8
  import urllib.request
9
9
  from urllib.error import URLError, HTTPError
10
10
  from defusedxml.ElementTree import fromstring as xml_fromstring
11
+ import ssl
12
+ # certifi is optional: if unavailable, use the default SSL context
13
+ try:
14
+ import certifi # type: ignore
15
+ except Exception: # pragma: no cover - optional dependency
16
+ certifi = None
11
17
  import fosslight_util.constant as constant
12
18
 
13
19
  logger = logging.getLogger(constant.LOGGER_NAME)
@@ -19,6 +25,15 @@ def get_license_from_pom(group_id: str = None,
19
25
  pom_path: str = None,
20
26
  check_parent: bool = True) -> str:
21
27
 
28
+ def get_ssl_context():
29
+ try:
30
+ if certifi is not None:
31
+ return ssl.create_default_context(cafile=certifi.where())
32
+ return ssl.create_default_context()
33
+ except Exception as e:
34
+ logger.debug(f"Failed to create SSL context: {e}")
35
+ return None
36
+
22
37
  def build_urls(g, a, v):
23
38
  group_path = g.replace('.', '/')
24
39
  name = f"{a}-{v}.pom"
@@ -27,11 +42,25 @@ def get_license_from_pom(group_id: str = None,
27
42
  return [repo1, google]
28
43
 
29
44
  def fetch_pom(g, a, v):
45
+ ssl_ctx = get_ssl_context()
30
46
  for url in build_urls(g, a, v):
31
47
  try:
48
+ if ssl_ctx is not None:
49
+ with urllib.request.urlopen(url, context=ssl_ctx) as resp:
50
+ return resp.read().decode('utf-8')
32
51
  with urllib.request.urlopen(url) as resp:
33
52
  return resp.read().decode('utf-8')
34
- except (HTTPError, URLError):
53
+ except ssl.SSLError as e:
54
+ logger.warning(
55
+ f"SSL certificate verification failed for {url}. "
56
+ f"Please fix system certificates or use certifi. (error: {e})"
57
+ )
58
+ continue
59
+ except (HTTPError, URLError) as e:
60
+ logger.warning(f"Failed to fetch POM from {url}: {e}")
61
+ continue
62
+ except Exception as e:
63
+ logger.warning(f"Unexpected error fetching POM from {url}: {e}")
35
64
  continue
36
65
  return None
37
66
 
@@ -66,10 +95,12 @@ def get_license_from_pom(group_id: str = None,
66
95
  visited.add(key)
67
96
  content = fetch_pom(g, a, v)
68
97
  if not content:
98
+ logger.warning(f"Failed to obtain POM content for {g}:{a}:{v} from remote sources.")
69
99
  return ''
70
100
  try:
71
101
  root = xml_fromstring(content)
72
- except Exception:
102
+ except Exception as e:
103
+ logger.warning(f"Failed to parse POM for {g}:{a}:{v}: {e}")
73
104
  return ''
74
105
  licenses = extract_licenses(root)
75
106
  if licenses:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.1.35
3
+ Version: 2.1.36
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Download-URL: https://github.com/fosslight/fosslight_util
@@ -6,7 +6,7 @@ fosslight_util/correct.py,sha256=1WEAL-9_KhjFPLucPhv0PNN3K7avm0z8mU6sTuSyeHM,386
6
6
  fosslight_util/cover.py,sha256=qqqKzxqFwKimal764FaugRUBcHWdeKt8af6xeK0mH8E,2040
7
7
  fosslight_util/download.py,sha256=AWwD3FWhF-bMagWINJ-Dg1VMuycXbe8VXX7qQ09YjYs,23565
8
8
  fosslight_util/exclude.py,sha256=oeBwkc4T80mXdt6_0ak3FGwwzvXpSO-P4Wfd1OT2i3Y,6070
9
- fosslight_util/get_pom_license.py,sha256=x4_RHpM91s01j1OUWpKIxUjTGDH6y5AxTNDGkMajs4I,4253
9
+ fosslight_util/get_pom_license.py,sha256=vmh2LG1_4U7ts9SSpN3_UAANWbx5GBAVjremwm62OFY,5639
10
10
  fosslight_util/help.py,sha256=VomACZeXEMCiT1nxUwPqQAiVdNaMarwHVz9e10qbFc0,4954
11
11
  fosslight_util/oss_item.py,sha256=8890JHb5ZoKQWAwN7Fl8badnlYatJtF4MVJz1rdS4yQ,6938
12
12
  fosslight_util/output_format.py,sha256=BP23LspxawDZ_a99oWLVKWUQ-G7P5uoUpjEXhkRFKwc,8801
@@ -25,9 +25,9 @@ fosslight_util/write_yaml.py,sha256=QlEKoIPQsEaYERfbP53TeKgnllYzhLQWm5wYjnWtVjE,
25
25
  fosslight_util/resources/frequentLicenselist.json,sha256=GUhzK6tu7ok10fekOnmVmUgIGRC-acGABZKTNKfDyYA,4776157
26
26
  fosslight_util/resources/frequent_license_nick_list.json,sha256=ryU2C_6ZxHbz90_sUN9OvI9GXkCMLu7oGcmd9W79YYo,5005
27
27
  fosslight_util/resources/licenses.json,sha256=mK55z-bhY7Mjpj2KsO1crKGGL-X3F6MBFQJ0zLlx010,240843
28
- fosslight_util-2.1.35.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
29
- fosslight_util-2.1.35.dist-info/METADATA,sha256=4mIqOpupjoKYzg0M95-7XTrRsPDaEsPCxpkP_vNrsgM,6365
30
- fosslight_util-2.1.35.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
31
- fosslight_util-2.1.35.dist-info/entry_points.txt,sha256=0yZggRWNwDaClDG8UmUA10UFG8cVX3Jiy5gG9nW7hJs,68
32
- fosslight_util-2.1.35.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
33
- fosslight_util-2.1.35.dist-info/RECORD,,
28
+ fosslight_util-2.1.36.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
29
+ fosslight_util-2.1.36.dist-info/METADATA,sha256=n-reuC9PkPU9QFJWRqn5UheXoG8y7ICNbolRgdcos6E,6365
30
+ fosslight_util-2.1.36.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
31
+ fosslight_util-2.1.36.dist-info/entry_points.txt,sha256=0yZggRWNwDaClDG8UmUA10UFG8cVX3Jiy5gG9nW7hJs,68
32
+ fosslight_util-2.1.36.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
33
+ fosslight_util-2.1.36.dist-info/RECORD,,