本文整理汇总了Python中pyamf.decode函数的典型用法代码示例。如果您正苦于以下问题:Python decode函数的具体用法?Python decode怎么用?Python decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode
def decode(self, bytes, encoding=pyamf.AMF3):
decoded = list(pyamf.decode(bytes, encoding=encoding))
if len(decoded) == 1:
return decoded[0]
return decoded
示例2: test_decode
def test_decode(self):
expected = [u'connect', 1.0]
bytes = '\x06\x0fconnect\x05?\xf0\x00\x00\x00\x00\x00\x00'
returned = [x for x in pyamf.decode(bytes)]
self.assertEqual(expected, returned)
示例3: test_decode
def test_decode(self):
expected = [u"connect", 1.0]
bytes = "\x06\x0fconnect\x05?\xf0\x00\x00\x00\x00\x00\x00"
returned = [x for x in pyamf.decode(bytes)]
self.assertEquals(expected, returned)
示例4: test_source_attr
def test_source_attr(self):
s = ('\n\x07Cflex.messaging.io.ArrayCollection\n\x0b\x01\rsource'
'\t\x05\x01\x06\x07foo\x06\x07bar\x01')
x = pyamf.decode(s, encoding=pyamf.AMF3).next()
self.assertTrue(isinstance(x, flex.ArrayCollection))
self.assertEqual(x, ['foo', 'bar'])
示例5: unpack
def unpack(self, size, data):
if not size:
raise PackerDecodeError('size not found')
elif size != len(data):
raise PackerDecodeError('size:%s != data length:%s' % (size,
len(data)))
return pyamf.decode(data).readElement()
示例6: test_no_pk
def test_no_pk(self):
"""
Ensure that Models without a primary key are correctly serialized.
See #691.
"""
instances = [models.NotSaved(name="a"), models.NotSaved(name="b")]
encoded = pyamf.encode(instances, encoding=pyamf.AMF3).getvalue()
decoded = pyamf.decode(encoded, encoding=pyamf.AMF3).next()
self.assertEqual(decoded[0]['name'], 'a')
self.assertEqual(decoded[1]['name'], 'b')
示例7: assertDecodes
def assertDecodes(self, bytes, cb, encoding=pyamf.AMF3, raw=False):
if not isinstance(bytes, basestring):
bytes = _join(bytes)
ret = list(pyamf.decode(bytes, encoding=encoding))
if not raw and len(ret) == 1:
ret = ret[0]
if callable(cb):
cb(ret)
else:
self.assertEqual(ret, cb)
示例8: test_numerical_keys_mixed_array
def test_numerical_keys_mixed_array(self):
"""
Numerical keys in L{pyamf.MixedArray} must not cause a KeyError on
decode.
@see: #843
"""
x = pyamf.MixedArray({'10': u'foobar'})
bytes = pyamf.encode(x, encoding=pyamf.AMF0)
d = list(pyamf.decode(bytes, encoding=pyamf.AMF0))
self.assertEqual(d, [{10: u'foobar'}])
示例9: read
def read(self, header, buf):
"""
Read (decode) packet from stream.
@param header: packet header
@type header: L{RTMPHeader}
@param buf: buffer holding packet data
@type buf: C{BufferedByteStream}
"""
amf = pyamf.decode(buf, encoding=pyamf.AMF0)
name = amf.next()
id = amf.next()
argv = tuple(amf)
return Invoke(name, argv, id, header)
示例10: __init__
def __init__(self, xml, bootstrapInfos):
self.bitrate = int(xml.attributes['bitrate'].nodeValue)
#self.width = int(xml.attributes['width'].nodeValue)
#self.height = int(xml.attributes['height'].nodeValue)
self.url = str(xml.attributes['url'].nodeValue)
bootstrapId = xml.attributes['bootstrapInfoId'].nodeValue
if bootstrapId.startswith('bootstrap_'):
self.index = int(bootstrapId[len('bootstrap_'):])
else:
self.index = int(bootstrapId[len('bootstrap'):])
self.bootstrapInfo = bootstrapInfos[bootstrapId]
metadata = str(xml.getElementsByTagName('metadata')[0].firstChild.nodeValue)
decoder = pyamf.decode(base64.b64decode(metadata), encoding=pyamf.AMF0)
if str(decoder.next()) == 'onMetaData':
self.metadata = decoder.next()
示例11: test_amf3
def test_amf3(self):
data = (
b'\nk\x11pyamf.SM\t_key\x17age_in_2000\x15birth_date\rheight\x19me'
b'asurements\tname\x01\x04\x1a\x08\x01B9\x15\xda$\x00\x00\x00\x05?'
b'\xfc=p\xa3\xd7\n=\t\x07\x01\x04\x01\x04\x02\x04\x03\x06\x15Heidi'
b' Klum\x01'
)
decoder = pyamf.decode(data, encoding=pyamf.AMF3)
heidi = decoder.next()
self.assertEqual(heidi, models.SuperModel(
birth_date=datetime.date(1973, 6, 1),
name='Heidi Klum',
measurements=[1, 2, 3],
height=1.765
))
示例12: test_amf0
def test_amf0(self):
data = (
b'\x10\x00\x08pyamf.SM\x00\x04_key\x05\x00\x0bage_in_2000\[email protected]:'
b'\x00\x00\x00\x00\x00\x00\x00\nbirth_date\x0bB9\x15\xda$\x00\x00'
b'\x00\x00\x00\x00\x06height\x00?\xfc=p\xa3\xd7\n=\x00\x0cmeasurem'
b'ents\n\x00\x00\x00\x03\x00?\xf0\x00\x00\x00\x00\x00\x00\[email protected]\x00'
'\x00\x00\x00\x00\x00\x00\[email protected]\x08\x00\x00\x00\x00\x00\x00\x00\x04'
'name\x02\x00\nHeidi Klum\x00\x00\t'
)
decoder = pyamf.decode(data, encoding=pyamf.AMF0)
heidi = decoder.next()
self.assertEqual(heidi, models.SuperModel(
birth_date=datetime.date(1973, 6, 1),
name='Heidi Klum',
measurements=[1, 2, 3],
height=1.765
))
示例13: test_amf3
def test_amf3(self):
"""
Test encoding in AMF3.
"""
import pyamf
ref_dict = {
'level': 'alevel',
'code': 'Some.Code.Here',
'description': 'Look mom, no hands!'
}
s = status.Status(
ref_dict['level'],
ref_dict['code'],
ref_dict['description'])
blob = pyamf.encode(s, encoding=pyamf.AMF3)
decoded_status = pyamf.decode(blob, encoding=pyamf.AMF3).next()
self.assertEqual(decoded_status, s)
示例14: Exception
print "send request: start"
try:
self.sock.send('start')
except socket.error, e:
raise Exception("Can't connect: %s" % e[1])
while len(msg) < 1024:
# read from server
amf = self.sock.recv(1024)
if amf == '':
print "Connection closed."
msg = msg + amf
for obj in pyamf.decode(amf):
print obj
return msg
def stop(self):
print "send request: stop"
self.sock.send('stop')
if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-p", "--port", default=appPort,
dest="port", help="port number [default: %default]")
示例15: loads
def loads(data):
"""returns a list of messages"""
stream = BufferedByteStream(data)
result = list(pyamf.decode(stream=stream, encoding=3))
stream.close()
return result