当前位置: 首页>>代码示例>>Python>>正文


Python wsgiserver.CherryPyWSGIServer类代码示例

本文整理汇总了Python中cherrypy.wsgiserver.CherryPyWSGIServer的典型用法代码示例。如果您正苦于以下问题:Python CherryPyWSGIServer类的具体用法?Python CherryPyWSGIServer怎么用?Python CherryPyWSGIServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CherryPyWSGIServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CherryPyLiveServerPlugin

class CherryPyLiveServerPlugin(AbstractLiveServerPlugin):
    """Live server plugin using cherrypy instead of the django server,
    that got its issues. Original code by Mikeal Rogers, released under
    Apache License.
    """

    name = 'cherrypyliveserver'
    activation_parameter = '--with-cherrypyliveserver'

    def start_server(self, address='0.0.0.0', port=8000, serve_static=True):
        from cherrypy.wsgiserver import CherryPyWSGIServer
        from threading import Thread

        _application = AdminMediaHandler(WSGIHandler())
        if serve_static:
            _application = StaticFilesHandler(_application)

        def application(environ, start_response):
            environ['PATH_INFO'] = environ['SCRIPT_NAME'] + \
                    environ['PATH_INFO']

            return _application(environ, start_response)

        self.httpd = CherryPyWSGIServer((address, port), application,
                                        server_name='django-test-http')
        self.httpd_thread = Thread(target=self.httpd.start)
        self.httpd_thread.start()
        # FIXME: This could be avoided by passing self to thread class starting
        # django and waiting for Event lock
        time.sleep(.5)

    def stop_server(self):
        self.httpd.stop()
开发者ID:olivergeorge,项目名称:django-nose-selenium,代码行数:33,代码来源:plugins.py

示例2: __call__

    def __call__(self, address=None):
        """
        start development web server
        address - where to serve, [interface:]port
        """
        if address is not None:
            interface = '127.0.0.1'
            port = address
            if ':' in port:
                interface, port = port.split(':')
            try:
                port = int(port)
            except: 
                raise InvalidArguments('Unable to parse port "%s"' % address)
        else:
            interface = '127.0.0.1'
            port = DEFAULT_RADAR_PORT

        from cherrypy.wsgiserver import CherryPyWSGIServer as WSGIServer

        app = RequestLogger(make_app(self.config))
        cherry_opts = config_section('cherrypy', self.config) 
        server = WSGIServer((interface, port), app, **cherry_opts)
        
        print "* serving on %s:%d" % (interface, port)
        try:
            server.start()
        except KeyboardInterrupt:
            server.stop()        
开发者ID:jab,项目名称:radarpost,代码行数:29,代码来源:app.py

示例3: main

def main():
    root_path = gettempdir()
    provider = FilesystemProvider(root_path)

    config = {
        "provider_mapping": {"/": provider},
        "http_authenticator": {
            "domain_controller": None  # None: dc.simple_dc.SimpleDomainController(user_mapping)
        },
        "simple_dc": {"user_mapping": {"*": True}},  # anonymous access
        "verbose": 1,
        "enable_loggers": [],
        "property_manager": True,  # True: use property_manager.PropertyManager
        "lock_manager": True,  # True: use lock_manager.LockManager
    }
    app = WsgiDAVApp(config)

    # For an example, use CherryPy
    from cherrypy.wsgiserver import CherryPyWSGIServer

    server = CherryPyWSGIServer(
        bind_addr=(config["host"], config["port"]),
        wsgi_app=app,
        server_name="WsgiDAV/{} {}".format(__version__, CherryPyWSGIServer.version),
    )

    try:
        server.start()
    except KeyboardInterrupt:
        print("Caught Ctrl-C, shutting down...")
    finally:
        server.stop()
开发者ID:mar10,项目名称:wsgidav,代码行数:32,代码来源:server_sample.py

示例4: handle

  def handle(self, **options):
    # Determine the port number
    if 'port' in options:
      port = int(options['port'] or settings.PORT)
    else:
      port = settings.PORT

    # Determine the number of threads
    if 'threads' in options:
      threads = int(options['threads'] or 25)
      if threads < 1:
        raise Exception("Invalid number of threads: %s" % threads)
    else:
      threads = 25

    # Determine the IP-address to listen on:
    # - either as command line argument
    # - either 0.0.0.0 by default, which means all active IPv4 interfaces
    address = 'address' in options and options['address'] or '0.0.0.0'

    # Validate the address and port number
    try:
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.bind( (address, port) )
      s.close()
    except socket.error as e:
      raise Exception("Invalid address '%s' and/or port '%s': %s" % (address, port, e))

    # Print a header message
    hostname = socket.getfqdn()
    print('Starting frePPLe %s web server\n' % VERSION)
    print('To access the server, point your browser to either of the following URLS:')
    if address == '0.0.0.0':
      print('    http://%s:%s/' % (hostname, port))
      for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
        print('    http://%s:%s/' % (ip, port))
    else:
      print('    http://%s:%s/' % (address, port))
    print('\nThree users are created by default: "admin", "frepple" and "guest" (the default password is equal to the user name)\n')
    print('Quit the server with CTRL-C.\n')

    # Start a separate thread that will check for updates
    # We don't wait for it to finish
    CheckUpdates().start()

    # Run the WSGI server
    server = CherryPyWSGIServer(
      (address, port),
      StaticFilesHandler(WSGIHandler()),
      numthreads=threads
      )
    # Want SSL support? Just set these attributes apparently, but I haven't tested or verified this
    #  server.ssl_certificate = <filename>
    #  server.ssl_private_key = <filename>
    try:
      server.start()
    except KeyboardInterrupt:
      server.stop()
开发者ID:WHELLINCK,项目名称:frePPLe,代码行数:58,代码来源:frepple_runserver.py

示例5: Command

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option("-h", "--host", dest="host", default=DEFAULT_HOST),
        make_option("-p", "--port", dest="port", default=DEFAULT_PORT),
        make_option("-d", "--daemon", dest="daemonize", action="store_true"),
    )
    requires_model_validation = False
    
    def handle(self, *args, **options):
        self.options = options
        self.server = CherryPyWSGIServer((options["host"], options["port"]), WSGIHandler())
        self.pidfile = os.path.join(settings.PROJECT_ROOT, "logs/wsgi.pid")
        try:
            action = args[0]
        except IndexError:
            print "You must provide an action. Possible actions are start, stop and restart."
            raise SystemExit
        if action == "start":
            print "Running %s:%d" % (options["host"], options["port"])
            self.daemonize()
            self.start()
        elif action == "stop":
            pid = open(self.pidfile, "r").read()
            self.stop(pid)
        elif action == "restart":
            pid = open(self.pidfile, "r").read()
            self.restart(pid)
    
    def daemonize(self):
        if self.options["daemonize"]:
            daemonize()
    
    def start(self):
        writepid(self.pidfile)
        try:
            self.server.start()
        except KeyboardInterrupt:
            # likely not a daemon so make sure to shutdown properly.
            self.server.stop()
    
    def stop(self, pid):
        os.kill(int(pid), signal.SIGHUP)
    
    def restart(self, pid):
        self.stop(pid)
        self.daemonize()
        self.start()
    
    def create_parser(self, prog_name, subcommand):
        """
        Create and return the ``OptionParser`` which will be used to
        parse the arguments to this command.
        """
        return OptionParser(prog=prog_name, usage=self.usage(subcommand),
            version = self.get_version(),
            option_list = self.option_list,
            conflict_handler = "resolve")
开发者ID:brosner,项目名称:oebfare,代码行数:57,代码来源:runwsgi.py

示例6: run

    def run(self):
        from cherrypy.wsgiserver import CherryPyWSGIServer
    #    Not possible to use 127.0.0.1 as this does not link to an
    #    externally accessible interface

        global server
        server = CherryPyWSGIServer((localIp(), portNo), BiFa())

        print "Started serving:"
        server.start()
开发者ID:JohnReid,项目名称:biopsy,代码行数:10,代码来源:main_server.py

示例7: launch_server_cherrypy

