mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Added 'native_path()' for use on pathnames from the setup script: split on
slashes, and put back together again using the local directory separator.
This commit is contained in:
parent
e2b4452d0c
commit
5091929c2c
1 changed files with 28 additions and 0 deletions
|
@ -458,3 +458,31 @@ def get_platform ():
|
||||||
return sys.platform
|
return sys.platform
|
||||||
|
|
||||||
# get_platform()
|
# get_platform()
|
||||||
|
|
||||||
|
|
||||||
|
def native_path (pathname):
|
||||||
|
"""Return 'pathname' as a name that will work on the native
|
||||||
|
filesystem, i.e. split it on '/' and put it back together again
|
||||||
|
using the current directory separator. Needed because filenames in
|
||||||
|
the setup script are always supplied in Unix style, and have to be
|
||||||
|
converted to the local convention before we can actually use them in
|
||||||
|
the filesystem. Raises DistutilsValueError if 'pathname' is
|
||||||
|
absolute (starts with '/') or contains local directory separators
|
||||||
|
(unless the local separator is '/', of course)."""
|
||||||
|
|
||||||
|
if pathname[0] == '/':
|
||||||
|
raise DistutilsValueError, "path '%s' cannot be absolute" % pathname
|
||||||
|
if pathname[-1] == '/':
|
||||||
|
raise DistutilsValueError, "path '%s' cannot end with '/'" % pathname
|
||||||
|
if os.sep != '/':
|
||||||
|
if os.sep in pathname:
|
||||||
|
raise DistutilsValueError, \
|
||||||
|
"path '%s' cannot contain '%c' character" % \
|
||||||
|
(pathname, os.sep)
|
||||||
|
|
||||||
|
paths = string.split (pathname, '/')
|
||||||
|
return apply (os.path.join, paths)
|
||||||
|
else:
|
||||||
|
return pathname
|
||||||
|
|
||||||
|
# native_path ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue