__init__.py
changeset 10266 813e30041a93
parent 9984 793377697c81
child 10272 3231fd2fa7a5
equal deleted inserted replaced
10234:a12e4459eee5 10266:813e30041a93
    69 #threading.settrace(log_thread)
    69 #threading.settrace(log_thread)
    70 
    70 
    71 class Binary(StringIO):
    71 class Binary(StringIO):
    72     """customize StringIO to make sure we don't use unicode"""
    72     """customize StringIO to make sure we don't use unicode"""
    73     def __init__(self, buf=''):
    73     def __init__(self, buf=''):
    74         assert isinstance(buf, (str, buffer)), \
    74         assert isinstance(buf, (str, buffer, bytearray)), \
    75                "Binary objects must use raw strings, not %s" % buf.__class__
    75                "Binary objects must use raw strings, not %s" % buf.__class__
    76         StringIO.__init__(self, buf)
    76         StringIO.__init__(self, buf)
    77 
    77 
    78     def write(self, data):
    78     def write(self, data):
    79         assert isinstance(data, (str, buffer)), \
    79         assert isinstance(data, (str, buffer, bytearray)), \
    80                "Binary objects must use raw strings, not %s" % data.__class__
    80                "Binary objects must use raw strings, not %s" % data.__class__
    81         StringIO.write(self, data)
    81         StringIO.write(self, data)
    82 
    82 
    83     def to_file(self, fobj):
    83     def to_file(self, fobj):
    84         """write a binary to disk
    84         """write a binary to disk