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

Python defer.deferredGenerator函数代码示例

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

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



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

示例1: require

def require(packageName, fixName):
    if (packageName, fixName) in _alreadyInstalled:
        return

    if (packageName, fixName) == ("twisted", "filepath_copyTo"):
        from twisted.python import filepath

        if filepath.FilePath("a") != filepath.FilePath("a"):
            from vmc.contrib.epsilon.hotfixes import filepath_copyTo

            filepath_copyTo.install()
    elif (packageName, fixName) == ("twisted", "timeoutmixin_calllater"):
        from twisted.protocols import policies

        if not hasattr(policies.TimeoutMixin, "callLater"):
            from vmc.contrib.epsilon.hotfixes import timeoutmixin_calllater

            timeoutmixin_calllater.install()
    elif (packageName, fixName) == ("twisted", "delayedcall_seconds"):
        from twisted.internet import base

        args = inspect.getargs(base.DelayedCall.__init__.func_code)[0]
        if "seconds" not in args:
            from vmc.contrib.epsilon.hotfixes import delayedcall_seconds

            delayedcall_seconds.install()
    elif (packageName, fixName) == ("twisted", "deferredgenerator_tfailure"):
        from twisted.internet import defer

        result = []

        def test():
            d = defer.waitForDeferred(defer.succeed(1))
            yield d
            result.append(d.getResult())

        defer.deferredGenerator(test)()
        if result == [1]:
            from vmc.contrib.epsilon.hotfixes import deferredgenerator_tfailure

            deferredgenerator_tfailure.install()
        else:
            assert result == [None]
    elif (packageName, fixName) == ("twisted", "proto_helpers_stringtransport"):
        from twisted.test.proto_helpers import StringTransport

        st = StringTransport()
        try:
            st.write(u"foo")
        except TypeError, e:
            pass
        else:
            from vmc.contrib.epsilon.hotfixes import proto_helpers_stringtransport

            proto_helpers_stringtransport.install()
开发者ID:mrader11,项目名称:vodafone-mobile-connect,代码行数:55,代码来源:hotfix.py


示例2: processLockRequest

def processLockRequest(resource, request):
    """
    Respond to a LOCK request. (RFC 2518, section 8.10)
    
    Relevant notes:
    
    """ 
    
    requestStream = request.stream
    depth = getDepth(request.headers)
    
    #log.error(request.headers.getRawHeaders("X-Litmus")[0])
    
    # generate DAVDocument from request body
    lockInfo = waitForDeferred(deferredGenerator(parseLockRequest)(requestStream))
    yield lockInfo
    lockInfo = lockInfo.getResult()
          
    assertExclusiveLock(lockInfo)   
    assertWriteLock(lockInfo)
    
    # we currently only allow lock depths of "0"
    assertZeroLockDepth(depth)
        
    # build the corresponding activelock element
    # e.g. http://www.webdav.org/specs/rfc2518.html#rfc.section.8.10.8
    activeLock = buildActiveLock(lockInfo, depth)  

    # extract the lock token
    lt = activeLock.childOfType(davxml.LockToken).childOfType(davxml.HRef)
    # make headers with lock token header
    lth = http_headers.Headers(
                               rawHeaders = {"Lock-Token": [lt]}
                               )
    
    
    ld = davxml.LockDiscovery(activeLock)

    
    ignored = waitForDeferred(deferredGenerator(resource._setLock)(ld, request))
    yield ignored
    ignored = ignored.getResult()
    
    # debug
    ignored = waitForDeferred(deferredGenerator(resource._getLock)())
    yield ignored
    ignored = ignored.getResult()
    
    pp = davxml.PropertyContainer(ld)
    yield Response(
                   code = responsecode.OK, 
                   headers = lth, 
                   stream = stream.MemoryStream(pp.toxml()))
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:53,代码来源:lock.py


示例3: http_COPY

    def http_COPY(self, request):
        """
        Wrap the request in an assertion that the lock token provided with
        the request corresponds to the lock token associated with the resource.
        """
        
        def __http_copy(self, request):
            """Assert that the destination is not locked."""
            
            destination_uri = request.headers.getHeader("destination")

            # assert that the destination exists
            if not destination_uri:
                msg = "No destination header in %s request." % (request.method,)
                log.error(msg)
                raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, msg))

            # assert that the destination is not locked
            dest = waitForDeferred(request.locateResource(destination_uri))
            yield dest
            dest = dest.getResult()
                       
            ignore = waitForDeferred(deferredGenerator(dest.assertNotLocked)(request))
            yield ignore
            ignore = ignore.getResult()
        
            dd = waitForDeferred(super(Lockable, self).http_COPY(request))
            yield dd
            yield dd.getResult()
            #yield deferredGenerator(super(Lockable, self).http_COPY)(request)
                
        return deferredGenerator(__http_copy)(self, request)
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:32,代码来源:lock.py


