Skip to content

Commit 4b57eee

Browse files
Add Pyramid tutorial using virtualenv and pyramid_rpc.
Fixes: #841
1 parent 66b58b4 commit 4b57eee

File tree

4 files changed

+74
-30
lines changed

4 files changed

+74
-30
lines changed

doc/tutorials/examples/gateways/pylons/pyramid_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pyamf.remoting.client import RemotingService
99

10-
url = 'http://127.0.0.1:8080/gateway'
10+
url = 'http://127.0.0.1:6543/gateway'
1111
client = RemotingService(url, logger=logging)
1212
service = client.getService('myservice')
1313
echo = service.echo('Hello World!')
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import logging
2-
3-
from pyramid.config import Configurator
41
from pyramid_rpc.amfgateway import PyramidGateway
52

6-
from paste.httpserver import serve
73

4+
def my_view(request):
5+
return {'project':'pyamf_tutorial'}
86

97
def echo(request, data):
108
"""
@@ -19,11 +17,5 @@ def echo(request, data):
1917
# Add other exposed functions and classes here
2018
}
2119

22-
echoGateway = PyramidGateway(services, logger=logging, debug=True)
23-
20+
echoGateway = PyramidGateway(services, debug=True)
2421

25-
if __name__ == '__main__':
26-
config = Configurator()
27-
config.add_view(echoGateway, name='gateway')
28-
app = config.make_wsgi_app()
29-
serve(app, host='0.0.0.0')
3.33 KB
Loading

doc/tutorials/gateways/pylons.rst

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
Pylons Project
33
******************
44

5+
.. image:: images/pylons-logo.png
6+
57
.. topic:: Introduction
68

79
The `Pylons Project`_ is a collection of web application framework
810
technologies. This tutorial describes how to setup a bare bones
911
application with a remoting gateway exposing a method.
1012

11-
**Note**: This tutorial provides examples for both Pyramid_ and the old
12-
`Pylons package`_ (versions 0.97-1.x). For new projects it is recommended
13+
**Note**: This tutorial provides examples for both Pyramid_ and the legacy
14+
`Pylons package`_ (versions 0.97-1.x). For new projects it is encouraged
1315
to use the Pyramid package, see the `Pylons FAQ`_ for more information.
1416

1517

@@ -19,49 +21,98 @@
1921
Pyramid
2022
=======
2123

22-
The Pyramid_ package supports extensibility through add-ons. For this tutorial
23-
we need RPC support for AMF_ which is available in the `pyramid_rpc`_ add-on.
24+
Pyramid_ is a small, fast, down-to-earth Python web application development
25+
framework. It is developed as part of the `Pylons Project`_.
2426

25-
Install_ the ``pyramid_rpc`` package:
27+
Example
28+
-------
29+
30+
1. Create a new virtual environment using the virtualenv_ tool:
2631

2732
.. code-block:: bash
2833
29-
$ easy_install pyramid_rpc
34+
$ virtualenv --no-site-packages pyramid_amf_env
3035
3136
32-
Example
33-
-------
37+
2. The Pyramid_ package supports extensibility through add-ons. For this tutorial
38+
we need AMF support which is available in the `pyramid_rpc`_ add-on.
39+
40+
Install the ``pyramid``, ``pyramid_rpc`` and ``pyamf`` packages:
41+
42+
.. code-block:: bash
43+
44+
$ cd pyramid_amf_env
45+
$ bin/easy_install pyramid pyramid_rpc pyamf
3446
35-
1. Create a new Python script called ``server.py`` with the following:
47+
48+
For more detailed instructions, refer to the Pyramid `installation documentation`_.
49+
50+
51+
3. Create a new Pyramid project (called ``pyamf_tutorial`` in this example):
52+
53+
.. code-block:: bash
54+
55+
$ bin/paster create -t pyramid_starter pyamf_tutorial
56+
57+
58+
4. Install the project into the enviroment:
59+
60+
.. code-block:: bash
61+
62+
$ cd pyamf_tutorial
63+
$ ../bin/python setup.py develop
64+
65+
66+
5. Replace the contents of ``pyamf_tutorial/views.py`` with the following:
3667

3768
.. literalinclude:: ../examples/gateways/pylons/pyramid_gateway.py
3869
:linenos:
3970

4071
You can easily expose more functions by adding them to the ``services`` dictionary
41-
given to ``PyramidGateway``.
72+
given to ``PyramidGateway``. Also see the `pyramid_rpc documentation`_.
73+
74+
75+
6. Add the view to the routing map, open ``pyamf_tutorial/__init__.py`` and look for the line:
4276

77+
.. code-block:: python
78+
79+
config.add_static_view('static', 'pyamf_tutorial:static')
80+
81+
Just above that line, configure the route to the view you created earlier.
4382

44-
2. Fire up the web server with:
83+
.. code-block:: python
84+
85+
config.add_view('pyamf_tutorial.views.echoGateway', name='gateway')
86+
87+
88+
7. Fire up the web server with:
4589

4690
.. code-block:: bash
4791
48-
$ python server.py
92+
$ ../bin/paster serve development.ini
4993
5094
That should print something like:
5195

5296
.. code-block:: bash
5397
54-
serving on 0.0.0.0:8080 view at http://127.0.0.1:8080
98+
Starting server in PID 16601.
99+
serving on 0.0.0.0:6543 view at http://127.0.0.1:6543
55100
56101
57-
3. To test the gateway you can use a Python AMF client like this:
102+
8. To test the gateway you can use a Python AMF client like this:
58103

59104
.. literalinclude:: ../examples/gateways/pylons/pyramid_client.py
60105
:linenos:
61106

62107

63-
Pylons
64-
======
108+
109+
Pylons (0.97-1.x)
110+
=================
111+
112+
This section of the tutorial covers the legacy `Pylons package`_.
113+
114+
Example
115+
-------
65116

66117
1. Create a new Pylons project with:
67118

@@ -141,5 +192,6 @@ Pylons
141192
.. _Pylons package: http://docs.pylonsproject.org/docs/pylons.html
142193
.. _pyramid_rpc: http://docs.pylonsproject.org/projects/pyramid_rpc/dev/
143194
.. _Pylons FAQ: http://docs.pylonsproject.org/faq/pylonsproject.html
144-
.. _AMF: http://docs.pylonsproject.org/projects/pyramid_rpc/dev/amf.html
145-
.. _Install: http://docs.pylonsproject.org/projects/pyramid_rpc/dev/#installation
195+
.. _pyramid_rpc documentation: http://docs.pylonsproject.org/projects/pyramid_rpc/dev/amf.html
196+
.. _virtualenv: http://pypi.python.org/pypi/virtualenv
197+
.. _installation documentation: http://docs.pylonsproject.org/projects/pyramid/1.1/narr/install.html#installing-chapter

0 commit comments

Comments
 (0)