Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Pylons howto 841 #13

Merged
merged 4 commits into from

2 participants

This page is out of date. Refresh to see the latest.
View
2  doc/html/tutorials.html
@@ -61,7 +61,7 @@
<p class="biglink"><a class="biglink" href="{{ pathto("tutorials/gateways/django") }}">Django</a><br/>
<span class="linkdescr">Getting started with AMF for <a href="http://djangoproject.com">Django</a></span></p>
<p class="biglink"><a class="biglink" href="{{ pathto("tutorials/gateways/pylons") }}">Pylons</a><br/>
- <span class="linkdescr">Setting up an AMF Remoting gateway in a <a href='http://pylonshq.com'>Pylons</a> project</span></p>
+ <span class="linkdescr">Setting up an AMF Remoting gateway using the <a href='http://pylonsproject.org'>Pylons</a> project</span></p>
<p><a class="biglink" href="{{ pathto("tutorials/gateways/twisted") }}">Twisted</a><br/>
<span class="linkdescr">Creating AMF Remoting gateways with <a href='http://twistedmatrix.com'>Twisted</a></span></p>
<p class="biglink"><a class="biglink" href="{{ pathto("tutorials/gateways/appengine") }}">Google App Engine</a><br/>
View
0  doc/tutorials/examples/gateways/pylons/client.py → ...torials/examples/gateways/pylons/pylons_client.py
File renamed without changes
View
0  doc/tutorials/examples/gateways/pylons/gateway.py → ...orials/examples/gateways/pylons/pylons_gateway.py
File renamed without changes
View
15 doc/tutorials/examples/gateways/pylons/pyramid_client.py
@@ -0,0 +1,15 @@
+import logging
+
+logging.basicConfig(
+ level=logging.DEBUG,
+ format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s'
+)
+
+from pyamf.remoting.client import RemotingService
+
+url = 'http://127.0.0.1:6543/gateway'
+client = RemotingService(url, logger=logging)
+service = client.getService('myservice')
+echo = service.echo('Hello World!')
+
+logging.debug(echo)
View
21 doc/tutorials/examples/gateways/pylons/pyramid_gateway.py
@@ -0,0 +1,21 @@
+from pyramid_rpc.amfgateway import PyramidGateway
+
+
+def my_view(request):
+ return {'project':'pyamf_tutorial'}
+
+def echo(request, data):
+ """
+ This is a function that we will expose.
+ """
+ # echo data back to the client
+ return data
+
+
+services = {
+ 'myservice.echo': echo,
+ # Add other exposed functions and classes here
+}
+
+echoGateway = PyramidGateway(services, debug=True)
+
View
BIN  doc/tutorials/gateways/images/pylons-logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
130 doc/tutorials/gateways/pylons.rst
@@ -1,21 +1,119 @@
-**********
- Pylons
-**********
+******************
+ Pylons Project
+******************
+
+.. image:: images/pylons-logo.png
.. topic:: Introduction
- The following tutorial describes how to set up a bare bones
- Pylons_ project with a gateway exposing a method.
+ The `Pylons Project`_ is a collection of web application framework
+ technologies. This tutorial describes how to setup a bare bones
+ application with a remoting gateway exposing a method.
+
+ **Note**: This tutorial provides examples for both Pyramid_ and the legacy
+ `Pylons package`_ (versions 0.97-1.x). For new projects it is encouraged
+ to use the Pyramid package, see the `Pylons FAQ`_ for more information.
- Since Pylons supports_ generic WSGI (:pep:`333`) apps as
- controllers, setting up a remoting gateway is trivial using the WSGI
- gateway.
.. contents::
-Example
+
+Pyramid
=======
+Pyramid_ is a small, fast, down-to-earth Python web application development
+framework. It is developed as part of the `Pylons Project`_.
+
+Example
+-------
+
+1. Create a new virtual environment using the virtualenv_ tool:
+
+ .. code-block:: bash
+
+ $ virtualenv --no-site-packages pyramid_amf_env
+
+
+2. The Pyramid_ package supports extensibility through add-ons. For this tutorial
+ we need AMF support which is available in the `pyramid_rpc`_ add-on.
+
+ Install the ``pyramid``, ``pyramid_rpc`` and ``pyamf`` packages:
+
+ .. code-block:: bash
+
+ $ cd pyramid_amf_env
+ $ bin/easy_install pyramid pyramid_rpc pyamf
+
+
+ For more detailed instructions, refer to the Pyramid `installation documentation`_.
+
+
+3. Create a new Pyramid project (called ``pyamf_tutorial`` in this example):
+
+ .. code-block:: bash
+
+ $ bin/paster create -t pyramid_starter pyamf_tutorial
+
+
+4. Install the project into the enviroment:
+
+ .. code-block:: bash
+
+ $ cd pyamf_tutorial
+ $ ../bin/python setup.py develop
+
+
+5. Replace the contents of ``pyamf_tutorial/views.py`` with the following:
+
+ .. literalinclude:: ../examples/gateways/pylons/pyramid_gateway.py
+ :linenos:
+
+ You can easily expose more functions by adding them to the ``services`` dictionary
+ given to ``PyramidGateway``. Also see the `pyramid_rpc documentation`_.
+
+
+6. Add the view to the routing map, open ``pyamf_tutorial/__init__.py`` and look for the line:
+
+ .. code-block:: python
+
+ config.add_static_view('static', 'pyamf_tutorial:static')
+
+ Just above that line, configure the route to the view you created earlier.
+
+ .. code-block:: python
+
+ config.add_view('pyamf_tutorial.views.echoGateway', name='gateway')
+
+
+7. Fire up the web server with:
+
+ .. code-block:: bash
+
+ $ ../bin/paster serve development.ini
+
+ That should print something like:
+
+ .. code-block:: bash
+
+ Starting server in PID 16601.
+ serving on 0.0.0.0:6543 view at http://127.0.0.1:6543
+
+
+8. To test the gateway you can use a Python AMF client like this:
+
+ .. literalinclude:: ../examples/gateways/pylons/pyramid_client.py
+ :linenos:
+
+
+
+Pylons (0.97-1.x)
+=================
+
+This section of the tutorial covers the legacy `Pylons package`_.
+
+Example
+-------
+
1. Create a new Pylons project with:
.. code-block:: bash
@@ -33,7 +131,7 @@ Example
3. Replace the contents of ``testproject/controllers/gateway.py`` with the following:
- .. literalinclude:: ../examples/gateways/pylons/gateway.py
+ .. literalinclude:: ../examples/gateways/pylons/pylons_gateway.py
:linenos:
You can easily expose more functions by adding them to the dictionary given to ``WSGIGateway``.
@@ -85,9 +183,15 @@ Example
8. To test the gateway you can use a Python AMF client like this:
- .. literalinclude:: ../examples/gateways/pylons/client.py
+ .. literalinclude:: ../examples/gateways/pylons/pylons_client.py
:linenos:
-.. _Pylons: http://pylonsproject.org
-.. _supports: http://wiki.pylonshq.com/display/pylonsdocs/Web+Server+Gateway+Interface+Support
+.. _Pylons Project: http://pylonsproject.org/
+.. _Pyramid: http://docs.pylonsproject.org/docs/pyramid.html
+.. _Pylons package: http://docs.pylonsproject.org/docs/pylons.html
+.. _pyramid_rpc: http://docs.pylonsproject.org/projects/pyramid_rpc/dev/
+.. _Pylons FAQ: http://docs.pylonsproject.org/faq/pylonsproject.html
+.. _pyramid_rpc documentation: http://docs.pylonsproject.org/projects/pyramid_rpc/dev/amf.html
+.. _virtualenv: http://pypi.python.org/pypi/virtualenv
+.. _installation documentation: http://docs.pylonsproject.org/projects/pyramid/1.1/narr/install.html#installing-chapter
Something went wrong with that request. Please try again.