@@ -762,6 +762,21 @@ def _is_duplicate_file(db_session, filename, hashes):
762
762
return None
763
763
764
764
765
+ def extract_wheel_metadata (path ):
766
+ """
767
+ Extract METADATA file and return it as a content. The name of the
768
+ .whl file is used to find the corresponding .dist-info dir.
769
+
770
+ See https://www.python.org/dev/peps/pep-0658/#specification
771
+ """
772
+ global _wheel_file_re
773
+ filename = os .path .basepath (path )
774
+ namever = _wheel_file_re .match (filename ).group ("namever" )
775
+ metafile = namever + ".dist-info/METADATA"
776
+ with zipfile .ZipFile (path ) as zfp :
777
+ return zfp .read (metafile )
778
+
779
+
765
780
@view_config (
766
781
route_name = "forklift.legacy.file_upload" ,
767
782
uses_session = True ,
@@ -1331,12 +1346,9 @@ def file_upload(request):
1331
1346
"Binary wheel '{filename}' has an unsupported "
1332
1347
"platform tag '{plat}'." .format (filename = filename , plat = plat ),
1333
1348
)
1334
- # Extract .metadata file
1335
- # https://www.python.org/dev/peps/pep-0658/#specification
1336
- with zipfile .ZipFile (temporary_filename ) as zfp :
1337
- metafile = wheel_info .group ("namever" ) + ".dist-info/METADATA"
1338
- with open (temporary_filename + ".metadata" , "wb" ) as fp :
1339
- fp .write (zfp .read (metafile ))
1349
+ wheel_metadata = extract_wheel_metadata (temporary_filename )
1350
+ with open (temporary_filename + ".metadata" , "wb" ) as fp :
1351
+ fp .write (wheel_metadata )
1340
1352
else :
1341
1353
has_wheel_metadata = False
1342
1354
0 commit comments