本文整理汇总了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)
示例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')
示例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')
示例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.