Esempio n. 1
0
 def _delegate(self, f, fvars, args=[]):
     def handle_class(cls):
         meth = web.ctx.method
         if meth == 'HEAD' and not hasattr(cls, meth):
             meth = 'GET'
         if not hasattr(cls, meth):
             raise web.nomethod(cls)
         tocall = getattr(cls(), meth)
         return tocall(*args)
         
     def is_class(o): return isinstance(o, (types.ClassType, type))
         
     if f is None:
         raise web.notfound()
     elif isinstance(f, application):
         return f.handle_with_processors()
     elif is_class(f):
         return handle_class(f)
     elif isinstance(f, basestring):
         if f.startswith('redirect '):
             url = f.split(' ', 1)[1]
             if web.ctx.method == "GET":
                 x = web.ctx.env.get('QUERY_STRING', '')
                 if x:
                     url += '?' + x
             raise web.redirect(url)
         elif '.' in f:
             x = f.split('.')
             if not len(x) == len(filter(None, x)):
                 raise web.internalerror()
             mod, cls = '.'.join(x[:-1]), x[-1]
             try:
                 mod = __import__(mod, globals(), locals(), [""])
             except: raise web.notfound()
             cls = getattr(mod, cls)
         else:
             cls = fvars.get(f)
         if cls:
             return handle_class(cls)
         else:
             raise web.notfound()
     elif hasattr(f, '__call__'):
         return f(*args)
     else:
         raise web.notfound()
    def _delegate(self, f, fvars, args=[]):
        def handle_class(cls):
            meth = web.ctx.method
            if meth == 'HEAD' and not hasattr(cls, meth):
                meth = 'GET'
            if not hasattr(cls, meth):
                raise web.nomethod(cls)
            tocall = getattr(cls(), meth)
            return tocall(*args)

        def is_class(o):
            return isinstance(o, (types.ClassType, type))

        if f is None:
            raise web.notfound()
        elif isinstance(f, application):
            return f.handle_with_processors()
        elif is_class(f):
            return handle_class(f)
        elif isinstance(f, basestring):
            if f.startswith('redirect '):
                url = f.split(' ', 1)[1]
                if web.ctx.method == "GET":
                    x = web.ctx.env.get('QUERY_STRING', '')
                    if x:
                        url += '?' + x
                raise web.redirect(url)
            elif '.' in f:
                x = f.split('.')
                mod, cls = '.'.join(x[:-1]), x[-1]
                mod = __import__(mod, globals(), locals(), [""])
                cls = getattr(mod, cls)
            else:
                cls = fvars[f]
            return handle_class(cls)
        elif hasattr(f, '__call__'):
            return f()
        else:
            return web.notfound()
Esempio n. 3
0
    def _delegate(self, f, fvars, args=[]):
        def handle_class(cls):
            meth = web.ctx.method
            if meth == "HEAD" and not hasattr(cls, meth):
                meth = "GET"
            if not hasattr(cls, meth):
                raise web.nomethod(cls)
            tocall = getattr(cls(), meth)
            return tocall(*args)

        def is_class(o):
            return isinstance(o, (types.ClassType, type))

        if f is None:
            raise NotFound
        elif isinstance(f, application):
            return f.handle()
        elif is_class(f):
            return handle_class(f)
        elif isinstance(f, str):
            if f.startswith("redirect "):
                url = f.split(" ", 1)[1]
                if web.ctx.method == "GET":
                    x = web.ctx.env.get("QUERY_STRING", "")
                    if x:
                        url += "?" + x
                raise web.redirect(url)
            elif "." in f:
                x = f.split(".")
                mod, cls = ".".join(x[:-1]), x[-1]
                mod = __import__(mod, globals(), locals(), [""])
                cls = getattr(mod, cls)
            else:
                cls = fvars[f]
            return handle_class(cls)
        elif hasattr(f, "__call__"):
            return f()
        else:
            return web.notfound()
Esempio n. 4
0
 def _delegate(self, f, fvars, args=[]):
     def handle_class(cls):
         meth = web.ctx.method
         if meth == 'HEAD' and not hasattr(cls, meth):
             meth = 'GET'
         if not hasattr(cls, meth):
             raise web.nomethod(cls)
         tocall = getattr(cls(), meth)
         return tocall(*args)
         
     def is_class(o): return isinstance(o, (types.ClassType, type))
         
     if f is None:
         raise web.notfound()
     elif isinstance(f, application):
         return f.handle_with_processors()
     elif is_class(f):
         return handle_class(f)
     elif isinstance(f, basestring):
         if f.startswith('redirect '):
             url = f.split(' ', 1)[1]
             if web.ctx.method == "GET":
                 x = web.ctx.env.get('QUERY_STRING', '')
                 if x:
                     url += '?' + x
             raise web.redirect(url)
         elif '.' in f:
             mod, cls = f.rsplit('.', 1)
             mod = __import__(mod, None, None, [''])
             cls = getattr(mod, cls)
         else:
             cls = fvars[f]
         return handle_class(cls)
     elif hasattr(f, '__call__'):
         return f()
     else:
         return web.notfound()