Rev 2298: Add safe_file_id as a helper in osutils. in http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/utf8_file_ids
John Arbash Meinel
john at arbash-meinel.com
Sat Feb 17 21:17:29 GMT 2007
At http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/utf8_file_ids
------------------------------------------------------------
revno: 2298
revision-id: john at arbash-meinel.com-20070217211722-yxx3xjxtxeijc8d7
parent: john at arbash-meinel.com-20070217211255-kzskwwv9rukq6r7r
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: utf8_file_ids
timestamp: Sat 2007-02-17 15:17:22 -0600
message:
Add safe_file_id as a helper in osutils.
modified:
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2007-02-17 01:42:57 +0000
+++ b/bzrlib/osutils.py 2007-02-17 21:17:22 +0000
@@ -922,6 +922,13 @@
return cache_utf8.encode(unicode_or_utf8_string)
+# TODO: jam 20070217 We start by just re-using safe_revision_id, but ultimately
+# we want to use a different dictionary cache, because trapping file ids
+# and revision ids in the same dict seemed to have a noticable effect on
+# performance.
+safe_file_id = safe_revision_id
+
+
_platform_normalizes_filenames = False
if sys.platform == 'darwin':
_platform_normalizes_filenames = True
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2007-02-17 01:42:57 +0000
+++ b/bzrlib/tests/test_osutils.py 2007-02-17 21:17:22 +0000
@@ -302,13 +302,40 @@
def test_bad_utf8_string(self):
# This check may eventually go away
self.assertRaises(BzrBadParameterNotUnicode,
- osutils.safe_utf8, '\xbb\xbb')
+ osutils.safe_revision_id, '\xbb\xbb')
def test_none(self):
"""Currently, None is a valid revision_id"""
self.assertEqual(None, osutils.safe_revision_id(None))
+class TestSafeFileId(TestCase):
+
+ def test_from_ascii_string(self):
+ f = 'foobar'
+ self.assertEqual('foobar', osutils.safe_file_id(f))
+
+ def test_from_unicode_string_ascii_contents(self):
+ self.assertEqual('bargam', osutils.safe_file_id(u'bargam'))
+
+ def test_from_unicode_string_unicode_contents(self):
+ self.assertEqual('bargam\xc2\xae',
+ osutils.safe_file_id(u'bargam\xae'))
+
+ def test_from_utf8_string(self):
+ self.assertEqual('foo\xc2\xae',
+ osutils.safe_file_id('foo\xc2\xae'))
+
+ def test_bad_utf8_string(self):
+ # This check may eventually go away
+ self.assertRaises(BzrBadParameterNotUnicode,
+ osutils.safe_file_id, '\xbb\xbb')
+
+ def test_none(self):
+ """Currently, None is a valid revision_id"""
+ self.assertEqual(None, osutils.safe_file_id(None))
+
+
class TestWin32Funcs(TestCase):
"""Test that the _win32 versions of os utilities return appropriate paths."""
More information about the bazaar-commits
mailing list