當前位置: 首頁>>代碼示例>>Python>>正文


Python BufferedByteStream.read_uchar方法代碼示例

本文整理匯總了Python中pyamf.util.BufferedByteStream.read_uchar方法的典型用法代碼示例。如果您正苦於以下問題:Python BufferedByteStream.read_uchar方法的具體用法?Python BufferedByteStream.read_uchar怎麽用?Python BufferedByteStream.read_uchar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyamf.util.BufferedByteStream的用法示例。


在下文中一共展示了BufferedByteStream.read_uchar方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Packet

# 需要導入模塊: from pyamf.util import BufferedByteStream [as 別名]
# 或者: from pyamf.util.BufferedByteStream import read_uchar [as 別名]
class Packet(object):
    """
    """


    format = None
    challengeKey = None


    def __init__(self):
        self.buffer = BufferedByteStream()


    def computeOffset(self, start, modulus, increment):
        """
        An offset is 4 consecutive bytes encoded at C{start}.

        s = sum of bytes

        offset = (s % modulus) + increment
        """
        self.buffer.seek(start)

        offset = (
            self.buffer.read_uchar() +
            self.buffer.read_uchar() +
            self.buffer.read_uchar() +
            self.buffer.read_uchar())

        offset %= modulus
        offset += increment

        return offset


    def getDigestAndPayload(self, offset, length):
        """
        Returns the C{digest} and C{payload} components.
        """
        self.buffer.seek(0)

        payload = self.buffer.read(offset)
        digest = self.buffer.read(length)
        payload += self.buffer.read()

        return digest, payload


    def setFormat(self, format):
        self.format = format


    def setChallengeKey(self, key):
        self.challengeKey = key


    def setChallengeDigest(self, digest):
        self.challengeDigest = digest


    def decode(self, data):
        """
        Decodes the data bytes into this packet.
        """
        raise NotImplementedError
開發者ID:njoyce,項目名稱:rtmpy,代碼行數:67,代碼來源:__init__.py

示例2: BaseNegotiator

# 需要導入模塊: from pyamf.util import BufferedByteStream [as 別名]
# 或者: from pyamf.util.BufferedByteStream import read_uchar [as 別名]
class BaseNegotiator(object):
    """
    Base functionality for negotiating an RTMP handshake.

    Call L{start} to begin negotiations.

    @ivar observer: An observer for handshake negotiations.
    @type observer: L{IHandshakeObserver}
    @ivar started: Whether negotiations have begun.
    @type started: C{bool}
    @ivar _buffer: Any data that has been received but not yet been consumed.
    @type _buffer: L{BufferedByteStream}
    """


    started = False

    nearRequest = None
    nearResponse = None

    farRequest = None
    farResponse = None

    protocolVersion = 3
    farProtocolVersion = None


    def __init__(self, observer, output):
        self.observer = observer
        self.output = output


    def start(self, uptime=0, version=0):
        """
        Called to start the handshaking negotiations.
        """
        if self.started:
            raise AlreadyStarted('Handshake negotiator cannot be restarted')

        self.started = True

        self.uptime = uptime
        self.version = version

        self._buffer = BufferedByteStream()


    def readPacket(self):
        if self._buffer.remaining() < HANDSHAKE_LENGTH:
            # we're expecting more data
            return

        packet = self._buffer.read(HANDSHAKE_LENGTH)
        self._buffer.consume()

        return packet


    def dataReceived(self, data):
        """
        Called when handshake data has been received.
        """
        if not self.started:
            raise HandshakeError('Data received, but negotiator not started')

        self._buffer.append(data)

        if self.farProtocolVersion is None:
            self.farProtocolVersion = self._buffer.read_uchar()

        packet = self.readPacket()

        if not packet:
            return

        if not self.farRequest:
            self.farRequest = self.buildFarRequest()

            self.farRequest.decode(packet)

            self.farRequestReceived(self.farRequest)

            packet = self.readPacket()

            if not packet:
                return

        if not self.farResponse:
            self.farResponse = self.buildFarResponse()

            self.farResponse.decode(packet)

            self.farResponseReceived(self.farResponse)


    def buildFarRequest(self):
        """
        """
        return RequestPacket()

#.........這裏部分代碼省略.........
開發者ID:njoyce,項目名稱:rtmpy,代碼行數:103,代碼來源:__init__.py

示例3: StateEngine

# 需要導入模塊: from pyamf.util import BufferedByteStream [as 別名]
# 或者: from pyamf.util.BufferedByteStream import read_uchar [as 別名]

#.........這裏部分代碼省略.........
        elif self.state == self.STATE_HANDSHAKE:
            self.handshake_dataReceived(data)
        elif self.state == self.STATE_STREAM:
            BaseStreamer.dataReceived(self, data)
        else:
            raise RuntimeError('Invalid state!')


    def startVersioning(self):
        """
        Start protocol version negotiations.
        """
        self.buffer = BufferedByteStream()


    def stopVersioning(self, reason=None):
        """
        Stop protocol version negotiations.

        @param reason: A L{failure.Failure} object if protocol version
            negotiations failed. C{None} means success.
        """
        del self.buffer


    def version_dataReceived(self, data):
        """
        """
        if not data:
            return

        self.buffer.append(data)

        self.peerProtocolVersion = self.buffer.read_uchar()

        self.versionReceived(self.peerProtocolVersion)


    def versionReceived(self, version):
        """
        Called when the peers' protocol version has been received.

        The default behaviour is to accept any known version. It is the
        responsibility for any overriding subclass to call L{versionSuccess} for
        negotiations to proceed.
        """
        if version == self.protocolVersion:
            self.versionSuccess()

            return

        raise UnknownProtocolVersion(
            'Unhandled protocol version %d' % (version,))


    def versionSuccess(self):
        """
        Protocol version negotiations have been successful, now on to
        handshaking.
        """
        try:
            data = self.buffer.read()
        except IOError:
            data = None

        self.stopVersioning()
開發者ID:Flumotion,項目名稱:rtmpy,代碼行數:70,代碼來源:__init__.py


注:本文中的pyamf.util.BufferedByteStream.read_uchar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。