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


Python ProtocolWrapper.dataReceived方法代码示例

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


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

示例1: parseFrames

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
    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,代码行数:36,代码来源:txws.py

示例2: _parseFrames

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
    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,代码行数:35,代码来源:websockets.py

示例3: dataReceived

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
    def dataReceived(self, data):
        # type: (bytes) -> None
        if not self.tlsStarted:
            ProtocolWrapper.dataReceived(self, data)
            return

        self.encrypted += data

        try:
            while 1:
                decryptedData = self._decrypt()

                self._check()

                encryptedData = self._encrypt()
                ProtocolWrapper.write(self, encryptedData)

                ProtocolWrapper.dataReceived(self, decryptedData)

                if decryptedData == b'' and encryptedData == b'':
                    break
        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,代码行数:28,代码来源:TwistedProtocolWrapper.py

示例4: parseFrames

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
    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,代码行数:36,代码来源:websocket.py

示例5: dataReceived

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
 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,代码行数:12,代码来源:websocket.py

示例6: dataReceived

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
 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,代码行数:13,代码来源:TLSTwistedProtocolWrapper.py

示例7: dataReceived

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
 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,代码行数:13,代码来源:websocket.py

示例8: _flushReceiveBIO

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
    def _flushReceiveBIO(self):
        """
        Try to receive any application-level bytes which are now available
        because of a previous write into the receive BIO.  This will take
        care of delivering any application-level bytes which are received to
        the protocol, as well as handling of the various exceptions which
        can come from trying to get such bytes.
        """
        # Keep trying this until an error indicates we should stop or we
        # close the connection.  Looping is necessary to make sure we
        # process all of the data which was put into the receive BIO, as
        # there is no guarantee that a single recv call will do it all.
        while not self._lostTLSConnection:
            try:
                bytes = self._tlsConnection.recv(2 ** 15)
            except WantReadError:
                # The newly received bytes might not have been enough to produce
                # any application data.
                break
            except ZeroReturnError:
                # TLS has shut down and no more TLS data will be received over
                # this connection.
                self._shutdownTLS()
                # Passing in None means the user protocol's connnectionLost
                # will get called with reason from underlying transport:
                self._tlsShutdownFinished(None)
            except Error as e:
                # Something went pretty wrong.  For example, this might be a
                # handshake failure (because there were no shared ciphers, because
                # a certificate failed to verify, etc).  TLS can no longer proceed.

                # Squash EOF in violation of protocol into ConnectionLost; we
                # create Failure before calling _flushSendBio so that no new
                # exception will get thrown in the interim.
                if e.args[0] == -1 and e.args[1] == 'Unexpected EOF':
                    failure = Failure(CONNECTION_LOST)
                else:
                    failure = Failure()

                self._flushSendBIO()
                self._tlsShutdownFinished(failure)
            else:
                # If we got application bytes, the handshake must be done by
                # now.  Keep track of this to control error reporting later.
                self._handshakeDone = True
                if not self._aborted:
                    ProtocolWrapper.dataReceived(self, bytes)

        # The received bytes might have generated a response which needs to be
        # sent now.  For example, the handshake involves several round-trip
        # exchanges without ever producing application-bytes.
        self._flushSendBIO()
开发者ID:Architektor,项目名称:PySnip,代码行数:54,代码来源:tls.py

示例9: parseFrames

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
    def parseFrames(self):
        """
        Find frames in incoming data and pass them to the underlying protocol.
        """

        start = self.buf.find("\x00")

        while start != -1:
            end = self.buf.find("\xff")
            if end == -1:
                # Incomplete frame, try again later.
                return
            else:
                frame, self.buf = self.buf[start + 1:end], self.buf[end + 1:]
                # Decode the frame, if we have a decoder.
                if self.codec:
                    frame = decoders[self.codec](frame)
                # Pass the frame to the underlying protocol.
                ProtocolWrapper.dataReceived(self, frame)
            start = self.buf.find("\x00")
开发者ID:yishenggudou,项目名称:twisted-websocket-test,代码行数:22,代码来源:websocket.py

示例10: handle_frames

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
    def handle_frames(self):
        """
        Use the correct frame parser and send parsed data to the underlying
        protocol
        """

        if self.version == HYBI00:
            frame_parser = HyBi00Frame(self.buf)
        elif self.version in (HYBI07, HYBI10, RFC6455):
            frame_parser = HyBi07Frame(self.buf)
        else:
            raise InvalidProtocolVersion(
                'Unknown version {!r}'.format(self.version)
            )

        try:
            frames, self.buf = frame_parser.parse()
        except WebSocketError as error:
            log.err(error)
            self.close(error)
            return

        for frame in frames:
            opcode, data = frame
            if opcode == DATA:
                # pass the frame to the underlying protocol
                ProtocolWrapper.dataReceived(self, data)
            elif opcode == CLOSE:
                # the other side want's to close
                reason, text = data
                log.msg('Closing connection: {!r} ({:d})'.format(
                    text, reason
                ))

                # close the connection
                self.close()
            elif opcode == PING:
                # send pong
                self.transport.write(
                    HyBi07Frame(data).generate(0xa)
                )
开发者ID:PyMamba,项目名称:mamba-framework,代码行数:43,代码来源:websocket.py

示例11: outReadEvent

# 需要导入模块: from twisted.protocols.policies import ProtocolWrapper [as 别名]
# 或者: from twisted.protocols.policies.ProtocolWrapper import dataReceived [as 别名]
 def outReadEvent(self, data):
     if data == "":
         ProtocolWrapper.loseConnection(self)
     else:
         ProtocolWrapper.dataReceived(self, data)
开发者ID:20after4,项目名称:Yaki,代码行数:7,代码来源:TLSTwistedProtocolWrapper.py


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