本文整理汇总了Python中pyamf.util.BufferedByteStream.getvalue方法的典型用法代码示例。如果您正苦于以下问题:Python BufferedByteStream.getvalue方法的具体用法?Python BufferedByteStream.getvalue怎么用?Python BufferedByteStream.getvalue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyamf.util.BufferedByteStream
的用法示例。
在下文中一共展示了BufferedByteStream.getvalue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendMessage
# 需要导入模块: from pyamf.util import BufferedByteStream [as 别名]
# 或者: from pyamf.util.BufferedByteStream import getvalue [as 别名]
def sendMessage(self, msg, stream, whenDone=None):
"""
Queues L{msg} for encoding into RTMP and being spit out to L{output}.
This is a low level api and is not for public consumption. Use
L{interfaces.IStream.sendMessage} instead.
@param msg: The message being sent to the peer.
@type msg: L{message.IMessage}
@param stream: The stream instance that is sending the message.
@type stream: L{interfaces.IStream}
@param whenDone: A callback fired when the message has been written to
the RTMP stream. See L{BaseStream.sendMessage}
"""
buf = BufferedByteStream()
e = self.encoder
# this will probably need to be rethought as this could block for an
# unacceptable amount of time. For most messages however it seems to be
# fast enough and the penalty for setting up a new thread is too high.
msg.encode(buf)
e.send(buf.getvalue(), msg.__data_type__,
stream.streamId, stream.timestamp, whenDone)
if e.active and not self._encoding_task:
self.startEncoding()
示例2: sendMessage
# 需要导入模块: from pyamf.util import BufferedByteStream [as 别名]
# 或者: from pyamf.util.BufferedByteStream import getvalue [as 别名]
def sendMessage(self, msg, stream, whenDone=None):
"""
Sends an RTMP message to the peer. Not part of a public api, use
C{stream.sendMessage} instead.
@param msg: The message being sent to the peer.
@type msg: L{message.IMessage}
@param stream: The stream instance that is sending the message.
@type stream: L{NetStream}
@param whenDone: A callback fired when the message has been written to
the RTMP stream. See L{BaseStream.sendMessage}
"""
buf = BufferedByteStream()
e = self.encoder
# this will probably need to be rethought as this could block for an
# unacceptable amount of time. For most messages however it seems to be
# fast enough and the penalty for setting up a new thread is too high.
msg.encode(buf)
e.send(buf.getvalue(), msg.__data_type__,
stream.streamId, stream.timestamp, whenDone)
if e.active and not self.encoder_task:
self.startEncoding()
示例3: _BackRelay
# 需要导入模块: from pyamf.util import BufferedByteStream [as 别名]
# 或者: from pyamf.util.BufferedByteStream import getvalue [as 别名]
class _BackRelay(protocol.ProcessProtocol):
def __init__(self, deferred):
self.deferred = deferred
self.s = BufferedByteStream()
def errReceived(self, text):
self.deferred.errback(failure.Failure(IOError()))
self.deferred = None
self.transport.loseConnection()
def outReceived(self, text):
self.s.write(text)
def processEnded(self, reason):
if self.deferred is not None:
result = self.s.getvalue()
self.deferred.callback(result)
示例4: StreamingChannel
# 需要导入模块: from pyamf.util import BufferedByteStream [as 别名]
# 或者: from pyamf.util.BufferedByteStream import getvalue [as 别名]
class StreamingChannel(object):
"""
"""
def __init__(self, channel, streamId, output):
self.type = None
self.channel = channel
self.streamId = streamId
self.output = output
self.stream = BufferedByteStream()
self._lastHeader = None
self._oldStream = channel.stream
channel.stream = self.stream
h = header.Header(channel.channelId)
# encode a continuation header for speed
header.encode(self.stream, h, h)
self._continuationHeader = self.stream.getvalue()
self.stream.consume()
def __del__(self):
try:
self.channel.stream = self._oldStream
except:
pass
def setType(self, type):
self.type = type
def sendData(self, data, timestamp):
c = self.channel
if timestamp < c.timestamp:
relTimestamp = timestamp
else:
relTimestamp = timestamp - c.timestamp
h = header.Header(c.channelId, relTimestamp, self.type, len(data), self.streamId)
if self._lastHeader is None:
h.full = True
c.setHeader(h)
c.append(data)
header.encode(self.stream, h, self._lastHeader)
self._lastHeader = h
c.marshallOneFrame()
while not c.complete():
self.stream.write(self._continuationHeader)
c.marshallOneFrame()
c.reset()
self.output.write(self.stream.getvalue())
self.stream.consume()
示例5: BaseNegotiator
# 需要导入模块: from pyamf.util import BufferedByteStream [as 别名]
# 或者: from pyamf.util.BufferedByteStream import getvalue [as 别名]
class BaseNegotiator(object):
"""
Base functionality for negotiating an RTMP handshake.
@ivar observer: An observer for handshake negotiations.
@type observer: L{IHandshakeObserver}
@ivar buffer: Any data that has not yet been consumed.
@type buffer: L{BufferedByteStream}
@ivar started: Determines whether negotiations have already begun.
@type started: C{bool}
@ivar my_syn: The initial handshake packet that will be sent by this
negotiator.
@type my_syn: L{Packet}
@ivar my_ack: The handshake packet that will be sent after the peer has sent
its syn.
@ivar peer_syn: The initial L{Packet} received from the peer.
@ivar peer_ack: The L{Packet} received in acknowledgement of my syn.
@ivar peer_version: The handshake version that the peer understands.
"""
implements(IHandshakeNegotiator)
def __init__(self, observer, transport):
self.observer = observer
self.transport = transport
self.started = False
def start(self, uptime=None, version=None):
"""
Called to start the handshaking negotiations.
"""
if self.started:
raise HandshakeError('Handshake negotiator cannot be restarted')
self.started = True
self.buffer = BufferedByteStream()
self.peer_version = None
self.my_syn = Packet(uptime, version)
self.my_ack = None
self.peer_syn = None
self.peer_ack = None
self.buildSynPayload(self.my_syn)
self._writePacket(self.my_syn)
def getPeerPacket(self):
"""
Attempts to decode a L{Packet} from the buffer. If there is not enough
data in the buffer then C{None} is returned.
"""
if self.buffer.remaining() < HANDSHAKE_LENGTH:
# we're expecting more data
return
packet = Packet()
packet.decode(self.buffer)
return packet
def _writePacket(self, packet, stream=None):
stream = stream or BufferedByteStream()
packet.encode(stream)
self.transport.write(stream.getvalue())
def dataReceived(self, data):
"""
Called when handshake data has been received. If an error occurs
whilst negotiating the handshake then C{self.observer.handshakeFailure}
will be called, citing the reason.
3 stages of data are received. The handshake version, the syn packet and
then the ack packet.
"""
if not self.started:
raise HandshakeError('Data was received, but negotiator was '
'not started')
self.buffer.append(data)
self._process()
def _process(self):
if not self.peer_syn:
self.peer_syn = self.getPeerPacket()
if not self.peer_syn:
return
#.........这里部分代码省略.........