def __call__(self, f): from uliweb.utils.common import safe_import if isinstance(f, (str, unicode)): _, f = safe_import(f) self.parse(f) return f
def __call__(self, f): from uliweb.utils.common import safe_import if isinstance(f, (str, unicode)): try: _, f = safe_import(f) except: log.error('Import error: rule=%s' % f) raise self.parse(f) return f
def prepare_request(self, request, endpoint): from uliweb.utils.common import safe_import #binding some variable to request request.settings = conf.settings request.application = self #get handler _klass = None if isinstance(endpoint, (str, unicode)): mod, handler = safe_import(endpoint) if inspect.ismethod(handler): if not handler.im_self: #instance method _klass = handler.im_class() else: #class method _klass = handler.im_self() #if _klass is class method, then the mod should be Class #so the real mod should be mod.__module__ mod = sys.modules[mod.__module__] # module, func = endpoint.rsplit('.', 1) # #if the module contains a class name, then import the class # #it set by expose() # x, last = module.rsplit('.', 1) # if last.startswith('views'): # mod = __import__(module, {}, {}, ['']) # handler = getattr(mod, func) # else: # module = x # mod = __import__(module, {}, {}, ['']) # _klass = getattr(mod, last)() # handler = getattr(_klass, func) elif callable(endpoint): handler = endpoint mod = sys.modules[handler.__module__] request.appname = '' for p in self.apps: t = p + '.' if handler.__module__.startswith(t): request.appname = p break request.function = handler.__name__ if _klass: request.view_class = _klass.__class__.__name__ handler = getattr(_klass, handler.__name__) else: request.view_class = None return mod, _klass, handler
def prepare_request(self, request, rule): from uliweb.utils.common import safe_import endpoint = rule.endpoint #bind endpoint to request request.rule = rule #get handler _klass = None if isinstance(endpoint, string_types): mod, handler = safe_import(endpoint) if inspect.ismethod(handler): if not handler.im_self: #instance method _klass = handler.im_class() else: #class method _klass = handler.im_self() #if _klass is class method, then the mod should be Class #so the real mod should be mod.__module__ mod = sys.modules[mod.__module__] # module, func = endpoint.rsplit('.', 1) # #if the module contains a class name, then import the class # #it set by expose() # x, last = module.rsplit('.', 1) # if last.startswith('views'): # mod = __import__(module, {}, {}, ['']) # handler = getattr(mod, func) # else: # module = x # mod = __import__(module, {}, {}, ['']) # _klass = getattr(mod, last)() # handler = getattr(_klass, func) elif callable(endpoint): handler = endpoint mod = sys.modules[handler.__module__] request.appname = '' for p in self.apps: t = p + '.' if handler.__module__.startswith(t): request.appname = p break request.function = handler.__name__ if _klass: request.view_class = _klass.__class__.__name__ handler = getattr(_klass, handler.__name__) else: request.view_class = None return mod, _klass, handler
def get_handler(self, endpoint): from uliweb.utils.common import safe_import #get handler _klass = None if isinstance(endpoint, string_types): mod, handler = safe_import(endpoint) if inspect.ismethod(handler): if not handler.im_self: #instance method _klass = handler.im_class() else: #class method _klass = handler.im_self() #if _klass is class method, then the mod should be Class #so the real mod should be mod.__module__ mod = sys.modules[mod.__module__] elif callable(endpoint): handler = endpoint mod = sys.modules[handler.__module__] return _klass, mod, handler