• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.maybeDeferred函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nevow.util.maybeDeferred函数的典型用法代码示例。如果您正苦于以下问题:Python maybeDeferred函数的具体用法?Python maybeDeferred怎么用?Python maybeDeferred使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了maybeDeferred函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: getResourceFor

 def getResourceFor(self, root, url):
     r = testutil.FakeRequest()
     self.request = r
     r.postpath = url.split('/')
     ctx = context.RequestContext(tag=self.request)
     return util.maybeDeferred(
         appserver.NevowSite(root).getPageContextForRequestContext, ctx)
开发者ID:pmw,项目名称:nevow,代码行数:7,代码来源:test_appserver.py


示例2: webFormPost

    def webFormPost(self, request, res, configurable, ctx, bindingName, args):
        """Accept a web form post, either redisplaying the original form (with
        errors) if validation fails, or redirecting to the appropriate location after
        the post succeeds. This hook exists specifically for formless.

        New in 0.5, _nevow_carryover_ is only used if an autocallable method
        returns a result that needs to be carried over.

        New in 0.5, autocallables may return a nevow.url.URL or URLOverlay
        instance rather than setting IRedirectAfterPost on the request.

        New in 0.5, autocallables may return a Page instance to have that Page
        instance rendered at the post target URL with no redirects at all. Useful
        for multi-step wizards.
        """
        def redirectAfterPost(aspects):
            hand = aspects.get(inevow.IHand)
            refpath = None
            if hand is not None:
                if isinstance(hand, Page):
                    refpath = url.here
                    if 'freeform_hand' not in inevow.IRequest(ctx).prepath:
                        refpath = refpath.child('freeform_hand')
                if isinstance(hand, (url.URL, url.URLOverlay)):
                    refpath, hand = hand, None

            if refpath is None:
                redirectAfterPost = request.getComponent(iformless.IRedirectAfterPost, None)
                if redirectAfterPost is None:
                    ref = request.getHeader('referer')
                    if ref:
                        refpath = url.URL.fromString(ref)
                    else:
                        refpath = url.here
                else:
                    warnings.warn("[0.5] IRedirectAfterPost is deprecated. Return a URL instance from your autocallable instead.", DeprecationWarning, 2)
                    ## Use the redirectAfterPost url
                    ref = str(redirectAfterPost)
                    refpath = url.URL.fromString(ref)

            if hand is not None or aspects.get(iformless.IFormErrors) is not None:
                magicCookie = '%s%s%s' % (now(),request.getClientIP(),random.random())
                refpath = refpath.replace('_nevow_carryover_', magicCookie)
                _CARRYOVER[magicCookie] = C = tpc.Componentized()
                for k, v in aspects.iteritems():
                    C.setComponent(k, v)

            destination = flat.flatten(refpath, ctx)
            request.redirect(destination)
            from nevow import static
            return static.Data('You posted a form to %s' % bindingName, 'text/plain'), ()

        return util.maybeDeferred(
            configurable.postForm, ctx, bindingName, args
        ).addCallback(
            self.onPostSuccess, request, ctx, bindingName, redirectAfterPost
        ).addErrback(
            self.onPostFailure, request, ctx, bindingName, redirectAfterPost
        )
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:59,代码来源:rend.py


示例3: _mapQuery

 def _mapQuery(self, curs, query, *args):
     curs.execute(query, *args)
     dx = u.maybeDeferred(curs.fetchall)
     def mapper(result, xcurs):
         columns = [d[0] for d in xcurs.description]
         return [dict(zip(columns, r)) for r in result]  
     def _error(error):
         print error      
     dx.addCallback(mapper, curs)
     dx.addErrback(_error)
     return dx
开发者ID:BackupTheBerlios,项目名称:weever-svn,代码行数:11,代码来源:store.py


示例4: deferredRender

def deferredRender(res, req):
    d = util.maybeDeferred(res.renderHTTP,
        context.PageContext(
            tag=res, parent=context.RequestContext(
                tag=req)))

    def done(result):
        if isinstance(result, str):
            req.write(result)
        return req
    d.addCallback(done)
    return d
开发者ID:StetHD,项目名称:nevow,代码行数:12,代码来源:test_static.py


示例5: mapQuery

 def mapQuery(self, curs, query, args):
     curs.execute(query, args)
     d = util.maybeDeferred(curs.fetchall)
     def printerror(error, curs, query, args):
         print error.printTraceback()
         print curs
         print query
         print args
     def finalize(result, curs):
         columns = [d[0] for d in curs.description]
         return [dict(zip(columns, r)) for r in result]
     d.addErrback(printerror, curs, query, args)
     d.addCallback(finalize, curs)
     d.addErrback(printerror, curs, query, args)
     return d
开发者ID:BackupTheBerlios,项目名称:weever-svn,代码行数:15,代码来源:store.py


示例6: deferredRender

def deferredRender(res, request=None):
    if request is None:
        request = testutil.FakeRequest()
        request.d = defer.Deferred()

    d = util.maybeDeferred(res.renderHTTP,
        context.PageContext(
            tag=res, parent=context.RequestContext(
                tag=request)))

    def done(result):
        if isinstance(result, str):
            request.write(result)
        request.d.callback(request.accumulator)
        return result
    d.addCallback(done)
    return request.d
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:17,代码来源:test_rend.py


