def _cp_dispatch(self, vpath): """Used to handle permalink URL. reference http://cherrypy.readthedocs.org/en/latest/advanced.html""" # Notice path contains bytes. if len(vpath) > 0: # /the/full/path/ path = [] while len(vpath) > 0: path.append(unquote_url(vpath.pop(0))) cherrypy.request.params['path_b'] = b"/".join(path) return self return vpath
def decorated(cls_or_self=None, vpath=None): if inspect.isclass(cls_or_self): # cherrypy.poppath is a class decorator cls = cls_or_self setattr(cls, cherrypy.dispatch.Dispatcher.dispatch_method_name, decorated) return cls # We're in the actual function self = cls_or_self parms = {} for arg in args: if not vpath: break parms[arg] = unquote_url(vpath.pop(0)) # Build repo path. path = [] while len(vpath) > 0: path.append(unquote_url(vpath.pop(0))) parms['path'] = b"/".join(path) if handler is not None: if handler_call: return handler(**parms) else: cherrypy.request.params.update(parms) # @UndefinedVariable return handler cherrypy.request.params.update(parms) # @UndefinedVariable # If we are the ultimate handler, then to prevent our _cp_dispatch # from being called again, we will resolve remaining elements through # getattr() directly. if vpath: return getattr(self, vpath.pop(0), None) else: return self
def _cp_dispatch(self, vpath): """ Used to dispatch `/prefs/<panelid>` The `panelid` make reference to a plugin panel. """ # Notice vpath contains bytes. if len(vpath) > 0: # /the/full/path/ path = [] while len(vpath) > 0: path.append(decode_s(unquote_url(vpath.pop(0)))) cherrypy.request.params['panelid'] = "/".join(path) return self return vpath
def test_unquote_url(self): self.assertEqual(b'this is some path', unquote_url('this%20is%20some%20path')) self.assertEqual(b'this is some path', unquote_url(b'this%20is%20some%20path'))