def get_handler(self, path): handler = None for pat, h in Configuration.fileDispatchers: if callable(pat): matcher = pat elif isinstance(pat, basestring): matcher = re.compile(pat).match elif hasattr(pat, "match"): matcher = pat.match m = matcher(path) if m: log.debug("found match against path %s: %s ", path, m) handler = h break log.debug("handler: %s", handler) if not handler: return self._default_handler if isinstance(handler, basestring): try: return self._handlercache[handler] except KeyError: handler = import_from_string(handler) self._handlercache[handler] = handler return handler else: return handler
def load_services(): for service in Configuration.services: try: log.info("loading service '%s'", service) s=import_from_string(service) if callable(s): log.debug("service is callable, calling") s() else: initmethod=getattr(s, 'init_service', None) if initmethod: log.debug('found service init method %s', initmethod) initmethod() except: exception("error loading service %s", service) raise
def make_app(): """ several problems here. 1. an app might be specified other than as a string. 2. this imposes a restriction on constructors (that's OK) 3. this uses configuration, which isn't scoped if this itself creates the ContextMiddleware. Perhaps that always must come first. """ pipeline=Configuration.wsgiPipeline app=None for spec in reversed(pipeline): cls=import_from_string(spec) if app: app=cls(app) else: app=cls() return app
def dispatch(environ, *args, **kwargs): log.debug("in dispatch") controller_name=kwargs.pop('controller', None) if not controller_name: log.debug("no controller found") return controller=Configuration.controllers.get(controller_name) if not controller: log.warn('no such controller found: %s', controller_name) return if isinstance(controller, basestring): try: controller=import_from_string(controller) except ImportError: return get_http_exception(httplib.INTERNAL_SERVER_ERROR, comment="couldn't import controller %s" % controller) else: log.debug("got a non-string for controller: %s", controller) action=kwargs.pop('action', 'index') reqmeth=environ['REQUEST_METHOD'] if reqmeth=='HEAD': reqmeth='GET' method_qualified_action='%s_%s' % (action, reqmeth) meth=getattr(controller, method_qualified_action, None) if not meth: meth=getattr(controller, action, None) if not meth: log.debug(("no controller action found " "(looked for action %s in controller %s)"), action, controller) return if not getattr(meth, 'exposed', False): log.info("request for method that isn't exposed, not honoring") return log.debug("method is %s", meth) try: res=meth(*args, **kwargs) except webob.exc.HTTPException, e: res=e
def _get_session(self): session_data, mtime=Configuration.sessionStore.get_session(self._session_id) if not session_data: return if time.time() - mtime >= Configuration.sessionTimeout: staleAction=Configuration.sessionStaleAction if staleAction: if isinstance(staleAction, str): staleAction=import_from_string(staleAction) if isinstance(staleAction, Exception) or issubclass(staleAction, Exception): raise staleAction elif callable(staleAction): res=staleAction(self._session_id) if res and isinstance(res, Exception): raise res else: log.warn(("don't know what to do with " "Configuration.sessionStaleAction %s" % staleAction)) else: return session_data return None