question 293 Packaging & Databases · easy
Valid package names
An internal package index accepts uploads only under valid names, stored in their normalised form so that Market_Reports and market-reports can't be two different packages. Write normalize_name(name). A valid name is letters, digits, ., _ and -, and it starts and ends with a letter or digit. Normalising lower-cases the name and turns every run of ., _ and - into a single -.
Function
normalize_name(name)Returnsthe normalised name, e.g.
"Market_Reports" → "market-reports"Raises
ValueError when the name isn't valid (empty, other characters, or a separator at either end)Examples
callnormalize_name('Market_Reports')returns'market-reports'
callnormalize_name('zope.interface')returns'zope-interface'
callnormalize_name('-reports')raisesValueError