Python cherrypy.tree() Examples

The following are 21 code examples of cherrypy.tree(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cherrypy , or try the search function .
Example #1
Source File: helper.py    From bazarr with GNU General Public License v3.0 6 votes vote down vote up
def get_app(self, app=None):
        """Obtain a new (decorated) WSGI app to hook into the origin server."""
        if app is None:
            app = cherrypy.tree

        if self.validate:
            try:
                from wsgiref import validate
            except ImportError:
                warnings.warn(
                    'Error importing wsgiref. The validator will not run.')
            else:
                # wraps the app in the validator
                app = validate.validator(app)

        return app 
Example #2
Source File: helper.py    From moviegrabber with GNU General Public License v3.0 6 votes vote down vote up
def get_app(self, app=None):
        """Obtain a new (decorated) WSGI app to hook into the origin server."""
        if app is None:
            app = cherrypy.tree
        
        if self.conquer:
            try:
                import wsgiconq
            except ImportError:
                warnings.warn("Error importing wsgiconq. pyconquer will not run.")
            else:
                app = wsgiconq.WSGILogger(app, c_calls=True)
        
        if self.validate:
            try:
                from wsgiref import validate
            except ImportError:
                warnings.warn("Error importing wsgiref. The validator will not run.")
            else:
                #wraps the app in the validator
                app = validate.validator(app)
        
        return app 
Example #3
Source File: modwsgi.py    From moviegrabber with GNU General Public License v3.0 6 votes vote down vote up
def application(environ, start_response):
    import cherrypy
    global loaded
    if not loaded:
        loaded = True
        modname = "cherrypy.test." + environ['testmod']
        mod = __import__(modname, globals(), locals(), [''])
        mod.setup_server()
        
        cherrypy.config.update({
            "log.error_file": os.path.join(curdir, "test.error.log"),
            "log.access_file": os.path.join(curdir, "test.access.log"),
            "environment": "test_suite",
            "engine.SIGHUP": None,
            "engine.SIGTERM": None,
            })
    return cherrypy.tree(environ, start_response) 
Example #4
Source File: helper.py    From Tautulli with GNU General Public License v3.0 6 votes vote down vote up
def get_app(self, app=None):
        """Obtain a new (decorated) WSGI app to hook into the origin server."""
        if app is None:
            app = cherrypy.tree

        if self.validate:
            try:
                from wsgiref import validate
            except ImportError:
                warnings.warn(
                    'Error importing wsgiref. The validator will not run.')
            else:
                # wraps the app in the validator
                app = validate.validator(app)

        return app 
Example #5
Source File: modwsgi.py    From Tautulli with GNU General Public License v3.0 6 votes vote down vote up
def application(environ, start_response):
    global loaded
    if not loaded:
        loaded = True
        modname = 'cherrypy.test.' + environ['testmod']
        mod = __import__(modname, globals(), locals(), [''])
        mod.setup_server()

        cherrypy.config.update({
            'log.error_file': os.path.join(curdir, 'test.error.log'),
            'log.access_file': os.path.join(curdir, 'test.access.log'),
            'environment': 'test_suite',
            'engine.SIGHUP': None,
            'engine.SIGTERM': None,
        })
    return cherrypy.tree(environ, start_response) 
Example #6
Source File: modwsgi.py    From bazarr with GNU General Public License v3.0 6 votes vote down vote up
def application(environ, start_response):
    import cherrypy
    global loaded
    if not loaded:
        loaded = True
        modname = 'cherrypy.test.' + environ['testmod']
        mod = __import__(modname, globals(), locals(), [''])
        mod.setup_server()

        cherrypy.config.update({
            'log.error_file': os.path.join(curdir, 'test.error.log'),
            'log.access_file': os.path.join(curdir, 'test.access.log'),
            'environment': 'test_suite',
            'engine.SIGHUP': None,
            'engine.SIGTERM': None,
        })
    return cherrypy.tree(environ, start_response) 
Example #7
Source File: helper.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_app(self, app=None):
        """Obtain a new (decorated) WSGI app to hook into the origin server."""
        if app is None:
            app = cherrypy.tree

        if self.validate:
            try:
                from wsgiref import validate
            except ImportError:
                warnings.warn(
                    'Error importing wsgiref. The validator will not run.')
            else:
                # wraps the app in the validator
                app = validate.validator(app)

        return app 
Example #8
Source File: modwsgi.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def application(environ, start_response):
    global loaded
    if not loaded:
        loaded = True
        modname = 'cherrypy.test.' + environ['testmod']
        mod = __import__(modname, globals(), locals(), [''])
        mod.setup_server()

        cherrypy.config.update({
            'log.error_file': os.path.join(curdir, 'test.error.log'),
            'log.access_file': os.path.join(curdir, 'test.access.log'),
            'environment': 'test_suite',
            'engine.SIGHUP': None,
            'engine.SIGTERM': None,
        })
    return cherrypy.tree(environ, start_response) 
Example #9
Source File: modfastcgi.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def erase_script_name(environ, start_response):
    environ['SCRIPT_NAME'] = ''
    return cherrypy.tree(environ, start_response) 
Example #10
Source File: modfcgid.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def start(self, modulename):
        cherrypy.server.httpserver = servers.FlupFCGIServer(
            application=cherrypy.tree, bindAddress=('127.0.0.1', 4000))
        cherrypy.server.httpserver.bind_addr = ('127.0.0.1', 4000)
        # For FCGI, we both start apache...
        self.start_apache()
        # ...and our local server
        helper.LocalServer.start(self, modulename) 
Example #11
Source File: modfastcgi.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def erase_script_name(environ, start_response):
    environ['SCRIPT_NAME'] = ''
    return cherrypy.tree(environ, start_response) 
Example #12
Source File: modfcgid.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def start(self, modulename):
        cherrypy.server.httpserver = servers.FlupFCGIServer(
            application=cherrypy.tree, bindAddress=('127.0.0.1', 4000))
        cherrypy.server.httpserver.bind_addr = ('127.0.0.1', 4000)
        # For FCGI, we both start apache...
        self.start_apache()
        # ...and our local server
        helper.LocalServer.start(self, modulename) 
Example #13
Source File: _cpwsgi_server.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, server_adapter=cherrypy.server):
        self.server_adapter = server_adapter
        self.max_request_header_size = self.server_adapter.max_request_header_size or 0
        self.max_request_body_size = self.server_adapter.max_request_body_size or 0
        
        server_name = (self.server_adapter.socket_host or
                       self.server_adapter.socket_file or
                       None)
        
        self.wsgi_version = self.server_adapter.wsgi_version
        s = wsgiserver.CherryPyWSGIServer
        s.__init__(self, server_adapter.bind_addr, cherrypy.tree,
                   self.server_adapter.thread_pool,
                   server_name,
                   max = self.server_adapter.thread_pool_max,
                   request_queue_size = self.server_adapter.socket_queue_size,
                   timeout = self.server_adapter.socket_timeout,
                   shutdown_timeout = self.server_adapter.shutdown_timeout,
                   )
        self.protocol = self.server_adapter.protocol_version
        self.nodelay = self.server_adapter.nodelay

        if sys.version_info >= (3, 0):
            ssl_module = self.server_adapter.ssl_module or 'builtin'
        else:
            ssl_module = self.server_adapter.ssl_module or 'pyopenssl'
        if self.server_adapter.ssl_context:
            adapter_class = wsgiserver.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain)
            self.ssl_adapter.context = self.server_adapter.ssl_context
        elif self.server_adapter.ssl_certificate:
            adapter_class = wsgiserver.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain)
        
        self.stats['Enabled'] = getattr(self.server_adapter, 'statistics', False) 
