<s> __author__ = '<STR_LIT>' <EOL> from BaseHTTPServer import BaseHTTPRequestHandler <EOL> from cynic . utils import get_stream_logger <EOL> class BaseHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> LOGGER_NAME = __name__ <EOL> def __init__ ( self , connection , client_address ) : <EOL> """<STR_LIT>""" <EOL> self . connection = connection <EOL> self . client_address = client_address <EOL> self . logger = get_stream_logger ( self . LOGGER_NAME ) <EOL> def handle ( self ) : <EOL> pass <EOL> class BaseHTTPHandler ( BaseHTTPRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> protocol_version = '<STR_LIT>' <EOL> CONTENT_TYPE = '<STR_LIT>' <EOL> TEMPLATE = '<STR_LIT>' <EOL> LOGGER_NAME = __name__ <EOL> def __init__ ( self , connection , client_address , <EOL> datapath = None , content_type = None ) : <EOL> """<STR_LIT>""" <EOL> self . connection = self . request = connection <EOL> self . client_address = client_address <EOL> self . server = self <EOL> self . setup ( ) <EOL> self . data = open ( datapath ) . read ( ) if datapath is not None else '<STR_LIT>' <EOL> self . logger = get_stream_logger ( self . LOGGER_NAME ) <EOL> if content_type is not None : <EOL> self . CONTENT_TYPE = content_type <EOL> def do_GET ( self ) : <EOL> """<STR_LIT>""" <EOL> body = self . TEMPLATE <EOL> if self . data : <EOL> body = self . data <EOL> self . send_response ( <NUM_LIT:200> ) <EOL> self . send_header ( '<STR_LIT>' , len ( body ) ) <EOL> self . send_header ( '<STR_LIT:Content-Type>' , self . CONTENT_TYPE ) <EOL> self . end_headers ( ) <EOL> self . wfile . write ( body ) <EOL> def log_message ( self , format , * args ) : <EOL> """<STR_LIT>""" <EOL> self . logger . info ( format % args ) </s>
