How to use the cherrypy.config function in CherryPy

To help you get started, we’ve selected a few CherryPy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github h3llrais3r / Auto-Subliminal / lib / cherrypy / _cpmodpy.py View on Github external
# Run any setup functions defined by a "PythonOption cherrypy.setup"
    # directive.
    options = req.get_options()
    if 'cherrypy.setup' in options:
        for function in options['cherrypy.setup'].split():
            atoms = function.split('::', 1)
            if len(atoms) == 1:
                mod = __import__(atoms[0], globals(), locals())
            else:
                modname, fname = atoms
                mod = __import__(modname, globals(), locals(), [fname])
                func = getattr(mod, fname)
                func()

    cherrypy.config.update({'log.screen': False,
                            'tools.ignore_headers.on': True,
                            'tools.ignore_headers.headers': ['Range'],
                            })

    engine = cherrypy.engine
    if hasattr(engine, 'signal_handler'):
        engine.signal_handler.unsubscribe()
    if hasattr(engine, 'console_control_handler'):
        engine.console_control_handler.unsubscribe()
    engine.autoreload.unsubscribe()
    cherrypy.server.unsubscribe()

    @engine.subscribe('log')
    def _log(msg, level):
        newlevel = apache.APLOG_ERR
        if logging.DEBUG >= level:
github cylc / cylc-flow / lib / cherrypy / _cpmodpy.py View on Github external
# Run any setup functions defined by a "PythonOption cherrypy.setup"
    # directive.
    options = req.get_options()
    if 'cherrypy.setup' in options:
        for function in options['cherrypy.setup'].split():
            atoms = function.split('::', 1)
            if len(atoms) == 1:
                mod = __import__(atoms[0], globals(), locals())
            else:
                modname, fname = atoms
                mod = __import__(modname, globals(), locals(), [fname])
                func = getattr(mod, fname)
                func()

    cherrypy.config.update({'log.screen': False,
                            "tools.ignore_headers.on": True,
                            "tools.ignore_headers.headers": ['Range'],
                            })

    engine = cherrypy.engine
    if hasattr(engine, "signal_handler"):
        engine.signal_handler.unsubscribe()
    if hasattr(engine, "console_control_handler"):
        engine.console_control_handler.unsubscribe()
    engine.autoreload.unsubscribe()
    cherrypy.server.unsubscribe()

    def _log(msg, level):
        newlevel = apache.APLOG_ERR
        if logging.DEBUG >= level:
            newlevel = apache.APLOG_DEBUG
github elamperti / bastardbot / webserver / webserver.py View on Github external
import os

import cherrypy

from models import *
from webserver.controllers import *
from webserver.plugins.googleapiplugin import GoogleApiPlugin

cherrypy.config.update({
    'server.socket_host': '0.0.0.0',  # Make it visible from everywhere
    'server.socket_port': 8080, 
    'log.screen': True,
    'engine.autoreload.on': True
})

class BastardBot(object):
    def __init__(self):
        conf = {
            '/': {
                'tools.sessions.on': True,
                'tools.sessions.storage_type': "file",
                'tools.sessions.storage_path': "webserver/sessions",
                'tools.sessions.timeout': 60
            }
        }
github 05sonicblue / GamezServer / cherrypy / lib / covercp.py View on Github external
def serve(path=localFile, port=8080, root=None):
    if coverage is None:
        raise ImportError("The coverage module could not be imported.")
    from coverage import coverage
    cov = coverage(data_file=path)
    cov.load()

    import cherrypy
    cherrypy.config.update({'server.socket_port': int(port),
                            'server.thread_pool': 10,
                            'environment': "production",
                            })
    cherrypy.quickstart(CoverStats(cov, root))
github jpwright / enmodal / server.py View on Github external
def run_server():
    # Enable WSGI access logging via Paste
    app_logged = TransLogger(app)

    # Mount the WSGI callable object (app) on the root directory
    cherrypy.tree.graft(app_logged, '/')

    # Set the configuration of the web server
    cherrypy.config.update({
        'engine.autoreload_on': True,
        'log.screen': True,
        'server.socket_port': PORT,
        'server.socket_host': '0.0.0.0'
    })

    # Start the CherryPy WSGI web server
    cherrypy.engine.start()
    cherrypy.engine.block()
github chaostoolkit / chaostoolkit-documentation / shared / code / tutorials / a-simple-walkthrough / sunset.py View on Github external
def run():

    cherrypy.config.update({
        "environment": "production",
        "log.screen": True,
        "server.socket_port": 8443,
        "server.ssl_module": "builtin",
        "server.ssl_private_key": key_path,
        "server.ssl_certificate": cert_path
    })
    PIDFile(cherrypy.engine, 'sunset.pid').subscribe()
    cherrypy.quickstart(Root())
github castorini / honk / server.py View on Github external
def start(config):
    cherrypy.config.update({
        "environment": "production",
        "log.screen": True
    })
    cherrypy.config.update(config["server"])
    rest_config = {"/": {
        "request.dispatch": cherrypy.dispatch.MethodDispatcher()
    }}
    train_script = make_abspath(config["train_script"])
    speech_dataset_path = make_abspath(config["speech_dataset_path"])
    lbl_service = load_service(config)
    train_service = TrainingService(train_script, speech_dataset_path, config["model_options"])
    cherrypy.tree.mount(ListenEndpoint(lbl_service), "/listen", rest_config)
    cherrypy.tree.mount(DataEndpoint(train_service), "/data", rest_config)
    cherrypy.tree.mount(EvaluateEndpoint(lbl_service), "/evaluate", rest_config)
    cherrypy.tree.mount(TrainEndpoint(train_service, lbl_service), "/train", rest_config)
    cherrypy.engine.start()
    cherrypy.engine.block()
github Cloud-CV / py-cloudcv / pcloudcv / connections / local_server.py View on Github external
def run(self):
        """
        Checks if port 8000 is free and starts running CherryPy server on the port.
        """
        with self.sync:
            try:
                cherrypy.process.servers.check_port('127.0.0.1', 8000)
            except IOError:
                sys.stderr.write("The port %s is not free\n" % 8000)


        cherrypy.config.update({'log.screen': False,
                        'log.error_file': None,
                        #'log.error_log': None
                        })

        cherrypy.server.socket_port = 8000
        cherrypy.quickstart(Path())
github kodi-community-addons / plugin.audio.spotify / resources / libs / cherrypy / tutorial / tut10_http_errors.py View on Github external
def toggleTracebacks(self):
        # simple function to toggle tracebacks on and off
        tracebacks = cherrypy.request.show_tracebacks
        cherrypy.config.update({'request.show_tracebacks': not tracebacks})

        # redirect back to the index
        raise cherrypy.HTTPRedirect('/')
github CouchPotato / CouchPotatoV1 / library / minify / __init__.py View on Github external
def minify(self, type, files, out):
        base = os.path.join(cherrypy.config.get('basePath'), 'media', type)
        url = 'cache/minify/' + out
        cache = os.path.join(cherrypy.config.get('runPath'), 'cache', 'minify')
        out = os.path.join(cache, out)

        # Check for dates, minify only on newer files
        goMinify = True
        if os.path.isfile(out):
            outTimestamp = int(os.path.getmtime(out))
            goMinify = False
            for file in files:
                fullPath = os.path.join(base, file)
                if int(os.path.getmtime(fullPath)) > outTimestamp:
                    goMinify = True

        if goMinify:
            log.debug('Minifying JS.')