mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Migrate definitions of several platform-dependent path-related variables
into the relevant path modules. See patch #686397.
This commit is contained in:
parent
4507ec70cf
commit
117910dc44
7 changed files with 77 additions and 57 deletions
|
@ -1620,12 +1620,14 @@ Higher-level operations on pathnames are defined in the
|
||||||
The constant string used by the operating system to refer to the current
|
The constant string used by the operating system to refer to the current
|
||||||
directory.
|
directory.
|
||||||
For example: \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
|
For example: \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
|
||||||
|
Also available via \module{os.path}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\begin{datadesc}{pardir}
|
\begin{datadesc}{pardir}
|
||||||
The constant string used by the operating system to refer to the parent
|
The constant string used by the operating system to refer to the parent
|
||||||
directory.
|
directory.
|
||||||
For example: \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
|
For example: \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
|
||||||
|
Also available via \module{os.path}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\begin{datadesc}{sep}
|
\begin{datadesc}{sep}
|
||||||
|
@ -1634,6 +1636,7 @@ for example, \character{/} for \POSIX{} or \character{:} for the
|
||||||
Macintosh. Note that knowing this is not sufficient to be able to
|
Macintosh. Note that knowing this is not sufficient to be able to
|
||||||
parse or concatenate pathnames --- use \function{os.path.split()} and
|
parse or concatenate pathnames --- use \function{os.path.split()} and
|
||||||
\function{os.path.join()} --- but it is occasionally useful.
|
\function{os.path.join()} --- but it is occasionally useful.
|
||||||
|
Also available via \module{os.path}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\begin{datadesc}{altsep}
|
\begin{datadesc}{altsep}
|
||||||
|
@ -1641,11 +1644,13 @@ An alternative character used by the operating system to separate pathname
|
||||||
components, or \code{None} if only one separator character exists. This is
|
components, or \code{None} if only one separator character exists. This is
|
||||||
set to \character{/} on Windows systems where \code{sep} is a
|
set to \character{/} on Windows systems where \code{sep} is a
|
||||||
backslash.
|
backslash.
|
||||||
|
Also available via \module{os.path}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\begin{datadesc}{extsep}
|
\begin{datadesc}{extsep}
|
||||||
The character which separates the base filename from the extension;
|
The character which separates the base filename from the extension;
|
||||||
for example, the \character{.} in \file{os.py}.
|
for example, the \character{.} in \file{os.py}.
|
||||||
|
Also available via \module{os.path}.
|
||||||
\versionadded{2.2}
|
\versionadded{2.2}
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
|
@ -1653,12 +1658,14 @@ for example, the \character{.} in \file{os.py}.
|
||||||
The character conventionally used by the operating system to separate
|
The character conventionally used by the operating system to separate
|
||||||
search patch components (as in \envvar{PATH}), such as \character{:} for
|
search patch components (as in \envvar{PATH}), such as \character{:} for
|
||||||
\POSIX{} or \character{;} for Windows.
|
\POSIX{} or \character{;} for Windows.
|
||||||
|
Also available via \module{os.path}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\begin{datadesc}{defpath}
|
\begin{datadesc}{defpath}
|
||||||
The default search path used by \function{exec*p*()} and
|
The default search path used by \function{exec*p*()} and
|
||||||
\function{spawn*p*()} if the environment doesn't have a \code{'PATH'}
|
\function{spawn*p*()} if the environment doesn't have a \code{'PATH'}
|
||||||
key.
|
key.
|
||||||
|
Also available via \module{os.path}.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
\begin{datadesc}{linesep}
|
\begin{datadesc}{linesep}
|
||||||
|
|
|
@ -7,8 +7,18 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
"basename","dirname","commonprefix","getsize","getmtime",
|
"basename","dirname","commonprefix","getsize","getmtime",
|
||||||
"getatime","getctime", "islink","exists","isdir","isfile",
|
"getatime","getctime", "islink","exists","isdir","isfile",
|
||||||
"walk","expanduser","expandvars","normpath","abspath",
|
"walk","expanduser","expandvars","normpath","abspath",
|
||||||
|
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
|
||||||
"realpath","supports_unicode_filenames"]
|
"realpath","supports_unicode_filenames"]
|
||||||
|
|
||||||
|
# strings representing various path-related bits and pieces
|
||||||
|
curdir = ':'
|
||||||
|
pardir = '::'
|
||||||
|
extsep = '.'
|
||||||
|
sep = ':'
|
||||||
|
pathsep = '\n'
|
||||||
|
defpath = ':'
|
||||||
|
altsep = None
|
||||||
|
|
||||||
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
|
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
|
||||||
|
|
||||||
def normcase(path):
|
def normcase(path):
|
||||||
|
|
|
@ -13,8 +13,24 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
"basename","dirname","commonprefix","getsize","getmtime",
|
"basename","dirname","commonprefix","getsize","getmtime",
|
||||||
"getatime","getctime", "islink","exists","isdir","isfile","ismount",
|
"getatime","getctime", "islink","exists","isdir","isfile","ismount",
|
||||||
"walk","expanduser","expandvars","normpath","abspath","splitunc",
|
"walk","expanduser","expandvars","normpath","abspath","splitunc",
|
||||||
|
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
|
||||||
"realpath","supports_unicode_filenames"]
|
"realpath","supports_unicode_filenames"]
|
||||||
|
|
||||||
|
# strings representing various path-related bits and pieces
|
||||||
|
curdir = '.'
|
||||||
|
pardir = '..'
|
||||||
|
extsep = '.'
|
||||||
|
sep = '\\'
|
||||||
|
pathsep = ';'
|
||||||
|
altsep = None
|
||||||
|
if 'ce' in sys.builtin_module_names:
|
||||||
|
defpath = '\\Windows'
|
||||||
|
elif 'os2' in sys.builtin_module_names:
|
||||||
|
# OS/2 w/ EMX
|
||||||
|
altsep = '/'
|
||||||
|
else:
|
||||||
|
defpath = '.;C:\\bin'
|
||||||
|
|
||||||
# Normalize the case of a pathname and map slashes to backslashes.
|
# Normalize the case of a pathname and map slashes to backslashes.
|
||||||
# Other normalizations (such as optimizing '../' away) are not done
|
# Other normalizations (such as optimizing '../' away) are not done
|
||||||
# (this is done by normpath).
|
# (this is done by normpath).
|
||||||
|
|
61
Lib/os.py
61
Lib/os.py
|
@ -26,10 +26,8 @@ import sys
|
||||||
|
|
||||||
_names = sys.builtin_module_names
|
_names = sys.builtin_module_names
|
||||||
|
|
||||||
altsep = None
|
|
||||||
|
|
||||||
__all__ = ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep",
|
__all__ = ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep",
|
||||||
"defpath", "name"]
|
"defpath", "name", "path"]
|
||||||
|
|
||||||
def _get_exports_list(module):
|
def _get_exports_list(module):
|
||||||
try:
|
try:
|
||||||
|
@ -40,16 +38,12 @@ def _get_exports_list(module):
|
||||||
if 'posix' in _names:
|
if 'posix' in _names:
|
||||||
name = 'posix'
|
name = 'posix'
|
||||||
linesep = '\n'
|
linesep = '\n'
|
||||||
curdir = '.'; pardir = '..'; sep = '/'; pathsep = ':'
|
|
||||||
defpath = ':/bin:/usr/bin'
|
|
||||||
from posix import *
|
from posix import *
|
||||||
try:
|
try:
|
||||||
from posix import _exit
|
from posix import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import posixpath
|
import posixpath as path
|
||||||
path = posixpath
|
|
||||||
del posixpath
|
|
||||||
|
|
||||||
import posix
|
import posix
|
||||||
__all__.extend(_get_exports_list(posix))
|
__all__.extend(_get_exports_list(posix))
|
||||||
|
@ -58,16 +52,12 @@ if 'posix' in _names:
|
||||||
elif 'nt' in _names:
|
elif 'nt' in _names:
|
||||||
name = 'nt'
|
name = 'nt'
|
||||||
linesep = '\r\n'
|
linesep = '\r\n'
|
||||||
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
|
|
||||||
defpath = '.;C:\\bin'
|
|
||||||
from nt import *
|
from nt import *
|
||||||
try:
|
try:
|
||||||
from nt import _exit
|
from nt import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import ntpath
|
import ntpath as path
|
||||||
path = ntpath
|
|
||||||
del ntpath
|
|
||||||
|
|
||||||
import nt
|
import nt
|
||||||
__all__.extend(_get_exports_list(nt))
|
__all__.extend(_get_exports_list(nt))
|
||||||
|
@ -76,27 +66,15 @@ elif 'nt' in _names:
|
||||||
elif 'os2' in _names:
|
elif 'os2' in _names:
|
||||||
name = 'os2'
|
name = 'os2'
|
||||||
linesep = '\r\n'
|
linesep = '\r\n'
|
||||||
curdir = '.'; pardir = '..'; pathsep = ';'
|
|
||||||
if sys.version.find('EMX GCC') == -1:
|
|
||||||
# standard OS/2 compiler (VACPP or Watcom?)
|
|
||||||
sep = '\\'; altsep = '/'
|
|
||||||
else:
|
|
||||||
# EMX
|
|
||||||
sep = '/'; altsep = '\\'
|
|
||||||
defpath = '.;C:\\bin'
|
|
||||||
from os2 import *
|
from os2 import *
|
||||||
try:
|
try:
|
||||||
from os2 import _exit
|
from os2 import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
if sys.version.find('EMX GCC') == -1:
|
if sys.version.find('EMX GCC') == -1:
|
||||||
import ntpath
|
import ntpath as path
|
||||||
path = ntpath
|
|
||||||
del ntpath
|
|
||||||
else:
|
else:
|
||||||
import os2emxpath
|
import os2emxpath as path
|
||||||
path = os2emxpath
|
|
||||||
del os2emxpath
|
|
||||||
|
|
||||||
import os2
|
import os2
|
||||||
__all__.extend(_get_exports_list(os2))
|
__all__.extend(_get_exports_list(os2))
|
||||||
|
@ -105,16 +83,12 @@ elif 'os2' in _names:
|
||||||
elif 'mac' in _names:
|
elif 'mac' in _names:
|
||||||
name = 'mac'
|
name = 'mac'
|
||||||
linesep = '\r'
|
linesep = '\r'
|
||||||
curdir = ':'; pardir = '::'; sep = ':'; pathsep = '\n'
|
|
||||||
defpath = ':'
|
|
||||||
from mac import *
|
from mac import *
|
||||||
try:
|
try:
|
||||||
from mac import _exit
|
from mac import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import macpath
|
import macpath as path
|
||||||
path = macpath
|
|
||||||
del macpath
|
|
||||||
|
|
||||||
import mac
|
import mac
|
||||||
__all__.extend(_get_exports_list(mac))
|
__all__.extend(_get_exports_list(mac))
|
||||||
|
@ -123,17 +97,13 @@ elif 'mac' in _names:
|
||||||
elif 'ce' in _names:
|
elif 'ce' in _names:
|
||||||
name = 'ce'
|
name = 'ce'
|
||||||
linesep = '\r\n'
|
linesep = '\r\n'
|
||||||
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
|
|
||||||
defpath = '\\Windows'
|
|
||||||
from ce import *
|
from ce import *
|
||||||
try:
|
try:
|
||||||
from ce import _exit
|
from ce import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
# We can use the standard Windows path.
|
# We can use the standard Windows path.
|
||||||
import ntpath
|
import ntpath as path
|
||||||
path = ntpath
|
|
||||||
del ntpath
|
|
||||||
|
|
||||||
import ce
|
import ce
|
||||||
__all__.extend(_get_exports_list(ce))
|
__all__.extend(_get_exports_list(ce))
|
||||||
|
@ -142,16 +112,12 @@ elif 'ce' in _names:
|
||||||
elif 'riscos' in _names:
|
elif 'riscos' in _names:
|
||||||
name = 'riscos'
|
name = 'riscos'
|
||||||
linesep = '\n'
|
linesep = '\n'
|
||||||
curdir = '@'; pardir = '^'; sep = '.'; pathsep = ','
|
|
||||||
defpath = '<Run$Dir>'
|
|
||||||
from riscos import *
|
from riscos import *
|
||||||
try:
|
try:
|
||||||
from riscos import _exit
|
from riscos import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import riscospath
|
import riscospath as path
|
||||||
path = riscospath
|
|
||||||
del riscospath
|
|
||||||
|
|
||||||
import riscos
|
import riscos
|
||||||
__all__.extend(_get_exports_list(riscos))
|
__all__.extend(_get_exports_list(riscos))
|
||||||
|
@ -160,18 +126,11 @@ elif 'riscos' in _names:
|
||||||
else:
|
else:
|
||||||
raise ImportError, 'no os specific module found'
|
raise ImportError, 'no os specific module found'
|
||||||
|
|
||||||
|
sys.modules['os.path'] = path
|
||||||
if sep=='.':
|
from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep
|
||||||
extsep = '/'
|
|
||||||
else:
|
|
||||||
extsep = '.'
|
|
||||||
|
|
||||||
__all__.append("path")
|
|
||||||
|
|
||||||
del _names
|
del _names
|
||||||
|
|
||||||
sys.modules['os.path'] = path
|
|
||||||
|
|
||||||
#'
|
#'
|
||||||
|
|
||||||
# Super directory utilities.
|
# Super directory utilities.
|
||||||
|
|
|
@ -12,8 +12,18 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
"basename","dirname","commonprefix","getsize","getmtime",
|
"basename","dirname","commonprefix","getsize","getmtime",
|
||||||
"getatime","getctime", "islink","exists","isdir","isfile","ismount",
|
"getatime","getctime", "islink","exists","isdir","isfile","ismount",
|
||||||
"walk","expanduser","expandvars","normpath","abspath","splitunc",
|
"walk","expanduser","expandvars","normpath","abspath","splitunc",
|
||||||
|
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
|
||||||
"realpath","supports_unicode_filenames"]
|
"realpath","supports_unicode_filenames"]
|
||||||
|
|
||||||
|
# strings representing various path-related bits and pieces
|
||||||
|
curdir = '.'
|
||||||
|
pardir = '..'
|
||||||
|
extsep = '.'
|
||||||
|
sep = '/'
|
||||||
|
altsep = '\\'
|
||||||
|
pathsep = ';'
|
||||||
|
defpath = '.;C:\\bin'
|
||||||
|
|
||||||
# Normalize the case of a pathname and map slashes to backslashes.
|
# Normalize the case of a pathname and map slashes to backslashes.
|
||||||
# Other normalizations (such as optimizing '../' away) are not done
|
# Other normalizations (such as optimizing '../' away) are not done
|
||||||
# (this is done by normpath).
|
# (this is done by normpath).
|
||||||
|
|
|
@ -12,6 +12,14 @@ Instead of importing this module directly, import os and refer to this module
|
||||||
as os.path.
|
as os.path.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# strings representing various path-related bits and pieces
|
||||||
|
curdir = '@'
|
||||||
|
pardir = '^'
|
||||||
|
extsep = '.'
|
||||||
|
sep = '.'
|
||||||
|
pathsep = ','
|
||||||
|
defpath = '<Run$Dir>'
|
||||||
|
altsep = None
|
||||||
|
|
||||||
# Imports - make an error-generating swi object if the swi module is not
|
# Imports - make an error-generating swi object if the swi module is not
|
||||||
# available (ie. we are not running on RISC OS Python)
|
# available (ie. we are not running on RISC OS Python)
|
||||||
|
|
|
@ -18,8 +18,18 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
"getatime","getctime","islink","exists","isdir","isfile","ismount",
|
"getatime","getctime","islink","exists","isdir","isfile","ismount",
|
||||||
"walk","expanduser","expandvars","normpath","abspath",
|
"walk","expanduser","expandvars","normpath","abspath",
|
||||||
"samefile","sameopenfile","samestat",
|
"samefile","sameopenfile","samestat",
|
||||||
|
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
|
||||||
"realpath","supports_unicode_filenames"]
|
"realpath","supports_unicode_filenames"]
|
||||||
|
|
||||||
|
# strings representing various path-related bits and pieces
|
||||||
|
curdir = '.'
|
||||||
|
pardir = '..'
|
||||||
|
extsep = '.'
|
||||||
|
sep = '/'
|
||||||
|
pathsep = ':'
|
||||||
|
defpath = ':/bin:/usr/bin'
|
||||||
|
altsep = None
|
||||||
|
|
||||||
# Normalize the case of a pathname. Trivial in Posix, string.lower on Mac.
|
# Normalize the case of a pathname. Trivial in Posix, string.lower on Mac.
|
||||||
# On MS-DOS this may also turn slashes into backslashes; however, other
|
# On MS-DOS this may also turn slashes into backslashes; however, other
|
||||||
# normalizations (such as optimizing '../' away) are not allowed
|
# normalizations (such as optimizing '../' away) are not allowed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue