def wsgi(global_options, arguments): parser = optparse.OptionParser( usage="%prog [global-options] wsgi [options] module:app") parser.add_option("-b", "--bind", metavar="ADDRESS", dest="address", default=":80", help="Bind the server to 'HOST', 'HOST:PORT', or 'unix:PATH'.") parser.add_option("--backlog", dest="backlog", type="int", help="The maximum number of pending connections.") parser.add_option("-x", "--x-headers", action="store_true", dest="xhead", default=False, help="Process X- headers received with requests.") options, args = parser.parse_args(arguments) args = ''.join(args) # First, find our application. if not args: parser.parse_args(['--help']) if not ':' in args: log.error("You must specify a module and callable to host as a WSGI application.") sys.exit(1) module, _, call = args.partition(':') try: mod = importer(module) except ImportError: log.error("Unable to import the module %r." % module) sys.exit(1) if not hasattr(mod, call) or not callable(getattr(mod, call)): log.error("No such attribute %r in module %r." % (call, module)) sys.exit(1) # Parse the address. address = parse_address(options.address) # Import the necessary modules. from pants.contrib.http import HTTPServer from pants.contrib.wsgi import WSGIConnector # Create the server now. connector = WSGIConnector(getattr(mod, call), global_options.debug) server = HTTPServer(connector, xheaders=options.xhead) backlog = options.backlog if options.backlog else socket.SOMAXCONN # Start listening. server.listen(address[1], address[0], backlog) # Return a function that will start things up. return pants.engine.start
class Engine(CooperativeEngine): def bind(self): connector = WSGIConnector(self.website) self.server = HTTPServer(connector) self.server.listen(host=self.website.network_address[0], port=self.website.network_address[1]) def start(self): pants.engine.start() def stop(self): pants.engine.stop() def start_checking(self, check_all): pants.cycle(check_all, 0.5)
def http(global_options, arguments): parser = optparse.OptionParser( usage="%prog [global-options] http [options] [path]") parser.add_option("-b", "--bind", metavar="ADDRESS", dest="address", default=":80", help="Bind the server to 'HOST', 'HOST:PORT', or 'unix:PATH'.") parser.add_option("--backlog", dest="backlog", type="int", help="The maximum number of pending connections.") parser.add_option("-x", "--x-headers", action="store_true", dest="xhead", default=False, help="Process X- headers received with requests.") parser.add_option("-i", "--index", metavar="FILE", dest="indices", action="append", default=[], help="Serve files named FILE if available rather than a directory listing.") options, args = parser.parse_args(arguments) args = ''.join(args) # First, find the directory. path = os.path.realpath(args) if not os.path.exists(path) or not os.path.isdir(path): log.error("The provided path %r is not a directory or does not exist." % path) sys.exit(1) # Parse the address. address = parse_address(options.address) # Fix up the indices list. indices = options.indices if not indices: indices.extend(['index.html', 'index.htm']) # Import the necessary modules. from pants.contrib.http import HTTPServer from pants.contrib.web import FileServer # Create the server now. Exclude .py from the blacklist though, for now. fs = FileServer(path, blacklist=['.*\.pyc'], defaults=indices) server = HTTPServer(fs, xheaders=options.xhead) backlog = options.backlog if options.backlog else socket.SOMAXCONN # Start listening. server.listen(address[1], address[0], backlog) # Return a function that will start things up. return pants.engine.start
class Engine(BaseEngine): def bind(self): connector = WSGIConnector(self.website) self.server = HTTPServer(connector) self.server.listen( host=self.website.address[0] , port=self.website.address[1] ) def start(self): engine.start() def stop(self): engine.stop() def start_restarter(self, check_all): cycle(check_all, 0.5)
class Engine(CooperativeEngine): def bind(self): connector = WSGIConnector(self.website) self.server = HTTPServer(connector) self.server.listen( host=self.website.network_address[0] , port=self.website.network_address[1] ) def start(self): pants.engine.start() def stop(self): pants.engine.stop() def start_checking(self, check_all): pants.cycle(check_all, 0.5)
def init(website): global server connector = WSGIConnector(website) server = HTTPServer(connector) server.listen(host=website.address[0], port=website.address[1])
def bind(self): connector = WSGIConnector(self.website) self.server = HTTPServer(connector) self.server.listen( host=self.website.address[0] , port=self.website.address[1] )
def bind(self): connector = WSGIConnector(self.website) self.server = HTTPServer(connector) self.server.listen(host=self.website.network_address[0], port=self.website.network_address[1])