1362
1362
return unicode_or_utf8_string.encode('utf-8')
1365
def safe_revision_id(unicode_or_utf8_string):
1366
"""Revision ids should now be utf8, but at one point they were unicode.
1368
:param unicode_or_utf8_string: A possibly Unicode revision_id. (can also be
1370
:return: None or a utf8 revision id.
1372
if (unicode_or_utf8_string is None
1373
or unicode_or_utf8_string.__class__ == bytes):
1374
return unicode_or_utf8_string
1375
raise TypeError('Unicode revision ids are no longer supported. '
1376
'Revision id generators should be creating utf8 revision '
1380
def safe_file_id(unicode_or_utf8_string):
1381
"""File ids should now be utf8, but at one point they were unicode.
1383
This is the same as safe_utf8, except it uses the cached encode functions
1384
to save a little bit of performance.
1386
:param unicode_or_utf8_string: A possibly Unicode file_id. (can also be
1388
:return: None or a utf8 file id.
1390
if (unicode_or_utf8_string is None
1391
or unicode_or_utf8_string.__class__ == bytes):
1392
return unicode_or_utf8_string
1393
raise TypeError('Unicode file ids are no longer supported. '
1394
'File id generators should be creating utf8 file ids.')
1397
1365
_platform_normalizes_filenames = False
1398
1366
if sys.platform == 'darwin':
1399
1367
_platform_normalizes_filenames = True