3838 re .VERBOSE )
3939
4040
41+ def try_decode (s ):
42+ if isinstance (s , bytes ):
43+ return s .decode ('utf8' )
44+ return s
45+
46+
4147class Wheel (Distribution ):
4248
4349 def __init__ (self , filename , metadata_version = None ):
@@ -51,6 +57,15 @@ def py_version(self):
5157 wheel_info = wheel_file_re .match (self .basefilename )
5258 return wheel_info .group ("pyver" )
5359
60+ @staticmethod
61+ def find_candidate_metadata_files (names ):
62+ """Filter files that may be METADATA files."""
63+ tuples = [
64+ x .split ('/' ) for x in map (try_decode , names )
65+ if 'METADATA' in x
66+ ]
67+ return [x [1 ] for x in sorted ([(len (x ), x ) for x in tuples ])]
68+
5469 def read (self ):
5570 fqn = os .path .abspath (os .path .normpath (self .filename ))
5671 if not os .path .exists (fqn ):
@@ -66,9 +81,7 @@ def read_file(name):
6681 raise ValueError ('Not a known archive format: %s' % fqn )
6782
6883 try :
69- tuples = [x .split ('/' ) for x in names if 'METADATA' in x ]
70- schwarz = sorted ([(len (x ), x ) for x in tuples ])
71- for path in [x [1 ] for x in schwarz ]:
84+ for path in self .find_candidate_metadata_files (names ):
7285 candidate = '/' .join (path )
7386 data = read_file (candidate )
7487 if b'Metadata-Version' in data :
0 commit comments