Skip to content

Commit edec2f9

Browse files
x:/path/to/dir is not treated as an absolute path. Fixes #12
1 parent cf20554 commit edec2f9

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Lib/pathlib.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
supports_symlinks = False
2323
_getfinalpathname = None
2424
else:
25+
if os.name == 'os2':
26+
_getfinalpathname = None
2527
nt = None
2628

2729

@@ -126,7 +128,7 @@ class _WindowsFlavour(_Flavour):
126128
has_drv = True
127129
pathmod = ntpath
128130

129-
is_supported = (os.name == 'nt')
131+
is_supported = (os.name in ['nt', 'os2'])
130132

131133
drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
132134
ext_namespace_prefix = '\\\\?\\'
@@ -264,6 +266,21 @@ def make_uri(self, path):
264266
return 'file:' + urlquote_from_bytes(path.as_posix().encode('utf-8'))
265267

266268
def gethomedir(self, username):
269+
if os.name == 'os2':
270+
if not username:
271+
try:
272+
return os.environ['HOME']
273+
except KeyError:
274+
import pwd
275+
return pwd.getpwuid(os.getuid()).pw_dir
276+
else:
277+
import pwd
278+
try:
279+
return pwd.getpwnam(username).pw_dir
280+
except KeyError:
281+
raise RuntimeError("Can't determine home directory "
282+
"for %r" % username)
283+
267284
if 'USERPROFILE' in os.environ:
268285
userhome = os.environ['USERPROFILE']
269286
elif 'HOMEPATH' in os.environ:
@@ -298,7 +315,7 @@ class _PosixFlavour(_Flavour):
298315
has_drv = False
299316
pathmod = posixpath
300317

301-
is_supported = (os.name != 'nt')
318+
is_supported = (os.name not in ['nt', 'os2'])
302319

303320
def splitroot(self, part, sep=sep):
304321
if part and part[0] == sep:
@@ -1078,7 +1095,7 @@ class Path(PurePath):
10781095

10791096
def __new__(cls, *args, **kwargs):
10801097
if cls is Path:
1081-
cls = WindowsPath if os.name == 'nt' else PosixPath
1098+
cls = WindowsPath if os.name in ['nt', 'os2'] else PosixPath
10821099
self = cls._from_parts(args, init=False)
10831100
if not self._flavour.is_supported:
10841101
raise NotImplementedError("cannot instantiate %r on your system"

0 commit comments

Comments
 (0)