<s> import BaseHTTPServer <EOL> from thrift . server import TServer <EOL> from thrift . transport import TTransport <EOL> class ResponseException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , handler ) : <EOL> self . handler = handler <EOL> class THttpServer ( TServer . TServer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> processor , <EOL> server_address , <EOL> inputProtocolFactory , <EOL> outputProtocolFactory = None , <EOL> server_class = BaseHTTPServer . HTTPServer ) : <EOL> """<STR_LIT>""" <EOL> if outputProtocolFactory is None : <EOL> outputProtocolFactory = inputProtocolFactory <EOL> TServer . TServer . __init__ ( self , processor , None , None , None , <EOL> inputProtocolFactory , outputProtocolFactory ) <EOL> thttpserver = self <EOL> class RequestHander ( BaseHTTPServer . BaseHTTPRequestHandler ) : <EOL> def do_POST ( self ) : <EOL> itrans = TTransport . TFileObjectTransport ( self . rfile ) <EOL> otrans = TTransport . TFileObjectTransport ( self . wfile ) <EOL> itrans = TTransport . TBufferedTransport ( <EOL> itrans , int ( self . headers [ '<STR_LIT>' ] ) ) <EOL> otrans = TTransport . TMemoryBuffer ( ) <EOL> iprot = thttpserver . inputProtocolFactory . getProtocol ( itrans ) <EOL> oprot = thttpserver . outputProtocolFactory . getProtocol ( otrans ) <EOL> try : <EOL> thttpserver . processor . process ( iprot , oprot ) <EOL> except ResponseException , exn : <EOL> exn . handler ( self ) <EOL> else : <EOL> self . send_response ( <NUM_LIT:200> ) <EOL> self . send_header ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . end_headers ( ) <EOL> self . wfile . write ( otrans . getvalue ( ) ) <EOL> self . httpd = server_class ( server_address , RequestHander ) <EOL> def serve ( self ) : <EOL> self . httpd . serve_forever ( ) </s>
