<s> import types <EOL> def format_exception_only ( etype , value ) : <EOL> """<STR_LIT>""" <EOL> if ( isinstance ( etype , BaseException ) or <EOL> isinstance ( etype , types . InstanceType ) or <EOL> etype is None or type ( etype ) is str ) : <EOL> return [ _format_final_exc_line ( etype , value ) ] <EOL> stype = etype . __name__ <EOL> if not issubclass ( etype , SyntaxError ) : <EOL> return [ _format_final_exc_line ( stype , value ) ] <EOL> lines = [ ] <EOL> try : <EOL> msg , ( filename , lineno , offset , badline ) = value . args <EOL> except Exception : <EOL> pass <EOL> else : <EOL> filename = filename or "<STR_LIT>" <EOL> lines . append ( '<STR_LIT>' % ( filename , lineno ) ) <EOL> if badline is not None : <EOL> lines . append ( '<STR_LIT>' % badline . strip ( ) ) <EOL> if offset is not None : <EOL> caretspace = badline . rstrip ( '<STR_LIT:\n>' ) [ : offset ] . lstrip ( ) <EOL> caretspace = ( ( c . isspace ( ) and c or '<STR_LIT:U+0020>' ) for c in caretspace ) <EOL> lines . append ( '<STR_LIT>' % '<STR_LIT>' . join ( caretspace ) ) <EOL> value = msg <EOL> lines . append ( _format_final_exc_line ( stype , value ) ) <EOL> return lines <EOL> def _format_final_exc_line ( etype , value ) : <EOL> """<STR_LIT>""" <EOL> valuestr = _some_str ( value ) <EOL> if value is None or not valuestr : <EOL> line = "<STR_LIT>" % etype <EOL> else : <EOL> line = "<STR_LIT>" % ( etype , valuestr ) <EOL> return line <EOL> def _some_str ( value ) : <EOL> try : <EOL> return unicode ( value ) <EOL> except Exception : <EOL> try : <EOL> return str ( value ) <EOL> except Exception : <EOL> pass <EOL> return '<STR_LIT>' % type ( value ) . __name__ </s>
