1
# Module 'os2emxpath' -- common operations on OS/2 pathnames
2
"""Common pathname manipulations, OS/2 EMX version.
4
Instead of importing this module directly, import os and refer to this
10
from genericpath import *
11
from genericpath import _unicode
12
from ntpath import (expanduser, expandvars, isabs, islink, splitdrive,
13
splitext, split, walk)
15
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
16
"basename","dirname","commonprefix","getsize","getmtime",
17
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
18
"ismount","walk","expanduser","expandvars","normpath","abspath",
19
"splitunc","curdir","pardir","sep","pathsep","defpath","altsep",
20
"extsep","devnull","realpath","supports_unicode_filenames"]
22
# strings representing various path-related bits and pieces
32
# Normalize the case of a pathname and map slashes to backslashes.
33
# Other normalizations (such as optimizing '../' away) are not done
34
# (this is done by normpath).
37
"""Normalize case of pathname.
39
Makes all characters lowercase and all altseps into seps."""
40
return s.replace('\\', '/').lower()
43
# Join two (or more) paths.
46
"""Join two or more pathname components, inserting sep as needed"""
51
elif path == '' or path[-1:] in '/\\:':
60
"""Split a pathname into UNC mount point and relative path specifiers.
62
Return a 2-tuple (unc, rest); either part may be empty.
63
If unc is not empty, it has the form '//host/mount' (or similar
64
using backslashes). unc+rest is always the input path.
65
Paths containing drive letters never have an UNC part.
68
return '', p # Drive letter present
70
if firstTwo == '/' * 2 or firstTwo == '\\' * 2:
72
# vvvvvvvvvvvvvvvvvvvv equivalent to drive letter
73
# \\machine\mountpoint\directories...
74
# directory ^^^^^^^^^^^^^^^
76
index = normp.find('/', 2)
78
##raise RuntimeError, 'illegal UNC path: "' + p + '"'
80
index = normp.find('/', index + 1)
83
return p[:index], p[index:]
87
# Return the tail (basename) part of a path.
90
"""Returns the final component of a pathname"""
94
# Return the head (dirname) part of a path.
97
"""Returns the directory component of a pathname"""
101
# alias exists to lexists
105
# Is a path a directory?
107
# Is a path a mount point? Either a root (with or without drive letter)
108
# or an UNC path with at most a / or \ after the mount point.
111
"""Test whether a path is a mount point (defined as root of drive)"""
112
unc, rest = splitunc(path)
114
return rest in ("", "/", "\\")
115
p = splitdrive(path)[1]
116
return len(p) == 1 and p[0] in '/\\'
119
# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
122
"""Normalize path, eliminating double slashes, etc."""
123
path = path.replace('\\', '/')
124
prefix, path = splitdrive(path)
125
while path[:1] == '/':
126
prefix = prefix + '/'
128
comps = path.split('/')
130
while i < len(comps):
133
elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
136
elif comps[i] == '' and i > 0 and comps[i-1] != '':
140
# If the path is now empty, substitute '.'
141
if not prefix and not comps:
143
return prefix + '/'.join(comps)
146
# Return an absolute path.
148
"""Return the absolute version of a path"""
150
if isinstance(path, _unicode):
154
path = join(cwd, path)
155
return normpath(path)
157
# realpath is a no-op on systems without islink support
160
supports_unicode_filenames = False
1
# Module 'os2emxpath' -- common operations on OS/2 pathnames
2
"""Common pathname manipulations, OS/2 EMX version.
4
Instead of importing this module directly, import os and refer to this
10
from genericpath import *
11
from genericpath import _unicode
12
from ntpath import (expanduser, expandvars, isabs, islink, splitdrive,
13
splitext, split, walk)
15
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
16
"basename","dirname","commonprefix","getsize","getmtime",
17
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
18
"ismount","walk","expanduser","expandvars","normpath","abspath",
19
"splitunc","curdir","pardir","sep","pathsep","defpath","altsep",
20
"extsep","devnull","realpath","supports_unicode_filenames"]
22
# strings representing various path-related bits and pieces
32
# Normalize the case of a pathname and map slashes to backslashes.
33
# Other normalizations (such as optimizing '../' away) are not done
34
# (this is done by normpath).
37
"""Normalize case of pathname.
39
Makes all characters lowercase and all altseps into seps."""
40
return s.replace('\\', '/').lower()
43
# Join two (or more) paths.
46
"""Join two or more pathname components, inserting sep as needed"""
51
elif path == '' or path[-1:] in '/\\:':
60
"""Split a pathname into UNC mount point and relative path specifiers.
62
Return a 2-tuple (unc, rest); either part may be empty.
63
If unc is not empty, it has the form '//host/mount' (or similar
64
using backslashes). unc+rest is always the input path.
65
Paths containing drive letters never have a UNC part.
68
return '', p # Drive letter present
70
if firstTwo == '/' * 2 or firstTwo == '\\' * 2:
72
# vvvvvvvvvvvvvvvvvvvv equivalent to drive letter
73
# \\machine\mountpoint\directories...
74
# directory ^^^^^^^^^^^^^^^
76
index = normp.find('/', 2)
78
##raise RuntimeError, 'illegal UNC path: "' + p + '"'
80
index = normp.find('/', index + 1)
83
return p[:index], p[index:]
87
# Return the tail (basename) part of a path.
90
"""Returns the final component of a pathname"""
94
# Return the head (dirname) part of a path.
97
"""Returns the directory component of a pathname"""
101
# alias exists to lexists
105
# Is a path a directory?
107
# Is a path a mount point? Either a root (with or without drive letter)
108
# or a UNC path with at most a / or \ after the mount point.
111
"""Test whether a path is a mount point (defined as root of drive)"""
112
unc, rest = splitunc(path)
114
return rest in ("", "/", "\\")
115
p = splitdrive(path)[1]
116
return len(p) == 1 and p[0] in '/\\'
119
# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
122
"""Normalize path, eliminating double slashes, etc."""
123
path = path.replace('\\', '/')
124
prefix, path = splitdrive(path)
125
while path[:1] == '/':
126
prefix = prefix + '/'
128
comps = path.split('/')
130
while i < len(comps):
133
elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
136
elif comps[i] == '' and i > 0 and comps[i-1] != '':
140
# If the path is now empty, substitute '.'
141
if not prefix and not comps:
143
return prefix + '/'.join(comps)
146
# Return an absolute path.
148
"""Return the absolute version of a path"""
150
if isinstance(path, _unicode):
154
path = join(cwd, path)
155
return normpath(path)
157
# realpath is a no-op on systems without islink support
160
supports_unicode_filenames = False