MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_file_references

Function get_file_references

src/packagedcode/pypi.py:1320–1343  ·  view source on GitHub ↗

Yield FileReference found in a ``dist`` importlib_metadata.Distribution.

(dist)

Source from the content-addressed store, hash-verified

1318
1319
1320def get_file_references(dist):
1321 """
1322 Yield FileReference found in a ``dist`` importlib_metadata.Distribution.
1323 """
1324 if not dist.files:
1325 return
1326
1327 for filepath in dist.files or []:
1328 # FIXME: the path is relative to the "site-packages" directory or the
1329 # root of a wheel but this should be a scan path
1330 ref = models.FileReference(
1331 path=as_posixpath(str(filepath)),
1332 size=filepath.size,
1333 )
1334
1335 filehash = filepath.hash
1336 if filehash:
1337 algo = filehash.mode
1338 value = filehash.value
1339 if algo in ('sha256', 'sha512'):
1340 # convert back to hex as this is a base64 without padding otherwise
1341 value = urlsafe_b64decode(value).hex()
1342 setattr(ref, algo, value)
1343 yield ref
1344
1345
1346class PypiWheelHandler(models.DatafileHandler):

Callers 1

parse_metadataFunction · 0.70

Calls 2

as_posixpathFunction · 0.90
urlsafe_b64decodeFunction · 0.70

Tested by

no test coverage detected