__init__.py
changeset 11102 cd1267c1243e
parent 10907 9ae707db5265
child 11274 d0f6fe008ec4
equal deleted inserted replaced
11101:66fb68c25f83 11102:cd1267c1243e
    32 from six.moves import builtins
    32 from six.moves import builtins
    33 
    33 
    34 CW_SOFTWARE_ROOT = __path__[0]
    34 CW_SOFTWARE_ROOT = __path__[0]
    35 
    35 
    36 import sys, os, logging
    36 import sys, os, logging
    37 from io import BytesIO
    37 if (2, 7) <= sys.version_info < (2, 7, 4):
       
    38     # http://bugs.python.org/issue10211
       
    39     from StringIO import StringIO as BytesIO
       
    40 else:
       
    41     from io import BytesIO
    38 
    42 
    39 from six.moves import cPickle as pickle
    43 from six.moves import cPickle as pickle
    40 
    44 
    41 from logilab.common.deprecation import deprecated
    45 from logilab.common.deprecation import deprecated
    42 from logilab.common.logging_ext import set_log_methods
    46 from logilab.common.logging_ext import set_log_methods
    77     _allowed_types = (binary_type, bytearray, buffer if PY2 else memoryview)
    81     _allowed_types = (binary_type, bytearray, buffer if PY2 else memoryview)
    78 
    82 
    79     def __init__(self, buf=b''):
    83     def __init__(self, buf=b''):
    80         assert isinstance(buf, self._allowed_types), \
    84         assert isinstance(buf, self._allowed_types), \
    81                "Binary objects must use bytes/buffer objects, not %s" % buf.__class__
    85                "Binary objects must use bytes/buffer objects, not %s" % buf.__class__
    82         super(Binary, self).__init__(buf)
    86         # don't call super, BytesIO may be an old-style class (on python < 2.7.4)
       
    87         BytesIO.__init__(self, buf)
    83 
    88 
    84     def write(self, data):
    89     def write(self, data):
    85         assert isinstance(data, self._allowed_types), \
    90         assert isinstance(data, self._allowed_types), \
    86                "Binary objects must use bytes/buffer objects, not %s" % data.__class__
    91                "Binary objects must use bytes/buffer objects, not %s" % data.__class__
    87         super(Binary, self).write(data)
    92         # don't call super, BytesIO may be an old-style class (on python < 2.7.4)
       
    93         BytesIO.write(self, data)
    88 
    94 
    89     def to_file(self, fobj):
    95     def to_file(self, fobj):
    90         """write a binary to disk
    96         """write a binary to disk
    91 
    97 
    92         the writing is performed in a safe way for files stored on
    98         the writing is performed in a safe way for files stored on