314
def _posix_path_from_environ(key):
315
"""Get unicode path from `key` in environment or None if not present
317
Note that posix systems use arbitrary byte strings for filesystem objects,
318
so a path that raises BadFilenameEncoding here may still be accessible.
320
return os.environ.get(key, None)
310
323
def _posix_get_home_dir():
311
324
"""Get the home directory of the current user as a unicode path"""
312
325
path = posixpath.expanduser("~")
417
430
realpath = _posix_realpath
418
431
pathjoin = os.path.join
419
432
normpath = _posix_normpath
433
path_from_environ = _posix_path_from_environ
420
434
_get_home_dir = _posix_get_home_dir
421
435
getuser_unicode = _posix_getuser_unicode
474
488
"""Replacer for shutil.rmtree: could remove readonly dirs/files"""
475
489
return shutil.rmtree(path, ignore_errors, onerror)
491
get_unicode_argv = getattr(win32utils, 'get_unicode_argv', get_unicode_argv)
492
path_from_environ = win32utils.get_environ_unicode
477
493
_get_home_dir = win32utils.get_home_location
478
494
getuser_unicode = win32utils.get_user_name
1362
1378
return unicode_or_utf8_string.encode('utf-8')
1381
def safe_revision_id(unicode_or_utf8_string):
1382
"""Revision ids should now be utf8, but at one point they were unicode.
1384
:param unicode_or_utf8_string: A possibly Unicode revision_id. (can also be
1386
:return: None or a utf8 revision id.
1388
if (unicode_or_utf8_string is None
1389
or unicode_or_utf8_string.__class__ == bytes):
1390
return unicode_or_utf8_string
1391
raise TypeError('Unicode revision ids are no longer supported. '
1392
'Revision id generators should be creating utf8 revision '
1396
def safe_file_id(unicode_or_utf8_string):
1397
"""File ids should now be utf8, but at one point they were unicode.
1399
This is the same as safe_utf8, except it uses the cached encode functions
1400
to save a little bit of performance.
1402
:param unicode_or_utf8_string: A possibly Unicode file_id. (can also be
1404
:return: None or a utf8 file id.
1406
if (unicode_or_utf8_string is None
1407
or unicode_or_utf8_string.__class__ == bytes):
1408
return unicode_or_utf8_string
1409
raise TypeError('Unicode file ids are no longer supported. '
1410
'File id generators should be creating utf8 file ids.')
1365
1413
_platform_normalizes_filenames = False
1366
1414
if sys.platform == 'darwin':
1367
1415
_platform_normalizes_filenames = True
2537
2585
raise exception_class(path)
2588
def is_environment_error(evalue):
2589
"""True if exception instance is due to a process environment issue
2591
This includes OSError and IOError, but also other errors that come from
2592
the operating system or core libraries but are not subclasses of those.
2594
if isinstance(evalue, (EnvironmentError, select.error)):
2596
if sys.platform == "win32" and win32utils._is_pywintypes_error(evalue):
2540
2601
def read_mtab(path):
2541
2602
"""Read an fstab-style file and extract mountpoint+filesystem information.