File: addressbook.rst

package info (click to toggle)
pyamf 0.6.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,692 kB
  • sloc: python: 17,944; xml: 455; makefile: 116; sql: 38; java: 11; sh: 7
file content (143 lines) | stat: -rw-r--r-- 4,317 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
***************
  Addressbook
***************

.. topic:: Introduction

   This page describes how to setup the Addressbook example application
   using the `Flex SDK`_ and SQLAlchemy_.

   This example demonstrates loading and saving persistent objects with
   lazy-loaded values.

   Check the :doc:`SQLAlchemy Adapter<../gateways/sqlalchemy>` page for
   more info on using SQLAlchemy with PyAMF.

   A live demo can be found on the PyAMF blog_.

.. contents::

Download
========

Clone the PyAMF repository with:

.. code-block:: bash

    git clone git://github.com/hydralabs/pyamf.git pyamf
    cd doc/tutorials/examples/actionscript/addressbook-example/python

Alternatively, if you just want to have a look, you can browse_ the example online.


Gateway
=======

**Note**: make sure you have SQLAlchemy_ >= 0.4 installed.

The remoting gateway for the Adobe Flash Player and Python AMF clients starts on
http://localhost:8000 when you launch the `development server`_:

.. code-block:: bash

    python server.py

You should see something like:

.. code-block:: bash

    Running SQLAlchemy AMF gateway on http://localhost:8000
    Press Ctrl-c to stop server.


Options
-------

When you run `python server.py --help` it will display the various options available
for this example server:

.. code-block:: bash

    Usage: server.py [options]

    Options:
      -h, --help            show this help message and exit
      -p PORT, --port=PORT  port number [default: 8000]
      --host=HOST           host address [default: localhost]


Clients
=======

Flash Player
------------

You can simply open the `SWF file`_ and it will connect to http://localhost:8000.

.. image:: images/addressbook_example.png

Python
------

The Python AMF client can be started by running the following from the `python`
folder:

.. code-block:: bash

    python client.py

You should see something like this for the client:

.. code-block:: bash

    Added user: Bill Lumbergh
    Load users:
	1. Bill (2009-12-26 19:45:22.522754)

And the server prints:

.. code-block:: bash

    2009-12-26 20:45:22,470 DEBUG [root] remoting.decode start
    2009-12-26 20:45:22,471 DEBUG [root] Remoting target: u'ExampleService.insertDefaultData'
    2009-12-26 20:45:22,471 DEBUG [root] remoting.decode end
    2009-12-26 20:45:22,472 DEBUG [root] AMF Request: <Envelope amfVersion=0>
     (u'/1', <Request target=u'ExampleService.insertDefaultData'>[]</Request>)
    </Envelope>
    2009-12-26 20:45:22,536 DEBUG [root] AMF Response: <Envelope amfVersion=0>
     (u'/1', <Response status=/onResult>u'Added user: Bill Lumbergh'</Response>)
    </Envelope>
    localhost - - [26/Dec/2009 20:45:22] "POST / HTTP/1.1" 200 57
    2009-12-26 20:45:22,541 DEBUG [root] remoting.decode start
    2009-12-26 20:45:22,541 DEBUG [root] Remoting target: u'ExampleService.loadAll'
    2009-12-26 20:45:22,541 DEBUG [root] remoting.decode end
    2009-12-26 20:45:22,541 DEBUG [root] AMF Request: <Envelope amfVersion=0>
     (u'/2', <Request target=u'ExampleService.loadAll'>[u'org.pyamf.examples.addressbook.models.User']</Request>)
    </Envelope>
    2009-12-26 20:45:22,545 DEBUG [root] AMF Response: <Envelope amfVersion=0>
     (u'/2', <Response status=/onResult>[<models.User object at 0x10285c750>]</Response>)
    </Envelope>
    localhost - - [26/Dec/2009 20:45:22] "POST / HTTP/1.1" 200 865

Options
_______

When you run `python client.py --help` it will display the various options available
for this example client:

.. code-block:: bash

    Usage: client.py [options]

    Options:
      -h, --help            show this help message and exit
      -p PORT, --port=PORT  port number [default: 8000]
      --host=HOST           host address [default: localhost]


.. _Flex SDK: http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK
.. _SQLAlchemy: http://www.sqlalchemy.org
.. _blog: http://blog.pyamf.org/2009/03/sqlalchemy-and-flash-addressbook-example
.. _browse: http://github.com/hydralabs/pyamf/tree/master/doc/tutorials/examples/actionscript/addressbook
.. _development server: http://github.com/hydralabs/pyamf/tree/master/doc/tutorials/examples/actionscript/addressbook/python/server.py
.. _SWF file: http://github.com/hydralabs/pyamf/tree/master/doc/tutorials/examples/actionscript/addressbook/flex/deploy/sa_example.swf