def html_safe(klass):
 if ('__html__' in klass.__dict__):
  raise ValueError(("can't apply @html_safe to %s because it defines __html__()." % klass.__name__))
 if ('__str__' not in klass.__dict__):
  raise ValueError(("can't apply @html_safe to %s because it doesn't define __str__()." % klass.__name__))
 klass_str = klass.__str__
 klass.__str__ = (lambda self: mark_safe(klass_str(self)))
 klass.__html__ = (lambda self: str(self))
 return klass

def html_safe ( klass ) : if ( '__html__' in klass . __dict__ ) : raise ValueError ( ( "can't apply @html_safe to %s because it defines __html__()." % klass . __name__ ) ) if ( '__str__' not in klass . __dict__ ) : raise ValueError ( ( "can't apply @html_safe to %s because it doesn't define __str__()." % klass . __name__ ) ) klass_str = klass . __str__ klass . __str__ = ( lambda self : mark_safe ( klass_str ( self ) ) ) klass . __html__ = ( lambda self : str ( self ) ) return klass
a decorator that defines the __html__ method .