def launch_server_cherrypy(host, port, app):
    """use cherrypy's wsgiserver, a multithreaded scallable server"""
    from cherrypy.wsgiserver import  CherryPyWSGIServer

    server = CherryPyWSGIServer((host, port), app)
    logging.info("Starting CherryPy server, listening on port %s", port)
    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:10,代码来源:wsgi.py

示例8: Command

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option("-h", "--host", dest="host", default=DEFAULT_HOST),
        make_option("-p", "--port", dest="port", default=DEFAULT_PORT, type="int"),
        make_option("-d", "--daemon", dest="daemonize", action="store_true"),
    )
    requires_model_validation = False

    def handle(self, *args, **options):
        self.server = CherryPyWSGIServer((options["host"], options["port"]), WSGIHandler())
        self.pidfile = settings.APP_DIR.joinpath("wsgi.pid")
        try:
            action = args[0]
        except IndexError:
            action = "start"
        if options["daemonize"]:
            daemonize()
        if action == "start":
            self.start(create_pid_file=options["daemonize"])
        elif action == "stop":
            pid = open(self.pidfile, "r").read()
            self.stop(pid)
        elif action == "restart":
            pid = open(self.pidfile, "r").read()
            self.restart(pid)

    def start(self, create_pid_file=False):
        if create_pid_file:
            writepid(self.pidfile)
        try:
            self.server.start()
        except KeyboardInterrupt:
            # likely not a daemon so make sure to shutdown properly.
            self.server.stop()

    def stop(self, pid):
        os.kill(int(pid), signal.SIGHUP)

    def restart(self, pid):
        self.stop(pid)
        self.start()

    def create_parser(self, prog_name, subcommand):
        """
        Create and return the ``OptionParser`` which will be used to
        parse the arguments to this command.
        """
        return OptionParser(
            prog=prog_name,
            usage=self.usage(subcommand),
            version=self.get_version(),
            option_list=self.option_list,
            conflict_handler="resolve",
        )
开发者ID:amitu,项目名称:dutils,代码行数:54,代码来源:runwsgi.py

示例9: start

 def start(self):
     from cherrypy.wsgiserver import CherryPyWSGIServer
     hostname = self.config['server_host']['host']
     port = int(self.config['server_host']['port'])
     scheme = self.config['server_host']['scheme']
     server = CherryPyWSGIServer((hostname, port), self.server)
     try:
         logging.debug('starting CherryPy at %s://%s:%s',
                 scheme, hostname, port)
         print "Starting CherryPy at %s://%s:%s" % (scheme, hostname, port)
         server.start()
     except KeyboardInterrupt:
         server.stop()
开发者ID:cdent,项目名称:tiddlybeaker,代码行数:13,代码来源:__init__.py

示例10: CherryPyLiveServerPlugin

class CherryPyLiveServerPlugin(Plugin):
    name = 'cherrypyliveserver'
    activation_parameter = '--with-cherrypyliveserver'
    nosedjango = True

    def __init__(self):
        Plugin.__init__(self)
        self.server_started = False
        self.server_thread = None

    def options(self, parser, env=os.environ):
        Plugin.options(self, parser, env)

    def configure(self, options, config):
        Plugin.configure(self, options, config)

    def startTest(self, test):
        from django.conf import settings

        if not self.server_started and \
           getattr(test, 'start_live_server', False):

            self.start_server(
                address=getattr(settings, "LIVE_SERVER_ADDRESS", DEFAULT_LIVE_SERVER_ADDRESS),
                port=int(getattr(settings, "LIVE_SERVER_PORT", DEFAULT_LIVE_SERVER_PORT))
            )
            self.server_started = True

    def finalize(self, result):
        self.stop_test_server()

    def start_server(self, address='0.0.0.0', port=8000):
        _application = AdminMediaHandler(WSGIHandler())

        def application(environ, start_response):
            environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
            return _application(environ, start_response)

        from cherrypy.wsgiserver import CherryPyWSGIServer
        from threading import Thread
        self.httpd = CherryPyWSGIServer((address, port), application, server_name='django-test-http')
        self.httpd_thread = Thread(target=self.httpd.start)
        self.httpd_thread.start()
        #FIXME: This could be avoided by passing self to thread class starting django
        # and waiting for Event lock
        time.sleep(.5)

    def stop_test_server(self):
        if self.server_started:
            self.httpd.stop()
            self.server_started = False
