def run(create_publisher, host='', port=80): """Runs a Medusa HTTP server that publishes a Quixote application. """ server = http_server.http_server(host, port) publisher = create_publisher() handler = QuixoteHandler(publisher, server) server.install_handler(handler) asyncore.loop()
def run(create_publisher, host="", port=80): """Runs a Medusa HTTP server that publishes a Quixote application. """ server = http_server.http_server(host, port) publisher = create_publisher() handler = QuixoteHandler(publisher, server) server.install_handler(handler) asyncore.loop()
def __init__(self, address, port): rs = None # resolver.caching_resolver ('127.0.0.1') lg = logger.file_logger (sys.stdout) self.hs = http_server.http_server (address, port, rs, lg) if address=='': address='localhost' print "Started server at: http://%s:%s/" % (address, port) sys.stdout.flush()
def run(self): print 'Serving application %r on port %d' % (self.approot, self.port) server = http_server.http_server('', self.port) publisher = self.publishclass(self.approot) if self.config_file: publisher.read_config(self.config_file) publisher.setup_logs() dh = QuixoteHandler(publisher, self.approot, server) server.install_handler(dh) asyncore.loop()
def start(port): global running # install signal handler for SIGTERM and SIGINT import signal def signalHandler(signum, frame): global running log.message("RECEIVED SIGNAL", signum) running = 0 signal.signal(signal.SIGTERM, signalHandler) signal.signal(signal.SIGINT, signalHandler) # create server logger = emptyLogger() server = http_server.http_server('', int(port), logger_object = logger) fsys = filesys.os_filesystem ('website') default = default_handler.default_handler (fsys) server.install_handler(default) handler = igerpc() server.install_handler(handler) handler = xmlrpc() server.install_handler(handler) status = status_handler.status_extension([server]) server.install_handler(status) running = 1 # get poll function import select if hasattr(select, "poll"): poll = asyncore.poll3 else: poll = asyncore.poll # main loop try: while running: for scheduler in schedulers.itervalues(): scheduler.tick() poll(timeout = 1.0) except KeyboardInterrupt: log.message("KeyboardInterrupt") except asyncore.ExitNow: log.message("ExitNow") except: traceback.print_exc()
def __init__(self, addr, logHttp=True, logResponses=True, logRequests=True, status=False): if not logHttp: _level = logging.ERROR else: _level = logging.INFO self.httpSrv = http_server.http_server(addr[0], addr[1], logger_object=logger.python_logger(level=_level)) self.httpSrv.channel_class = MedusaXmlRpcChannel self.xmlRpcDispatcher = MedusaXmlRpcHandler(logger_object=logger.python_logger(level=_level), logRequests=logRequests, logResponses=logResponses) self.httpSrv.install_handler(self.xmlRpcDispatcher) if status: sh = status_handler.status_extension([self.httpSrv, self.xmlRpcDispatcher]) self.httpSrv.install_handler(sh)
def startServer(namespace, servername, configPath=None): if configPath is None: configPath = os.path.dirname(namespace.__file__) print "config path is %s" % configPath print 'Now serving %s on port 8080' % servername server = http_server.http_server('', 8080) publisher = SessionPublisher(namespace) try: publisher.read_config(os.path.join(configPath, "default.conf")) except IOError, e: print e return
def startServer (namespace,servername,configPath=None): if configPath is None: configPath = os.path.dirname(namespace.__file__) print "config path is %s" % configPath print 'Now serving %s on port 8080' % servername server = http_server.http_server('', 8080) publisher = SessionPublisher(namespace) try: publisher.read_config(os.path.join(configPath,"default.conf")) except IOError,e: print e return
def main(): from quixote import enable_ptl enable_ptl() if len(sys.argv) == 2: port = int(sys.argv[1]) else: port = 8080 print 'Now serving the Quixote demo on port %d' % port server = http_server.http_server('', port) publisher = Publisher('quixote.demo') # When initializing the Publisher in your own driver script, # you'll want to parse a configuration file. ##publisher.read_config("/full/path/to/demo.conf") publisher.setup_logs() dh = QuixoteHandler(publisher, 'Quixote/demo', server) server.install_handler(dh) asyncore.loop()
def __init__(self, addr, logHttp=True, logResponses=True, logRequests=True, status=False): if not logHttp: _level = logging.ERROR else: _level = logging.INFO self.httpSrv = http_server.http_server( addr[0], addr[1], logger_object=logger.python_logger(level=_level)) self.httpSrv.channel_class = MedusaXmlRpcChannel self.xmlRpcDispatcher = MedusaXmlRpcHandler( logger_object=logger.python_logger(level=_level), logRequests=logRequests, logResponses=logResponses) self.httpSrv.install_handler(self.xmlRpcDispatcher) if status: sh = status_handler.status_extension( [self.httpSrv, self.xmlRpcDispatcher]) self.httpSrv.install_handler(sh)
raise Usage("Configuration error: port must be an integer") # handler section handler = {} handler['root'] = './root' handler['defaults'] = 'index.html, index.pt' if config.has_section('handler'): handler.update(dict(config.items('handler'))) handler['defaults'] = tuple(handler['defaults'].split()) except ConfigParser.Error, msg: raise Usage("Configuration error: %s" % msg) # Stop, drop, and roll. # ===================== server = http_server.http_server(**network) server.install_handler(handler(**filesystem)) asyncore.loop() except Usage, err: print >> sys.stderr, err.msg print >> sys.stderr, "`man 1 httpy' for usage." return 2 if __name__ == "__main__": sys.exit(main())
# 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 medusa import unix_user_handler uh = unix_user_handler.unix_user_handler ('public_html') hs.install_handler (uh) # =========================================================================== # FTP Server # ===========================================================================
PUBLISHING_ROOT='/home/medusa' 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': ic = sample_input_collector (request) 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()
def __init__(self, host=None, port=8182): if host is None: host = gethostname() hs = http_server(host, port) hs.install_handler(self) asyncore.loop()
# -*- Mode: Python -*- # Create a simple HTTP server import asyncore from medusa import http_server hs = http_server.http_server ( '/usr/local/etc/httpd/docs', 8080 ) # Enter async main loop asyncore.loop()
from 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()
# -*- Mode: Python -*- # This is something you might want to use on a machine running Windows # NT or Windows 95 - simultaneously publish the directory 'd:/public' # via http and ftp, on the standard ports. import asyncore from medusa import http_server from medusa import ftp_server # Change this path to publish a different directory DIRECTORY = 'd:/public' hs = http_server.http_server(DIRECTORY, 80) fs = ftp_server.ftp_server(ftp_server.dummy_authorizer(DIRECTORY), port = 21 ) # Run the async main loop asyncore.loop()
__version__ = (0, 1) __author__ = 'Chad Whitacre <*****@*****.**>' import asyncore import sys from medusa import http_server from httpy.Handler import Handler from httpy.Configuration import ConfigError from httpy.Configuration import Configuration def main(argv=None): if argv is None: argv = sys.argv[1:] try: config = Configuration(argv) except ConfigError, err: print >> sys.stderr, err.msg print >> sys.stderr, "`man 1 httpy' for usage." return 2 else: server = http_server.http_server(**config.server) server.install_handler(Handler(**config.handler)) asyncore.loop() if __name__ == "__main__": sys.exit(main())
# 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 from 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 from 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
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 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()