当前位置: 首页>>代码示例>>Python>>正文


Python basic.FileSender方法代码示例

本文整理汇总了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()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_basic.py

示例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()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_basic.py

示例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)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_basic.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:ftp.py

示例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)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:test_basic.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_basic.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:smtp.py

示例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
    ## 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:smtp.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:maildir.py

示例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
    ## 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:nntp.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:nntp.py

示例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()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:test_tpfile.py

示例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') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_tpfile.py

示例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()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:stdio_test_consumer.py

示例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 
开发者ID:nerevu,项目名称:riko,代码行数:8,代码来源:io.py


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