• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python policies.ProtocolWrapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: makeConnection

    def makeConnection(self, transport):
        """
        Connect this wrapper to the given transport and initialize the
        necessary L{OpenSSL.SSL.Connection} with a memory BIO.
        """
        self._tlsConnection = self.factory._createConnection(self)
        self._appSendBuffer = []

        # Add interfaces provided by the transport we are wrapping:
        for interface in providedBy(transport):
            directlyProvides(self, interface)

        # Intentionally skip ProtocolWrapper.makeConnection - it might call
        # wrappedProtocol.makeConnection, which we want to make conditional.
        Protocol.makeConnection(self, transport)
        self.factory.registerProtocol(self)
        if self._connectWrapped:
            # Now that the TLS layer is initialized, notify the application of
            # the connection.
            ProtocolWrapper.makeConnection(self, transport)

        # Now that we ourselves have a transport (initialized by the
        # ProtocolWrapper.makeConnection call above), kick off the TLS
        # handshake.
        self._checkHandshakeStatus()
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:25,代码来源:tls.py


示例2: parseFrames

    def parseFrames(self):
        """
        Find frames in incoming data and pass them to the underlying protocol.
        """

        if self.flavor == HYBI00:
            parser = parse_hybi00_frames
        elif self.flavor in (HYBI07, HYBI10, RFC6455):
            parser = parse_hybi07_frames
        else:
            raise WSException("Unknown flavor %r" % self.flavor)

        try:
            frames, self.buf = parser(self.buf)
        except WSException as wse:
            # Couldn't parse all the frames, something went wrong, let's bail.
            self.close(wse.args[0])
            return

        for frame in frames:
            opcode, data = frame
            if opcode == NORMAL:
                # Business as usual. Decode the frame, if we have a decoder.
                if self.codec:
                    data = decoders[self.codec](data)
                # Pass the frame to the underlying protocol.
                ProtocolWrapper.dataReceived(self, data)
            elif opcode == CLOSE:
                # The other side wants us to close. I wonder why?
                reason, text = data
                log.msg("Closing connection: %r (%d)" % (text, reason))

                # Close the connection.
                self.close()
开发者ID:voneiden,项目名称:txWS,代码行数:34,代码来源:txws.py


示例3: __init__

 def __init__(self, factory, wrappedProtocol):
     ProtocolWrapper.__init__(self, factory, wrappedProtocol)
     AsyncStateMachine.__init__(self)
     self.fakeSocket = _FakeSocket(self)
     self.tlsConnection = TLSConnection(self.fakeSocket)
     self.tlsStarted = False
     self.connectionLostCalled = False
开发者ID:20after4,项目名称:Yaki,代码行数:7,代码来源:TLSTwistedProtocolWrapper.py


示例4: writeSequence

    def writeSequence(self, data):
        # type: (List[bytes]) -> None
        if not self.tlsStarted:
            ProtocolWrapper.writeSequence(self, b''.join(data))
            return

        self.write(b''.join(data))
开发者ID:appknox,项目名称:m2crypto,代码行数:7,代码来源:TwistedProtocolWrapper.py


示例5: __init__

 def __init__(self, factory, wrappedProtocol, connectedDeferred, host, port):
     ProtocolWrapper.__init__(self, factory, wrappedProtocol)
     self._connectedDeferred = connectedDeferred
     self._host = host
     self._port = port
     self._buf = b''
     self.state = 0
开发者ID:chojar,项目名称:GlobaLeaks,代码行数:7,代码来源:socks.py


示例6: dataReceived

    def dataReceived(self, data):
        """
        Append the data to the buffer list and parse the whole.
        """
        self._buffer.append(data)

        if self.challenge:
            buf = "".join(self._buffer)
            if len(buf) >= 8:
                challenge, buf = buf[:8], buf[8:]
                self._buffer = [buf]
                nonce = self.challenge(challenge)
                self.transport.write(nonce)
                self.challenge = None
                if self.connected:
                    ProtocolWrapper.connectionMade(self)
                self.dataReceived("") # Kick it off proper
                if self.pending_dc:
                    self.pending_dc = False
                    self.loseConnection()
        else:
            self._parseFrames()
            if self._pending_frames:
                self._sendFrames()

        self._parseFrames()
开发者ID:DesertBus,项目名称:sockjs-twisted,代码行数:26,代码来源:oldwebsockets.py


示例7: makeConnection

    def makeConnection(self, transport):
        """
        Connect this wrapper to the given transport and initialize the
        necessary L{OpenSSL.SSL.Connection} with a memory BIO.
        """
        tlsContext = self.factory._contextFactory.getContext()
        self._tlsConnection = Connection(tlsContext, None)
        if self.factory._isClient:
            self._tlsConnection.set_connect_state()
        else:
            self._tlsConnection.set_accept_state()
        self._appSendBuffer = []

        # Intentionally skip ProtocolWrapper.makeConnection - it might call
        # wrappedProtocol.makeConnection, which we want to make conditional.
        Protocol.makeConnection(self, transport)
        self.factory.registerProtocol(self)
        if self._connectWrapped:
            # Now that the TLS layer is initialized, notify the application of
            # the connection.
            ProtocolWrapper.makeConnection(self, transport)

        # Now that we ourselves have a transport (initialized by the
        # ProtocolWrapper.makeConnection call above), kick off the TLS
        # handshake.
        try:
            self._tlsConnection.do_handshake()
        except WantReadError:
            # This is the expected case - there's no data in the connection's
            # input buffer yet, so it won't be able to complete the whole
            # handshake now.  If this is the speak-first side of the
            # connection, then some bytes will be in the send buffer now; flush
            # them.
            self._flushSendBIO()
开发者ID:BillAndersan,项目名称:twisted,代码行数:34,代码来源:tls.py


示例8: connectionMade

 def connectionMade(self):
     """
     Log the new connection and initialize the buffer list.
     """
     ProtocolWrapper.connectionMade(self)
     log.msg("Opening connection with %s" % self.transport.getPeer())
     self._buffer = []
开发者ID:Fugiman,项目名称:sockjs-twisted,代码行数:7,代码来源:websockets.py


示例9: _parseFrames

    def _parseFrames(self):
        """
        Find frames in incoming data and pass them to the underlying protocol.
        """
        try:
            frames, rest = _parseFrames("".join(self._buffer))
        except _WSException:
            # Couldn't parse all the frames, something went wrong, let's bail.
            log.err()
            self.loseConnection()
            return

        self._buffer[:] = [rest]

        for frame in frames:
            opcode, data = frame
            if opcode == _CONTROLS.NORMAL:
                # Business as usual. Decode the frame, if we have a decoder.
                # Pass the frame to the underlying protocol.
                ProtocolWrapper.dataReceived(self, data)
            elif opcode == _CONTROLS.CLOSE:
                # The other side wants us to close. I wonder why?
                reason, text = data
                log.msg("Closing connection: %r (%d)" % (text, reason))

                # Close the connection.
                self.loseConnection()
                return
            elif opcode == _CONTROLS.PING:
                # 5.5.2 PINGs must be responded to with PONGs.
                # 5.5.3 PONGs must contain the data that was sent with the
                # provoking PING.
                self.transport.write(_makeFrame(data, _opcode=_CONTROLS.PONG))
开发者ID:Fugiman,项目名称:sockjs-twisted,代码行数:33,代码来源:websockets.py


示例10: connectionLost

 def connectionLost(self, reason):
     # type: (AnyStr) -> None
     # reason = [Failure instance: Traceback (failure with no
     # frames): <class 'twisted.internet.error.ConnectionDone'>:
     # Connection was closed cleanly. ] (<type 'instance'>)
     self.clear()
     ProtocolWrapper.connectionLost(self, reason)
开发者ID:appknox,项目名称:m2crypto,代码行数:7,代码来源:TwistedProtocolWrapper.py


示例11: writeSequence

 def writeSequence(self, seq):
     if not self.tlsStarted:
         ProtocolWrapper.writeSequence(self, seq)
     else:
         #Because of the FakeSocket, write operations are guaranteed to
         #terminate immediately.
         AsyncStateMachine.setWriteOp(self, "".join(seq))
开发者ID:20after4,项目名称:Yaki,代码行数:7,代码来源:TLSTwistedProtocolWrapper.py


示例12: makeConnection

 def makeConnection(self, transport):
     """
     Fire the Deferred at C{self.factory.connectionNotification} with the
     real protocol.
     """
     ProtocolWrapper.makeConnection(self, transport)
     self.factory.connectionNotification.callback(self.wrappedProtocol)
开发者ID:eriknelson,项目名称:gam3,代码行数:7,代码来源:ui.py


