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


Python ClientFactory.buildProtocol方法代码示例

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


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

示例1: buildProtocol

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
 def buildProtocol(self, address):
     """ Overriden method to distinguish between the two protocols. """
     
     if address.port == 8888:
         self.protocol = DirectoryProtocol
         self.dirProto = ClientFactory.buildProtocol(self, address)
         return self.dirProto
     else:
         self.protocol = PeerProtocol
         return ClientFactory.buildProtocol(self, address)
开发者ID:SokratisVidros,项目名称:eurechat,代码行数:12,代码来源:chatClient.py

示例2: buildProtocol

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
 def buildProtocol(self, addr):
     log.msg("Building protocol for %r" % addr)
     proto = ClientFactory.buildProtocol(self, addr)
     proto.app = self.app
     self.proto = proto
     self.join.ready()
     return proto
开发者ID:ojii,项目名称:bottu,代码行数:9,代码来源:irc.py

示例3: test_send_peh_upon_connection

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
    def test_send_peh_upon_connection(self):
        '''To test client protocol we isloate it from the ClientFactory'''
        with patch.object(datetime, 'datetime', Mock(wraps=datetime.datetime)) as patched:
            fixed_date = datetime.datetime(2014, 1, 1, 12, 0, 0)
            patched.now.return_value = fixed_date

            factory = ClientFactory()
            factory.comaster = self.comaster

            factory.protocol = MaraClientProtocol
            proto = factory.buildProtocol(('127.0.0.1', 0))
            proto.construct = MaraFrame

            # Disable unnesesary behaviour
            def stop():
                proto.stop()
                reactor.stop()
            proto.sendPoll = MagicMock(side_effect=stop)

            transport = proto_helpers.StringTransport()
            proto.makeConnection(transport)

            bytes_sent_to_device = transport.value()
            result = MaraFrame.parse(bytes_sent_to_device)
            self.assertEqual(result.dest, 0xFF)
            self.assertEqual(result.source, 2)

            # We don't need to check BCC since it's already coded into MaraFrame
            self.assertEqual(result.peh, fixed_date)

            reactor.run()
            # Shuld have stopped
            self.assertEqual(self.comaster.update_peh_timestamp.call_count, 1)
            self.assertEqual(self.comaster.update_peh_timestamp.call_args[0][0],
                             fixed_date)
开发者ID:D3f0,项目名称:txscada,代码行数:37,代码来源:test_protocol_peh.py

示例4: test_connectTCP

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
    def test_connectTCP(self):
        """
        Called on the object returned by L{loggedReactor}, C{connectTCP} calls
        the wrapped reactor's C{connectTCP} method with the original factory
        wrapped in a L{_TrafficLoggingFactory}.
        """
        class RecordDataProtocol(Protocol):
            def dataReceived(self, data):
                self.data = data
        proto = RecordDataProtocol()
        factory = ClientFactory()
        factory.protocol = lambda: proto
        reactor = MemoryReactor()
        logged = loggedReactor(reactor)
        logged.connectTCP('192.168.1.2', 1234, factory, 21, '127.0.0.2')
        [(host, port, factory, timeout, bindAddress)] = reactor.tcpClients
        self.assertEqual('192.168.1.2', host)
        self.assertEqual(1234, port)
        self.assertIsInstance(factory, _TrafficLoggingFactory)
        self.assertEqual(21, timeout)
        self.assertEqual('127.0.0.2', bindAddress)

        # Verify that the factory and protocol specified are really being used
        protocol = factory.buildProtocol(None)
        protocol.makeConnection(None)
        protocol.dataReceived("foo")
        self.assertEqual(proto.data, "foo")
开发者ID:eventable,项目名称:CalendarServer,代码行数:29,代码来源:test_trafficlogger.py

示例5: testStor

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [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

示例6: testRetr

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [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

示例7: testShortFileListings

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [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

示例8: buildProtocol

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
 def buildProtocol(self, addr):
     """Provision protocol with the dedicated logger
     """
     proto = ClientFactory.buildProtocol(self, addr)
     proto.log = self.log
     
     return proto
开发者ID:AlternativeValue-ALVA,项目名称:jasmin,代码行数:9,代码来源:factory.py

示例9: buildProtocol

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
 def buildProtocol(self, addr):
     p = ClientFactory.buildProtocol(self, addr)
     if not hasattr(self,'deferred'):
         self.deferred = defer.Deferred()
     self.reactor.callLater(0, self.deferred.callback, p)
     del self.deferred
     return p
开发者ID:dpnova,项目名称:txmemcache,代码行数:9,代码来源:client.py

示例10: SpdyProtocolTest

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
class SpdyProtocolTest(TestCase):
    def setUp(self):
        self.factory = ClientFactory()
        self.factory.protocol = spdy.SpdyProtocol
        self.proto = self.factory.buildProtocol(('127.0.0.1', 0))
        self.tr = proto_helpers.StringTransport()
        self.proto.makeConnection(self.tr)

    def tearDown(self):
        return self.tr.loseConnection()
    
    def send(self, data):
        self.proto.dataReceived(data)    

    def testExampleFrames(self):
        called = []
        def request(streamId, headers):
            called.append(None)
            self.assertEqual(1, streamId)
            self.assertEqual('GET', headers.getRawHeaders('method')[0])
        self.proto.requestFactory = request
        self.send(example_frames)
        self.assertEqual(1, len(called))
        
                
开发者ID:myers,项目名称:txspdy,代码行数:25,代码来源:test_spdy.py

示例11: buildProtocol

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
 def buildProtocol(self, addr):
     """
     Instantiate sub protocol.
     """
     p = ClientFactory.buildProtocol(self, addr)
     p.initialAction = self.deferreds.pop(0)
     return p
开发者ID:cybergrind,项目名称:twotp,代码行数:9,代码来源:epmd.py

示例12: buildProtocol

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
 def buildProtocol(self, address):
     logger.vdebug(
         'Building protocol in StarboundClientFactory to address %s',
         address
     )
     protocol = ClientFactory.buildProtocol(self, address)
     protocol.server_protocol = self.server_protocol
     return protocol
开发者ID:8r2y5,项目名称:StarryPy,代码行数:10,代码来源:server.py

示例13: buildProtocol

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
 def buildProtocol(self, addr):
     r = ClientFactory.buildProtocol(self, addr)
     r.postHandshakeEndpoint = self.postHandshakeEndpoint
     r.postHandshakeFactory = self.postHandshakeFactory
     r.handshakeDone = self.handshakeDone
     r._timestamps = self._timestamps
     r._timer = self._timer
     return r
开发者ID:kloesing,项目名称:twisted-socks,代码行数:10,代码来源:socksclient.py

示例14: makeProto

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
 def makeProto(self, *a, **kw):
     protoClass = kw.pop('_protoClass', self.protocol)
     fac = ClientFactory(*a, **kw)
     fac.protocol = protoClass
     proto = fac.buildProtocol(None)
     transport = proto_helpers.StringTransport()
     transport.abortConnection = lambda: None
     proto.makeConnection(transport)
     return fac, proto
开发者ID:mikalv,项目名称:txi2p,代码行数:11,代码来源:test_protocol.py

示例15: buildProtocol

# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import buildProtocol [as 别名]
    def buildProtocol(self, addr):
        """Provision protocol
        """
        proto = ClientFactory.buildProtocol(self, addr)

        # Setup logger
        proto.log = self.log
        
        return proto
开发者ID:MeherBouhdid,项目名称:jasmin,代码行数:11,代码来源:factory.py


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