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 |