示例13: parseFrames

    def parseFrames(self):
        """
        Find frames in incoming data and pass them to the underlying protocol.
        """

        try:
            frames, self.buf = parse_hybi07_frames(self.buf)
        except WSException:
            # Couldn't parse all the frames, something went wrong, let's bail.
            log.err()
            self.loseConnection()
            return

        for frame in frames:
            opcode, data = frame
            if opcode == NORMAL:
                # Business as usual. Decode the frame, if we have a decoder.
                if self.codec:
                    data = decoders[self.codec](data)
                # Pass the frame to the underlying protocol.
                ProtocolWrapper.dataReceived(self, data)
            elif opcode == CLOSE:
                # The other side wants us to close. I wonder why?
                reason, text = data
                log.msg("Closing connection: %r (%d)" % (text, reason))

                # Close the connection.
                self.loseConnection()
                return
            elif opcode == PING:
                # 5.5.2 PINGs must be responded to with PONGs.
                # 5.5.3 PONGs must contain the data that was sent with the
                # provoking PING.
                raise AssertionError("this doesn't work")  # due to unknown symbol below
开发者ID:ABI-Software,项目名称:buildbot,代码行数:34,代码来源:websocket.py


示例14: __init__

 def __init__(self, factory, wrappedProtocol, connectedDeferred, host, port, optimistic = False):
     ProtocolWrapper.__init__(self, factory, wrappedProtocol)
     self._connectedDeferred = connectedDeferred
     self._host = host
     self._port = port
     self._optimistic = optimistic
     self._buf = ''
     self.state = 0
开发者ID:Acidburn0zzz,项目名称:Tor2web-3.0,代码行数:8,代码来源:socks.py


示例15: writeSequence

    def writeSequence(self, data):
        if debug:
            print 'TwistedProtocolWrapper.writeSequence'
        if not self.tlsStarted:
            ProtocolWrapper.writeSequence(self, ''.join(data))
            return

        self.write(''.join(data))
开发者ID:mikedougherty,项目名称:M2Crypto,代码行数:8,代码来源:TwistedProtocolWrapper.py


示例16: dataReceived

 def dataReceived(self, data):
     if not data:
         return
     try:
         dat = json.loads(data)
     except ValueError:
         self.transport.loseConnection()
     else:
         for d in dat:
             ProtocolWrapper.dataReceived(self, d)
开发者ID:Fugiman,项目名称:sockjs-twisted,代码行数:10,代码来源:websocket.py


示例17: dataReceived

 def dataReceived(self, data):
     try:
         if not self.tlsStarted:
             ProtocolWrapper.dataReceived(self, data)
         else:
             self.fakeSocket.data += data
             while self.fakeSocket.data:
                 AsyncStateMachine.inReadEvent(self)
     except TLSError, e:
         self.connectionLost(Failure(e))
         ProtocolWrapper.loseConnection(self)
开发者ID:20after4,项目名称:Yaki,代码行数:11,代码来源:TLSTwistedProtocolWrapper.py


示例18: dataReceived

 def dataReceived(self, data):
     if not data:
         return
     try:
         dat = json.loads(data)
     except ValueError:
         self.transport.loseConnection()
     else:
         for d in dat:
             d = normalize(d, self.parent._options['encoding'])
             ProtocolWrapper.dataReceived(self, d)
开发者ID:INTERACT-IV,项目名称:sockjs-twisted,代码行数:11,代码来源:websocket.py


示例19: __init__

 def __init__(self, *args, **kwargs):
     ProtocolWrapper.__init__(self, *args, **kwargs)
     self.buf = ''
     self.codec = None
     self.location = '/'
     self.host = ''
     self.origin = ''
     self.version = None
     self.state = HANDSHAKE
     self.pending_frames = []
     self.protocols = []
     self.headers = {}
开发者ID:PyMamba,项目名称:mamba-framework,代码行数:12,代码来源:websocket.py


示例20: _clientHello

 def _clientHello(self):
     try:
         # We rely on OpenSSL implicitly starting with client hello
         # when we haven't yet established an SSL connection
         encryptedData = self._encrypt(clientHello=1)
         ProtocolWrapper.write(self, encryptedData)
         self.helloDone = 1
     except BIO.BIOError as e:
         # See http://www.openssl.org/docs/apps/verify.html#DIAGNOSTICS
         # for the error codes returned by SSL_get_verify_result.
         e.args = (m2.ssl_get_verify_result(self.ssl._ptr()), e.args[0])
         raise e
开发者ID:appknox,项目名称:m2crypto,代码行数:12,代码来源:TwistedProtocolWrapper.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python policies.WrappingFactory类代码示例发布时间:2022-05-27
下一篇:
Python loopback.loopbackAsync函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap