fosslight-util 2.2.23__tar.gz → 2.2.25__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 (59) hide show
  1. {fosslight_util-2.2.23/src/fosslight_util.egg-info → fosslight_util-2.2.25}/PKG-INFO +1 -1
  2. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/pyproject.toml +1 -1
  3. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/_get_downloadable_url.py +72 -67
  4. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/write_cyclonedx.py +60 -3
  5. {fosslight_util-2.2.23 → fosslight_util-2.2.25/src/fosslight_util.egg-info}/PKG-INFO +1 -1
  6. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util.egg-info/SOURCES.txt +1 -0
  7. fosslight_util-2.2.25/tests/test_download_pypi.py +102 -0
  8. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/LICENSE +0 -0
  9. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/MANIFEST.in +0 -0
  10. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/README.md +0 -0
  11. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/setup.cfg +0 -0
  12. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/__init__.py +0 -0
  13. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/compare_yaml.py +0 -0
  14. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/constant.py +0 -0
  15. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/correct.py +0 -0
  16. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/cover.py +0 -0
  17. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/download.py +0 -0
  18. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/exclude.py +0 -0
  19. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/get_pom_license.py +0 -0
  20. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/help.py +0 -0
  21. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/merge.py +0 -0
  22. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/oss_item.py +0 -0
  23. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/output_format.py +0 -0
  24. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/parsing_yaml.py +0 -0
  25. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/read_excel.py +0 -0
  26. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
  27. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
  28. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/resources/licenses.json +0 -0
  29. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/set_log.py +0 -0
  30. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/spdx_licenses.py +0 -0
  31. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/time.py +0 -0
  32. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/timer_thread.py +0 -0
  33. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/write_excel.py +0 -0
  34. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/write_opossum.py +0 -0
  35. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/write_scancodejson.py +0 -0
  36. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/write_spdx.py +0 -0
  37. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/write_txt.py +0 -0
  38. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util/write_yaml.py +0 -0
  39. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
  40. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util.egg-info/entry_points.txt +0 -0
  41. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util.egg-info/requires.txt +0 -0
  42. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/src/fosslight_util.egg-info/top_level.txt +0 -0
  43. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_chromium_gitiles.py +0 -0
  44. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_cyclonedx.py +0 -0
  45. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_decide_checkout.py +0 -0
  46. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_download.py +0 -0
  47. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_download_maven.py +0 -0
  48. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_download_packagist.py +0 -0
  49. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_download_timeout.py +0 -0
  50. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_download_user_agent.py +0 -0
  51. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_download_version_attempts.py +0 -0
  52. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_download_version_hint.py +0 -0
  53. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_opossum.py +0 -0
  54. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_spdx.py +0 -0
  55. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_spdx_licenses.py +0 -0
  56. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_text.py +0 -0
  57. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_write_excel_hidden_sheet.py +0 -0
  58. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/tests/test_write_output.py +0 -0
  59. {fosslight_util-2.2.23 → fosslight_util-2.2.25}/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.23
3
+ Version: 2.2.25
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.23"
10
+ version = "2.2.25"
11
11
  description = "FOSSLight Util"
12
12
  readme = "README.md"
13
13
  license = "Apache-2.0"
@@ -8,6 +8,7 @@ import requests
8
8
  import xml.etree.ElementTree as ET
9
9
  from lastversion import latest
10
10
  from bs4 import BeautifulSoup
11
+ from urllib.parse import quote, unquote
11
12
  from urllib.request import urlopen
12
13
  import fosslight_util.constant as constant
13
14
 
@@ -952,87 +953,91 @@ def get_download_location_for_go(link):
952
953
  return ret, new_link
953
954
 
954
955
 
955
- def get_available_wheel_urls(name, version):
956
- try:
957
- api_url = f'https://pypi.org/pypi/{name}/{version}/json'
958
- response = requests.get(api_url, timeout=_HTTP_TIMEOUT)
959
- if response.status_code == 200:
960
- data = response.json()
961
- wheel_urls = []
956
+ def _pypi_api_path(value):
957
+ """Encode one PyPI JSON path segment without changing '.' or '-'."""
958
+ return quote(value or "", safe=".-_")
962
959
 
963
- for file_info in data.get('urls', []):
964
- if file_info.get('packagetype') == 'bdist_wheel':
965
- wheel_urls.append(file_info.get('url'))
966
960
 