开发者ID:PolicyStat,项目名称:nosedjango,代码行数:51,代码来源:cherrypy_plugin.py

示例11: start_server

def start_server(config):
    """
    Make a server and start it up as a daemon.
    """
    port = int(config['port'])
    local_host = config['local_host']

    server = CherryPyWSGIServer((local_host, port), create_app(config))

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
        sys.exit(0)
开发者ID:cdent,项目名称:tsapp,代码行数:14,代码来源:server.py

示例12: wsgi_worker_function

def wsgi_worker_function(options, args):
    if len(args) > 0:
        appfile = args[0]
        try:
            application = extract_application(appfile)
        except AttributeError:
            sys.exit("Could not find application in %s" % filename)

        server = CherryPyWSGIServer((options.host, int(options.port)), application, request_queue_size=500)
        print >>sys.stderr, "Serving on %s:%s\n" % (options.host, options.port)
        server.start()

    else:
        sys.exit("Is necesary application file.")
开发者ID:pombredanne,项目名称:py-cherryserver,代码行数:14,代码来源:cherryserver.py

示例13: serve

def serve(application, host='127.0.0.1', port=8080):
	"""CherryPy-based WSGI-HTTP server."""
	
	# Instantiate the server with our configuration and application.
	server = CherryPyWSGIServer((host, int(port)), application, server_name=host)
	
	# Try to be handy as many terminals allow clicking links.
	print("serving on http://{0}:{1}".format(host, port))
	
	# Bind and launch the server; this is a blocking operation.
	try:
		server.start()
	except KeyboardInterrupt:
		server.stop()  # CherryPy has some of its own shutdown work to do.
开发者ID:marrow,项目名称:WebCore,代码行数:14,代码来源:cherrypy_.py

示例14: handle

  def handle(self, **options):
    from cherrypy.wsgiserver import CherryPyWSGIServer

    # Determine the port number
    port = options['port']

    # Determine the number of threads
    threads = options['threads']
    if threads < 1:
      raise Exception("Invalid number of threads: %s" % threads)

    # Determine the IP-address to listen on:
    # - either as command line argument
    # - either 0.0.0.0 by default, which means all active IPv4 interfaces
    address = options['address'] or '0.0.0.0'

    # Validate the address and port number
    try:
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.bind( (address, port) )
      s.close()
    except socket.error as e:
      raise Exception("Invalid address '%s' and/or port '%s': %s" % (address, port, e))

    # Print a header message
    hostname = socket.getfqdn()
    print('Starting frePPLe %s web server\n' % VERSION)
    print('To access the server, point your browser to either of the following URLS:')
    if address == '0.0.0.0':
      print('    http://%s:%s/' % (hostname, port))
      for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
        print('    http://%s:%s/' % (ip, port))
    else:
      print('    http://%s:%s/' % (address, port))
    print('Quit the server with CTRL-C.\n')

    # Run the WSGI server
    server = CherryPyWSGIServer(
      (address, port),
      StaticFilesHandler(WSGIHandler()),
      numthreads=threads
      )
    # Want SSL support? Just set these attributes apparently, but I haven't tested or verified this
    #  server.ssl_certificate = <filename>
    #  server.ssl_private_key = <filename>
    try:
      server.start()
    except KeyboardInterrupt:
      server.stop()
开发者ID:frePPLe,项目名称:frePPLe,代码行数:49,代码来源:runwebserver.py

示例15: RunWSGIServer

class RunWSGIServer(Thread):

  def __init__(self, address, port):
    self.address = address
    self.port = port
    super(RunWSGIServer,self).__init__()

  def run(self):
    try:
      self.server = CherryPyWSGIServer((address, port),
        StaticFilesHandler(WSGIHandler())
        )
      self.server.start()
    except Exception as e:
      log("Server error: %s" % e)
开发者ID:bartyboy123,项目名称:frePPLe,代码行数:15,代码来源:freppleserver.py


注:本文中的cherrypy.wsgiserver.CherryPyWSGIServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。