<s> from django . conf import settings <EOL> from django . utils . html import escape <EOL> flatatt = lambda attrs : u'<STR_LIT>' . join ( [ u'<STR_LIT>' % ( k , escape ( v ) ) for k , v in attrs . items ( ) ] ) <EOL> def smart_unicode ( s ) : <EOL> if not isinstance ( s , basestring ) : <EOL> if hasattr ( s , '<STR_LIT>' ) : <EOL> s = unicode ( s ) <EOL> else : <EOL> s = unicode ( str ( s ) , settings . DEFAULT_CHARSET ) <EOL> elif not isinstance ( s , unicode ) : <EOL> s = unicode ( s , settings . DEFAULT_CHARSET ) <EOL> return s <EOL> class StrAndUnicode ( object ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return self . __unicode__ ( ) . encode ( settings . DEFAULT_CHARSET ) <EOL> class ErrorDict ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return self . as_ul ( ) <EOL> def as_ul ( self ) : <EOL> if not self : return u'<STR_LIT>' <EOL> return u'<STR_LIT>' % '<STR_LIT>' . join ( [ u'<STR_LIT>' % ( k , v ) for k , v in self . items ( ) ] ) <EOL> def as_text ( self ) : <EOL> return u'<STR_LIT:\n>' . join ( [ u'<STR_LIT>' % ( k , u'<STR_LIT:\n>' . join ( [ u'<STR_LIT>' % i for i in v ] ) ) for k , v in self . items ( ) ] ) <EOL> class ErrorList ( list ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return self . as_ul ( ) <EOL> def as_ul ( self ) : <EOL> if not self : return u'<STR_LIT>' <EOL> return u'<STR_LIT>' % '<STR_LIT>' . join ( [ u'<STR_LIT>' % e for e in self ] ) <EOL> def as_text ( self ) : <EOL> if not self : return u'<STR_LIT>' <EOL> return u'<STR_LIT:\n>' . join ( [ u'<STR_LIT>' % e for e in self ] ) <EOL> class ValidationError ( Exception ) : <EOL> def __init__ ( self , message ) : <EOL> "<STR_LIT>" <EOL> if isinstance ( message , list ) : <EOL> self . messages = ErrorList ( [ smart_unicode ( msg ) for msg in message ] ) <EOL> else : <EOL> assert isinstance ( message , basestring ) , ( "<STR_LIT>" % repr ( message ) ) <EOL> message = smart_unicode ( message ) <EOL> self . messages = ErrorList ( [ message ] ) <EOL> def __str__ ( self ) : <EOL> return repr ( self . messages ) </s>
