def prep_handler(self, environ): path_info = environ['PATH_INFO'] if not path_info: #empty path info (no trailing slash) breaks our relative urls environ['koji.redirect'] = environ['REQUEST_URI'] + '/' raise ServerRedirect elif path_info == '/': method = 'index' else: method = path_info.lstrip('/').split('/')[0] environ['koji.method'] = method self.logger.info("Method: %s", method) func = self.handler_index.get(method) if not func: raise URLNotFound #parse form args data = {} fs = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ.copy(), keep_blank_values=True) for field in fs.list: if field.filename: val = field else: val = field.value data.setdefault(field.name, []).append(val) # replace singleton lists with single values # XXX - this is a bad practice, but for now we strive to emulate mod_python.publisher for arg in data: val = data[arg] if isinstance(val, list) and len(val) == 1: data[arg] = val[0] environ['koji.form'] = fs args, varargs, varkw, defaults = inspect.getargspec(func) if not varkw: # remove any unexpected args data = dslice(data, args, strict=False) #TODO (warning in header or something?) return func, data
def prep_handler(self, environ): path_info = environ['PATH_INFO'] if not path_info: #empty path info (no trailing slash) breaks our relative urls environ['koji.redirect'] = environ['REQUEST_URI'] + '/' raise ServerRedirect elif path_info == '/': method = 'index' else: method = path_info.lstrip('/').split('/')[0] environ['koji.method'] = method self.logger.info("Method: %s", method) func = self.handler_index.get(method) if not func: raise URLNotFound #parse form args data = {} fs = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ.copy(), keep_blank_values=True) for field in fs.list: if field.filename: val = field else: val = field.value data.setdefault(field.name, []).append(val) # replace singleton lists with single values # XXX - this is a bad practice, but for now we strive to emulate mod_python.publisher for arg in data: val = data[arg] if isinstance(val, list) and len(val) == 1: data[arg] = val[0] environ['koji.form'] = fs args, varargs, varkw, defaults = inspect.getargspec(func) if not varkw: # remove any unexpected args data = dslice(data, args, strict=False) #TODO (warning in header or something?) return func, data