Example #14
Source File: modfastcgi.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
def erase_script_name(environ, start_response):
    environ['SCRIPT_NAME'] = ''
    return cherrypy.tree(environ, start_response) 
Example #15
Source File: modfcgid.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
def start(self, modulename):
        cherrypy.server.httpserver = servers.FlupFCGIServer(
            application=cherrypy.tree, bindAddress=('127.0.0.1', 4000))
        cherrypy.server.httpserver.bind_addr = ('127.0.0.1', 4000)
        # For FCGI, we both start apache...
        self.start_apache()
        # ...and our local server
        helper.LocalServer.start(self, modulename) 
Example #16
Source File: modfcgid.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def start(self, modulename):
        cherrypy.server.httpserver = servers.FlupFCGIServer(
            application=cherrypy.tree, bindAddress=('127.0.0.1', 4000))
        cherrypy.server.httpserver.bind_addr = ('127.0.0.1', 4000)
        # For FCGI, we both start apache...
        self.start_apache()
        # ...and our local server
        helper.LocalServer.start(self, modulename) 
Example #17
Source File: modfastcgi.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def erase_script_name(environ, start_response):
    environ['SCRIPT_NAME'] = ''
    return cherrypy.tree(environ, start_response) 
Example #18
Source File: _cpwsgi_server.py    From bazarr with GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, server_adapter=cherrypy.server):
        self.server_adapter = server_adapter
        self.max_request_header_size = (
            self.server_adapter.max_request_header_size or 0
        )
        self.max_request_body_size = (
            self.server_adapter.max_request_body_size or 0
        )

        server_name = (self.server_adapter.socket_host or
                       self.server_adapter.socket_file or
                       None)

        self.wsgi_version = self.server_adapter.wsgi_version
        s = wsgiserver.CherryPyWSGIServer
        s.__init__(self, server_adapter.bind_addr, cherrypy.tree,
                   self.server_adapter.thread_pool,
                   server_name,
                   max=self.server_adapter.thread_pool_max,
                   request_queue_size=self.server_adapter.socket_queue_size,
                   timeout=self.server_adapter.socket_timeout,
                   shutdown_timeout=self.server_adapter.shutdown_timeout,
                   accepted_queue_size=self.server_adapter.accepted_queue_size,
                   accepted_queue_timeout=self.server_adapter.accepted_queue_timeout,
                   )
        self.protocol = self.server_adapter.protocol_version
        self.nodelay = self.server_adapter.nodelay

        if sys.version_info >= (3, 0):
            ssl_module = self.server_adapter.ssl_module or 'builtin'
        else:
            ssl_module = self.server_adapter.ssl_module or 'pyopenssl'
        if self.server_adapter.ssl_context:
            adapter_class = wsgiserver.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain)
            self.ssl_adapter.context = self.server_adapter.ssl_context
        elif self.server_adapter.ssl_certificate:
            adapter_class = wsgiserver.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain)

        self.stats['Enabled'] = getattr(
            self.server_adapter, 'statistics', False) 
