Rev 2501: Add convenience utf8 decode routine for handling strings that might be None in http://bazaar.launchpad.net/~bzr/bzr/dirstate
Robert Collins
robertc at robertcollins.net
Sun Mar 4 22:11:37 GMT 2007
At http://bazaar.launchpad.net/~bzr/bzr/dirstate
------------------------------------------------------------
revno: 2501
revision-id: robertc at robertcollins.net-20070304221043-gxthr6yo2w4yy6mx
parent: mbp at sourcefrog.net-20070304080909-xjsidexprse2bar5
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Mon 2007-03-05 09:10:43 +1100
message:
Add convenience utf8 decode routine for handling strings that might be None
modified:
bzrlib/cache_utf8.py cache_utf8.py-20060810004311-x4cph46la06h9azm-1
bzrlib/tests/test_cache_utf8.py test_cache_utf8.py-20060810004311-x4cph46la06h9azm-2
=== modified file 'bzrlib/cache_utf8.py'
--- a/bzrlib/cache_utf8.py 2007-02-10 02:48:43 +0000
+++ b/bzrlib/cache_utf8.py 2007-03-04 22:10:43 +0000
@@ -24,6 +24,12 @@
_utf8_encode = codecs.getencoder("utf-8")
_utf8_decode = codecs.getdecoder("utf-8")
+# wrap _utf8_decode to support None->None for optional strings.
+def _utf8_decode_with_None(bytestring, _utf8_decode=_utf8_decode):
+ if bytestring is None:
+ return (None, 0)
+ else:
+ return _utf8_decode(bytestring)
# Map revisions from and to utf8 encoding
# Whenever we do an encode/decode operation, we save the result, so that
=== modified file 'bzrlib/tests/test_cache_utf8.py'
--- a/bzrlib/tests/test_cache_utf8.py 2007-02-09 16:41:00 +0000
+++ b/bzrlib/tests/test_cache_utf8.py 2007-03-04 22:10:43 +0000
@@ -109,3 +109,6 @@
utf8_x = cache_utf8.encode(uni_x)
self.assertIs(utf8_x, x)
+
+ def test_decode_with_None(self):
+ self.assertEqual((None, 0), cache_utf8._utf8_decode_with_None(None))
More information about the bazaar-commits
mailing list