本文整理汇总了Python中twisted.protocols.basic.FileSender方法的典型用法代码示例。如果您正苦于以下问题:Python basic.FileSender方法的具体用法?Python basic.FileSender怎么用?Python basic.FileSender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.protocols.basic
的用法示例。
在下文中一共展示了basic.FileSender方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_transfer
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def test_transfer(self):
"""
L{basic.FileSender} sends the content of the given file using a
C{IConsumer} interface via C{beginFileTransfer}. It returns a
L{Deferred} which fires with the last byte sent.
"""
source = BytesIO(b"Test content")
consumer = proto_helpers.StringTransport()
sender = basic.FileSender()
d = sender.beginFileTransfer(source, consumer)
sender.resumeProducing()
# resumeProducing only finishes after trying to read at eof
sender.resumeProducing()
self.assertIsNone(consumer.producer)
self.assertEqual(b"t", self.successResultOf(d))
self.assertEqual(b"Test content", consumer.value())
示例2: test_transferMultipleChunks
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def test_transferMultipleChunks(self):
"""
L{basic.FileSender} reads at most C{CHUNK_SIZE} every time it resumes
producing.
"""
source = BytesIO(b"Test content")
consumer = proto_helpers.StringTransport()
sender = basic.FileSender()
sender.CHUNK_SIZE = 4
d = sender.beginFileTransfer(source, consumer)
# Ideally we would assertNoResult(d) here, but <http://tm.tl/6291>
sender.resumeProducing()
self.assertEqual(b"Test", consumer.value())
sender.resumeProducing()
self.assertEqual(b"Test con", consumer.value())
sender.resumeProducing()
self.assertEqual(b"Test content", consumer.value())
# resumeProducing only finishes after trying to read at eof
sender.resumeProducing()
self.assertEqual(b"t", self.successResultOf(d))
self.assertEqual(b"Test content", consumer.value())
示例3: test_abortedTransfer
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def test_abortedTransfer(self):
"""
The C{Deferred} returned by L{basic.FileSender.beginFileTransfer} fails
with an C{Exception} if C{stopProducing} when the transfer is not
complete.
"""
source = BytesIO(b"Test content")
consumer = proto_helpers.StringTransport()
sender = basic.FileSender()
d = sender.beginFileTransfer(source, consumer)
# Abort the transfer right away
sender.stopProducing()
failure = self.failureResultOf(d)
failure.trap(Exception)
self.assertEqual("Consumer asked us to stop producing",
str(failure.value))
示例4: send
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def send(self, consumer):
assert not self._send, "Can only call IReadFile.send *once* per instance"
self._send = True
d = basic.FileSender().beginFileTransfer(self.fObj, consumer)
d.addBoth(self._close)
return d
示例5: test_interface
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def test_interface(self):
"""
L{basic.FileSender} implements the L{IPullProducer} interface.
"""
sender = basic.FileSender()
self.assertTrue(verifyObject(IProducer, sender))
示例6: test_producerRegistered
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def test_producerRegistered(self):
"""
When L{basic.FileSender.beginFileTransfer} is called, it registers
itself with provided consumer, as a non-streaming producer.
"""
source = BytesIO(b"Test content")
consumer = proto_helpers.StringTransport()
sender = basic.FileSender()
sender.beginFileTransfer(source, consumer)
self.assertEqual(consumer.producer, sender)
self.assertFalse(consumer.streaming)
示例7: smtpState_data
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def smtpState_data(self, code, resp):
s = basic.FileSender()
d = s.beginFileTransfer(
self.getMailData(), self.transport, self.transformChunk)
def ebTransfer(err):
self.sendError(err.value)
d.addCallbacks(self.finishedFileTransfer, ebTransfer)
self._expected = SUCCESS
self._okresponse = self.smtpState_msgSent
示例8: smtpState_msgSent
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def smtpState_msgSent(self, code, resp):
if self._from is not None:
self.sentMail(code, resp, len(self.successAddresses),
self.toAddressesResult, self.log)
self.toAddressesResult = []
self._from = None
self.sendLine('RSET')
self._expected = SUCCESS
self._okresponse = self.smtpState_from
##
## Helpers for FileSender
##
示例9: startUp
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def startUp(self):
"""
Start transferring the message to the mailbox.
"""
self.createTempFile()
if self.fh != -1:
self.filesender = basic.FileSender()
self.filesender.beginFileTransfer(self.msg, self)
示例10: _gotArticle
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def _gotArticle(self, result):
(index, id, article) = result
self.currentIndex = index
self.sendLine('220 %d %s article' % (index, id))
s = basic.FileSender()
d = s.beginFileTransfer(article, self.transport)
d.addCallback(self.finishedFileTransfer)
##
## Helper for FileSender
##
示例11: _gotBody
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def _gotBody(self, result):
(index, id, body) = result
self.currentIndex = index
self.sendLine('221 %d %s article retrieved' % (index, id))
self.lastsent = ''
s = basic.FileSender()
d = s.beginFileTransfer(body, self.transport)
d.addCallback(self.finishedFileTransfer)
示例12: connectionMade
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def connectionMade(self):
s = basic.FileSender()
d = s.beginFileTransfer(self.f, self.transport, lambda x: x)
d.addCallback(lambda r: self.transport.loseConnection())
示例13: testSendingEmptyFile
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def testSendingEmptyFile(self):
fileSender = basic.FileSender()
consumer = abstract.FileDescriptor()
consumer.connected = 1
emptyFile = BytesIO(b'')
d = fileSender.beginFileTransfer(emptyFile, consumer, lambda x: x)
# The producer will be immediately exhausted, and so immediately
# unregistered
self.assertIsNone(consumer.producer)
# Which means the Deferred from FileSender should have been called
self.assertTrue(d.called,
'producer unregistered with deferred being called')
示例14: connectionMade
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def connectionMade(self):
d = basic.FileSender().beginFileTransfer(open(self.junkPath, 'rb'),
self.transport)
d.addErrback(failed)
d.addCallback(lambda ign: self.transport.loseConnection())
示例15: __init__
# 需要导入模块: from twisted.protocols import basic [as 别名]
# 或者: from twisted.protocols.basic import FileSender [as 别名]
def __init__(self, filename, transform=None, delay=0, verbose=False):
self.f = open(filename, 'rb')
self.transform = transform
self.delay = delay
self.producer = FileSender()
self.logger = gogo.Gogo(__name__, verbose=verbose).logger