Rev 4806: Create a StreamWriter helper that doesn't trigger implicit decode('ascii') on write(a_str). in http://bazaar.launchpad.net/~lifeless/bzr/subunit
Robert Collins
robertc at robertcollins.net
Sun Dec 13 05:28:16 GMT 2009
At http://bazaar.launchpad.net/~lifeless/bzr/subunit
------------------------------------------------------------
revno: 4806
revision-id: robertc at robertcollins.net-20091213052803-naih51i2khxktgqu
parent: robertc at robertcollins.net-20091213035929-iwbndgy759olzlj5
committer: Robert Collins <robertc at robertcollins.net>
branch nick: subunit
timestamp: Sun 2009-12-13 16:28:03 +1100
message:
Create a StreamWriter helper that doesn't trigger implicit decode('ascii') on write(a_str).
=== modified file 'NEWS'
--- a/NEWS 2009-11-12 07:38:22 +0000
+++ b/NEWS 2009-12-13 05:28:03 +0000
@@ -55,12 +55,18 @@
Internals
*********
+* New helper osutils.StreamWriter which encodes unicode objects but
+ passes str objects straight through. This is used for selftest but
+ may be useful for diff and other operations that generate mixed output.
+ (Robert Collins)
+
Testing
*******
* ``bzrlib.tests.TestCase`` now subclasses ``testtools.testcase.TestCase``.
This permits features in testtools such as getUniqueInteger and
- getUniqueString to be used. (Robert Collins)
+ getUniqueString to be used. Because of this, testtools version 0.9.2 or
+ newer is now a dependency to run bzr selftest. (Robert Collins)
* -Dhpssvfs will now trigger on ``RemoteBzrDir._ensure_real``, providing
more debugging of VFS access triggers. (Robert Collins)
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2009-10-23 16:31:03 +0000
+++ b/bzrlib/osutils.py 2009-12-13 05:28:03 +0000
@@ -1959,3 +1959,18 @@
if use_cache:
_cached_concurrency = concurrency
return concurrency
+
+
+class StreamWriter(codecs.StreamWriter):
+ """A stream writer that doesn't decode str arguments."""
+
+ def __init__(self, codec, stream, errors='strict'):
+ codecs.StreamWriter.__init__(self, stream, errors)
+ self.encode = codec.encode
+
+ def write(self, object):
+ if type(object) == str:
+ self.stream.write(object)
+ else:
+ data, _ = self.encode(object, self.errors)
+ self.stream.write(data)
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-12-13 03:59:29 +0000
+++ b/bzrlib/tests/__init__.py 2009-12-13 05:28:03 +0000
@@ -590,7 +590,8 @@
# specifically a built in file with encoding 'UTF-8' will still try
# to encode using ascii.
new_encoding = osutils.get_terminal_encoding()
- stream = codecs.getwriter(new_encoding)(stream)
+ codec = codecs.lookup(new_encoding)
+ stream = osutils.StreamWriter(codec, stream)
stream.encoding = new_encoding
self.stream = unittest._WritelnDecorator(stream)
self.descriptions = descriptions
More information about the bazaar-commits
mailing list