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


Python protocol.makeConnection函数代码示例

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


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

示例1: doRead

    def doRead(self):
        """Called when my socket is ready for reading.

        This accepts a connection and calls self.protocol() to handle the
        wire-level protocol.
        """
        try:
            if platformType == "posix":
                numAccepts = self.numberAccepts
            else:
                # win32 event loop breaks if we do more than one accept()
                # in an iteration of the event loop.
                numAccepts = 1
            for i in range(numAccepts):
                # we need this so we can deal with a factory's buildProtocol
                # calling our loseConnection
                if self.disconnecting:
                    return
                try:
                    skt, addr = self.socket.accept()
                except socket.error, e:
                    if e.args[0] in (EWOULDBLOCK, EAGAIN):
                        self.numberAccepts = i
                        break
                    elif e.args[0] == EPERM:
                        # Netfilter on Linux may have rejected the
                        # connection, but we get told to try to accept()
                        # anyway.
                        continue
                    elif e.args[0] in (EMFILE, ENOBUFS, ENFILE, ENOMEM, ECONNABORTED):

                        # Linux gives EMFILE when a process is not allowed
                        # to allocate any more file descriptors.  *BSD and
                        # Win32 give (WSA)ENOBUFS.  Linux can also give
                        # ENFILE if the system is out of inodes, or ENOMEM
                        # if there is insufficient memory to allocate a new
                        # dentry.  ECONNABORTED is documented as possible on
                        # both Linux and Windows, but it is not clear
                        # whether there are actually any circumstances under
                        # which it can happen (one might expect it to be
                        # possible if a client sends a FIN or RST after the
                        # server sends a SYN|ACK but before application code
                        # calls accept(2), however at least on Linux this
                        # _seems_ to be short-circuited by syncookies.

                        log.msg("Could not accept new connection (%s)" % (
                            errorcode[e.args[0]],))
                        break
                    raise

                protocol = self.factory.buildProtocol(self._buildAddr(addr))
                if protocol is None:
                    skt.close()
                    continue
                s = self.sessionno
                self.sessionno = s+1
                transport = self.transport(skt, protocol, addr, self, s)
                transport = self._preMakeConnection(transport)
                protocol.makeConnection(transport)
            else:
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:60,代码来源:tcp.py

示例2: connect_protocol

    def connect_protocol(self, protocol):
        t = StringTransport()
        protocol.makeConnection(t)

        # ... and let's skip the handshake
        protocol.dataReceived('.')

        return t
开发者ID:DxCx,项目名称:twimp,代码行数:8,代码来源:test_proto.py

示例3: openShell

 def openShell(self, transport):
     """
     Use our protocol as shell session.
     """
     protocol = EchoProtocol()
     # Connect the new protocol to the transport and the transport
     # to the new protocol so they can communicate in both directions.
     protocol.makeConnection(transport)
     transport.makeConnection(session.wrapProtocol(protocol))
开发者ID:matanmaz,项目名称:SshTelnetProxy,代码行数:9,代码来源:sshsimpleserver.py

示例4: _cbLogin

    def _cbLogin(self, ial):
        interface, protocol, logout = ial
        assert interface is ITelnetProtocol
        self.protocol = protocol
        self.logout = logout
        self.state = 'Command'

        protocol.makeConnection(self.transport)
        self.transport.protocol = protocol
开发者ID:Almad,项目名称:twisted,代码行数:9,代码来源:telnet.py

示例5: makeProtocol

 def makeProtocol(self):
     env = HoneyPotEnvironment()
     user = HoneyPotAvatar("root", env)
     
     serverProtocol = insults.ServerProtocol(
         HoneyPotInteractiveProtocol, user, env)
     serverProtocol.makeConnection(protocol)
     protocol.makeConnection(session.wrapProtocol(serverProtocol))
     #honeypot = HoneyPotInteractiveProtocol(user, env)
     return serverProtocol
开发者ID:hiviah,项目名称:kippo-telnet,代码行数:10,代码来源:telnet.py

