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


Python ClientFactory.noisy方法代码示例

本文整理汇总了Python中twisted.internet.protocol.ClientFactory.noisy方法的典型用法代码示例。如果您正苦于以下问题:Python ClientFactory.noisy方法的具体用法?Python ClientFactory.noisy怎么用?Python ClientFactory.noisy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.protocol.ClientFactory的用法示例。


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

示例1: testStor

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import noisy [as 别名]
    def testStor(self):
        # Connect
        client = ftp.FTPClient(passive=self.passive)
        client.debug = 1
        factory = ClientFactory()
        factory.noisy = 0
        factory.buildProtocol = lambda s, c=client: c
        reactor.connectTCP('localhost', self.ftp_port, factory)

        expectedContent = "Hello\n"*4
        
        def gotResult(c):
            c.write(expectedContent)
            c.finish()

        def gotErr(f):
            self.errback(f)

        t = client.storeFile("HelloThere")
        t[0].addCallbacks(gotResult, gotErr)
        t[1].addCallbacks(self.callback, self.errback)

        # Wait for a result
        id = reactor.callLater(5, self.errback, "timed out") # timeout so we don't freeze
        while not hasattr(self, 'result') and not hasattr(self, 'error'):
            reactor.iterate()
        try:
            id.cancel()
        except ValueError: pass

        error = getattr(self, 'error', None)
        if error:
            raise error[0], error[1], error[2]

        self.assertEquals(open('HelloThere').read(), expectedContent)
开发者ID:fxia22,项目名称:ASM_xf,代码行数:37,代码来源:test_ftp.py

示例2: testShortFileListings

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import noisy [as 别名]
    def testShortFileListings(self):

        # Connect
        client = ftp.FTPClient(passive=self.passive)
        factory = ClientFactory()
        factory.noisy = 0
        factory.buildProtocol = lambda s, c=client: c
        reactor.connectTCP('localhost', self.ftp_port, factory)

        # Issue the command and set the callbacks
        p = BufferingProtocol()
        d = client.nlst('.', p)
        d.addCallbacks(self.callback, self.errback)

        # Wait for the result
        id = reactor.callLater(5, self.errback, "timed out") # timeout so we don't freeze
        while not hasattr(self, 'result') and not hasattr(self, 'error'):
            reactor.iterate()
        try:
            id.cancel()
        except ValueError: pass

        error = getattr(self, 'error', None)
        if error:
            raise error[0], error[1], error[2]

        # Check that the listing contains this file (ftp_crap)
        filenames = p.buf.getvalue().split('\r\n')
        self.failUnless('ftp_crap' in filenames,
                        'ftp_crap not in file listing')
开发者ID:fxia22,项目名称:ASM_xf,代码行数:32,代码来源:test_ftp.py

示例3: testRetr

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import noisy [as 别名]
    def testRetr(self):
        # Connect
        client = ftp.FTPClient(passive=self.passive)
        factory = ClientFactory()
        factory.noisy = 0
        factory.buildProtocol = lambda s, c=client: c
        reactor.connectTCP('localhost', self.ftp_port, factory)

        # download ftp_crap
        

        proto = BufferingProtocol()
        d = client.retr(os.path.basename('ftp_crap'), proto)
        d.addCallbacks(self.callback, self.errback)

        # Wait for a result
        id = reactor.callLater(5, self.errback, "timed out") # timeout so we don't freeze
        while not hasattr(self, 'result') and not hasattr(self, 'error'):
            reactor.iterate()
        try:
            id.cancel()
        except ValueError: pass

        error = getattr(self, 'error', None)
        if error:
            raise error[0], error[1], error[2]

        # Check that the file is the same as read directly off the disk
        self.failUnless(type(self.result) == types.ListType,
                        'callback result is wrong type: ' + str(self.result))
        data = proto.buf.getvalue()
        self.failUnless(data == open('ftp_crap', "rb").read(),
                        'RETRieved file does not match original')
开发者ID:fxia22,项目名称:ASM_xf,代码行数:35,代码来源:test_ftp.py

示例4: gotError

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import noisy [as 别名]
            except Exception, e:
                self.callbackException = sys.exc_info()
                raise

        errors = [None, None]
        def gotError(failure, x, errors_=errors):
            errors_[x] = failure

        # These LIST commands should should both fail
        d = client.list('.', ftp.FTPFileListProtocol())
        d.addCallbacks(badResult, gotError, errbackArgs=(0,))
        d = client.list('.', ftp.FTPFileListProtocol())
        d.addCallbacks(badResult, gotError, errbackArgs=(1,))

        factory = ClientFactory()
        factory.noisy = 0
        factory.buildProtocol = lambda s,c=client: c
        reactor.connectTCP('localhost', self.ftp_port, factory)
        while None in errors and not self.callbackException:
            reactor.iterate()

        if self.callbackException:
            ce = self.callbackException
            raise ce[0], ce[1], ce[2]

        log.flushErrors(ftp.ConnectionLost)


class FTPPassiveClientAndServerTests(FTPClientAndServerTests):
    """Identical to FTPClientTests, except with passive transfers.
开发者ID:fxia22,项目名称:ASM_xf,代码行数:32,代码来源:test_ftp.py


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