Yield FileReference found in a ``dist`` importlib_metadata.Distribution.
(dist)
| 1318 | |
| 1319 | |
| 1320 | def 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 | |
| 1346 | class PypiWheelHandler(models.DatafileHandler): |
no test coverage detected