示例4: http_PROPPATCH

 def http_PROPPATCH(self, request):
     """
     Wrap the request in an assertion that the lock token provided with
     the request corresponds to the lock token associated with the resource.
     """
     return deferredGenerator(self.assertNotLocked)(request).addCallback(
                                                                         super(Lockable, self).http_PROPPATCH) 
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:7,代码来源:lock.py


示例5: isLocked

    def isLocked(self, request):
        """
        A resource is considered mutable in this context, if 
        -- it is not locked
        -- the request provides the opaquelocktoken corresponding to the lock on this resource
        """
        
        # get the local lock token
        llt = waitForDeferred(deferredGenerator(self._lockToken)())
        yield llt
        llt = llt.getResult()
    
        # get the remote lock token
        rlt = getOpaqueLockToken(request)   

        if self.exists():
            # a resource that does not exist can not be locked
            yield False

        elif llt == None:
            # this resource has no lock associated with it, ergo not locked
            yield False        

        elif rlt == llt:
            # this resource has a lock token associated with it, but the same
            # lock token has been supplied, ergo not locked (for this request)
            yield False
        
        else:
            # resource is locked
            yield True
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:31,代码来源:lock.py


示例6: testDeferredYielding

    def testDeferredYielding(self):
        # See the comment _deferGenerator about d.callback(Deferred).
        def _genDeferred():
            yield getThing()
        _genDeferred = deferredGenerator(_genDeferred)

        return self.assertFailure(_genDeferred(), TypeError)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:7,代码来源:test_defgen.py


示例7: testBuggyGen

    def testBuggyGen(self):
        def _genError():
            yield waitForDeferred(getThing())
            1/0
        _genError = deferredGenerator(_genError)

        return self.assertFailure(_genError(), ZeroDivisionError)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:7,代码来源:test_defgen.py


示例8: http_MOVE

 def http_MOVE(self, request):
     """
     Wrap the request in an assertion that the lock token provided with
     the request corresponds to the lock token associated with the resource.
     
     TODO: assert that the destination file is not locked.
     """       
     return deferredGenerator(self.assertNotLocked)(request).addCallback(
                                                                         super(Lockable, self).http_MOVE)
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:9,代码来源:lock.py


示例9: testStackUsage2

    def testStackUsage2(self):
        def _loop():
            for x in range(5000):
                # Test with yielding a random value
                yield 1
            yield 0

        _loop = deferredGenerator(_loop)
        return _loop().addCallback(self.assertEqual, 0)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:9,代码来源:test_defgen.py


示例10: testMultipleShutdowns

 def testMultipleShutdowns(self):
     def runner():
         for k in xrange(10):
             yield waitForDeferred(self.broker.shutdown())
             d = Deferred()
             reactor.callLater(0.02, d.callback, None)
             yield waitForDeferred(d)
     runner = deferredGenerator(runner)
     return runner()
开发者ID:D3f0,项目名称:txscada,代码行数:9,代码来源:test_database.py


示例11: testDeferredYielding

    def testDeferredYielding(self):
        """
        Ensure that yielding a Deferred directly is trapped as an
        error.
        """
        # See the comment _deferGenerator about d.callback(Deferred).
        def _genDeferred():
            yield getThing()
        _genDeferred = deferredGenerator(_genDeferred)

        return self.assertFailure(_genDeferred(), TypeError)
开发者ID:0004c,项目名称:VTK,代码行数:11,代码来源:test_defgen.py


示例12: _removeLock

 def _removeLock(self, request):
     """
     Remove the lockDiscovery property from the resource.
     """ 
             
     ignore = waitForDeferred(deferredGenerator(self.assertNotLocked)(request))
     yield ignore
     ignore = ignore.getResult()
     
     self.removeDeadProperty(davxml.LockDiscovery)
     
     yield Response(responsecode.NO_CONTENT)
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:12,代码来源:lock.py


示例13: _put

    def _put(self, stream): 

        if not self.isWritableFile():
            message = "http_PUT: not authorized to put file: " + self.fp.path
            log.error(message)
            raise HTTPError(StatusResponse(responsecode.UNAUTHORIZED, message))
         
        response = waitForDeferred(deferredGenerator(self.__putDelete)())
        yield response
        response = response.getResult()
        
        xx  = waitForDeferred(deferredGenerator(self.__putFile)(stream))
        yield xx
        xx = xx.getResult()
        
        self._registerWithParent()
        
        xx = waitForDeferred(deferredGenerator(self._updateMetadata)())
        yield xx
        
        yield response
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:21,代码来源:put.py


