def encode(self, value): "Return a bytestring representation of the value" if MAJOR_VERSION >= 3: if isinstance(value, bytes): return value return unicode(value).encode(self.encoding, self.encoding_errors) else: if isinstance(value, unicode): return value.encode(self.encoding, self.encoding_errors) elif isinstance(value, bytes): return value else: return str(value)