967
- return wheel_urls
968
- else:
969
- logger.warning(f'Cannot get PyPI API data for {name}({version})')
970
- return []
961
+ def _pypi_release_files(name, version):
962
+ """Return the ``urls`` list from the PyPI JSON API for one release."""
963
+ api_url = (
964
+ f"https://pypi.org/pypi/{_pypi_api_path(name)}/{_pypi_api_path(version)}/json"
965
+ )
966
+ response = requests.get(api_url, timeout=_HTTP_TIMEOUT)
967
+ if response.status_code != 200:
968
+ logger.warning(f'Cannot get PyPI API data for {name}({version})')
969
+ return []
970
+ files = response.json().get('urls') or []
971
+ return [item for item in files if isinstance(item, dict)]
972
+
973
+
974
+ def _pypi_file_rank(file_info, suffixes):
975
+ filename = (file_info.get('filename') or file_info.get('url') or '').lower()
976
+ for index, suffix in enumerate(suffixes):
977
+ if filename.endswith(suffix):
978
+ return index
979
+ return len(suffixes)
980
+
981
+
982
+ def _select_pypi_download_url(files):
983
+ """Prefer an sdist URL from the JSON file list, then a wheel."""
984
+ sdists = [
985
+ item for item in files
986
+ if item.get('packagetype') == 'sdist' and item.get('url')
987
+ ]
988
+ if sdists:
989
+ chosen = sorted(sdists, key=lambda item: _pypi_file_rank(item, ('.tar.gz', '.tgz', '.zip')))[0]
990
+ return chosen.get('url'), False
991
+
992
+ wheels = [
993
+ item for item in files
994
+ if item.get('packagetype') == 'bdist_wheel' and item.get('url')
995
+ ]
996
+ for wheel in wheels:
997
+ url = wheel.get('url') or ''
998
+ if 'py3-none-any' in url or 'py2.py3-none-any' in url:
999
+ return url, True
1000
+ if wheels:
1001
+ return wheels[0].get('url'), True
1002
+ return '', False
1003
+
971
1004
 
1005
+ def get_available_wheel_urls(name, version):
1006
+ try:
1007
+ files = _pypi_release_files(name, version)
1008
+ return [
1009
+ item.get('url') for item in files
1010
+ if item.get('packagetype') == 'bdist_wheel' and item.get('url')
1011
+ ]
972
1012
  except Exception as error:
973
1013
  logger.warning(f'Failed to get wheel URLs from PyPI API: {error}')
974
1014
  return []
975
1015
 
976
1016
 
977
1017
  def get_download_location_for_pypi(link):
978
- # get the url for downloading source file: https://docs.pypi.org/api/ Predictable URLs
1018
+ """Resolve a PyPI project URL to the file URL published in the JSON API."""
979
1019
  ret = False
980
1020
  new_link = ''
981
- host = 'https://files.pythonhosted.org'
982
1021
 
983
1022
  try:
984
1023
  dn_loc_re = re.findall(r'pypi.org\/project\/?([^\/]*)\/?([^\/]*)', link)
