diff options
author | Jeremy Kloth <jeremy.kloth@gmail.com> | 2011-09-12 17:12:42 (GMT) |
---|---|---|
committer | Jeremy Kloth <jeremy.kloth@gmail.com> | 2011-09-12 17:12:42 (GMT) |
commit | aa2b442bdccf68c191a0023084b1160804fb5e4c (patch) | |
tree | 6e6b9ade0d959ea36e21fa72d1f308215e7fc80c /Lib/packaging/metadata.py | |
parent | 4c3124c2b94add8cc168ebe29aa47f0f7326d7d8 (diff) | |
download | cpython-aa2b442bdccf68c191a0023084b1160804fb5e4c.zip cpython-aa2b442bdccf68c191a0023084b1160804fb5e4c.tar.gz cpython-aa2b442bdccf68c191a0023084b1160804fb5e4c.tar.bz2 |
Factor out the distribution file-system safe name functions from install_distinfo to allow all metadata consumers access to them.
Diffstat (limited to 'Lib/packaging/metadata.py')
-rw-r--r-- | Lib/packaging/metadata.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/packaging/metadata.py b/Lib/packaging/metadata.py index dbb53b2..a3db51c 100644 --- a/Lib/packaging/metadata.py +++ b/Lib/packaging/metadata.py @@ -182,6 +182,7 @@ _UNICODEFIELDS = ('Author', 'Maintainer', 'Summary', 'Description') _MISSING = object() +_FILESAFE = re.compile('[^A-Za-z0-9.]+') class Metadata: """The metadata of a release. @@ -285,9 +286,18 @@ class Metadata: # # Public API # - def get_fullname(self): - """Return the distribution name with version""" - return '%s-%s' % (self['Name'], self['Version']) + def get_fullname(self, filesafe=False): + """Return the distribution name with version. + + If filesafe is true, return a filename-escaped form.""" + name, version = self['Name'], self['Version'] + if filesafe: + # For both name and version any runs of non-alphanumeric or '.' + # characters are replaced with a single '-'. Additionally any + # spaces in the version string become '.' + name = _FILESAFE.sub('-', name) + version = _FILESAFE.sub('-', version.replace(' ', '.')) + return '%s-%s' % (name, version) def is_metadata_field(self, name): """return True if name is a valid metadata key""" |