Python cherrypy.NotFound() Examples
The following are 29
code examples of cherrypy.NotFound().
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: _cptools.py From bazarr with GNU General Public License v3.0 | 6 votes |
def handler(self, *args, **kwargs): """Use this tool as a CherryPy page handler. For example:: class Root: nav = tools.staticdir.handler(section="/nav", dir="nav", root=absDir) """ @expose def handle_func(*a, **kw): handled = self.callable(*args, **self._merged_args(kwargs)) if not handled: raise cherrypy.NotFound() return cherrypy.serving.response.body return handle_func
Example #2
Source File: static.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def _attempt(filename, content_types, debug=False): if debug: cherrypy.log('Attempting %r (content_types %r)' % (filename, content_types), 'TOOLS.STATICDIR') try: # you can set the content types for a # complete directory per extension content_type = None if content_types: r, ext = os.path.splitext(filename) content_type = content_types.get(ext[1:], None) serve_file(filename, content_type=content_type, debug=debug) return True except cherrypy.NotFound: # If we didn't find the static file, continue handling the # request. We might find a dynamic handler instead. if debug: cherrypy.log('NotFound', 'TOOLS.STATICFILE') return False
Example #3
Source File: _cptools.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def handler(self, *args, **kwargs): """Use this tool as a CherryPy page handler. For example:: class Root: nav = tools.staticdir.handler(section="/nav", dir="nav", root=absDir) """ def handle_func(*a, **kw): handled = self.callable(*args, **self._merged_args(kwargs)) if not handled: raise cherrypy.NotFound() return cherrypy.serving.response.body handle_func.exposed = True return handle_func
Example #4
Source File: static.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def _attempt(filename, content_types, debug=False): if debug: cherrypy.log('Attempting %r (content_types %r)' % (filename, content_types), 'TOOLS.STATICDIR') try: # you can set the content types for a # complete directory per extension content_type = None if content_types: r, ext = os.path.splitext(filename) content_type = content_types.get(ext[1:], None) serve_file(filename, content_type=content_type, debug=debug) return True except cherrypy.NotFound: # If we didn't find the static file, continue handling the # request. We might find a dynamic handler instead. if debug: cherrypy.log('NotFound', 'TOOLS.STATICFILE') return False
Example #5
Source File: _cptools.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def handler(self, *args, **kwargs): """Use this tool as a CherryPy page handler. For example:: class Root: nav = tools.staticdir.handler(section="/nav", dir="nav", root=absDir) """ @expose def handle_func(*a, **kw): handled = self.callable(*args, **self._merged_args(kwargs)) if not handled: raise cherrypy.NotFound() return cherrypy.serving.response.body return handle_func
Example #6
Source File: static.py From bazarr with GNU General Public License v3.0 | 6 votes |
def _attempt(filename, content_types, debug=False): if debug: cherrypy.log('Attempting %r (content_types %r)' % (filename, content_types), 'TOOLS.STATICDIR') try: # you can set the content types for a # complete directory per extension content_type = None if content_types: r, ext = os.path.splitext(filename) content_type = content_types.get(ext[1:], None) serve_file(filename, content_type=content_type, debug=debug) return True except cherrypy.NotFound: # If we didn't find the static file, continue handling the # request. We might find a dynamic handler instead. if debug: cherrypy.log('NotFound', 'TOOLS.STATICFILE') return False
Example #7
Source File: _cptools.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def handler(self, *args, **kwargs): """Use this tool as a CherryPy page handler. For example:: class Root: nav = tools.staticdir.handler(section="/nav", dir="nav", root=absDir) """ @expose def handle_func(*a, **kw): handled = self.callable(*args, **self._merged_args(kwargs)) if not handled: raise cherrypy.NotFound() return cherrypy.serving.response.body return handle_func
Example #8
Source File: static.py From opsbro with MIT License | 6 votes |
def _attempt(filename, content_types, debug=False): if debug: cherrypy.log('Attempting %r (content_types %r)' % (filename, content_types), 'TOOLS.STATICDIR') try: # you can set the content types for a # complete directory per extension content_type = None if content_types: r, ext = os.path.splitext(filename) content_type = content_types.get(ext[1:], None) serve_file(filename, content_type=content_type, debug=debug) return True except cherrypy.NotFound: # If we didn't find the static file, continue handling the # request. We might find a dynamic handler instead. if debug: cherrypy.log('NotFound', 'TOOLS.STATICFILE') return False
Example #9
Source File: _cptools.py From opsbro with MIT License | 6 votes |
def handler(self, *args, **kwargs): """Use this tool as a CherryPy page handler. For example:: class Root: nav = tools.staticdir.handler(section="/nav", dir="nav", root=absDir) """ def handle_func(*a, **kw): handled = self.callable(*args, **self._merged_args(kwargs)) if not handled: raise cherrypy.NotFound() return cherrypy.serving.response.body handle_func.exposed = True return handle_func
Example #10
Source File: api_items.py From smarthome with GNU General Public License v3.0 | 6 votes |
def read(self, id=None): """ Handle GET requests """ if self.items is None: self.items = Items.get_instance() if id == 'structs': # /api/items/structs self.logger.info("ItemsController.root(): item_name = {}".format(id)) result = self.items.return_struct_definitions() return json.dumps(result) #raise cherrypy.NotFound #self.logger.info("LogController (GET): logfiles = {}".format(logs)) #return json.dumps({'logs':logs, 'default': self.root_logname}) return None
Example #11
Source File: api_logics.py From smarthome with GNU General Public License v3.0 | 6 votes |
def read(self, logicname=None): """ return an object with type info about all logics """ # create a list of dicts, where each dict contains the information for one logic self.logger.info("LogicsController.read()") if self.plugins is None: self.plugins = Plugins.get_instance() if self.scheduler is None: self.scheduler = Scheduler.get_instance() self.logics_initialize() if self.logics is None: # SmartHomeNG has not yet initialized the logics module (still starting up) raise cherrypy.NotFound if logicname is None: return self.get_logics_info() else: return self.get_logic_info(logicname)
Example #12
Source File: static.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _attempt(filename, content_types, debug=False): if debug: cherrypy.log('Attempting %r (content_types %r)' % (filename, content_types), 'TOOLS.STATICDIR') try: # you can set the content types for a # complete directory per extension content_type = None if content_types: r, ext = os.path.splitext(filename) content_type = content_types.get(ext[1:], None) serve_file(filename, content_type=content_type, debug=debug) return True except cherrypy.NotFound: # If we didn't find the static file, continue handling the # request. We might find a dynamic handler instead. if debug: cherrypy.log('NotFound', 'TOOLS.STATICFILE') return False
Example #13
Source File: _cpdispatch.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request func, vpath = self.find_handler(path_info) if func: # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace('%2F', '/') for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.NotFound()
Example #14
Source File: _cpdispatch.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" func = self.find_handler(path_info) if func: cherrypy.serving.request.handler = LateParamPageHandler(func) else: cherrypy.serving.request.handler = cherrypy.NotFound()
Example #15
Source File: _cpdispatch.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request resource, vpath = self.find_handler(path_info) if resource: # Set Allow header avail = [m for m in dir(resource) if m.isupper()] if "GET" in avail and "HEAD" not in avail: avail.append("HEAD") avail.sort() cherrypy.serving.response.headers['Allow'] = ", ".join(avail) # Find the subhandler meth = request.method.upper() func = getattr(resource, meth, None) if func is None and meth == "HEAD": func = getattr(resource, "GET", None) if func: # Grab any _cp_config on the subhandler. if hasattr(func, "_cp_config"): request.config.update(func._cp_config) # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace("%2F", "/") for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.HTTPError(405) else: request.handler = cherrypy.NotFound()
Example #16
Source File: _cpdispatch.py From moviegrabber with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request func, vpath = self.find_handler(path_info) if func: # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace("%2F", "/") for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.NotFound()
Example #17
Source File: _cpdispatch.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request resource, vpath = self.find_handler(path_info) if resource: # Set Allow header avail = [m for m in dir(resource) if m.isupper()] if 'GET' in avail and 'HEAD' not in avail: avail.append('HEAD') avail.sort() cherrypy.serving.response.headers['Allow'] = ', '.join(avail) # Find the subhandler meth = request.method.upper() func = getattr(resource, meth, None) if func is None and meth == 'HEAD': func = getattr(resource, 'GET', None) if func: # Grab any _cp_config on the subhandler. if hasattr(func, '_cp_config'): request.config.update(func._cp_config) # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace('%2F', '/') for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.HTTPError(405) else: request.handler = cherrypy.NotFound()
Example #18
Source File: _cpdispatch.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" func = self.find_handler(path_info) if func: cherrypy.serving.request.handler = LateParamPageHandler(func) else: cherrypy.serving.request.handler = cherrypy.NotFound()
Example #19
Source File: _cpdispatch.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" func = self.find_handler(path_info) if func: cherrypy.serving.request.handler = LateParamPageHandler(func) else: cherrypy.serving.request.handler = cherrypy.NotFound()
Example #20
Source File: _cpdispatch.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request resource, vpath = self.find_handler(path_info) if resource: # Set Allow header avail = [m for m in dir(resource) if m.isupper()] if 'GET' in avail and 'HEAD' not in avail: avail.append('HEAD') avail.sort() cherrypy.serving.response.headers['Allow'] = ', '.join(avail) # Find the subhandler meth = request.method.upper() func = getattr(resource, meth, None) if func is None and meth == 'HEAD': func = getattr(resource, 'GET', None) if func: # Grab any _cp_config on the subhandler. if hasattr(func, '_cp_config'): request.config.update(func._cp_config) # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace('%2F', '/') for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.HTTPError(405) else: request.handler = cherrypy.NotFound()
Example #21
Source File: _cpdispatch.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request func, vpath = self.find_handler(path_info) if func: # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace('%2F', '/') for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.NotFound()
Example #22
Source File: _cpdispatch.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" func = self.find_handler(path_info) if func: cherrypy.serving.request.handler = LateParamPageHandler(func) else: cherrypy.serving.request.handler = cherrypy.NotFound()
Example #23
Source File: _cpdispatch.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request resource, vpath = self.find_handler(path_info) if resource: # Set Allow header avail = [m for m in dir(resource) if m.isupper()] if 'GET' in avail and 'HEAD' not in avail: avail.append('HEAD') avail.sort() cherrypy.serving.response.headers['Allow'] = ', '.join(avail) # Find the subhandler meth = request.method.upper() func = getattr(resource, meth, None) if func is None and meth == 'HEAD': func = getattr(resource, 'GET', None) if func: # Grab any _cp_config on the subhandler. if hasattr(func, '_cp_config'): request.config.update(func._cp_config) # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace('%2F', '/') for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.HTTPError(405) else: request.handler = cherrypy.NotFound()
Example #24
Source File: _cpdispatch.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request func, vpath = self.find_handler(path_info) if func: # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace('%2F', '/') for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.NotFound()
Example #25
Source File: rest.py From smarthome with GNU General Public License v3.0 | 5 votes |
def REST_dispatch(self, root, resource, **params): # if this gets called, we assume that default has already # traversed down the tree to the right location and this is # being called for a raw resource method = cherrypy.request.method if method in self.REST_map: try: m = getattr(self,self.REST_map[method]) except: self.logger.info("REST_dispatch *1: Unsupported method = {} for resource '{}'".format(method, resource)) raise cherrypy.HTTPError(status=404) result = self.REST_dispatch_execute(m, method, root, resource, **params) if result != None: return result else: raise cherrypy.NotFound else: if method in self.REST_defaults: try: m = getattr(self,self.REST_defaults[method]) except: self.logger.info("REST_dispatch: Unsupported method = {} for resource '{}'".format(method, resource)) raise cherrypy.HTTPError(status=404) result = self.REST_dispatch_execute(m, method, root, resource, **params) if result != None: return result else: raise cherrypy.NotFound raise cherrypy.NotFound
Example #26
Source File: rest.py From smarthome with GNU General Public License v3.0 | 5 votes |
def default(self, *vpath, **params): if not vpath: resource = None # self.logger.info("RESTResource.default: vpath = '{}', params = '{}'".format(list(vpath), dict(**params))) return self.REST_dispatch(True, resource, **params) # return list(**params) # self.logger.info("RESTResource.default: vpath = '{}', params = '{}'".format(list(vpath), dict(**params))) # Make a copy of vpath in a list vpath = list(vpath) atom = vpath.pop(0) # Coerce the ID to the correct db type resource = self.REST_instantiate(atom) if resource is None: if cherrypy.request.method == "PUT": # PUT is special since it can be used to create # a resource resource = self.REST_create(atom) else: raise cherrypy.NotFound # There may be further virtual path components. # Try to map them to methods in children or this class. if vpath: a = vpath.pop(0) if a in self.REST_children: c = self.REST_children[a] c.parent = resource return c.default(*vpath, **params) method = getattr(self, a, None) if method and getattr(method, "expose_resource"): return method(resource, *vpath, **params) else: # path component was specified but doesn't # map to anything exposed and callable raise cherrypy.NotFound # No further known vpath components. Call a default handler # based on the method return self.REST_dispatch(False, resource,**params)
Example #27
Source File: _cpdispatch.py From opsbro with MIT License | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" func = self.find_handler(path_info) if func: cherrypy.serving.request.handler = LateParamPageHandler(func) else: cherrypy.serving.request.handler = cherrypy.NotFound()
Example #28
Source File: _cpdispatch.py From opsbro with MIT License | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request resource, vpath = self.find_handler(path_info) if resource: # Set Allow header avail = [m for m in dir(resource) if m.isupper()] if "GET" in avail and "HEAD" not in avail: avail.append("HEAD") avail.sort() cherrypy.serving.response.headers['Allow'] = ", ".join(avail) # Find the subhandler meth = request.method.upper() func = getattr(resource, meth, None) if func is None and meth == "HEAD": func = getattr(resource, "GET", None) if func: # Grab any _cp_config on the subhandler. if hasattr(func, "_cp_config"): request.config.update(func._cp_config) # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace("%2F", "/") for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.HTTPError(405) else: request.handler = cherrypy.NotFound()
Example #29
Source File: _cpdispatch.py From opsbro with MIT License | 5 votes |
def __call__(self, path_info): """Set handler and config for the current request.""" request = cherrypy.serving.request func, vpath = self.find_handler(path_info) if func: # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace("%2F", "/") for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.NotFound()