Going to transmit an object of some class between your Flex application and Python server (using PyAMF) you first have to register a class alias in both frameworks for proper serialization into AMF and back.
In AS3 you will probably write something like:
package model
{
[RemoteClass(alias="model.MyClass")]
public class MyClass {
public var a:uint
public var b:String
}
}
while the corresponding class on server side and its registration will look like:
class MyClass:
def __init__(self, *args, **kwargs):
self.a = args[0]
self.b = args[1]
pyamf.register_class(MyClass, "model.MyClass")
it seems tempting to have a syntax, for registering server side class in similar way as it is done in Flex:
@RemoteClass(alias="model.MyClass")
class MyClass:
def __init__(self, *args, **kwargs):
self.a = args[0]
self.b = args[1]
The magic is done with a Class Decorator, a quite new feature, presented in Python 2.6.
Here is the class decorator performing registration:
class RemoteClass(object):
def __init__(self, alias):
self.alias = alias
def __call__(self, klass):
pyamf.register_class(klass, self.alias)
return klass
Happy coding
[...] This post was mentioned on Twitter by Anthony Cintron, Nick Joyce. Nick Joyce said: RT @supdun: Remote Class Registration for PyAMF. It worked so seamlessly with out current project: http://bit.ly/68RnHa #pyamf #django # … [...]
[...] This post was Twitted by nick_joyce [...]