904
905
return unicode_or_utf8_string.encode('utf-8')
907
def safe_revision_id(unicode_or_utf8_string):
908
_revision_id_warning = ('Unicode revision ids were deprecated in bzr 0.15.'
909
' Revision id generators should be creating utf8'
913
def safe_revision_id(unicode_or_utf8_string, warn=True):
908
914
"""Revision ids should now be utf8, but at one point they were unicode.
916
:param unicode_or_utf8_string: A possibly Unicode revision_id. (can also be
918
:param warn: Functions that are sanitizing user data can set warn=False
919
:return: None or a utf8 revision id.
921
if (unicode_or_utf8_string is None
922
or unicode_or_utf8_string.__class__ == str):
923
return unicode_or_utf8_string
925
symbol_versioning.warn(_revision_id_warning, DeprecationWarning,
927
return cache_utf8.encode(unicode_or_utf8_string)
930
_file_id_warning = ('Unicode file ids were deprecated in bzr 0.15. File id'
931
' generators should be creating utf8 file ids.')
934
def safe_file_id(unicode_or_utf8_string, warn=True):
935
"""File ids should now be utf8, but at one point they were unicode.
910
937
This is the same as safe_utf8, except it uses the cached encode functions
911
938
to save a little bit of performance.
940
:param unicode_or_utf8_string: A possibly Unicode file_id. (can also be
942
:param warn: Functions that are sanitizing user data can set warn=False
943
:return: None or a utf8 file id.
913
if unicode_or_utf8_string is None:
915
if isinstance(unicode_or_utf8_string, str):
916
# TODO: jam 20070209 Eventually just remove this check.
918
utf8_str = cache_utf8.get_cached_utf8(unicode_or_utf8_string)
919
except UnicodeDecodeError:
920
raise errors.BzrBadParameterNotUnicode(unicode_or_utf8_string)
945
if (unicode_or_utf8_string is None
946
or unicode_or_utf8_string.__class__ == str):
947
return unicode_or_utf8_string
949
symbol_versioning.warn(_file_id_warning, DeprecationWarning,
922
951
return cache_utf8.encode(unicode_or_utf8_string)
925
# TODO: jam 20070217 We start by just re-using safe_revision_id, but ultimately
926
# we want to use a different dictionary cache, because trapping file ids
927
# and revision ids in the same dict seemed to have a noticable effect on
929
safe_file_id = safe_revision_id
932
954
_platform_normalizes_filenames = False
933
955
if sys.platform == 'darwin':
934
956
_platform_normalizes_filenames = True