示例7: _addTopic

 def _addTopic(self, curs, queries, args):
     add_topic = queries[0]
     add_post = queries[1]
     topic_args = args[0]
     post_args = args[1]
     curs.execute(add_topic, topic_args)
     d = u.maybeDeferred(curs.execute, "SELECT MAX(t.id) FROM thread t")
     d.addCallback(lambda _: curs.fetchone())
     def insTopic(result):
         post_args['thread_id'] = result[0]
         curs.execute(add_post, post_args)
         return result[0]
     def _error(error):
         print error
     d.addCallback(insTopic)
     d.addErrback(_error)
     return d    
开发者ID:BackupTheBerlios,项目名称:weever-svn,代码行数:17,代码来源:adapt.py


示例8: getResourceFor

def getResourceFor(root, url):
    """
    Perform traversal for C{url} beginning at C{root}.

    @param root: The L{nevow.inevow.IResource} at which to begin.

    @param url: The relative path string of the url of the resource to
        retrieve.
    @type url: L{bytes}

    @return: A L{Deferred} that fires with a L{PageContext} for the discovered
        resource.
    """
    request = testutil.FakeRequest()
    request.postpath = url.split('/')
    ctx = context.RequestContext(tag=request)
    return util.maybeDeferred(
        appserver.NevowSite(root).getPageContextForRequestContext, ctx)
开发者ID:twisted,项目名称:nevow,代码行数:18,代码来源:test_appserver.py


示例9: postForm

    def postForm(self, ctx, bindingName, args):
        """Accept a form post to the given bindingName.
        The post arguments are given in args.

        This will invoke the IInputProcessor for the
        binding with the given name. If it succeeds, the
        property will be modified or the method will have
        been called. If it fails, a ValidateError exception
        will be raised.
        """
        def _callback(binding):
            ctx.remember(binding, iformless.IBinding)
            ctx.remember(self, iformless.IConfigurable)
            rv = iformless.IInputProcessor(binding).process(ctx, self, args)
            ctx.remember(rv, inevow.IHand)
            ctx.remember('%r success.' % bindingName, inevow.IStatusMessage)
            return rv
        return util.maybeDeferred(self.getBinding, ctx, 
                                  bindingName).addCallback(_callback)
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:19,代码来源:rend.py


示例10: onManualPost

 def onManualPost(self, ctx, method, bindingName, kwargs):
     # This is copied from rend.Page.onWebFormPost
     def redirectAfterPost(aspects):
         redirectAfterPost = request.getComponent(iformless.IRedirectAfterPost, None)
         if redirectAfterPost is None:
             ref = request.getHeader('referer') or ''
         else:
             ## Use the redirectAfterPost url
             ref = str(redirectAfterPost)
         from nevow import url
         refpath = url.URL.fromString(ref)
         magicCookie = str(now())
         refpath = refpath.replace('_nevow_carryover_', magicCookie)
         _CARRYOVER[magicCookie] = C = compy.Componentized(aspects)
         request.redirect(str(refpath))
         from nevow import static
         return static.Data('You posted a form to %s' % bindingName, 'text/plain'), ()
     request = inevow.IRequest(ctx)
     return util.maybeDeferred(method, **kwargs
         ).addCallback(self.onPostSuccess, request, ctx, bindingName,redirectAfterPost
         ).addErrback(self.onPostFailure, request, ctx, bindingName,redirectAfterPost)
开发者ID:BackupTheBerlios,项目名称:weever-svn,代码行数:21,代码来源:main.py


示例11: getBinding

    def getBinding(self, ctx, name):
        """Massage bind_* methods and attributes into an
        IBinding. The bind_* method or attribute can either
        already implement IBinding or be a list of twoples
        which will be massaged into a MethodBinding as
        described in the ConfigurableMixin class docstring.
        """
        def _get_binding(binding):
            if callable(binding):
                binding = util.maybeDeferred(binding, ctx)
            return binding

        def _convert_list(binding):
            if isinstance(binding, list):
                binding = annotate.MethodBinding(
                    name, annotate.Method(arguments=[
                    annotate.Argument(n, v, v.id)
                    for (n, v) in binding]))
            return binding

        binding = util.maybeDeferred(getattr, self, 'bind_%s' % name)
        return binding.addCallback(_get_binding).addCallback(_convert_list)
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:22,代码来源:rend.py


示例12: formRenderer

 def formRenderer(ctx, data):
     cf = ctx.locate(iformless.IConfigurableFactory)
     return util.maybeDeferred(cf.locateConfigurable, ctx, configurableKey
                               ).addCallback(_formRenderIt)
开发者ID:StetHD,项目名称:nevow,代码行数:4,代码来源:webform.py


示例13: renderResource

 def renderResource(self, u):
     request = FakeRequest()
     ctx = context.RequestContext(tag=request)
     return util.maybeDeferred(inevow.IResource(u).renderHTTP, ctx).addCallback(
         lambda r: (r, request.redirected_to))
开发者ID:StetHD,项目名称:nevow,代码行数:5,代码来源:test_url.py


示例14: _get_binding

 def _get_binding(binding):
     if isinstance(binding, collections.Callable):
         binding = util.maybeDeferred(binding, ctx)
     return binding
开发者ID:perkinslr,项目名称:nevow-py3,代码行数:4,代码来源:rend.py


示例15: _get_binding

 def _get_binding(binding):
     if callable(binding):
         binding = util.maybeDeferred(binding, ctx)
     return binding
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:4,代码来源:rend.py



注:本文中的nevow.util.maybeDeferred函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.qual函数代码示例发布时间:2022-05-27
下一篇:
Python url.URL类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap