def _process_request(self, path_info): path = splitpath(path_info) handler, handler_args = self._find_object(path) if not handler is None: args, vargs, kwargs, defaults = None, None, None, None try: args, varargs, kwargs, defaults = inspect.getargspec(handler) args = args[1:] except: pass if defaults is None: defaults = () min_len = len(args) - len(defaults) max_len = len(args) handler_len = len(handler_args) if not hasattr(handler, 'container'): if not handler_args and max_len != 0: handler.__dict__['container'] = True else: handler.__dict__['container'] = False # now we call the redirect method # if it forces an redirect the __iter__ method skips the next # part. call it magic if you like -.- fix_slash(self.request, handler.container) if min_len <= handler_len <= max_len: parent = handler.im_class() parent.request = self.request return handler(parent, *handler_args) raise PageNotFound
def process_request(self): """Process a single request.""" path_info = self.request.environ.get('PATH_INFO', '/').strip('/') parts = path_info.strip('/').split('/') if not len(parts) or not parts[0]: handler = 'show_index' args = () else: handler = 'show_%s' % parts[0] args = tuple(parts[1:]) if hasattr(self, handler): return getattr(self, handler)(*args) fix_slash(self.request.environ, True) raise PageNotFound()
def process_request(self): """Process a single request.""" path_info = self.request.environ.get('PATH_INFO', '/')[1:] if hasattr(self, 'slash_append') and self.slash_append: fix_slash(self.request.environ, True) for url, cls in self.urls: matchobj = url.search(path_info) if not matchobj is None: cls = cls() cls.request = self.request handler = getattr(cls, self.request.environ['REQUEST_METHOD']) if handler in (True, False): return fix_slash(self.request.environ, handler) return handler(*matchobj.groups()) raise PageNotFound()
def process_request(self): """Process a single request.""" path_info = self.request.environ.get('PATH_INFO', '/')[1:] if hasattr(self, 'slash_append') and self.slash_append: fix_slash(self.request.environ, True) for url, module in self.urls: matchobj = url.search(path_info) if not matchobj is None: args = matchobj.groups() if module in (True, False): return fix_slash(self.request.environ, module) elif not '.' in module: handler = getattr(self, module) else: parts = module.split('.') mname, fname = '.'.join(parts[:-1]), parts[-1] package = __import__(mname, '', '', ['']) handler = getattr(package, fname) args = list(args) args.insert(0, self.request) args = tuple(args) return handler(*args) raise PageNotFound()
def process_request(self): """Process a single request.""" path_info = self.request.environ.get('PATH_INFO', '/')[1:] if hasattr(self, 'slash_append') and self.slash_append: fix_slash(self.request.environ, True) for url, module in self.urls: matchobj = url.search(path_info) if not matchobj is None: args = matchobj.groups() new_args = [] for pos, value in enumerate(args): search = '$%d' % (pos + 1) if search in module: module = module.replace(search, value.replace('.', '_')) else: new_args.append(value) args = tuple(new_args) if not '.' in module: if not hasattr(self, module): raise PageNotFound handler = getattr(self, module) else: parts = module.split('.') mname, fname = '.'.join(parts[:-1]), parts[-1] try: package = __import__(mname, '', '', ['']) handler = getattr(package, fname) except (ImportError, AttributeError): raise PageNotFound args = list(args) args.insert(0, self.request) args = tuple(args) if handler in (True, False): return fix_slash(self.request.environ, handler) return handler(*args) raise PageNotFound()
def process_request(self): """Process a single request.""" if not hasattr(self, 'root'): raise AttributeError, 'ObjectApplication requires a root object.' path = self.request.environ.get('PATH_INFO', '').strip('/') parts = path.split('/') # Resolve the path handler = self.root args = [] for part in parts: if part.startswith('_'): raise PageNotFound node = getattr(handler, part, None) if node is None: if part: args.append(part) else: handler = node container = None # Find handler and make first container check import inspect if inspect.ismethod(handler): if handler.__name__ == 'index': # the handler is called index so it's the leaf of # itself. we don't want a slash, even if forced container = False else: index = getattr(handler, 'index', None) if not index is None: if not hasattr(index, 'container'): container = True handler = index else: raise PageNotFound() # update with hardcoded container information if container is None and hasattr(handler, 'container'): container = handler.container # Check for handler arguments and update container handler_args, varargs, _, defaults = inspect.getargspec(handler) if defaults is None: defaults = 0 else: defaults = len(defaults) max_len = len(handler_args) - 1 min_len = max_len - defaults cur_len = len(args) if varargs: max_len = -1 # check if the number of arguments fits our handler if max_len == -1: if cur_len < min_len: raise PageNotFound elif min_len <= cur_len <= max_len: if container is None: container = cur_len < max_len else: raise PageNotFound() if container is None: container = False fix_slash(self.request.environ, container) # call handler parent = handler.im_class() if hasattr(self, 'request'): parent.request = self.request return handler(parent, *args)