<s> """<STR_LIT>""" <EOL> from handler import Handler <EOL> import MySQLdb <EOL> class MySQLHandler ( Handler ) : <EOL> """<STR_LIT>""" <EOL> conn = None <EOL> def __init__ ( self , config = None ) : <EOL> """<STR_LIT>""" <EOL> Handler . __init__ ( self , config ) <EOL> self . hostname = self . config [ '<STR_LIT>' ] <EOL> self . port = int ( self . config [ '<STR_LIT:port>' ] ) <EOL> self . username = self . config [ '<STR_LIT:username>' ] <EOL> self . password = self . config [ '<STR_LIT:password>' ] <EOL> self . database = self . config [ '<STR_LIT>' ] <EOL> self . table = self . config [ '<STR_LIT>' ] <EOL> self . col_time = self . config [ '<STR_LIT>' ] <EOL> self . col_metric = self . config [ '<STR_LIT>' ] <EOL> self . col_value = self . config [ '<STR_LIT>' ] <EOL> self . _connect ( ) <EOL> def get_default_config_help ( self ) : <EOL> """<STR_LIT>""" <EOL> config = super ( MySQLHandler , self ) . get_default_config_help ( ) <EOL> config . update ( { <EOL> } ) <EOL> return config <EOL> def get_default_config ( self ) : <EOL> """<STR_LIT>""" <EOL> config = super ( MySQLHandler , self ) . get_default_config ( ) <EOL> config . update ( { <EOL> } ) <EOL> return config <EOL> def __del__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _close ( ) <EOL> def process ( self , metric ) : <EOL> """<STR_LIT>""" <EOL> self . _send ( str ( metric ) ) <EOL> def _send ( self , data ) : <EOL> """<STR_LIT>""" <EOL> data = data . strip ( ) . split ( '<STR_LIT:U+0020>' ) <EOL> try : <EOL> cursor = self . conn . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" <EOL> % ( self . table , self . col_metric , <EOL> self . col_time , self . col_value ) , <EOL> ( data [ <NUM_LIT:0> ] , data [ <NUM_LIT:2> ] , data [ <NUM_LIT:1> ] ) ) <EOL> cursor . close ( ) <EOL> self . conn . commit ( ) <EOL> pass <EOL> except BaseException , e : <EOL> self . log . error ( "<STR_LIT>" , e ) <EOL> self . _connect ( ) <EOL> def _connect ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _close ( ) <EOL> self . conn = MySQLdb . Connect ( host = self . hostname , <EOL> port = self . port , <EOL> user = self . username , <EOL> passwd = self . password , <EOL> db = self . database ) <EOL> def _close ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . conn : <EOL> self . conn . commit ( ) <EOL> self . conn . close ( ) </s>
