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 ntpath
import (expanduser
, expandvars
, isabs
, islink
, splitdrive
,
12 splitext
, split
, walk
)
14 __all__
= ["normcase","isabs","join","splitdrive","split","splitext",
15 "basename","dirname","commonprefix","getsize","getmtime",
16 "getatime","getctime", "islink","exists","lexists","isdir","isfile",
17 "ismount","walk","expanduser","expandvars","normpath","abspath",
18 "splitunc","curdir","pardir","sep","pathsep","defpath","altsep",
19 "extsep","devnull","realpath","supports_unicode_filenames"]
21 # strings representing various path-related bits and pieces
31 # Normalize the case of a pathname and map slashes to backslashes.
32 # Other normalizations (such as optimizing '../' away) are not done
33 # (this is done by normpath).
36 """Normalize case of pathname.
38 Makes all characters lowercase and all altseps into seps."""
39 return s
.replace('\\', '/').lower()
42 # Join two (or more) paths.
45 """Join two or more pathname components, inserting sep as needed"""
50 elif path
== '' or path
[-1:] in '/\\:':
59 """Split a pathname into UNC mount point and relative path specifiers.
61 Return a 2-tuple (unc, rest); either part may be empty.
62 If unc is not empty, it has the form '//host/mount' (or similar
63 using backslashes). unc+rest is always the input path.
64 Paths containing drive letters never have an UNC part.
67 return '', p
# Drive letter present
69 if firstTwo
== '/' * 2 or firstTwo
== '\\' * 2:
71 # vvvvvvvvvvvvvvvvvvvv equivalent to drive letter
72 # \\machine\mountpoint\directories...
73 # directory ^^^^^^^^^^^^^^^
75 index
= normp
.find('/', 2)
77 ##raise RuntimeError, 'illegal UNC path: "' + p + '"'
79 index
= normp
.find('/', index
+ 1)
82 return p
[:index
], p
[index
:]
86 # Return the tail (basename) part of a path.
89 """Returns the final component of a pathname"""
93 # Return the head (dirname) part of a path.
96 """Returns the directory component of a pathname"""
100 # alias exists to lexists
104 # Is a path a directory?
106 # Is a path a mount point? Either a root (with or without drive letter)
107 # or an UNC path with at most a / or \ after the mount point.
110 """Test whether a path is a mount point (defined as root of drive)"""
111 unc
, rest
= splitunc(path
)
113 return rest
in ("", "/", "\\")
114 p
= splitdrive(path
)[1]
115 return len(p
) == 1 and p
[0] in '/\\'
118 # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
121 """Normalize path, eliminating double slashes, etc."""
122 path
= path
.replace('\\', '/')
123 prefix
, path
= splitdrive(path
)
124 while path
[:1] == '/':
125 prefix
= prefix
+ '/'
127 comps
= path
.split('/')
129 while i
< len(comps
):
132 elif comps
[i
] == '..' and i
> 0 and comps
[i
-1] not in ('', '..'):
135 elif comps
[i
] == '' and i
> 0 and comps
[i
-1] != '':
139 # If the path is now empty, substitute '.'
140 if not prefix
and not comps
:
142 return prefix
+ '/'.join(comps
)
145 # Return an absolute path.
147 """Return the absolute version of a path"""
149 path
= join(os
.getcwd(), path
)
150 return normpath(path
)
152 # realpath is a no-op on systems without islink support
155 supports_unicode_filenames
= False