Git Product home page Git Product logo

py3amf's Introduction

Py3AMF

Py3AMF is fork of PyAMF to support Python3

Why Py3AMF

By states of issues and PR in PyAMF, it dosen't seems to be under developing. And another PR that supports Py3 has been discontinued for over two years. This is the only Python AMF Project which trying to support Py3 under developing on GitHub.

State

Pass setup.py test But, adapters were not tested

Warning

This project isn't completed. If you want to make it fast, please send PR.

Install

This was tested on Ubuntu 16.04.2 and macOS 10.12.4

To install, you can use pip3 on your environment.

pip3 install Py3AMF

Or, you can use setup.py to develop.

git clone [email protected]:StdCarrot/Py3AMF.git
cd Py3AMF
# python3 setup.py test
python3 setup.py install

Simple example

Everything is same with PyAMF, but you have to concern str and bytes types.

import pyamf
from pyamf import remoting
from pyamf.flex import messaging
import uuid
import requests

msg = messaging.RemotingMessage(operation='retrieveUser', 
                                destination='so.stdc.flexact.common.User',
                                messageId=str(uuid.uuid4()).upper(),
                                body=['user_id'])
req = remoting.Request(target='UserService', body=[msg])
ev = remoting.Envelope(pyamf.AMF3)        
ev['/0'] = req

# Encode request 
bin_msg = remoting.encode(ev)

# Send request; You can use other channels like RTMP
resp = requests.post('http://example.com/amf', 
                     data=bin_msg.getvalue(), 
                     headers={'Content-Type': 'application/x-amf'})

# Decode response
resp_msg = remoting.decode(resp.content)
print(resp_msg.bodies)

TODO

  • Check adapters

PyAMF provides Action Message Format (AMF) support for Python that is compatible with the Adobe Flash Player. It includes integration with Python web frameworks like Django, Pylons, Twisted, SQLAlchemy, web2py and more.

The Adobe Integrated Runtime and Adobe Flash Player use AMF to communicate between an application and a remote server. AMF encodes remote procedure calls (RPC) into a compact binary representation that can be transferred over HTTP/HTTPS or the RTMP/RTMPS protocol. Objects and data values are serialized into this binary format, which increases performance, allowing applications to load data up to 10 times faster than with text-based formats such as XML or SOAP.

AMF3, the default serialization for ActionScript 3.0, provides various advantages over AMF0, which is used for ActionScript 1.0 and 2.0. AMF3 sends data over the network more efficiently than AMF0. AMF3 supports sending int and uint objects as integers and supports data types that are available only in ActionScript 3.0, such as ByteArray, ArrayCollection, ObjectProxy and IExternalizable.

py3amf's People

Contributors

arnar avatar elmordo avatar feisley avatar frewsxcv avatar imdagger avatar m-src avatar mexicarne avatar mmiko avatar njoyce avatar paulopaixaoamaral avatar romankharin avatar stdcarrot avatar stumitchell avatar thijstriemstra avatar tml avatar wasw100 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

py3amf's Issues

Pytest deprecation warnings

I am on python 3.6.2 and when I run my tests through pytest I get the following warnings related to Py3AMF:

  /Users/nilswerner/.pyenv/versions/3.6.2/envs/drf-formulator-feed/lib/python3.6/site-packages/pyamf/remoting/__init__.py:139: DeprecationWarning: generator 'Envelope.__iter__' raisedStopIteration
    for request in iter(self):
  /Users/nilswerner/.pyenv/versions/3.6.2/envs/drf-formulator-feed/lib/python3.6/site-packages/pyamf/remoting/__init__.py:139: DeprecationWarning: generator 'Envelope.__iter__' raisedStopIteration
    for request in iter(self):

