2222def compute_hash (data ):
2323 """Compute the urlsafe base64 encoded SHA256 hash of data."""
2424 hash_digest = hashlib .sha256 (data ).digest ()
25- return base64 .urlsafe_b64encode (hash_digest ).rstrip (b'=' ).decode (' ascii' )
25+ return base64 .urlsafe_b64encode (hash_digest ).rstrip (b"=" ).decode (" ascii" )
2626
2727
2828def validate_wheel (wheel_path ):
2929 """Validate that wheel contents match its RECORD file."""
3030 errors = []
3131
32- with zipfile .ZipFile (wheel_path , 'r' ) as wheel :
32+ with zipfile .ZipFile (wheel_path , "r" ) as wheel :
3333 # Find the RECORD file
3434 record_path = None
3535 for name in wheel .namelist ():
36- if name .endswith (' .dist-info/RECORD' ):
36+ if name .endswith (" .dist-info/RECORD" ):
3737 record_path = name
3838 break
3939
@@ -42,7 +42,7 @@ def validate_wheel(wheel_path):
4242 return errors
4343
4444 # Parse the RECORD file
45- record_content = wheel .read (record_path ).decode (' utf-8' )
45+ record_content = wheel .read (record_path ).decode (" utf-8" )
4646 record_entries = {}
4747
4848 reader = csv .reader (io .StringIO (record_content ))
@@ -51,16 +51,13 @@ def validate_wheel(wheel_path):
5151 continue
5252
5353 file_path , hash_str , size_str = row [0 ], row [1 ], row [2 ]
54- record_entries [file_path ] = {
55- 'hash' : hash_str ,
56- 'size' : int (size_str ) if size_str else None
57- }
54+ record_entries [file_path ] = {"hash" : hash_str , "size" : int (size_str ) if size_str else None }
5855
5956 # Get all files in the wheel (excluding directories)
6057 wheel_files = set ()
6158 for name in wheel .namelist ():
6259 # Skip directories (they end with /)
63- if not name .endswith ('/' ):
60+ if not name .endswith ("/" ):
6461 wheel_files .add (name )
6562
6663 record_files = set (record_entries .keys ())
@@ -87,25 +84,23 @@ def validate_wheel(wheel_path):
8784 file_data = wheel .read (file_path )
8885
8986 # Check size
90- if record_entry [' size' ] is not None :
87+ if record_entry [" size" ] is not None :
9188 actual_size = len (file_data )
92- if actual_size != record_entry [' size' ]:
89+ if actual_size != record_entry [" size" ]:
9390 errors .append (
94- f"Size mismatch for { file_path } : "
95- f"RECORD says { record_entry ['size' ]} , actual is { actual_size } "
91+ f"Size mismatch for { file_path } : RECORD says { record_entry ['size' ]} , actual is { actual_size } "
9692 )
9793
9894 # Check hash
99- if record_entry [' hash' ]:
95+ if record_entry [" hash" ]:
10096 # Parse the hash format (algorithm=base64hash)
101- if '=' in record_entry [' hash' ]:
102- algo , expected_hash = record_entry [' hash' ].split ('=' , 1 )
103- if algo == ' sha256' :
97+ if "=" in record_entry [" hash" ]:
98+ algo , expected_hash = record_entry [" hash" ].split ("=" , 1 )
99+ if algo == " sha256" :
104100 actual_hash = compute_hash (file_data )
105101 if actual_hash != expected_hash :
106102 errors .append (
107- f"Hash mismatch for { file_path } : "
108- f"RECORD says { expected_hash } , actual is { actual_hash } "
103+ f"Hash mismatch for { file_path } : RECORD says { expected_hash } , actual is { actual_hash } "
109104 )
110105 else :
111106 errors .append (f"Unknown hash algorithm { algo } for { file_path } (expected sha256)" )
@@ -143,4 +138,4 @@ def main():
143138
144139
145140if __name__ == "__main__" :
146- sys .exit (main ())
141+ sys .exit (main ())
0 commit comments