示例#1
1
	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()
示例#2
0
 def receivedata(self, buffersize=4, notreceived=True):
     data = ''
     remaining = 4
     while len(data) < 4:
         tt = select.select([self.server], [], [], 30)
         if not tt[0]:
             raise
         u = self.server.recv(remaining)
         if u == '':
             raise
         data = data + u
         remaining = 4 - len(data)
     length = struct.unpack('>L', data)[0]
     data = ''
     remaining = length
     while len(data) < length:
         tt = select.select([self.server], [], [], 30)
         if not tt[0]:
             raise
         u = self.server.recv(remaining)
         if u == '':
             raise
         data = data + u
         remaining = length - len(data)
     data = pyamf.decode(data).readElement()
     if self.__callback != None:
         self.__callback(data)
     else:
         print(data)
     return data
示例#3
0
    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)
示例#4
0
    def decode(self, bytes, encoding=pyamf.AMF3):
        decoded = list(pyamf.decode(bytes, encoding=encoding))

        if len(decoded) == 1:
            return decoded[0]

        return decoded
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    def decode(self, bytes, encoding=pyamf.AMF3):
        decoded = list(pyamf.decode(bytes, encoding=encoding))

        if len(decoded) == 1:
            return decoded[0]

        return decoded
示例#8
0
    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'])
示例#9
0
    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'])
示例#10
0
    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()
示例#11
0
    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 = next(pyamf.decode(encoded, encoding=pyamf.AMF3))
        self.assertEqual(decoded[0]['name'], 'a')
        self.assertEqual(decoded[1]['name'], 'b')
示例#12
0
    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')
示例#13
0
async def intercept_request(req):
    if req.resourceType == 'other' \
            and req.method == 'POST' \
            and 'content-type' in req.headers \
            and 'amf' in req.headers['content-type']:

        req_body = req.postData
        # amf = pyamf_remoting.decode(req_body)
        amf = pyamf.decode(req_body)
        # await req.abort()
        print(req_body)
        print(amf)
示例#14
0
def amfparser(srcpath, n, dstpath):
    fsize = os.path.getsize(srcpath)
    srchandle = open(srcpath, 'rb')
    srchandle.seek(n)
    rdata = srchandle.read(fsize - n)
    decdata = pyamf.decode(zlib.decompressobj().decompress(rdata))
    srchandle.close()
    
    wdata = {}
    dsthandle = open(dstpath, 'w')
    wdata[k] = [elem[k] for elem in decdata for k in elem]
    dsthandle .write(json.dumps(wdata, encoding='utf-8', ensure_ascii=False))
    dsthandle.close()
示例#15
0
    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)
示例#16
0
    def assertDecodes(self, bytes, cb, encoding=pyamf.AMF3, raw=False):
        if not isinstance(bytes, six.string_types):
            bytes = _join(bytes)

        ret = list(pyamf.decode(bytes, encoding=encoding))

        if not raw and len(ret) == 1:
            ret = ret[0]

        if python.callable(cb):
            cb(ret)
        else:
            self.assertEqual(ret, cb)
示例#17
0
    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'}])
示例#18
0
文件: packets.py 项目: smira/fmspy
    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)
示例#19
0
    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)
示例#20
0
文件: test_amf0.py 项目: LiiiQin/test
    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'}])
示例#21
0
	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()
示例#22
0
    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))
示例#23
0
    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
        ))
示例#24
0
    def test_amf0(self):
        data = (
            b'\x10\x00\x08pyamf.SM\x00\x04_key\x05\x00\x0bage_in_2000\x00@:'
            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\x00@\x00'
            '\x00\x00\x00\x00\x00\x00\x00@\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))
示例#25
0
    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)
示例#26
0
    def test_amf0(self):
        data = (
            b'\x10\x00\x08pyamf.SM\x00\x04_key\x05\x00\x0bage_in_2000\x00@:'
            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\x00@\x00'
            '\x00\x00\x00\x00\x00\x00\x00@\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
        ))
示例#27
0
    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)
示例#28
0
 def loads(data):
     """returns a list of messages"""
     stream = BufferedByteStream(data)
     result = list(pyamf.decode(stream=stream, encoding=3))
     stream.close()
     return result
 def encdec(self, encoding):
     return pyamf.decode(pyamf.encode(self.obj, encoding=encoding),
         encoding=encoding).next()
示例#30
0
def loads(s):
    for data in decode(decompress(s)):
        return data
示例#31
0
 def AMF3_to_B64(self, Packet):
     Data = base64.b64decode(Packet)
     Ret = []
     for obj in pyamf.decode(Data):
         Ret.append(obj)
     return Ret
示例#32
0
import pyamf

# from pyamf.remoting
# from pyamf.amf3 import

from pyamf import tests
from pyamf.tests.gateway import *
# from pyamf.amf3 import

import requests
from pyamf import remoting
response = requests.get('http://jgsb.agri.gov.cn/flexapps/hqApp.swf').content

# print remoting.decode(response.encode('u8'))
ins = pyamf.decode(response)
# print dir(ins)
# print ins.context
# # print ins.stream, type(ins.stream)
# print dir(ins.stream)
# data = ins.stream.read()
# print type(data)

print[elem[k] for elem in ins for k in elem]
示例#33
0
文件: client.py 项目: 84322146/pyamf
        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]")
示例#34
0
import os
from tkinter import filedialog
import pyamf
from pyamf import remoting as pyamf_remoting

with open(filedialog.askopenfilename(), 'rb') as f:
    content: bytes = f.read()
    decoded = pyamf_remoting.decode(content)  # ✔️
    decoded2 = pyamf.decode(f)  # ⚠️

    print("done!")
示例#35
0
        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",
示例#36
0
    def decode(self, bytes, amf3):
        encoding = pyamf.AMF3 if amf3 else pyamf.AMF0

        return list(pyamf.decode(bytes, encoding=encoding))
示例#37
0
    def decode(self, bytes, amf3):
        encoding = pyamf.AMF3 if amf3 else pyamf.AMF0

        return list(pyamf.decode(bytes, encoding=encoding))
示例#38
0
 def encdec(self, encoding):
     return pyamf.decode(pyamf.encode(self.obj, encoding=encoding),
                         encoding=encoding).next()