示例6: execCommand

    def execCommand(self, protocol, cmd):
        cfg = config()
        if cfg.has_option('honeypot', 'exec_enabled'):
            if ( cfg.get('honeypot', 'exec_enabled') != "true" ):
                print 'exec disabled not executing command: "%s"' % cmd
                raise os.OSError

        print 'Executing command: "%s"' % cmd
        serverProtocol = LoggingServerProtocol(HoneyPotProtocol, self, self.env, cmd)
        serverProtocol.makeConnection(protocol)
        protocol.makeConnection(session.wrapProtocol(serverProtocol))
开发者ID:DTherHtun,项目名称:kippo-g0tmi1k,代码行数:11,代码来源:honeypot.py

示例7: testMessages

 def testMessages(self):
     self.output = StringIOWithoutClosing()
     self.transport = internet.protocol.FileWrapper(self.output)
     protocol =  MyVirtualPOP3()
     protocol.makeConnection(self.transport)
     protocol.service = self.factory
     protocol.lineReceived('APOP [email protected] world')
     protocol.lineReceived('UIDL')
     protocol.lineReceived('RETR 1')
     protocol.lineReceived('QUIT')
     if self.output.getvalue() != self.expectedOutput:
         #print `self.output.getvalue()`
         #print `self.expectedOutput`
         raise AssertionError(self.output.getvalue(), self.expectedOutput)
开发者ID:fxia22,项目名称:ASM_xf,代码行数:14,代码来源:test_pop3.py

示例8: test_writeSequence

    def test_writeSequence(self):
        """
        L{ThrottlingProtocol.writeSequence} is called on the underlying factory.
        """
        server = Server()
        tServer = TestableThrottlingFactory(task.Clock(), server)
        protocol = tServer.buildProtocol(
            address.IPv4Address('TCP', '127.0.0.1', 0))
        transport = StringTransportWithDisconnection()
        transport.protocol = protocol
        protocol.makeConnection(transport)

        protocol.writeSequence([b'bytes'] * 4)
        self.assertEqual(transport.value(), b"bytesbytesbytesbytes")
        self.assertEqual(tServer.writtenThisSecond, 20)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:15,代码来源:test_policies.py

示例9: _cbLogin

    def _cbLogin(self, ial):
        """
        Fired on a successful login
        """
        interface, protocol, logout = ial
        self.protocol = protocol
        self.logout = logout
        self.state = 'Command'

        # Remove the short timeout of the login prompt. Timeout will be
        # provided later by the HoneyPotBaseProtocol class.
        self.transport.setTimeout(None)

        # replace myself with avatar protocol
        protocol.makeConnection(self.transport)
        self.transport.protocol = protocol
开发者ID:cowrie,项目名称:cowrie,代码行数:16,代码来源:transport.py

示例10: _cbLogin

    def _cbLogin(self, ial):
        """
        Fired on a successful login
        """
        interface, protocol, logout = ial
        protocol.windowSize = self.windowSize
        self.protocol = protocol
        self.logout = logout
        self.state = 'Command'

        self.transport.write(b'\n')

        # Remove the short timeout of the login prompt.
        self.transport.setTimeout(CONFIG.getint('honeypot', 'interactive_timeout', fallback=300))

        # replace myself with avatar protocol
        protocol.makeConnection(self.transport)
        self.transport.protocol = protocol
开发者ID:Mato-Z,项目名称:cowrie,代码行数:18,代码来源:transport.py

示例11: testMessages

 def testMessages(self):
     from twisted.mail import protocols
     protocol =  protocols.DomainSMTP()
     protocol.service = self.factory
     protocol.factory = self.factory
     protocol.receivedHeader = spameater
     protocol.makeConnection(self.transport)
     protocol.lineReceived('HELO yyy.com')
     for message in self.messages:
         protocol.lineReceived('MAIL FROM:<%s>' % message[0])
         for target in message[1]:
             protocol.lineReceived('RCPT TO:<%s>' % target)
         protocol.lineReceived('DATA')
         protocol.dataReceived(message[2])
         protocol.lineReceived('.')
     protocol.lineReceived('QUIT')
     if self.mbox != self.factory.domains['baz.com'].messages:
         raise AssertionError(self.factory.domains['baz.com'].messages)
     protocol.setTimeout(None)