示例14: assertNotLocked

    def assertNotLocked(self, request):
        il =  waitForDeferred(deferredGenerator(self.isLocked)(request))
        yield il
        il = il.getResult()
        
        if il is True:

            error = "Resource is locked and you don't have the proper token handy."
            log.error(error)
            raise HTTPError(StatusResponse(responsecode.LOCKED, error))
        
        # we must forward the request to possible callbacks
        yield request
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:13,代码来源:lock.py


示例15: _setLock

 def _setLock(self, lockDiscovery, request):
     """
     Lock this resource with the supplied activelock.
     """
     
     ignore = waitForDeferred(deferredGenerator(self.assertNotLocked)(request))
     yield ignore
     ignore = ignore.getResult()    
     
     # the lockDiscovery property is protected, it must therefore be
     # set through writeDeadProperty instead of through writeProperty
     self.writeDeadProperty(lockDiscovery)
     
     yield lockDiscovery
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:14,代码来源:lock.py


示例16: initCluster

def initCluster(locator):
	"""This method must be called first"""
	global cluster
	
	for name, value in globals().items():
		if isinstance(value, type):
			if issubclass(value, Model):
				setattr(value, 'locator', locator)
	
	def initShards():
		shards = defer.waitForDeferred(cluster.startup())
		yield shards
		shards = shards.getResult()
	d = defer.deferredGenerator(initShards)
	return d()
开发者ID:oscar810429,项目名称:pndfs,代码行数:15,代码来源:cluster.py


示例17: _lockToken

 def _lockToken(self):
     """
     @return the uri of the opaquelocktoken of the lock on this resource, if the latter exists, otherwise None.
     
     See: http://webdav.org/specs/rfc2518.html#rfc.section.6.4
     """
     lockDiscovery = waitForDeferred(deferredGenerator(self._getLock)())
     yield lockDiscovery
     lockDiscovery = lockDiscovery.getResult()
     
     if lockDiscovery is None: 
         yield None
     else:
         href = str(lockDiscovery.childOfType(davxml.ActiveLock).childOfType(davxml.LockToken).childOfType(davxml.HRef))
         yield href
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:15,代码来源:lock.py


示例18: testHandledTerminalFailure

    def testHandledTerminalFailure(self):
        """
        Create a Deferred Generator which yields a Deferred which fails and
        handles the exception which results.  Assert that the Deferred
        Generator does not errback its Deferred.
        """
        class TerminalException(Exception):
            pass

        def _genFailure():
            x = waitForDeferred(defer.fail(TerminalException("Handled Terminal Failure")))
            yield x
            try:
                x.getResult()
            except TerminalException:
                pass
        _genFailure = deferredGenerator(_genFailure)
        return _genFailure().addCallback(self.assertEqual, None)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:18,代码来源:test_defgen.py


示例19: __lockPreconditions

    def __lockPreconditions(self, request):

        if not self.exists():
            error = "File not found in LOCK request: %s" % ( self.fp.path, )
            raise HTTPError(StatusResponse(responsecode.NOT_FOUND, error))
        
        if not self.isWritableFile():
            error = "No write permission for file."
            raise HTTPError(StatusResponse(responsecode.UNAUTHORIZED, error))
       
        ignore = waitForDeferred(deferredGenerator(self.assertNotLocked)(request))
        yield ignore
        ignore = ignore.getResult()
        
        # for some reason, the result of preconditions_LOCK is handed as an argument to http_LOCK
        # (i guess so that the request can be modified during the preconditions call). anyway,
        # we must yield the request at the end.
        yield request
开发者ID:infothrill,项目名称:angel-app-svnmirror,代码行数:18,代码来源:lock.py


示例20: getPageFromAny

def getPageFromAny(upstreams, factory=client.HTTPClientFactory,
		   context_factory=None):
	if not upstreams:
		raise error.Error(http.INTERNAL_SERVER_ERROR)

	def subgen():
		lastError = None
		for (identifier, url, args, kwargs) in upstreams:
			subfactory = client._makeGetterFactory(url,
							       factory,
							       context_factory,
							       *args, **kwargs)
			wait = defer.waitForDeferred(subfactory.deferred)
			yield wait
			try:
				yield (wait.getResult(), identifier, subfactory)
				return
			except ConnectError:
				lastError = sys.exc_info()[1]
		raise lastError and lastError or error.Error(http.INTERNAL_SERVER_ERROR)
	return defer.deferredGenerator(subgen)()
开发者ID:bussiere,项目名称:couchdb-lounge,代码行数:21,代码来源:fetcher.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python defer.execute函数代码示例发布时间:2022-05-27
下一篇:
Python base.ThreadedResolver类代码示例发布时间: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