diff options
author | PJ Eby <distutils-sig@python.org> | 2005-06-05 18:59:37 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-06-05 18:59:37 +0000 |
commit | 0c9e886999bb42cf825054778b1664e41f8164b4 (patch) | |
tree | c2b0f62ab2390372d3fe5ecb42f0246bf8e2abf5 /pkg_resources.py | |
parent | 992e379c8850a2a23da24e5586799f7ba933e692 (diff) | |
download | external_python_setuptools-0c9e886999bb42cf825054778b1664e41f8164b4.tar.gz external_python_setuptools-0c9e886999bb42cf825054778b1664e41f8164b4.tar.bz2 external_python_setuptools-0c9e886999bb42cf825054778b1664e41f8164b4.zip |
Add "safe_name" and "safe_version" functions to allow sanitizing of
distribution names and versions in arbitrary packages that might be built
using EasyInstall.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041040
Diffstat (limited to 'pkg_resources.py')
-rw-r--r-- | pkg_resources.py | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/pkg_resources.py b/pkg_resources.py index 489fe61d..927b7942 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -22,11 +22,23 @@ __all__ = [ 'InvalidOption', 'Distribution', 'Requirement', 'yield_lines', 'get_importer', 'find_distributions', 'find_on_path', 'register_finder', 'split_sections', 'declare_namespace', 'register_namespace_handler', + 'safe_name', 'safe_version' ] import sys, os, zipimport, time, re, imp from sets import ImmutableSet + + + + + + + + + + + class ResolutionError(Exception): """Abstract base for dependency resolution errors""" @@ -57,6 +69,17 @@ def get_provider(moduleName): loader = getattr(module, '__loader__', None) return _find_adapter(_provider_factories, loader)(module) + + + + + + + + + + + def get_platform(): """Return this platform's string for platform-specific distributions @@ -80,6 +103,24 @@ def compatible_platforms(provided,required): return False + + + + + + + + + + + + + + + + + + class IMetadataProvider: def has_metadata(name): @@ -424,22 +465,22 @@ def require(*requirements): dist.install_on(sys.path) +def safe_name(name): + """Convert an arbitrary string to a standard distribution name + Any runs of non-alphanumeric characters are replaced with a single '-'. + """ + return re.sub('[^A-Za-z0-9]+', '-', name) +def safe_version(version): + """Convert an arbitrary string to a standard version string - - - - - - - - - - - - + Spaces become dots, and all other non-alphanumeric characters become + dashes, with runs of multiple dashes condensed to a single dash. + """ + version = version.replace(' ','.') + return re.sub('[^A-Za-z0-9.]+', '-', version) |