Some syntactic sugar for registering remote class

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Some syntactic sugar for registering remote class

Ilya Persky
Hi guys!

It seems nice to register PyAMF classes in the way similar to client side:

@RemoteClass(alias="model.MyClass")
class MyClass:
    def __init__(self, *args, **kwargs):
        self.a = args[0]
        self.b = args[1]

It can be achieved with the help of Python 2.6 Class Decorators feature:

class RemoteClass(object):

    def __init__(self, alias):
        self.alias = alias

    def __call__(self, klass):
        pyamf.register_class(klass, self.alias)
        return klass


Best regards, Ilya.
--
http://oitar.biz/blog/


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Some syntactic sugar for registering remote class

Nick Joyce
Hi Ilya,

Looks pretty neat! A nice use of class decorators ;)

Cheers,

Nick


On 16 Nov 2009, at 18:04, Ilya Persky wrote:

Hi guys!

It seems nice to register PyAMF classes in the way similar to client side:

@RemoteClass(alias="model.MyClass")
class MyClass:
    def __init__(self, *args, **kwargs):
        self.a = args[0]
        self.b = args[1]

It can be achieved with the help of Python 2.6 Class Decorators feature:

class RemoteClass(object):

    def __init__(self, alias):
        self.alias = alias

    def __call__(self, klass):
        pyamf.register_class(klass, self.alias)
        return klass


Best regards, Ilya.
--
http://oitar.biz/blog/

_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Some syntactic sugar for registering remote class

Thijs Triemstra
Thanks for sharing that Ilya! I created a ticket [1] so we don't forget to
add an example to our documentation for this.

Cheers,

Thijs

[1] http://pyamf.org/ticket/706

On Tue, November 17, 2009 04:13, Nick Joyce wrote:

> Hi Ilya,
>
> Looks pretty neat! A nice use of class decorators ;)
>
> Cheers,
>
> Nick
>
>
> On 16 Nov 2009, at 18:04, Ilya Persky wrote:
>
>> Hi guys!
>>
>> It seems nice to register PyAMF classes in the way similar to client
>> side:
>>
>> @RemoteClass(alias="model.MyClass")
>> class MyClass:
>>     def __init__(self, *args, **kwargs):
>>         self.a = args[0]
>>         self.b = args[1]
>>
>> It can be achieved with the help of Python 2.6 Class Decorators feature:
>>
>> class RemoteClass(object):
>>
>>     def __init__(self, alias):
>>         self.alias = alias
>>
>>     def __call__(self, klass):
>>         pyamf.register_class(klass, self.alias)
>>         return klass
>>
>>
>> Best regards, Ilya.
>> --
>> http://oitar.biz/blog/
>>
>> _______________________________________________
>> PyAMF users mailing list - [hidden email]
>> http://lists.pyamf.org/mailman/listinfo/users
>
> _______________________________________________
> PyAMF users mailing list - [hidden email]
> http://lists.pyamf.org/mailman/listinfo/users
>


_______________________________________________
PyAMF users mailing list - [hidden email]
http://lists.pyamf.org/mailman/listinfo/users