本文整理汇总了Python中twisted.internet.defer.deferredGenerator函数的典型用法代码示例。如果您正苦于以下问题:Python deferredGenerator函数的具体用法?Python deferredGenerator怎么用?Python deferredGenerator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了deferredGenerator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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()))
示例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)
示例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)
示例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
示例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)
示例7: testBuggyGen
def testBuggyGen(self):
def _genError():
yield waitForDeferred(getThing())
1/0
_genError = deferredGenerator(_genError)
return self.assertFailure(_genError(), ZeroDivisionError)
示例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)
示例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)
示例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()
示例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)
示例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)
示例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
示例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
示例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