def encode(self, value): "Return a bytestring representation of the value" if isinstance(value, Token): return b(value.value) elif isinstance(value, bytes): return value elif isinstance(value, (int, long)): value = b(str(value)) elif isinstance(value, float): value = b(repr(value)) elif not isinstance(value, basestring): value = unicode(value) if isinstance(value, unicode): value = value.encode(self.encoding, self.encoding_errors) return value
def __unicode__(self): if isinstance(self.args[0], unicode): return self.args[0] return unicode(self.args[0])