if not cl: request.error(411) else: cl = int(cl) # using a 'numeric' terminator self.request.channel.set_terminator(cl) def collect_incoming_data(self, data): self.data.append(data) def found_terminator(self): # set the terminator back to the default self.request.channel.set_terminator('\r\n\r\n') self.handler.continue_request("".join(self.data), self.request) if __name__ == '__main__': class rpc_demo(xmlrpc_handler): def call(self, method, params): print('method="%s" params=%s' % (method, params)) return "Sure, that works" import supervisor.medusa.asyncore_25 as asyncore hs = http_server.http_server('', 8000) rpc = rpc_demo() hs.install_handler(rpc) asyncore.loop()
# Testing # =========================================================================== if __name__ == '__main__': import sys if len(sys.argv) < 2: print(('Usage: %s <worker_threads>' % sys.argv[0])) else: nthreads = string.atoi(sys.argv[1]) import asyncore_25 as asyncore from supervisor.medusa import http_server # create a generic web server hs = http_server.http_server('', 7080) # create a request queue q = request_queue() # create a script handler sh = script_handler(q) # install the script handler on the web server hs.install_handler(sh) # get a couple of CGI modules import test_module import pi_module # install the module on the script handler
# Testing # =========================================================================== if __name__ == '__main__': import sys if len(sys.argv) < 2: print 'Usage: %s <worker_threads>' % sys.argv[0] else: nthreads = string.atoi (sys.argv[1]) import asyncore_25 as asyncore from supervisor.medusa import http_server # create a generic web server hs = http_server.http_server ('', 7080) # create a request queue q = request_queue() # create a script handler sh = script_handler (q) # install the script handler on the web server hs.install_handler (sh) # get a couple of CGI modules import test_module import pi_module # install the module on the script handler
# Default HTTP handler # =========================================================================== # The 'default' handler for the HTTP server is one that delivers # files normally - this is the expected behavior of a web server. # Note that you needn't use it: Your web server might not want to # deliver files! # This default handler uses the filesystem object we just constructed. dh = default_handler.default_handler (fs) # =========================================================================== # HTTP Server # =========================================================================== hs = http_server.http_server (IP_ADDRESS, HTTP_PORT, rs, lg) # Here we install the default handler created above. hs.install_handler (dh) # =========================================================================== # Unix user `public_html' directory support # =========================================================================== if os.name == 'posix': from supervisor.medusa import unix_user_handler uh = unix_user_handler.unix_user_handler ('public_html') hs.install_handler (uh) # =========================================================================== # FTP Server # ===========================================================================
# Default HTTP handler # =========================================================================== # The 'default' handler for the HTTP server is one that delivers # files normally - this is the expected behavior of a web server. # Note that you needn't use it: Your web server might not want to # deliver files! # This default handler uses the filesystem object we just constructed. dh = default_handler.default_handler(fs) # =========================================================================== # HTTP Server # =========================================================================== hs = http_server.http_server(IP_ADDRESS, HTTP_PORT, rs, lg) # Here we install the default handler created above. hs.install_handler(dh) # =========================================================================== # Unix user `public_html' directory support # =========================================================================== if os.name == 'posix': from supervisor.medusa import unix_user_handler uh = unix_user_handler.unix_user_handler('public_html') hs.install_handler(uh) # =========================================================================== # FTP Server # ===========================================================================
class sample_input_collector: def __init__(self, request, length): self.request = request self.length = length def collect_incoming_data(self, data): print 'data from %s: <%s>' % (self.request, repr(data)) class post_script_handler(script_handler.script_handler): def handle_request(self, request): if request.command == 'post': cl = default_handler.get_header(CONTENT_LENGTH, request.header) ic = sample_input_collector(request, cl) request.collector = ic print request.header return script_handler.script_handler.handle_request(self, request) lg = logger.file_logger(sys.stdout) fs = filesys.os_filesystem(PUBLISHING_ROOT) dh = default_handler.default_handler(fs) ph = post_script_handler(fs) hs = http_server.http_server('', 8081, logger_object=lg) hs.install_handler(dh) hs.install_handler(ph) asyncore.loop()
from supervisor.medusa import filesys # For this demo, we'll just use a dictionary of usernames/passwords. # You can of course use anything that supports the mapping interface, # and it would be pretty easy to set this up to use the crypt module # on unix. users = { 'mozart' : 'jupiter', 'beethoven' : 'pastoral' } # The filesystem we will be giving access to fs = filesys.os_filesystem('/home/medusa') # The 'default' handler - delivers files for the HTTP GET method. dh = default_handler.default_handler(fs) # Supports the HTTP PUT method... ph = put_handler.put_handler(fs, '/.*') # ... but be sure to wrap it with an auth handler: ah = auth_handler.auth_handler(users, ph) # Create a Web Server hs = http_server.http_server(ip='', port=8080) # install the handlers we created: hs.install_handler(dh) # for GET hs.install_handler(ah) # for PUT asyncore.loop()
# =========================================================================== if __name__ == "__main__": import sys if len(sys.argv) < 2: print("Usage: %s <worker_threads>" % sys.argv[0]) else: nthreads = int(sys.argv[1]) import supervisor.medusa.asyncore_25 as asyncore from supervisor.medusa import http_server # create a generic web server hs = http_server.http_server("", 7080) # create a request queue q = request_queue() # create a script handler sh = script_handler(q) # install the script handler on the web server hs.install_handler(sh) # get a couple of CGI modules import supervisor.medusa.thread.test_module as test_module import supervisor.medusa.thread.pi_module as pi_module # install the module on the script handler
class sample_input_collector: def __init__ (self, request, length): self.request = request self.length = length def collect_incoming_data (self, data): print(('data from %s: <%s>' % (self.request, repr(data)))) class post_script_handler (script_handler.script_handler): def handle_request (self, request): if request.command == 'post': cl = default_handler.get_header(CONTENT_LENGTH, request.header) ic = sample_input_collector(request, cl) request.collector = ic print((request.header)) return script_handler.script_handler.handle_request (self, request) lg = logger.file_logger (sys.stdout) fs = filesys.os_filesystem (PUBLISHING_ROOT) dh = default_handler.default_handler (fs) ph = post_script_handler (fs) hs = http_server.http_server ('', 8081, logger_object = lg) hs.install_handler (dh) hs.install_handler (ph) asyncore.loop()