Example #19
Source File: _cpwsgi_server.py    From opsbro with MIT License 4 votes vote down vote up
def __init__(self, server_adapter=cherrypy.server):
        self.server_adapter = server_adapter
        self.max_request_header_size = (
            self.server_adapter.max_request_header_size or 0
        )
        self.max_request_body_size = (
            self.server_adapter.max_request_body_size or 0
        )

        server_name = (self.server_adapter.socket_host or
                       self.server_adapter.socket_file or
                       None)

        self.wsgi_version = self.server_adapter.wsgi_version
        s = wsgiserver.CherryPyWSGIServer
        s.__init__(self, server_adapter.bind_addr, cherrypy.tree,
                   self.server_adapter.thread_pool,
                   server_name,
                   max=self.server_adapter.thread_pool_max,
                   request_queue_size=self.server_adapter.socket_queue_size,
                   timeout=self.server_adapter.socket_timeout,
                   shutdown_timeout=self.server_adapter.shutdown_timeout,
                   accepted_queue_size=self.server_adapter.accepted_queue_size,
                   accepted_queue_timeout=self.server_adapter.accepted_queue_timeout,
                   )
        self.protocol = self.server_adapter.protocol_version
        self.nodelay = self.server_adapter.nodelay

        if sys.version_info >= (3, 0):
            ssl_module = self.server_adapter.ssl_module or 'builtin'
        else:
            ssl_module = self.server_adapter.ssl_module or 'pyopenssl'
        if self.server_adapter.ssl_context:
            adapter_class = wsgiserver.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain)
            self.ssl_adapter.context = self.server_adapter.ssl_context
        elif self.server_adapter.ssl_certificate:
            adapter_class = wsgiserver.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain)

        self.stats['Enabled'] = getattr(
            self.server_adapter, 'statistics', False) 
