Python cherrypy.Application() Examples
The following are 30
code examples of cherrypy.Application().
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: _cpchecker.py From bazarr with GNU General Public License v3.0 | 6 votes |
def check_app_config_brackets(self): """Check for Application config with extraneous brackets in section names. """ for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: continue for key in app.config.keys(): if key.startswith('[') or key.endswith(']'): warnings.warn( 'The application mounted at %r has config ' 'section names with extraneous brackets: %r. ' 'Config *files* need brackets; config *dicts* ' '(e.g. passed to tree.mount) do not.' % (sn, key))
Example #2
Source File: _cpconfig.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def merge(base, other): """Merge one app config (from a dict, file, or filename) into another. If the given config is a filename, it will be appended to the list of files to monitor for "autoreload" changes. """ if isinstance(other, basestring): cherrypy.engine.autoreload.files.add(other) # Load other into base for section, value_map in reprconf.as_dict(other).items(): if not isinstance(value_map, dict): raise ValueError( "Application config must include section headers, but the " "config you tried to merge doesn't have any sections. " "Wrap your config in another dict with paths as section " "headers, for example: {'/': config}.") base.setdefault(section, {}).update(value_map)
Example #3
Source File: test_wsgi_vhost.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def setup_server(): class ClassOfRoot(object): def __init__(self, name): self.name = name def index(self): return "Welcome to the %s website!" % self.name index.exposed = True default = cherrypy.Application(None) domains = {} for year in range(1997, 2008): app = cherrypy.Application(ClassOfRoot('Class of %s' % year)) domains['www.classof%s.example' % year] = app cherrypy.tree.graft(cherrypy._cpwsgi.VirtualHost(default, domains))
Example #4
Source File: _cpchecker.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def check_site_config_entries_in_app_config(self): """Check for mounted Applications that have site-scoped config.""" for sn, app in iteritems(cherrypy.tree.apps): if not isinstance(app, cherrypy.Application): continue msg = [] for section, entries in iteritems(app.config): if section.startswith('/'): for key, value in iteritems(entries): for n in ("engine.", "server.", "tree.", "checker."): if key.startswith(n): msg.append("[%s] %s = %s" % (section, key, value)) if msg: msg.insert(0, "The application mounted at %r contains the following " "config entries, which are only allowed in site-wide " "config. Move them to a [global] section and pass them " "to cherrypy.config.update() instead of tree.mount()." % sn) warnings.warn(os.linesep.join(msg))
Example #5
Source File: _cpchecker.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def check_app_config_entries_dont_start_with_script_name(self): """Check for Application config with sections that repeat script_name.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: continue if sn == '': continue sn_atoms = sn.strip("/").split("/") for key in app.config.keys(): key_atoms = key.strip("/").split("/") if key_atoms[:len(sn_atoms)] == sn_atoms: warnings.warn( "The application mounted at %r has config " \ "entries that start with its script name: %r" % (sn, key))
Example #6
Source File: test_wsgi_vhost.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def setup_server(): class ClassOfRoot(object): def __init__(self, name): self.name = name @cherrypy.expose def index(self): return 'Welcome to the %s website!' % self.name default = cherrypy.Application(None) domains = {} for year in range(1997, 2008): app = cherrypy.Application(ClassOfRoot('Class of %s' % year)) domains['www.classof%s.example' % year] = app cherrypy.tree.graft(cherrypy._cpwsgi.VirtualHost(default, domains))
Example #7
Source File: _cpchecker.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def check_site_config_entries_in_app_config(self): """Check for mounted Applications that have site-scoped config.""" for sn, app in six.iteritems(cherrypy.tree.apps): if not isinstance(app, cherrypy.Application): continue msg = [] for section, entries in six.iteritems(app.config): if section.startswith('/'): for key, value in six.iteritems(entries): for n in ('engine.', 'server.', 'tree.', 'checker.'): if key.startswith(n): msg.append('[%s] %s = %s' % (section, key, value)) if msg: msg.insert(0, 'The application mounted at %r contains the ' 'following config entries, which are only allowed ' 'in site-wide config. Move them to a [global] ' 'section and pass them to cherrypy.config.update() ' 'instead of tree.mount().' % sn) warnings.warn(os.linesep.join(msg))
Example #8
Source File: _cpchecker.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def check_app_config_entries_dont_start_with_script_name(self): """Check for App config with sections that repeat script_name.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: continue if sn == '': continue sn_atoms = sn.strip('/').split('/') for key in app.config.keys(): key_atoms = key.strip('/').split('/') if key_atoms[:len(sn_atoms)] == sn_atoms: warnings.warn( 'The application mounted at %r has config ' 'entries that start with its script name: %r' % (sn, key))
Example #9
Source File: _cpconfig.py From bazarr with GNU General Public License v3.0 | 6 votes |
def merge(base, other): """Merge one app config (from a dict, file, or filename) into another. If the given config is a filename, it will be appended to the list of files to monitor for "autoreload" changes. """ if isinstance(other, text_or_bytes): cherrypy.engine.autoreload.files.add(other) # Load other into base for section, value_map in reprconf.as_dict(other).items(): if not isinstance(value_map, dict): raise ValueError( 'Application config must include section headers, but the ' "config you tried to merge doesn't have any sections. " 'Wrap your config in another dict with paths as section ' "headers, for example: {'/': config}.") base.setdefault(section, {}).update(value_map)
Example #10
Source File: test_wsgi_vhost.py From bazarr with GNU General Public License v3.0 | 6 votes |
def setup_server(): class ClassOfRoot(object): def __init__(self, name): self.name = name @cherrypy.expose def index(self): return 'Welcome to the %s website!' % self.name default = cherrypy.Application(None) domains = {} for year in range(1997, 2008): app = cherrypy.Application(ClassOfRoot('Class of %s' % year)) domains['www.classof%s.example' % year] = app cherrypy.tree.graft(cherrypy._cpwsgi.VirtualHost(default, domains))
Example #11
Source File: _cpchecker.py From bazarr with GNU General Public License v3.0 | 6 votes |
def check_site_config_entries_in_app_config(self): """Check for mounted Applications that have site-scoped config.""" for sn, app in iteritems(cherrypy.tree.apps): if not isinstance(app, cherrypy.Application): continue msg = [] for section, entries in iteritems(app.config): if section.startswith('/'): for key, value in iteritems(entries): for n in ('engine.', 'server.', 'tree.', 'checker.'): if key.startswith(n): msg.append('[%s] %s = %s' % (section, key, value)) if msg: msg.insert(0, 'The application mounted at %r contains the ' 'following config entries, which are only allowed ' 'in site-wide config. Move them to a [global] ' 'section and pass them to cherrypy.config.update() ' 'instead of tree.mount().' % sn) warnings.warn(os.linesep.join(msg))
Example #12
Source File: _cpchecker.py From bazarr with GNU General Public License v3.0 | 6 votes |
def check_app_config_entries_dont_start_with_script_name(self): """Check for Application config with sections that repeat script_name. """ for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: continue if sn == '': continue sn_atoms = sn.strip('/').split('/') for key in app.config.keys(): key_atoms = key.strip('/').split('/') if key_atoms[:len(sn_atoms)] == sn_atoms: warnings.warn( 'The application mounted at %r has config ' 'entries that start with its script name: %r' % (sn, key))
Example #13
Source File: _cpconfig.py From opsbro with MIT License | 6 votes |
def merge(base, other): """Merge one app config (from a dict, file, or filename) into another. If the given config is a filename, it will be appended to the list of files to monitor for "autoreload" changes. """ if isinstance(other, basestring): cherrypy.engine.autoreload.files.add(other) # Load other into base for section, value_map in reprconf.as_dict(other).items(): if not isinstance(value_map, dict): raise ValueError( "Application config must include section headers, but the " "config you tried to merge doesn't have any sections. " "Wrap your config in another dict with paths as section " "headers, for example: {'/': config}.") base.setdefault(section, {}).update(value_map)
Example #14
Source File: _cpchecker.py From opsbro with MIT License | 6 votes |
def check_app_config_brackets(self): """Check for Application config with extraneous brackets in section names. """ for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: continue for key in app.config.keys(): if key.startswith("[") or key.endswith("]"): warnings.warn( "The application mounted at %r has config " "section names with extraneous brackets: %r. " "Config *files* need brackets; config *dicts* " "(e.g. passed to tree.mount) do not." % (sn, key))
Example #15
Source File: _cpchecker.py From opsbro with MIT License | 6 votes |
def check_site_config_entries_in_app_config(self): """Check for mounted Applications that have site-scoped config.""" for sn, app in iteritems(cherrypy.tree.apps): if not isinstance(app, cherrypy.Application): continue msg = [] for section, entries in iteritems(app.config): if section.startswith('/'): for key, value in iteritems(entries): for n in ("engine.", "server.", "tree.", "checker."): if key.startswith(n): msg.append("[%s] %s = %s" % (section, key, value)) if msg: msg.insert(0, "The application mounted at %r contains the " "following config entries, which are only allowed " "in site-wide config. Move them to a [global] " "section and pass them to cherrypy.config.update() " "instead of tree.mount()." % sn) warnings.warn(os.linesep.join(msg))
Example #16
Source File: test_wsgi_vhost.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def setup_server(): class ClassOfRoot(object): def __init__(self, name): self.name = name @cherrypy.expose def index(self): return 'Welcome to the %s website!' % self.name default = cherrypy.Application(None) domains = {} for year in range(1997, 2008): app = cherrypy.Application(ClassOfRoot('Class of %s' % year)) domains['www.classof%s.example' % year] = app cherrypy.tree.graft(cherrypy._cpwsgi.VirtualHost(default, domains))
Example #17
Source File: _cpchecker.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def check_site_config_entries_in_app_config(self): """Check for mounted Applications that have site-scoped config.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue msg = [] for section, entries in app.config.items(): if section.startswith('/'): for key, value in entries.items(): for n in ('engine.', 'server.', 'tree.', 'checker.'): if key.startswith(n): msg.append('[%s] %s = %s' % (section, key, value)) if msg: msg.insert(0, 'The application mounted at %r contains the ' 'following config entries, which are only allowed ' 'in site-wide config. Move them to a [global] ' 'section and pass them to cherrypy.config.update() ' 'instead of tree.mount().' % sn) warnings.warn(os.linesep.join(msg))
Example #18
Source File: desktop_app_main.py From djanban with MIT License | 6 votes |
def add_server(self, netloc, path, config): """Add a new CherryPy Application for a Virtual Host. Creates a new CherryPy WSGI Server instance if the host resolves to a different IP address or port. """ from cherrypy._cpwsgi_server import CPWSGIServer from cherrypy.process.servers import ServerAdapter host, port = urllib.splitnport(netloc, 80) host = socket.gethostbyname(host) bind_addr = (host, port) if bind_addr not in self.servers: self.servers.append(bind_addr) server = CPWSGIServer() server.bind_addr = bind_addr adapter = ServerAdapter(cherrypy.engine, server, server.bind_addr) adapter.subscribe() self.domains[netloc] = cherrypy.Application(root=None, config={path.rstrip('/') or '/': config})
Example #19
Source File: _cpchecker.py From opsbro with MIT License | 6 votes |
def check_app_config_entries_dont_start_with_script_name(self): """Check for Application config with sections that repeat script_name. """ for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: continue if sn == '': continue sn_atoms = sn.strip("/").split("/") for key in app.config.keys(): key_atoms = key.strip("/").split("/") if key_atoms[:len(sn_atoms)] == sn_atoms: warnings.warn( "The application mounted at %r has config " "entries that start with its script name: %r" % (sn, key))
Example #20
Source File: _cpchecker.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def check_app_config_entries_dont_start_with_script_name(self): """Check for App config with sections that repeat script_name.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: continue if sn == '': continue sn_atoms = sn.strip('/').split('/') for key in app.config.keys(): key_atoms = key.strip('/').split('/') if key_atoms[:len(sn_atoms)] == sn_atoms: warnings.warn( 'The application mounted at %r has config ' 'entries that start with its script name: %r' % (sn, key))
Example #21
Source File: _cpchecker.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def check_config_types(self): """Assert that config values are of the same type as default values.""" self._known_types(cherrypy.config) for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue self._known_types(app.config) # -------------------- Specific config warnings -------------------- #
Example #22
Source File: _cpchecker.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def check_config_namespaces(self): """Process config and warn on each unknown config namespace.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue self._known_ns(app) # -------------------------- Config Types -------------------------- #
Example #23
Source File: _cpchecker.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def check_compatibility(self): """Process config and warn on each obsolete or deprecated entry.""" self._compat(cherrypy.config) for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue self._compat(app.config) # ------------------------ Known Namespaces ------------------------ #
Example #24
Source File: _cpchecker.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def check_app_config_brackets(self): """Check for Application config with extraneous brackets in section names.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: continue for key in app.config.keys(): if key.startswith("[") or key.endswith("]"): warnings.warn( "The application mounted at %r has config " \ "section names with extraneous brackets: %r. " "Config *files* need brackets; config *dicts* " "(e.g. passed to tree.mount) do not." % (sn, key))
Example #25
Source File: _cpchecker.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def check_skipped_app_config(self): """Check for mounted Applications that have no config.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: msg = "The Application mounted at %r has an empty config." % sn if self.global_config_contained_paths: msg += (" It looks like the config you passed to " "cherrypy.config.update() contains application-" "specific sections. You must explicitly pass " "application config via " "cherrypy.tree.mount(..., config=app_config)") warnings.warn(msg) return
Example #26
Source File: _cpchecker.py From opsbro with MIT License | 5 votes |
def check_skipped_app_config(self): """Check for mounted Applications that have no config.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: msg = "The Application mounted at %r has an empty config." % sn if self.global_config_contained_paths: msg += (" It looks like the config you passed to " "cherrypy.config.update() contains application-" "specific sections. You must explicitly pass " "application config via " "cherrypy.tree.mount(..., config=app_config)") warnings.warn(msg) return
Example #27
Source File: _cpchecker.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def check_skipped_app_config(self): """Check for mounted Applications that have no config.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue if not app.config: msg = 'The Application mounted at %r has an empty config.' % sn if self.global_config_contained_paths: msg += (' It looks like the config you passed to ' 'cherrypy.config.update() contains application-' 'specific sections. You must explicitly pass ' 'application config via ' 'cherrypy.tree.mount(..., config=app_config)') warnings.warn(msg) return
Example #28
Source File: _cpchecker.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def check_config_types(self): """Assert that config values are of the same type as default values.""" self._known_types(cherrypy.config) for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue self._known_types(app.config) # -------------------- Specific config warnings -------------------- #
Example #29
Source File: _cpchecker.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def check_config_namespaces(self): """Process config and warn on each unknown config namespace.""" for sn, app in cherrypy.tree.apps.items(): if not isinstance(app, cherrypy.Application): continue self._known_ns(app) # -------------------------- Config Types -------------------------- #
Example #30
Source File: _cptree.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __repr__(self): """Generate a representation of the Application instance.""" return '%s.%s(%r, %r)' % (self.__module__, self.__class__.__name__, self.root, self.script_name)