1- import io
21import os
32import re
43import abc
@@ -124,11 +123,7 @@ def _from_text(cls, text):
124123 config = ConfigParser (delimiters = '=' )
125124 # case sensitive: https://stackoverflow.com/q/1611799/812183
126125 config .optionxform = str
127- try :
128- config .read_string (text )
129- except AttributeError : # pragma: nocover
130- # Python 2 has no read_string
131- config .readfp (io .StringIO (text ))
126+ config .read_string (text )
132127 return EntryPoint ._from_config (config )
133128
134129 def __iter__ (self ):
@@ -469,47 +464,29 @@ def zip_children(self):
469464
470465 return dict .fromkeys (child .split (posixpath .sep , 1 )[0 ] for child in names )
471466
472- def is_egg (self , search ):
473- base = self .base
467+ def search (self , name ):
474468 return (
475- base == search . versionless_egg_name
476- or base . startswith ( search . prefix )
477- and base . endswith ( '.egg' )
469+ self . joinpath ( child )
470+ for child in self . children ( )
471+ if name . matches ( child , self . base )
478472 )
479473
480- def search (self , name ):
481- for child in self .children ():
482- n_low = child .lower ()
483- if (
484- n_low in name .exact_matches
485- or n_low .replace ('.' , '_' ).startswith (name .prefix )
486- and n_low .endswith (name .suffixes )
487- # legacy case:
488- or self .is_egg (name )
489- and n_low == 'egg-info'
490- ):
491- yield self .joinpath (child )
492-
493474
494475class Prepared :
495476 """
496477 A prepared search for metadata on a possibly-named package.
497478 """
498479
499- normalized = ''
500- prefix = ''
480+ normalized = None
501481 suffixes = '.dist-info' , '.egg-info'
502482 exact_matches = ['' ][:0 ]
503- versionless_egg_name = ''
504483
505484 def __init__ (self , name ):
506485 self .name = name
507486 if name is None :
508487 return
509488 self .normalized = self .normalize (name )
510- self .prefix = self .normalized + '-'
511489 self .exact_matches = [self .normalized + suffix for suffix in self .suffixes ]
512- self .versionless_egg_name = self .normalized + '.egg'
513490
514491 @staticmethod
515492 def normalize (name ):
@@ -518,6 +495,37 @@ def normalize(name):
518495 """
519496 return re .sub (r"[-_.]+" , "-" , name ).lower ().replace ('-' , '_' )
520497
498+ @staticmethod
499+ def legacy_normalize (name ):
500+ """
501+ Normalize the package name as found in the convention in
502+ older packaging tools versions and specs.
503+ """
504+ return name .lower ().replace ('-' , '_' )
505+
506+ def matches (self , cand , base ):
507+ low = cand .lower ()
508+ pre , ext = os .path .splitext (low )
509+ name , sep , rest = pre .partition ('-' )
510+ return (
511+ low in self .exact_matches
512+ or ext in self .suffixes
513+ and (not self .normalized or name .replace ('.' , '_' ) == self .normalized )
514+ # legacy case:
515+ or self .is_egg (base )
516+ and low == 'egg-info'
517+ )
518+
519+ def is_egg (self , base ):
520+ normalized = self .legacy_normalize (self .name or '' )
521+ prefix = normalized + '-' if normalized else ''
522+ versionless_egg_name = normalized + '.egg' if self .name else ''
523+ return (
524+ base == versionless_egg_name
525+ or base .startswith (prefix )
526+ and base .endswith ('.egg' )
527+ )
528+
521529
522530@install
523531class MetadataPathFinder (NullFinder , DistributionFinder ):
0 commit comments