@@ -34,10 +34,6 @@ class InvalidSdistFilename(ValueError):
3434
3535# Core metadata spec for `Name`
3636_validate_regex = re .compile (r"[A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9]" , re .IGNORECASE )
37- _canonicalize_table = str .maketrans (
38- "ABCDEFGHIJKLMNOPQRSTUVWXYZ_." ,
39- "abcdefghijklmnopqrstuvwxyz--" ,
40- )
4137_normalized_regex = re .compile (r"[a-z0-9]|[a-z0-9]([a-z0-9-](?!--))*[a-z0-9]" )
4238# PEP 427: The build number must start with a digit.
4339_build_tag_regex = re .compile (r"(\d+)(.*)" )
@@ -48,8 +44,8 @@ def canonicalize_name(name: str, *, validate: bool = False) -> NormalizedName:
4844 raise InvalidName (f"name is invalid: { name !r} " )
4945 # Ensure all ``.`` and ``_`` are ``-``
5046 # Emulates ``re.sub(r"[-_.]+", "-", name).lower()`` from PEP 503
51- # About 2x faster, safe since packages only support alphanumeric characters
52- value = name .translate ( _canonicalize_table )
47+ # Much faster than re, and even faster than str.translate
48+ value = name .lower (). replace ( "_" , "-" ). replace ( "." , "-" )
5349 # Condense repeats (faster than regex)
5450 while "--" in value :
5551 value = value .replace ("--" , "-" )
0 commit comments