985
- oss_name = dn_loc_re[0][0]
986
- oss_name = re.sub(r"[-_.]+", "-", oss_name)
987
- oss_version = dn_loc_re[0][1]
988
-
989
- # 1. Source distribution 시도
990
- new_link = f'{host}/packages/source/{oss_name[0]}/{oss_name}/{oss_name}-{oss_version}.tar.gz'
991
- try:
992
- res = urlopen(new_link, timeout=_HTTP_TIMEOUT)
993
- if res.getcode() == 200:
994
- ret = True
995
- return ret, new_link
996
- except Exception:
997
- oss_name = re.sub(r"[-]+", "_", oss_name)
998
- new_link = f'{host}/packages/source/{oss_name[0]}/{oss_name}/{oss_name}-{oss_version}.tar.gz'
999
- try:
1000
- res = urlopen(new_link, timeout=_HTTP_TIMEOUT)
1001
- if res.getcode() == 200:
1002
- ret = True
1003
- return ret, new_link
1004
- except Exception:
1005
- pass
1006
-
1007
- # 2. Source distribution이 없으면 wheel 파일들을 시도
1008
- wheel_urls = get_available_wheel_urls(oss_name, oss_version)
1009
-
1010
- if wheel_urls:
1011
- # Pure Python wheel을 우선적으로 찾기
1012
- for wheel_url in wheel_urls:
1013
- if 'py3-none-any' in wheel_url or 'py2.py3-none-any' in wheel_url:
1014
- try:
1015
- res = urlopen(wheel_url, timeout=_HTTP_TIMEOUT)
1016
- if res.getcode() == 200:
1017
- ret = True
1018
- new_link = wheel_url
1019
- logger.info(f'Using wheel file : {wheel_url}')
1020
- return ret, new_link
1021
- except Exception:
1022
- continue
1023
-
1024
- # Pure Python wheel이 없으면 첫 번째 wheel 시도
1025
- if wheel_urls:
1026
- try:
1027
- res = urlopen(wheel_urls[0], timeout=_HTTP_TIMEOUT)
1028
- if res.getcode() == 200:
1029
- ret = True
1030
- new_link = wheel_urls[0]
1031
- logger.info(f'Using wheel file : {wheel_urls[0]}')
1032
- return ret, new_link
1033
- except Exception:
1034
- pass
1035
-
1024
+ if not dn_loc_re:
1025
+ return ret, new_link
1026
+ oss_name = unquote(dn_loc_re[0][0])
1027
+ oss_version = unquote(dn_loc_re[0][1])
1028
+ if not oss_name or not oss_version:
1029
+ return ret, new_link
1030
+
1031
+ chosen_url, is_wheel = _select_pypi_download_url(
1032
+ _pypi_release_files(oss_name, oss_version)
1033
+ )
1034
+ if chosen_url:
1035
+ ret = True
1036
+ new_link = chosen_url
1037
+ if is_wheel:
1038
+ logger.info(f'Using wheel file : {chosen_url}')
1039
+ return ret, new_link
1040
+ logger.warning(f'Cannot find the link for pypi (url:{link})')
1036
1041
  except Exception as error:
1037
1042
  ret = False
1038
1043
  logger.warning(f'Cannot find the link for pypi (url:{link}({new_link})) e:{str(error)}')
@@ -8,6 +8,7 @@ import os
8
8
  import logging
9
9
  import re
10
10
  from pathlib import Path
11
+ from urllib.parse import quote, unquote
11
12
  from fosslight_util.constant import (FOSSLIGHT_BINARY, FOSSLIGHT_DEPENDENCY, FOSSLIGHT_SCANNER,
12
13
  FOSSLIGHT_SOURCE, LOGGER_NAME)
13
14
  import traceback
@@ -66,6 +67,62 @@ except Exception as error:
66
67
  logger.info(f'Failed to import cyclonedx-python-lib: {error}')
67
68
 
68
69
 
70
+ class _DependencyPurl(PackageURL if _cyclonedx_import_error is None else object):
71
+ """Serialize parsed fields with PURL encoding, without folding npm case."""
72
+
73
+ def to_string(self, encode=True):
74
+ # PURL specification 5.4: ':' is allowed only in qualifier values; other
75
+ # components must percent-encode it and other separators used as data.
76
+ def encode_component(value, allow_colon=False):
77
+ if not encode:
78
+ return value
79
+ safe = '.-_~:' if allow_colon else '.-_~'
80
+ return quote(str(value), safe=safe)
81
+
82
+ parts = ['pkg:', self.type, '/']
83
+ if self.namespace:
84
+ parts.extend(('/'.join(encode_component(segment) for segment in self.namespace.split('/')), '/'))
85
+ parts.append(encode_component(self.name))
86
+ if self.version:
87
+ parts.extend(('@', encode_component(self.version)))
88
+ if self.qualifiers:
89
+ parts.extend(('?', '&'.join(
90
+ f'{key}={encode_component(value, allow_colon=True)}'
91
+ for key, value in sorted(self.qualifiers.items()) if value)))
92
+ if self.subpath:
93
+ parts.extend(('#', '/'.join(encode_component(segment) for segment in self.subpath.split('/'))))
94
+ return ''.join(parts)
95
+
96
+
97
+ def _parse_dependency_purl(value):
98
+ parsed = PackageURL.from_string(value)
99
+ if parsed.type == 'npm':
100
+ package_path = value.split('?', 1)[0].split('#', 1)[0]
101
+ package_path = package_path.split(':', 1)[1].strip().lstrip('/').rstrip('/').split('/', 1)[1]
102
+ # Remove the version before splitting the namespace/name. Its decoded
103
+ # or unencoded value may contain slashes (e.g., link:../local-lib). A raw
104
+ # '@' after the first character is the version delimiter (this also covers
105
+ # an empty version, e.g. 'name@'). A leading '@' is the npm scope marker
106
+ # (e.g. '@scope/name') and must be kept.
107
+ version_idx = package_path.find('@', 1)
108
+ if version_idx != -1:
109
+ package_path = package_path[:version_idx].rstrip('/')
110
+ namespace = unquote(package_path.rsplit('/', 1)[0]) if '/' in package_path else None
111
+ name = unquote(package_path.rsplit('/', 1)[-1])
112
+ parsed = PackageURL(
113
+ type=parsed.type, namespace=namespace, name=name,
114
+ version=parsed.version, qualifiers=parsed.qualifiers, subpath=parsed.subpath,
115
+ normalize_purl=False,
116
+ )
117
+ # Normalize the output, not the source spelling. Parsed fields also allow
118
+ # dependency lookup to match equivalent encoded and unencoded references.
119
+ return _DependencyPurl(
120
+ type=parsed.type, namespace=parsed.namespace, name=parsed.name,
121
+ version=parsed.version, qualifiers=parsed.qualifiers, subpath=parsed.subpath,
122
+ normalize_purl=False,
123
+ )
124
+
125
+
69
126
  def write_cyclonedx(output_file_without_ext, output_extension, scan_item, scanner_covers=None):
