def __call__(self, request): matched_dict = False regexes = self.compiled_regexes urls = self.url_list if self.translator: request = self.translator(request) split_uri = request['PATH_INFO'].split('/', 2) split_uri = [x for x in split_uri if x] #remove any empty strings #Potential FIXME: If split_uri is empty, we set the fist item to something #that wouldn't be in the url. It feels like a hack, but seems to work. #Could this be a potential security risk or source of a bug? if not split_uri: split_uri = ['||||'] #Here, we figure out which item in the url list we want to access. for url_item in urls: if regexes[url_item['kp.regex']].search(split_uri[0]): PopWsgiURI(request) matched_dict = url_item break if not matched_dict: return self.errorhandler(500, 'Page not found and no 404 handler configured') if self.app_objs.get(matched_dict['kp.regex']): #Have we found this app object before? app = self.app_objs[matched_dict['kp.regex']] #If so, pull it out of app_objs else: #otherwise, find the app object try: module = _importWsgiModule(matched_dict['kp.import_path']) app = getattr(module, matched_dict['kp.app_object']) self.app_objs[matched_dict['kp.regex']] = app except ImportError: #FIXME: We should probably display some kind of error page rather than dying return self.errorhandler(404, 'Module not found.') except AttributeError: return self.errorhandler(404, 'Page found, but app object missing.') request.update(matched_dict) if matched_dict.get('kp.nounicode'): #Convert all elements in the request to strings request = dict([(str(k), str(v)) for k, v in request.iteritems()]) return _WsgiHandler(app, request, WSGIConfig, Debug=True)
def _getWsgiHandler(request): request = WSGILikeTranslator(request) return _WsgiHandler(app_object, request, WSGIConfig)