<s> """<STR_LIT>""" <EOL> LOG_EMERG = <NUM_LIT:0> <EOL> LOG_ALERT = <NUM_LIT:1> <EOL> LOG_CRIT = <NUM_LIT:2> <EOL> LOG_ERR = <NUM_LIT:3> <EOL> LOG_WARNING = <NUM_LIT:4> <EOL> LOG_NOTICE = <NUM_LIT:5> <EOL> LOG_INFO = <NUM_LIT:6> <EOL> LOG_DEBUG = <NUM_LIT:7> <EOL> LOG_KERN = <NUM_LIT:0> <EOL> LOG_USER = <NUM_LIT:1> <EOL> LOG_MAIL = <NUM_LIT:2> <EOL> LOG_DAEMON = <NUM_LIT:3> <EOL> LOG_AUTH = <NUM_LIT:4> <EOL> LOG_SYSLOG = <NUM_LIT:5> <EOL> LOG_LPR = <NUM_LIT:6> <EOL> LOG_NEWS = <NUM_LIT:7> <EOL> LOG_UUCP = <NUM_LIT:8> <EOL> LOG_CRON = <NUM_LIT:9> <EOL> LOG_AUTHPRIV = <NUM_LIT:10> <EOL> LOG_LOCAL0 = <NUM_LIT:16> <EOL> LOG_LOCAL1 = <NUM_LIT> <EOL> LOG_LOCAL2 = <NUM_LIT> <EOL> LOG_LOCAL3 = <NUM_LIT> <EOL> LOG_LOCAL4 = <NUM_LIT:20> <EOL> LOG_LOCAL5 = <NUM_LIT> <EOL> LOG_LOCAL6 = <NUM_LIT> <EOL> LOG_LOCAL7 = <NUM_LIT> <EOL> priority_names = { <EOL> "<STR_LIT>" : LOG_ALERT , <EOL> "<STR_LIT>" : LOG_CRIT , <EOL> "<STR_LIT>" : LOG_DEBUG , <EOL> "<STR_LIT>" : LOG_EMERG , <EOL> "<STR_LIT>" : LOG_ERR , <EOL> "<STR_LIT:error>" : LOG_ERR , <EOL> "<STR_LIT:info>" : LOG_INFO , <EOL> "<STR_LIT>" : LOG_NOTICE , <EOL> "<STR_LIT>" : LOG_EMERG , <EOL> "<STR_LIT>" : LOG_WARNING , <EOL> "<STR_LIT>" : LOG_WARNING , <EOL> } <EOL> facility_names = { <EOL> "<STR_LIT>" : LOG_AUTH , <EOL> "<STR_LIT>" : LOG_AUTHPRIV , <EOL> "<STR_LIT>" : LOG_CRON , <EOL> "<STR_LIT>" : LOG_DAEMON , <EOL> "<STR_LIT>" : LOG_KERN , <EOL> "<STR_LIT>" : LOG_LPR , <EOL> "<STR_LIT>" : LOG_MAIL , <EOL> "<STR_LIT>" : LOG_NEWS , <EOL> "<STR_LIT>" : LOG_AUTH , <EOL> "<STR_LIT>" : LOG_SYSLOG , <EOL> "<STR_LIT:user>" : LOG_USER , <EOL> "<STR_LIT>" : LOG_UUCP , <EOL> "<STR_LIT>" : LOG_LOCAL0 , <EOL> "<STR_LIT>" : LOG_LOCAL1 , <EOL> "<STR_LIT>" : LOG_LOCAL2 , <EOL> "<STR_LIT>" : LOG_LOCAL3 , <EOL> "<STR_LIT>" : LOG_LOCAL4 , <EOL> "<STR_LIT>" : LOG_LOCAL5 , <EOL> "<STR_LIT>" : LOG_LOCAL6 , <EOL> "<STR_LIT>" : LOG_LOCAL7 , <EOL> } <EOL> import socket <EOL> class syslog_client : <EOL> def __init__ ( self , address = '<STR_LIT>' ) : <EOL> self . address = address <EOL> self . stream = <NUM_LIT:0> <EOL> if isinstance ( address , type ( '<STR_LIT>' ) ) : <EOL> try : <EOL> self . socket = socket . socket ( socket . AF_UNIX , socket . SOCK_DGRAM ) <EOL> self . socket . connect ( address ) <EOL> except socket . error : <EOL> self . socket = socket . socket ( socket . AF_UNIX , <EOL> socket . SOCK_STREAM ) <EOL> self . stream = <NUM_LIT:1> <EOL> else : <EOL> self . socket = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) <EOL> log_format_string = '<STR_LIT>' <EOL> def log ( self , message , facility = LOG_USER , priority = LOG_INFO ) : <EOL> message = self . log_format_string % ( <EOL> self . encode_priority ( facility , priority ) , <EOL> message <EOL> ) <EOL> if self . stream : <EOL> self . socket . send ( message ) <EOL> else : <EOL> self . socket . sendto ( message , self . address ) <EOL> def encode_priority ( self , facility , priority ) : <EOL> if type ( facility ) == type ( '<STR_LIT>' ) : <EOL> facility = facility_names [ facility ] <EOL> if type ( priority ) == type ( '<STR_LIT>' ) : <EOL> priority = priority_names [ priority ] <EOL> return ( facility << <NUM_LIT:3> ) | priority <EOL> def close ( self ) : <EOL> if self . stream : <EOL> self . socket . close ( ) </s>
