def write(self, data): if isinstance(data, unicode): raise TypeError("not a byte value: %r" %(data,)) StringIO.write(self, data)