<s> """<STR_LIT>""" <EOL> import os <EOL> from cStringIO import StringIO <EOL> import chardet <EOL> from pycopia import reports <EOL> NO_MESSAGE = reports . NO_MESSAGE <EOL> from pycopia import ezmail <EOL> class EmailReport ( reports . NullReport ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , formatter = "<STR_LIT>" , recipients = None , From = None , attach_logfile = False ) : <EOL> self . _logfile = None <EOL> self . _message = ezmail . MultipartMessage ( ) <EOL> self . _message . From ( From ) <EOL> self . _message . To ( recipients ) <EOL> self . _attach_logfile = attach_logfile <EOL> self . _formatter , ext = reports . get_formatter ( formatter ) <EOL> filename = property ( lambda s : None ) <EOL> filenames = property ( lambda s : [ ] ) <EOL> mimetype = property ( lambda s : s . _formatter . MIMETYPE ) <EOL> def initialize ( self , config = None ) : <EOL> self . _fo = StringIO ( ) <EOL> self . write ( self . _formatter . initialize ( ) ) <EOL> def logfile ( self , lf ) : <EOL> self . _logfile = str ( lf ) <EOL> def write ( self , text ) : <EOL> self . _fo . write ( text ) <EOL> def writeline ( self , text ) : <EOL> self . _fo . write ( text ) <EOL> self . _fo . write ( "<STR_LIT:\n>" ) <EOL> def finalize ( self ) : <EOL> """<STR_LIT>""" <EOL> self . write ( self . _formatter . finalize ( ) ) <EOL> report = ezmail . MIMEText . MIMEText ( self . _fo . getvalue ( ) , <EOL> self . _formatter . MIMETYPE . split ( "<STR_LIT:/>" ) [ <NUM_LIT:1> ] ) <EOL> report [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . _message . attach ( report ) <EOL> if self . _attach_logfile and self . _logfile : <EOL> try : <EOL> lfd = open ( self . _logfile , "<STR_LIT:rb>" ) . read ( ) <EOL> except : <EOL> pass <EOL> else : <EOL> logmsg = ezmail . MIMEText . MIMEText ( lfd , charset = chardet . detect ( lfd ) ) <EOL> logmsg [ "<STR_LIT>" ] = '<STR_LIT>' % ( <EOL> os . path . basename ( self . _logfile ) , ) <EOL> self . _message . attach ( logmsg ) <EOL> ezmail . mail ( self . _message ) <EOL> def add_title ( self , title ) : <EOL> self . _message . add_header ( "<STR_LIT>" , title ) <EOL> self . write ( self . _formatter . title ( title ) ) <EOL> def add_heading ( self , text , level = <NUM_LIT:1> ) : <EOL> self . write ( self . _formatter . heading ( text , level ) ) <EOL> def add_message ( self , msgtype , msg , level = <NUM_LIT:1> ) : <EOL> self . write ( self . _formatter . message ( msgtype , msg , level ) ) <EOL> def add_summary ( self , entries ) : <EOL> lines = map ( self . _formatter . summaryline , entries ) <EOL> self . write ( "<STR_LIT:\n>" . join ( lines ) ) <EOL> self . write ( "<STR_LIT:\n>" ) <EOL> def passed ( self , msg = NO_MESSAGE , level = <NUM_LIT:1> ) : <EOL> self . add_message ( "<STR_LIT>" , msg , level ) <EOL> def failed ( self , msg = NO_MESSAGE , level = <NUM_LIT:1> ) : <EOL> self . add_message ( "<STR_LIT>" , msg , level ) <EOL> def expectedfail ( self , msg = NO_MESSAGE , level = <NUM_LIT:1> ) : <EOL> self . add_message ( "<STR_LIT>" , msg , level ) <EOL> def incomplete ( self , msg = NO_MESSAGE , level = <NUM_LIT:1> ) : <EOL> self . add_message ( "<STR_LIT>" , msg , level ) <EOL> def abort ( self , msg = NO_MESSAGE , level = <NUM_LIT:1> ) : <EOL> self . add_message ( "<STR_LIT>" , msg , level ) <EOL> def info ( self , msg , level = <NUM_LIT:1> ) : <EOL> self . add_message ( "<STR_LIT>" , msg , level ) <EOL> def diagnostic ( self , msg , level = <NUM_LIT:1> ) : <EOL> self . add_message ( "<STR_LIT>" , msg , level ) <EOL> def add_text ( self , text ) : <EOL> self . write ( self . _formatter . text ( text ) ) <EOL> def add_url ( self , text , url ) : <EOL> self . write ( self . _formatter . url ( text , url ) ) <EOL> def newpage ( self ) : <EOL> self . write ( self . _formatter . newpage ( ) ) <EOL> def newsection ( self ) : <EOL> self . write ( self . _formatter . section ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> rpt = EmailReport ( "<STR_LIT>" , recipients = [ "<STR_LIT>" ] ) <EOL> rpt . initialize ( ) <EOL> rpt . add_title ( "<STR_LIT>" ) <EOL> rpt . info ( "<STR_LIT>" ) <EOL> rpt . finalize ( ) </s>