tests/unit/test_drf_service/test_amf_client.py::test_get_filename_response
  /Users/nilswerner/.pyenv/versions/3.6.2/envs/drf-formulator-feed/lib/python3.6/site-packages/pyamf/remoting/__init__.py:139: DeprecationWarning: generator 'Envelope.__iter__' raisedStopIteration
    for request in iter(self):
  /Users/nilswerner/.pyenv/versions/3.6.2/envs/drf-formulator-feed/lib/python3.6/site-packages/pyamf/remoting/__init__.py:139: DeprecationWarning: generator 'Envelope.__iter__' raisedStopIteration
    for request in iter(self):```

I tried to pass a bytearray but it went wrong

tim 20180622182921
msg = messaging.RemotingMessage(
messageId=str(uuid.uuid1()).upper(),
clometOd=None,
operation='findBizObjEx',
destination='superSystemFacadeService',
timeTolive=0,
timestamp=0
)
string = "78daa5524d6fd33018fe2b93cf69643b8d49bc5"
userDtoBytes = bytearray(string, encoding='utf-8')
msg.headers['userDtoBytes'] = userDtoBytes"
userDtoBytes = bytearray(string, encoding='utf-8')
msg.headers['userDtoBytes'] = userDtoBytes

I tried to construct this request but an exception was thrown!
Seems to be an argument that does not support passing a bytearray
I hope to get your reply

Traceback (most recent call last):
File "C:/Users/EDZ/PycharmProjects/untitled1/pyamf_test.py", line 62, in
ihotel_spider.construct_flex_message()
File "C:/Users/EDZ/PycharmProjects/untitled1/pyamf_test.py", line 56, in construct_flex_message
bin_msg = remoting.encode(ev)
File "C:\Users\EDZ\Envs\py2\lib\site-packages\pyamf\remoting_init_.py", line 724, in encode
write_body(name, message, stream, encoder, strict)
File "C:\Users\EDZ\Envs\py2\lib\site-packages\pyamf\remoting_init
.py", line 550, in _write_body
encode_body(message)
File "C:\Users\EDZ\Envs\py2\lib\site-packages\pyamf\remoting_init
.py", line 523, in _encode_body
encoder.writeElement(x)
File "cpyamf/codec.pyx", line 623, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10902)
File "cpyamf/codec.pyx", line 629, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10661)
File "cpyamf/amf0.pyx", line 581, in cpyamf.amf0.Encoder.handleBasicTypes (cpyamf\amf0.c:7975)
File "cpyamf/amf0.pyx", line 577, in cpyamf.amf0.Encoder.writeAMF3 (cpyamf\amf0.c:7917)
File "cpyamf/codec.pyx", line 645, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10786)
File "cpyamf/amf3.pyx", line 930, in cpyamf.amf3.Encoder.writeObject (cpyamf\amf3.c:11500)
File "cpyamf/codec.pyx", line 629, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10661)
File "cpyamf/amf3.pyx", line 1034, in cpyamf.amf3.Encoder.handleBasicTypes (cpyamf\amf3.c:12466)
File "cpyamf/codec.pyx", line 587, in cpyamf.codec.Encoder.handleBasicTypes (cpyamf\codec.c:9961)
File "cpyamf/amf3.pyx", line 790, in cpyamf.amf3.Encoder.writeDict (cpyamf\amf3.c:10088)
File "cpyamf/codec.pyx", line 645, in cpyamf.codec.Encoder.writeElement (cpyamf\codec.c:10786)
File "cpyamf/amf3.pyx", line 911, in cpyamf.amf3.Encoder.writeObject (cpyamf\amf3.c:11322)
File "C:\Users\EDZ\Envs\py2\lib\site-packages\pyamf\alias.py", line 404, in getEncodableAttributes
return obj.dict.copy()
AttributeError: 'bytearray' object has no attribute 'dict'

Failed to decode AMF data: Unsupported ActionScript type 0xa2

Hi, i have problem decoding amf data included with this character �
this is my code :

    def decodeEnvelope(self, resp):
        # Decode the Base64 encoded response to bytes
        decoded_bytes = base64.b64decode(resp)

        # Attempt to decode the bytes as unicode with ignoring errors
        decoded_data = decoded_bytes.decode('latin-1', errors='ignore')
        
        # Decode the AMF (Action Message Format) data directly
        try:
            decodedAMF = remoting.decode(decoded_data)
            return decodedAMF
        except Exception as e:
            print(f"Failed to decode AMF data: {e}")
            return None

and the resp data is AAAAAAABAAsvMS9vblJlc3VsdAAEbnVsbAAAAuIDAAZzdGF0dXMAP/AAAAAAAAAABWVycm9yAAAAAAAAAAAAAAN1aWQCAAYzNjAxMDkACnNlc3Npb25rZXkCACAxMGE5YjY0YzgxMDdiM2M5NWE1YTVhZDMwMDBjYmI5NgAEaGFzaAIAQGY3ZmFmMzlmYzA1OGEyNzFmZTNmNzRlMzE0Njc3MTg4ZGExN2ZhZmNmZjk3OGQ3MjExNTZlMTNkMmYwOWU0MDcAC3N5c3RlbV90aW1lAgAKdHNqS2lRSFdvUgAEbmV3cwIB8U5ld3M8YnI+LSA5MCsgTGV2ZWwgc2tpbGxzIGFyZSBub3cgYXZhaWxhYmxlIGluIHRoZSBhY2FkZW15ITxicj4tIEVtYmxlbSsgaXMgbm93IGF2YWlsYWJsZSE8YnI+LSBOZXcgRXh0cmVtZSBUYWxlbnQgQ2F0YWNseXNtIGlzIG5vdyBhdmFpbGFibGUhPGJyPi0gTmV3IFBldHMgYXJlIGF2YWlsYWJsZSBpbiBlYWNoIHZpbGxhZ2VzIHBldCBzaG9wITxicj4tIEdlYXIgRmlsdGVycyBhcmUgbm93IGF2YWlsYWJsZSBmb3IgRW1ibGVtKyE8YnI+LSBTa2lsbCBQcmVzZXQgdXBkYXRlZCAzIHNsb3RzL2ZyZWUgdXNlciwgNiBzbG90cy9lbWJsZW0sIDkgc2xvdHMvZW1ibGVtKzxicj48YnI+QnVnIEZpeGVzPGJyPi0gRml4ZWQgYW4gaXNzdWUgd2l0aCBDbGFuIFNob3AsIHNvbWUgaXRlbXMgd2VyZW6SdCBidXlhYmxlLjxicj4tIEZpeGVkIGFuIGlzc3VlIHdpdGggRXllIG9mIE1pcnJvciBUaXRhbiB3aGVuIHVzaW5nIFN1cnByaXNlIEF0dGFjayBDbGFzcyBhbmQgU2VuanV0c3UuAAtjbGFuX3NlYXNvbgIAAjM2AAtjcmV3X3NlYXNvbgIAATUAAAk=

DeprecationWarning in Python 3.12

There is two DeprecationWarning in Python 3.12.

pyamf/util/__init__.py:217: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    datetime.datetime.utcfromtimestamp(-31536000.0)
pyamf/adapters/__init__.py:44
  /home/benoit/Repos/openzim/warc2zim/.hatch/warc2zim/lib/python3.12/site-packages/pyamf/adapters/__init__.py:44: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    import pkg_resources

First one is probably minor to fix.

Second one is kind of a blocker for Python 3.12, but there is a fallback in the code, so it probably still works in most situations.

The second one can probably easily be fixed with https://docs.python.org/3/library/importlib.resources.html with something like this:

try:
    from importlib import resources
    ....
except:
  try:
    import pkg_resources
    packageDir = pkg_resources.resource_filename('pyamf', 'adapters')
  except:
    packageDir = os.path.dirname(__file__)

pyamf.DecodeError: Malformed stream (amfVersion=15423)

C:\xampp_2015\htdocs\Py3AMF>a
Traceback (most recent call last):
File "C:\xampp_2015\htdocs\Py3AMF\test.py", line 24, in
resp_msg = remoting.decode(resp.content)
File "C:\xampp_2015\htdocs\Py3AMF\pyamf\remoting_init_.py", line 631, in decode
raise pyamf.DecodeError(
pyamf.DecodeError: Malformed stream (amfVersion=15423)

Dictionary and Vector Support

It seems, the Python Py3amf does not have last 2 objects supported from this list:

undefined-marker=0x00 
null-marker=0x01 
false-marker=0x02 
true-marker=0x03 
integer-marker=0x04
double-marker=0x05 
string-marker=0x06 
xml-doc-marker=0x07 
date-marker=0x08 
array-marker=0x09 
object-marker=0x0A 
xml-marker=0x0B 
byte-array-marker=0x0C
vector-int-marker=0x0D
vector-uint-marker=0x0E
vector-double-marker=0x0F
vector-object-marker=0x10
dictionary-marker=0x11

If I am wrong, please tell me where. When I try to parse amf3 content that has dictionary, it fails.

Unable to decode error messages from AMF gateway (Static attributes %r expected when decoding %r)

Hi. I am trying to use Py3AMF to communicate with an AMF gateway, and I'm getting a bunch of errors in the process, due to poor understanding of the gateway on the remote end (completely because of me). However, I am unable to use pyamf.remoting.decode() to parse the resulting error messages from the server, despite them being valid AMF. I get the following error:

AttributeError: Static attributes {'destination', 'headers', 'rootCause', 'timeToLive', 'timestamp', 'extendedData', 'clientId', 'body', 'messageId'} expected when decoding <class 'pyamf.flex.messaging.ErrorMessage'>

Below is the full hex dump of one such responses that the library refuses to parse, with some data redacted with '#':

00 00 00 01 00 12 41 70 70 65 6E 64 54 6F 47 61 74 65 77 61 79 55 72 6C 00 00 00 00 28 02 00 25 3F 50 48 50 53 45 53 53 49 44 3D 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 5D 00 01 00 0B 2F 31 2F 6F 6E 53 74 61 74 75 73 00 04 6E 75 6C 6C 00 00 01 1F 11 0A 0B 49 66 6C 65 78 2E 6D 65 73 73 61 67 69 6E 67 2E 6D 65 73 73 61 67 65 73 2E 45 72 72 6F 72 4D 65 73 73 61 67 65 1B 63 6F 72 72 65 6C 61 74 69 6F 6E 49 64 01 13 66 61 75 6C 74 43 6F 64 65 06 29 41 4D 46 50 48 50 5F 52 55 4E 54 49 4D 45 5F 45 52 52 4F 52 17 66 61 75 6C 74 44 65 74 61 69 6C 06 81 7F 43 3A 5C 50 72 6F 67 72 61 6D 20 46 69 6C 65 73 20 28 78 38 36 29 5C 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 5C 61 6D 66 70 68 70 5C 73 65 72 76 69 63 65 73 5C 23 23 23 23 23 23 23 23 2E 70 68 70 20 6F 6E 20 6C 69 6E 65 20 33 30 32 17 66 61 75 6C 74 53 74 72 69 6E 67 06 57 4D 69 73 73 69 6E 67 20 61 72 67 75 6D 65 6E 74 20 31 20 66 6F 72 20 47 65 74 23 23 23 23 23 3A 3A 74 65 73 74 23 23 23 23 28 29 01

Am I doing it wrong, or is there something wrong with the module? How can I handle error messages gracefully? Right now I am catching AttributeError, but I'm missing out on the error message data.

old release disappeared

I see a new release (0.8.11) of Py3AMF is available on PyPI. However the older 0.8.10 is no longer available for download there. The problem is that external projects depend on it, namely oe-alliance-core, the basis of a ton of satellite receiver set top boxes. That build is now broken. Is there any way you could put 0.8.10 on PyPI again, until things in openoe-alliance catch up?

Incidentally, there's no 0.8.11 on your github either.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.