Django and PyAMF, AMF remoting

21 views
Skip to first unread message

Arnar

unread,
Nov 9, 2007, 11:41:28 AM11/9/07
to Django users, d...@pyamf.org
Hi folks,

Some here might be interested in the following, others - excuse this
annoyance :o)

A few folks (Nick Joyce and Thijs Triemstra mostly) are working on
PyAMF, an AMF encoder and decoder in Python. It may be considered pre-
alpha for the moment. It includes Remoting gateways for Twisted, WSGI
and now Django as well.

Exposing functions for AMF remoting is simple, define a gateway (a
dispatcher) like this:

# yourproject/yourapp/amfgateway.py

from pyamf import gateway

def echo(data):
return data

echoGateway = gateway.BaseGateway({'echo': echo}) # could include
other functions as well


and add them to urlconf via a generic view:

# yourproject/urls.py

urlpatterns = patterns('',

# AMF Remoting Gateway
(r'^gateway/', 'pyamf.gateway.djangogateway.DjangoGateway',
{'gateway':
'yourproject.yourapp.amfgateway.echoGateway'}),

)


Hope you check it out and give us a hand with testing. The project
website is http://pyamf.org/

cheers,
Arnar

ps. we are aware of DjangoAMF, PyAMF is meant as a more generic AMF
implementation - not exclusive to Django.

Bert Heymans

unread,
Nov 22, 2007, 10:50:55 AM11/22/07
to Django users
Hi Arnar,

Cool, I'm checking it out at this moment, I'd love to use it. I'm
trying out the example on the wiki here http://pyamf.org/wiki/DjangoHowto
but I can't get it to work just yet.

Maybe I did something wrong or the install script didn't behave like
it's supposed to in my environment (Mac OSX 10.4, python 2.5). I got
the PyAMF code from the subverison repository here ( svn co
http://svn.pyamf.org/pyamf/trunk pyamf )

Installing went fine (sudo python setup.py install), and the tests are
OK (python setup.py test) but somehow I can't access the django
package. This is the output I get in a terminal:

Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyamf.gateway.django import DjangoGateway
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyamf/gateway/django.py", line 37, in <module>
_thismodule = sys.modules['django']
KeyError: 'django'
>>> import pyamf.gateway
>>> dir(pyamf.gateway)
['BaseGateway', 'ServiceRequest', 'ServiceWrapper', '__builtins__',
'__doc__', '__file__', '__name__', '__path__', 'remoting', 'sys',
'traceback', 'types']

You see, no 'django' in the list. Anyway, if I look at the sourcecode
it's all there in the gateway package there's 'django', 'twisted' and
'wsgi'.

I'll post my solution when I solve the problem, but I'd appreciate it
if anyone could already give help me with some pointers :)

Bert


On Nov 9, 5:41 pm, Arnar <arna...@gmail.com> wrote:
> Hi folks,
>
> Some here might be interested in the following, others - excuse this
> annoyance :o)
>
> A few folks (Nick Joyce and Thijs Triemstra mostly) are working onPyAMF, an AMF encoder and decoder in Python. It may be considered pre-
> alpha for the moment. It includes Remoting gateways for Twisted, WSGI
> and now Django as well.
>
> Exposing functions for AMF remoting is simple, define a gateway (a
> dispatcher) like this:
>
> # yourproject/yourapp/amfgateway.py
>
> frompyamfimport gateway
>
> def echo(data):
> return data
>
> echoGateway = gateway.BaseGateway({'echo': echo}) # could include
> other functions as well
>
> and add them to urlconf via a generic view:
>
> # yourproject/urls.py
>
> urlpatterns = patterns('',
>
> # AMF Remoting Gateway
> (r'^gateway/', 'pyamf.gateway.djangogateway.DjangoGateway',
> {'gateway':
> 'yourproject.yourapp.amfgateway.echoGateway'}),
>
> )
>
> Hope you check it out and give us a hand with testing. The project
> website ishttp://pyamf.org/
>
> cheers,
> Arnar
>
> ps. we are aware of DjangoAMF,PyAMFis meant as a more generic AMF

Arnar

unread,
Nov 26, 2007, 12:50:03 PM11/26/07
to Django users
Hello Bert,

Sorry for the late reply.

On Nov 22, 3:50 pm, Bert Heymans <bert.heym...@gmail.com> wrote:
> Installing went fine (sudo python setup.py install), and the tests are
> OK (python setup.py test) but somehow I can't access the django
> package. This is the output I get in a terminal:
>
> Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.>>> from pyamf.gateway.django import DjangoGateway
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "pyamf/gateway/django.py", line 37, in <module>
> _thismodule = sys.modules['django']
> KeyError: 'django'>>> import pyamf.gateway
> >>> dir(pyamf.gateway)
>
> ['BaseGateway', 'ServiceRequest', 'ServiceWrapper', '__builtins__',
> '__doc__', '__file__', '__name__', '__path__', 'remoting', 'sys',
> 'traceback', 'types']
>
> You see, no 'django' in the list. Anyway, if I look at the sourcecode
> it's all there in the gateway package there's 'django', 'twisted' and
> 'wsgi'.

It is finding the pyamf.gateway.django package allright, the line it
fails on is in that module. Is Django on your python path?

It is due to a trick we have to use to both call our subpackage
"django" and still be able to import the real (top-level) django
package. The trick is to mess with sys.modules a bit (see the code).

Please stop by on the pyamf developers list and post us steps to
reproduce this and we'll sort it out.

cheers,
Arnar

Bert Heymans

unread,
Nov 27, 2007, 4:39:50 AM11/27/07
to Django users
Hi Arnar,

Thanks for clearing that up, that explains why it works in the context
django and not just in the python shell. I understand now, I'll stop
by the pyamf developers list for sure this week :)

Cheers,

Bert

On Nov 26, 6:50 pm, Arnar <arna...@gmail.com> wrote:
> Hello Bert,
>
> Sorry for the late reply.
>
> On Nov 22, 3:50 pm, Bert Heymans <bert.heym...@gmail.com> wrote:
>
>
>
> > Installing went fine (sudopythonsetup.py install), and the tests are
> > OK (pythonsetup.py test) but somehow I can't access thedjango
> > package. This is the output I get in a terminal:
>
> >Python2.5 (r25:51918, Sep 19 2006, 08:49:13)
> > [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> > Type "help", "copyright", "credits" or "license" for more information.>>> from pyamf.gateway.djangoimport DjangoGateway
>
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > File "pyamf/gateway/django.py", line 37, in <module>
> > _thismodule = sys.modules['django']
> > KeyError: 'django'>>> import pyamf.gateway
> > >>> dir(pyamf.gateway)
>
> > ['BaseGateway', 'ServiceRequest', 'ServiceWrapper', '__builtins__',
> > '__doc__', '__file__', '__name__', '__path__', 'remoting', 'sys',
> > 'traceback', 'types']
>
> > You see, no 'django' in the list. Anyway, if I look at the sourcecode
> > it's all there in the gateway package there's 'django', 'twisted' and
> > 'wsgi'.
>
> It is finding the pyamf.gateway.djangopackage allright, the line it
Reply all
Reply to author
Forward
0 new messages