70
127
  success = True
71
128
  error_msg = ''
@@ -119,7 +176,7 @@ def write_cyclonedx(output_file_without_ext, output_extension, scan_item, scanne
119
176
  if oss_item.copyright != '':
120
177
  comp.copyright = oss_item.copyright
121
178
  if scanner_name == FOSSLIGHT_DEPENDENCY and file_item.purl:
122
- comp.purl = PackageURL.from_string(file_item.purl)
179
+ comp.purl = _parse_dependency_purl(file_item.purl)
123
180
  if scanner_name != FOSSLIGHT_DEPENDENCY:
124
181
  if file_item.checksum != '0':
125
182
  comp.hashes = [HashType(alg=HashAlgorithm.SHA_1, content=file_item.checksum)]
@@ -164,11 +221,11 @@ def write_cyclonedx(output_file_without_ext, output_extension, scan_item, scanne
164
221
 
165
222
  if len(bom.components) > 0:
166
223
  for comp_purl in relation_tree:
167
- comp = bom.get_component_by_purl(PackageURL.from_string(comp_purl))
224
+ comp = bom.get_component_by_purl(_parse_dependency_purl(comp_purl))
168
225
  if comp:
169
226
  dep_comp_list = []
170
227
  for dep_comp_purl in relation_tree[comp_purl]:
171
- dep_comp = bom.get_component_by_purl(PackageURL.from_string(dep_comp_purl))
228
+ dep_comp = bom.get_component_by_purl(_parse_dependency_purl(dep_comp_purl))
172
229
  if dep_comp:
173
230
  dep_comp_list.append(dep_comp)
174
231
  bom.register_dependency(comp, dep_comp_list)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.2.23
3
+ Version: 2.2.25
4
4
  Summary: FOSSLight Util
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0
@@ -43,6 +43,7 @@ tests/test_decide_checkout.py
43
43
  tests/test_download.py
44
44
  tests/test_download_maven.py
45
45
  tests/test_download_packagist.py
46
+ tests/test_download_pypi.py
46
47
  tests/test_download_timeout.py
47
48
  tests/test_download_user_agent.py
48
49
  tests/test_download_version_attempts.py
@@ -0,0 +1,102 @@
1
+ # Copyright (c) 2026 LG Electronics Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """PyPI project URLs resolve to the file URL from the JSON API."""
4
+
5
+ from unittest.mock import Mock, patch
6
+
7
+ from fosslight_util._get_downloadable_url import get_download_location_for_pypi
8
+
9
+ _SDIST = (
10
+ "https://files.pythonhosted.org/packages/9b/5a/abc/"
11
+ "winrt_windows_storage_streams-4!10.0.28000.2957.tar.gz"
12
+ )
13
+ _WHEEL = (
14
+ "https://files.pythonhosted.org/packages/d5/8d/abc/"
15
+ "winrt_windows_storage_streams-4!10.0.28000.2957-py3-none-any.whl"
16
+ )
17
+ _PROJECT = "https://pypi.org/project/winrt-Windows.Storage.Streams/4!10.0.28000.2957"
18
+
19
+
20
+ def _response(status_code, urls):
21
+ response = Mock()
22
+ response.status_code = status_code
23
+ response.json.return_value = {"urls": urls}
24
+ return response
25
+
26
+
27
+ @patch("fosslight_util._get_downloadable_url.requests.get")
28
+ def test_pypi_json_prefers_sdist_for_mixed_case_name(mock_get):
29
+ mock_get.return_value = _response(200, [
30
+ {"packagetype": "bdist_wheel", "filename": "pkg.whl", "url": _WHEEL},
31
+ {"packagetype": "sdist", "filename": "pkg.tar.gz", "url": _SDIST},
32
+ {"packagetype": "sdist", "filename": "pkg.zip", "url": "https://example.invalid/pkg.zip"},
33
+ ])
34
+
35
+ found, link = get_download_location_for_pypi(_PROJECT)
36
+
37
+ assert found is True
38
+ assert link == _SDIST
39
+ requested = mock_get.call_args.args[0]
40
+ assert "winrt-Windows.Storage.Streams" in requested
41
+ assert "4%2110.0.28000.2957" in requested
42
+ assert "packages/source/" not in link
43
+
44
+
45
+ @patch("fosslight_util._get_downloadable_url.requests.get")
46
+ def test_pypi_json_uses_pure_wheel_when_sdist_is_missing(mock_get):
47
+ platform_wheel = "https://files.pythonhosted.org/packages/aa/pkg-1.0-cp312-cp312-win_amd64.whl"
48
+ mock_get.return_value = _response(200, [
49
+ {"packagetype": "bdist_wheel", "filename": "pkg.whl", "url": platform_wheel},
50
+ {"packagetype": "bdist_wheel", "filename": "pkg-none.whl", "url": _WHEEL},
51
+ ])
52
+
53
+ found, link = get_download_location_for_pypi("https://pypi.org/project/pkg/1.0")
54
+
55
+ assert found is True
56
+ assert link == _WHEEL
57
+
58
+
59
+ @patch("fosslight_util._get_downloadable_url.requests.get")
60
+ def test_pypi_json_keeps_yanked_release_file(mock_get):
61
+ mock_get.return_value = _response(200, [
62
+ {"packagetype": "bdist_wheel", "filename": "pkg.whl", "url": _WHEEL, "yanked": True},
63
+ {"packagetype": "sdist", "filename": "pkg.tar.gz", "url": _SDIST, "yanked": True},
64
+ ])
65
+
66
+ found, link = get_download_location_for_pypi(_PROJECT)
67
+
68
+ assert found is True
69
+ assert link == _SDIST
70
+
71
+
72
+ @patch("fosslight_util._get_downloadable_url.requests.get")
73
+ def test_pypi_json_decodes_percent_encoded_version(mock_get):
74
+ mock_get.return_value = _response(200, [
75
+ {"packagetype": "sdist", "filename": "pkg.tar.gz", "url": _SDIST},
76
+ ])
77
+ encoded = "https://pypi.org/project/winrt-Windows.Storage.Streams/4%2110.0.28000.2957"
78
+
79
+ found, link = get_download_location_for_pypi(encoded)
80
+
81
+ assert found is True
82
+ assert link == _SDIST
83
+ encoded_request = mock_get.call_args.args[0]
84
+ assert "4%2110.0.28000.2957" in encoded_request
85
+ assert "%2521" not in encoded_request
86
+
87
+ mock_get.reset_mock()
88
+ mock_get.return_value = _response(200, [
89
+ {"packagetype": "sdist", "filename": "pkg.tar.gz", "url": _SDIST},
90
+ ])
91
+ get_download_location_for_pypi(_PROJECT)
92
+ assert mock_get.call_args.args[0] == encoded_request
93
+
94
+
95
+ @patch("fosslight_util._get_downloadable_url.requests.get")
96
+ def test_pypi_json_failure_does_not_invent_a_file_url(mock_get):
97
+ mock_get.return_value = _response(404, [])
98
+
99
+ found, link = get_download_location_for_pypi(_PROJECT)
100
+
101
+ assert found is False
102
+ assert link == ""
File without changes