|
22 | 22 | supports_symlinks = False |
23 | 23 | _getfinalpathname = None |
24 | 24 | else: |
| 25 | + if os.name == 'os2': |
| 26 | + _getfinalpathname = None |
25 | 27 | nt = None |
26 | 28 |
|
27 | 29 |
|
@@ -126,7 +128,7 @@ class _WindowsFlavour(_Flavour): |
126 | 128 | has_drv = True |
127 | 129 | pathmod = ntpath |
128 | 130 |
|
129 | | - is_supported = (os.name == 'nt') |
| 131 | + is_supported = (os.name in ['nt', 'os2']) |
130 | 132 |
|
131 | 133 | drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
132 | 134 | ext_namespace_prefix = '\\\\?\\' |
@@ -264,6 +266,21 @@ def make_uri(self, path): |
264 | 266 | return 'file:' + urlquote_from_bytes(path.as_posix().encode('utf-8')) |
265 | 267 |
|
266 | 268 | 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 | + |
267 | 284 | if 'USERPROFILE' in os.environ: |
268 | 285 | userhome = os.environ['USERPROFILE'] |
269 | 286 | elif 'HOMEPATH' in os.environ: |
@@ -298,7 +315,7 @@ class _PosixFlavour(_Flavour): |
298 | 315 | has_drv = False |
299 | 316 | pathmod = posixpath |
300 | 317 |
|
301 | | - is_supported = (os.name != 'nt') |
| 318 | + is_supported = (os.name not in ['nt', 'os2']) |
302 | 319 |
|
303 | 320 | def splitroot(self, part, sep=sep): |
304 | 321 | if part and part[0] == sep: |
@@ -1078,7 +1095,7 @@ class Path(PurePath): |
1078 | 1095 |
|
1079 | 1096 | def __new__(cls, *args, **kwargs): |
1080 | 1097 | if cls is Path: |
1081 | | - cls = WindowsPath if os.name == 'nt' else PosixPath |
| 1098 | + cls = WindowsPath if os.name in ['nt', 'os2'] else PosixPath |
1082 | 1099 | self = cls._from_parts(args, init=False) |
1083 | 1100 | if not self._flavour.is_supported: |
1084 | 1101 | raise NotImplementedError("cannot instantiate %r on your system" |
|
0 commit comments