Fix Binary on python < 2.7.4 (closes #10593811)
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 08 Feb 2016 11:01:46 +0100
changeset 11102 cd1267c1243e
parent 11101 66fb68c25f83
child 11103 d1798710f922
Fix Binary on python < 2.7.4 (closes #10593811) Before the fix for http://bugs.python.org/issue10211 we can't pass a buffer object to BytesIO, so keep using StringIO in that case. And because StringIO is an old-style class, we can't use super().
__init__.py
--- a/__init__.py	Thu Feb 11 22:00:48 2016 +0100
+++ b/__init__.py	Mon Feb 08 11:01:46 2016 +0100
@@ -34,7 +34,11 @@
 CW_SOFTWARE_ROOT = __path__[0]
 
 import sys, os, logging
-from io import BytesIO
+if (2, 7) <= sys.version_info < (2, 7, 4):
+    # http://bugs.python.org/issue10211
+    from StringIO import StringIO as BytesIO
+else:
+    from io import BytesIO
 
 from six.moves import cPickle as pickle
 
@@ -79,12 +83,14 @@
     def __init__(self, buf=b''):
         assert isinstance(buf, self._allowed_types), \
                "Binary objects must use bytes/buffer objects, not %s" % buf.__class__
-        super(Binary, self).__init__(buf)
+        # don't call super, BytesIO may be an old-style class (on python < 2.7.4)
+        BytesIO.__init__(self, buf)
 
     def write(self, data):
         assert isinstance(data, self._allowed_types), \
                "Binary objects must use bytes/buffer objects, not %s" % data.__class__
-        super(Binary, self).write(data)
+        # don't call super, BytesIO may be an old-style class (on python < 2.7.4)
+        BytesIO.write(self, data)
 
     def to_file(self, fobj):
         """write a binary to disk