本文整理汇总了Python中twisted.internet.defer.waitForDeferred方法的典型用法代码示例。如果您正苦于以下问题:Python defer.waitForDeferred方法的具体用法?Python defer.waitForDeferred怎么用?Python defer.waitForDeferred使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.defer
的用法示例。
在下文中一共展示了defer.waitForDeferred方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _genBasics
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def _genBasics(self):
x = waitForDeferred(getThing())
yield x
x = x.getResult()
self.assertEqual(x, "hi")
ow = waitForDeferred(getOwie())
yield ow
try:
ow.getResult()
except ZeroDivisionError as e:
self.assertEqual(str(e), 'OMG')
yield "WOOSH"
return
示例2: _readUntil
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def _readUntil(self, f):
"""Internal helper function which repeatedly calls f each time
after more data has been received, until it returns non-None."""
while True:
r = f()
if r is not None:
yield r
return
newdata = self.stream.read()
if isinstance(newdata, defer.Deferred):
newdata = defer.waitForDeferred(newdata)
yield newdata
newdata = newdata.getResult()
if newdata is None:
# End Of File
newdata = self.data
self.data = ''
yield newdata
return
self.data += str(newdata)
示例3: _readBoundaryLine
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def _readBoundaryLine(self):
# print("_readBoundaryLine")
line = self.stream.readline(size=1024)
if isinstance(line, defer.Deferred):
line = defer.waitForDeferred(line)
yield line
line = line.getResult()
if line == "--\r\n":
# THE END!
yield False
return
elif line != "\r\n":
raise MimeFormatError("Unexpected data on same line as boundary: %r" % (line,))
yield True
return
示例4: http_REPORT
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def http_REPORT(self, request):
"""
Respond to a REPORT request. (RFC 3253, section 3.6)
"""
if not self.exists():
log.error("File not found: %s" % (self,))
raise HTTPError(responsecode.NOT_FOUND)
#
# Check authentication and access controls
#
x = waitForDeferred(self.authorize(request, (davxml.Read(),)))
yield x
x.getResult()
#
# Read request body
#
try:
doc = waitForDeferred(davXMLFromStream(request.stream))
yield doc
doc = doc.getResult()
except ValueError, e:
log.error("Error while handling REPORT body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
示例5: http_PROPPATCH
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def http_PROPPATCH(self, request):
"""
Respond to a PROPPATCH request. (RFC 2518, section 8.2)
"""
if not self.exists():
log.error("File not found: %s" % (self,))
raise HTTPError(responsecode.NOT_FOUND)
x = waitForDeferred(self.authorize(request, (davxml.WriteProperties(),)))
yield x
x.getResult()
#
# Read request body
#
try:
doc = waitForDeferred(davXMLFromStream(request.stream))
yield doc
doc = doc.getResult()
except ValueError, e:
log.error("Error while handling PROPPATCH body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
示例6: http_DELETE
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def http_DELETE(self, request):
"""
Respond to a DELETE request. (RFC 2518, section 8.6)
"""
if not self.exists():
log.error("File not found: %s" % (self,))
raise HTTPError(responsecode.NOT_FOUND)
depth = request.headers.getHeader("depth", "infinity")
#
# Check authentication and access controls
#
parent = waitForDeferred(request.locateResource(parentForURL(request.uri)))
yield parent
parent = parent.getResult()
x = waitForDeferred(parent.authorize(request, (davxml.Unbind(),)))
yield x
x.getResult()
x = waitForDeferred(deleteResource(request, self, request.uri, depth))
yield x
yield x.getResult()
示例7: doTest
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def doTest(self, boundary, data, expected_args, expected_files):
# import time, gc, cgi, cStringIO
for bytes in range(1, 20):
# s = TestStream(data, maxReturn=bytes)
s = stream.IStream(data)
# t=time.time()
d = waitForDeferred(fileupload.parseMultipartFormData(s, boundary))
yield d
args, files = d.getResult()
# e=time.time()
# print "%.2g"%(e-t)
self.assertEquals(args, expected_args)
# Read file data back into memory to compare.
out = {}
for name, l in files.items():
out[name] = [(filename, ctype, f.read()) for (filename, ctype, f) in l]
self.assertEquals(out, expected_files)
# data=cStringIO.StringIO(data)
# t=time.time()
# d=cgi.parse_multipart(data, {'boundary':boundary})
# e=time.time()
# print "CGI: %.2g"%(e-t)
示例8: _run_cleanups
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def _run_cleanups(self):
"""Run the cleanups on the test case.
We expect that the cleanups on the test case can also return
asynchronous Deferreds. As such, we take the responsibility for
running the cleanups, rather than letting TestCase do it.
"""
while self.case._cleanups:
f, args, kwargs = self.case._cleanups.pop()
d = defer.maybeDeferred(f, *args, **kwargs)
thing = defer.waitForDeferred(d)
yield thing
try:
thing.getResult()
except Exception:
exc_info = sys.exc_info()
self.case._report_traceback(exc_info)
last_exception = exc_info[1]
yield last_exception
示例9: testUserRetrieval
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def testUserRetrieval(self):
realm = service.InMemoryWordsRealm("realmname")
# Make a user to play around with
d = wFD(realm.createUser(u"testuser"))
yield d
user = d.getResult()
# Make sure getting the user returns the same object
d = wFD(realm.getUser(u"testuser"))
yield d
retrieved = d.getResult()
self.assertIdentical(user, retrieved)
# Make sure looking up the user also returns the same object
d = wFD(realm.lookupUser(u"testuser"))
yield d
lookedUp = d.getResult()
self.assertIdentical(retrieved, lookedUp)
# Make sure looking up a user who does not exist fails
d = wFD(realm.lookupUser(u"nosuchuser"))
yield d
self.assertRaises(ewords.NoSuchUser, d.getResult)
示例10: testUserAddition
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def testUserAddition(self):
realm = service.InMemoryWordsRealm("realmname")
# Create and manually add a user to the realm
p = service.User("testuser")
d = wFD(realm.addUser(p))
yield d
user = d.getResult()
self.assertIdentical(p, user)
# Make sure getting that user returns the same object
d = wFD(realm.getUser(u"testuser"))
yield d
retrieved = d.getResult()
self.assertIdentical(user, retrieved)
# Make sure looking up that user returns the same object
d = wFD(realm.lookupUser(u"testuser"))
yield d
lookedUp = d.getResult()
self.assertIdentical(retrieved, lookedUp)
示例11: testGroupRetrieval
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def testGroupRetrieval(self):
realm = service.InMemoryWordsRealm("realmname")
d = wFD(realm.createGroup(u"testgroup"))
yield d
group = d.getResult()
d = wFD(realm.getGroup(u"testgroup"))
yield d
retrieved = d.getResult()
self.assertIdentical(group, retrieved)
d = wFD(realm.getGroup(u"nosuchgroup"))
yield d
self.assertRaises(ewords.NoSuchGroup, d.getResult)
示例12: testEnumeration
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def testEnumeration(self):
realm = service.InMemoryWordsRealm("realmname")
d = wFD(realm.createGroup(u"groupone"))
yield d
d.getResult()
d = wFD(realm.createGroup(u"grouptwo"))
yield d
d.getResult()
groups = wFD(realm.itergroups())
yield groups
groups = groups.getResult()
n = [g.name for g in groups]
n.sort()
self.assertEquals(n, ["groupone", "grouptwo"])
示例13: test_nickServLogin
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def test_nickServLogin(self):
"""
Sending NICK without PASS will prompt the user for their password.
When the user sends their password to NickServ, it will respond with a
Greeting.
"""
firstuser = wFD(self.realm.lookupUser(u'firstuser'))
yield firstuser
firstuser = firstuser.getResult()
user = TestCaseUserAgg(firstuser, self.realm, self.factory)
user.write('NICK firstuser extrainfo\r\n')
response = self._response(user, 'PRIVMSG')
self.assertEquals(len(response), 1)
self.assertEquals(response[0][0], service.NICKSERV)
self.assertEquals(response[0][1], 'PRIVMSG')
self.assertEquals(response[0][2], ['firstuser', 'Password?'])
user.transport.clear()
user.write('PRIVMSG nickserv firstuser_password\r\n')
self._assertGreeting(user)
示例14: test_joinTopicless
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def test_joinTopicless(self):
"""
When a user joins a group without a topic, no topic information is
sent to that user.
"""
firstuser = wFD(self.realm.lookupUser(u'firstuser'))
yield firstuser
firstuser = firstuser.getResult()
somechannel = wFD(self.realm.createGroup(u"somechannel"))
yield somechannel
somechannel = somechannel.getResult()
# Bring in one user, make sure he gets into the channel sanely
user = TestCaseUserAgg(firstuser, self.realm, self.factory)
self._login(user, "firstuser")
user.transport.clear()
user.write('JOIN #somechannel\r\n')
response = self._response(user)
responseCodes = [r[1] for r in response]
self.assertNotIn('332', responseCodes)
self.assertNotIn('333', responseCodes)
示例15: testGetGroupMode
# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import waitForDeferred [as 别名]
def testGetGroupMode(self):
user = wFD(self._loggedInUser(u'useruser'))
yield user
user = user.getResult()
add = wFD(self.realm.createGroup(u"somechannel"))
yield add
somechannel = add.getResult()
user.write('JOIN #somechannel\r\n')
user.transport.clear()
user.write('MODE #somechannel\r\n')
response = self._response(user)
self.assertEquals(len(response), 1)
self.assertEquals(response[0][1], '324')