Rev 4815: Python 2.4 doesn't use CodecInfo, so do a type check on the result of codecs.lookup. in http://people.canonical.com/~robertc/baz2.0/integration

Robert Collins robertc at robertcollins.net
Wed Dec 23 00:15:41 GMT 2009


At http://people.canonical.com/~robertc/baz2.0/integration

------------------------------------------------------------
revno: 4815
revision-id: robertc at robertcollins.net-20091223001534-31ih4557fim2mubl
parent: robertc at robertcollins.net-20091222235313-glrqgjra210hq2qm
committer: Robert Collins <robertc at robertcollins.net>
branch nick: integration
timestamp: Wed 2009-12-23 11:15:34 +1100
message:
  Python 2.4 doesn't use CodecInfo, so do a type check on the result of codecs.lookup.
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2009-12-22 23:09:50 +0000
+++ b/bzrlib/osutils.py	2009-12-23 00:15:34 +0000
@@ -2092,9 +2092,9 @@
 class UnicodeOrBytesToBytesWriter(codecs.StreamWriter):
     """A stream writer that doesn't decode str arguments."""
 
-    def __init__(self, codec, stream, errors='strict'):
+    def __init__(self, encode, stream, errors='strict'):
         codecs.StreamWriter.__init__(self, stream, errors)
-        self.encode = codec.encode
+        self.encode = encode
 
     def write(self, object):
         if type(object) is str:

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-12-22 23:53:13 +0000
+++ b/bzrlib/tests/__init__.py	2009-12-23 00:15:34 +0000
@@ -594,7 +594,12 @@
         # to encode using ascii.
         new_encoding = osutils.get_terminal_encoding()
         codec = codecs.lookup(new_encoding)
-        stream = osutils.UnicodeOrBytesToBytesWriter(codec, stream)
+        if type(codec) is tuple:
+            # Python 2.4
+            encode = codec[0]
+        else:
+            encode = codec.encode
+        stream = osutils.UnicodeOrBytesToBytesWriter(encode, stream)
         stream.encoding = new_encoding
         self.stream = unittest._WritelnDecorator(stream)
         self.descriptions = descriptions




More information about the bazaar-commits mailing list