Example #20
Source File: _cpwsgi_server.py    From cherrypy with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def __init__(self, server_adapter=cherrypy.server):
        """Initialize CPWSGIServer instance.

        Args:
            server_adapter (cherrypy._cpserver.Server): ...
        """
        self.server_adapter = server_adapter
        self.max_request_header_size = (
            self.server_adapter.max_request_header_size or 0
        )
        self.max_request_body_size = (
            self.server_adapter.max_request_body_size or 0
        )

        server_name = (self.server_adapter.socket_host or
                       self.server_adapter.socket_file or
                       None)

        self.wsgi_version = self.server_adapter.wsgi_version

        super(CPWSGIServer, self).__init__(
            server_adapter.bind_addr, cherrypy.tree,
            self.server_adapter.thread_pool,
            server_name,
            max=self.server_adapter.thread_pool_max,
            request_queue_size=self.server_adapter.socket_queue_size,
            timeout=self.server_adapter.socket_timeout,
            shutdown_timeout=self.server_adapter.shutdown_timeout,
            accepted_queue_size=self.server_adapter.accepted_queue_size,
            accepted_queue_timeout=self.server_adapter.accepted_queue_timeout,
            peercreds_enabled=self.server_adapter.peercreds,
            peercreds_resolve_enabled=self.server_adapter.peercreds_resolve,
        )
        self.ConnectionClass.RequestHandlerClass = CPWSGIHTTPRequest

        self.protocol = self.server_adapter.protocol_version
        self.nodelay = self.server_adapter.nodelay

        if sys.version_info >= (3, 0):
            ssl_module = self.server_adapter.ssl_module or 'builtin'
        else:
            ssl_module = self.server_adapter.ssl_module or 'pyopenssl'
        if self.server_adapter.ssl_context:
            adapter_class = cheroot.server.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain,
                self.server_adapter.ssl_ciphers)
            self.ssl_adapter.context = self.server_adapter.ssl_context
        elif self.server_adapter.ssl_certificate:
            adapter_class = cheroot.server.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain,
                self.server_adapter.ssl_ciphers)

        self.stats['Enabled'] = getattr(
            self.server_adapter, 'statistics', False) 
Example #21
Source File: _cpwsgi_server.py    From Tautulli with GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, server_adapter=cherrypy.server):
        """Initialize CPWSGIServer instance.

        Args:
            server_adapter (cherrypy._cpserver.Server): ...
        """
        self.server_adapter = server_adapter
        self.max_request_header_size = (
            self.server_adapter.max_request_header_size or 0
        )
        self.max_request_body_size = (
            self.server_adapter.max_request_body_size or 0
        )

        server_name = (self.server_adapter.socket_host or
                       self.server_adapter.socket_file or
                       None)

        self.wsgi_version = self.server_adapter.wsgi_version

        super(CPWSGIServer, self).__init__(
            server_adapter.bind_addr, cherrypy.tree,
            self.server_adapter.thread_pool,
            server_name,
            max=self.server_adapter.thread_pool_max,
            request_queue_size=self.server_adapter.socket_queue_size,
            timeout=self.server_adapter.socket_timeout,
            shutdown_timeout=self.server_adapter.shutdown_timeout,
            accepted_queue_size=self.server_adapter.accepted_queue_size,
            accepted_queue_timeout=self.server_adapter.accepted_queue_timeout,
            peercreds_enabled=self.server_adapter.peercreds,
            peercreds_resolve_enabled=self.server_adapter.peercreds_resolve,
        )
        self.ConnectionClass.RequestHandlerClass = CPWSGIHTTPRequest

        self.protocol = self.server_adapter.protocol_version
        self.nodelay = self.server_adapter.nodelay

        if sys.version_info >= (3, 0):
            ssl_module = self.server_adapter.ssl_module or 'builtin'
        else:
            ssl_module = self.server_adapter.ssl_module or 'pyopenssl'
        if self.server_adapter.ssl_context:
            adapter_class = cheroot.server.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain,
                self.server_adapter.ssl_ciphers)
            self.ssl_adapter.context = self.server_adapter.ssl_context
        elif self.server_adapter.ssl_certificate:
            adapter_class = cheroot.server.get_ssl_adapter_class(ssl_module)
            self.ssl_adapter = adapter_class(
                self.server_adapter.ssl_certificate,
                self.server_adapter.ssl_private_key,
                self.server_adapter.ssl_certificate_chain,
                self.server_adapter.ssl_ciphers)

        self.stats['Enabled'] = getattr(
            self.server_adapter, 'statistics', False)