<s> from django . conf import settings <EOL> from django . utils . html import strip_tags <EOL> from django . utils . text import unescape_entities <EOL> from django . utils . encoding import force_unicode <EOL> ROA_DJANGO_ERRORS = getattr ( settings , '<STR_LIT>' , False ) <EOL> class ROAException ( Exception ) : <EOL> def __init__ ( self , exception ) : <EOL> status_int = hasattr ( exception , '<STR_LIT>' ) <EOL> status_code = hasattr ( exception , '<STR_LIT>' ) <EOL> if status_code : <EOL> self . status_code = exception . status_code <EOL> elif status_int : <EOL> self . status_code = exception . status_int <EOL> else : <EOL> self . status_code = "<STR_LIT>" <EOL> if hasattr ( exception , '<STR_LIT:message>' ) : <EOL> self . msg = force_unicode ( exception . message ) <EOL> else : <EOL> self . msg = force_unicode ( exception ) <EOL> def __str__ ( self ) : <EOL> if ROA_DJANGO_ERRORS and '<STR_LIT>' in self . msg : <EOL> return self . parse_django_error ( ) <EOL> return self . msg <EOL> def parse_django_error ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> summary = self . msg . split ( u'<STR_LIT>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . split ( u'<STR_LIT>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> traceback = self . msg . split ( u'<STR_LIT>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . split ( u'<STR_LIT>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> return self . msg <EOL> result = [ ] <EOL> title = None <EOL> for line in strip_tags ( summary ) . split ( '<STR_LIT:\n>' ) : <EOL> line_content = unescape_entities ( line . strip ( ) ) <EOL> if line_content : <EOL> if line_content . endswith ( '<STR_LIT::>' ) : <EOL> title = line_content <EOL> elif title is None : <EOL> title = "<STR_LIT>" % line_content <EOL> else : <EOL> result . append ( "<STR_LIT>" % ( title , line_content ) ) <EOL> result . append ( "<STR_LIT>" % self . status_code ) <EOL> indent , indent2 = u'<STR_LIT:U+0020>' , u'<STR_LIT:U+0020>' <EOL> return u"<STR_LIT>" . strip ( ) % { <EOL> '<STR_LIT>' : indent . join ( force_unicode ( line ) for line in result ) , <EOL> '<STR_LIT>' : indent2 . join ( force_unicode ( line + "<STR_LIT:\n>" ) for line in traceback . split ( '<STR_LIT:\n>' ) ) , <EOL> } <EOL> class ROANotImplementedYetException ( Exception ) : <EOL> pass </s>