开发者ID:Almad,项目名称:twisted,代码行数:19,代码来源:test_smtp.py

示例12: addProtocolFactory

    def addProtocolFactory(self, deferred, canceller, protocolFactory):
        if canceller.cancelled:
            return None

        protocol = protocolFactory.buildProtocol(self._address)
        log.msg('EpicsSubscriptionProtocol: addProtocolFactory: Append %(p)s (length: %(l)d+1)', p=protocol, l=len(self._protocols), logLevel=_DEBUG)
        self._protocols.append(protocol)
        deferred.callback(protocol)

        if self.transport is not None:
            transport = EpicsSubscriptionTransport(self.transport, protocol, self)
            log.msg('EpicsSubscriptionProtocol: addProtocolFactory: Connected so call makeConnection %(t)s', t=transport, logLevel=_TRACE)
            protocol.makeConnection(transport)
            if self._connected:
                protocol.connectionMade()
                if self._data is not None:
                    protocol.dataReceived(self._data)

        else:
            log.msg('EpicsSubscriptionProtocol: addProtocolFactory: Not connected so do NOT call makeConnection', logLevel=_TRACE)
    
        return protocol
开发者ID:dylan171,项目名称:ControlSystemWeb,代码行数:22,代码来源:sub.py

示例13: doRead

    def doRead(self):
        """Called when my socket is ready for reading.

        This accepts a connection and calls self.protocol() to handle the
        wire-level protocol.
        """
        try:
            if platformType == "posix":
                numAccepts = self.numberAccepts
            else:
                # win32 event loop breaks if we do more than one accept()
                # in an iteration of the event loop.
                numAccepts = 1
            for i in range(numAccepts):
                # we need this so we can deal with a factory's buildProtocol
                # calling our loseConnection
                if self.disconnecting:
                    return
                try:
                    skt, addr = self.socket.accept()
                except socket.error, e:
                    if e.args[0] == EWOULDBLOCK:
                        self.numberAccepts = i
                        break
                    elif e.args[0] == EPERM:
                        continue
                    raise
                
                protocol = self.factory.buildProtocol(addr)
                if protocol is None:
                    skt.close()
                    continue
                s = self.sessionno
                self.sessionno = s+1
                transport = self.transport(skt, protocol, addr, self, s)
                transport = self._preMakeConnection(transport)
                protocol.makeConnection(transport)
            else:
开发者ID:fxia22,项目名称:ASM_xf,代码行数:38,代码来源:tcp.py

示例14: makeConnection

 def makeConnection(self, transport):
     self.transport = transport
     log.msg('DistributingProtocol: makeConnection: Transport is %(t)s', t=transport, logLevel=_TRACE)
     for protocol in self._protocols:
         log.msg('DistributingProtocol: makeConnection: Distribute to %(p)s', p=protocol, logLevel=_TRACE)
         protocol.makeConnection(DistributingTransport(transport))
开发者ID:dylan171,项目名称:ControlSystemWeb,代码行数:6,代码来源:dist.py

示例15: makeConnection

 def makeConnection(self, transport):
     self.transport = transport
     log.msg('EpicsSubscriptionProtocol: makeConnection: Transport is %(t)s', t=transport, logLevel=_DEBUG)
     for protocol in self._protocols:
         log.msg('EpicsSubscriptionProtocol: makeConnection: Distribute to %(p)s', p=protocol, logLevel=_TRACE)
         protocol.makeConnection(EpicsSubscriptionTransport(transport, protocol, self))
开发者ID:dylan171,项目名称:ControlSystemWeb,代码行数:6,代码来源:sub.py


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