Пример #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
    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
    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
Пример #29
0
 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
        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()