Merge branch 'master' of github.com:Pylons/pyramid
3 files deleted
11 files modified
| | |
| | | ~~~~~~~~~~~~~~~~~~ |
| | | |
| | | Python comes pre-installed on Mac OS X, but due to Apple's release cycle, |
| | | it is often out of date. Unless you have a need for a specific earlier version, |
| | | it is recommended to install the latest 2.x or 3.x version of Python. |
| | | it is often out of date. Unless you have a need for a specific earlier |
| | | version, it is recommended to install the latest 2.x or 3.x version of Python. |
| | | |
| | | You can install the latest verion of Python for Mac OS X from the binaries on |
| | | `python.org <https://www.python.org/download/mac/>`_. |
| | | `python.org <https://www.python.org/downloads/mac-osx/>`_. |
| | | |
| | | Alternatively, you can use the `homebrew <http://brew.sh/>`_ package manager. |
| | | |
| | |
| | | |
| | | Once you have a standard Python environment setup, getting started with |
| | | Pyramid is a breeze. Unfortunately "standard" is not so simple in Python. |
| | | For this Quick Tour, it means: |
| | | `Python <http://www.python.org/download/releases/>`_, a |
| | | `virtual environment <http://docs.python.org/dev/library/venv.html>`_ |
| | | (or `virtualenv for Python 2.7 <https://pypi.python.org/pypi/virtualenv>`_), |
| | | and `setuptools <https://pypi.python.org/pypi/setuptools/>`_. |
| | | For this Quick Tour, it means: `Python <https://www.python.org/downloads/>`_, |
| | | a `virtual environment <http://docs.python.org/dev/library/venv.html>`_ (or |
| | | `virtualenv for Python 2.7 <https://pypi.python.org/pypi/virtualenv>`_), and |
| | | `setuptools <https://pypi.python.org/pypi/setuptools/>`_. |
| | | |
| | | As an example, for Python 3.3+ on Linux: |
| | | |
| | |
| | | Application Running with ``pserve`` |
| | | =================================== |
| | | |
| | | Prior to scaffolds, our project mixed a number of operations details |
| | | Prior to scaffolds, our project mixed a number of operational details |
| | | into our code. Why should my main code care which HTTP server I want and |
| | | what port number to run on? |
| | | |
| | |
| | | collapsible) menu in the right of your browser, providing introspective |
| | | access to debugging information. Even better, if your web application |
| | | generates an error, you will see a nice traceback on the screen. When |
| | | you want to disable this toolbar, no need to change code: you can |
| | | you want to disable this toolbar, there's no need to change code: you can |
| | | remove it from ``pyramid.includes`` in the relevant ``.ini`` |
| | | configuration file. |
| | | |
| | |
| | | Of course, this only applies on ``Root``. Some other part of the site |
| | | (a.k.a. *context*) might have a different ACL. |
| | | |
| | | If you are not logged in and visit ``/hello``, you need to get |
| | | If you are not logged in and visit ``/howdy``, you need to get |
| | | shown the login screen. How does Pyramid know what is the login page to |
| | | use? We explicitly told Pyramid that the ``login`` view should be used |
| | | by decorating the view with ``@forbidden_view_config``. |
| | |
| | | .. literalinclude:: logging/tutorial/views.py |
| | | :linenos: |
| | | |
| | | #. Finally let's edit ``development.ini`` configuration file |
| | | to enable logging for our Pyramid application: |
| | | |
| | | .. literalinclude:: logging/development.ini |
| | | :language: ini |
| | | |
| | | #. Make sure the tests still pass: |
| | | |
| | | .. code-block:: bash |
| | |
| | | Analysis |
| | | ======== |
| | | |
| | | Our ``development.ini`` configuration file wires up Python standard |
| | | logging for our Pyramid application: |
| | | |
| | | .. literalinclude:: logging/development.ini |
| | | :language: ini |
| | | |
| | | In this, our ``tutorial`` Python package is setup as a logger |
| | | and configured to log messages at a ``DEBUG`` or higher level. When you |
| | | visit http://localhost:6543 your console will now show:: |
| | | In our configuration file ``development.ini``, our ``tutorial`` Python |
| | | package is setup as a logger and configured to log messages at a |
| | | ``DEBUG`` or higher level. When you visit http://localhost:6543 your |
| | | console will now show:: |
| | | |
| | | 2013-08-09 10:42:42,968 DEBUG [tutorial.views][MainThread] In home view |
| | | |
| | |
| | | Install Python 3.3 or greater |
| | | ----------------------------- |
| | | |
| | | Download the latest standard Python 3.3+ release (not development |
| | | release) from |
| | | `python.org <http://www.python.org/download/releases/>`_. On that page, you |
| | | must click the latest version, then scroll down to the "Downloads" section |
| | | for your operating system. |
| | | Download the latest standard Python 3.3+ release (not development release) |
| | | from `python.org <https://www.python.org/downloads/>`_. |
| | | |
| | | Windows and Mac OS X users can download and run an installer. |
| | | |
| | |
| | | version. |
| | | |
| | | Linux users can either use their package manager to install Python 3.3 |
| | | or may |
| | | `build Python 3.3 from source |
| | | or may `build Python 3.3 from source |
| | | <http://pyramid.readthedocs.org/en/master/narr/install.html#package-manager- |
| | | method>`_. |
| | | |
| | |
| | | |
| | | We will arrive at a directory structure of |
| | | ``workspace->project->package``, with our workspace named |
| | | ``quick_tutorial``. The following diagram shows how this is structured |
| | | and where our virtual environment will reside: |
| | | ``quick_tutorial``. The following tree diagram shows how this will be |
| | | structured and where our virtual environment will reside as we proceed through |
| | | the tutorial: |
| | | |
| | | .. figure:: ../_static/directory_structure_pyramid.png |
| | | :alt: Final directory structure |
| | | .. code-block:: text |
| | | |
| | | Final directory structure. |
| | | └── ~ |
| | | └── projects |
| | | └── quick_tutorial |
| | | ├── env |
| | | └── step_one |
| | | ├── intro |
| | | │ ├── __init__.py |
| | | │ └── app.py |
| | | └── setup.py |
| | | |
| | | For Linux, the commands to do so are as follows: |
| | | |
| | |
| | | .. code-block:: bash |
| | | |
| | | # Mac and Linux |
| | | $ export VENV=~/projects/quick_tutorial/env33/ |
| | | $ export VENV=~/projects/quick_tutorial/env |
| | | |
| | | # Windows |
| | | # TODO: This command does not work |
| | | c:\> set VENV=c:\projects\quick_tutorial\env33 |
| | | c:\> set VENV=c:\projects\quick_tutorial\env |
| | | |
| | | |
| | | .. _create-a-virtual-environment: |
| | |
| | | $ cd ..; cp -r view_classes static_assets; cd static_assets |
| | | $ $VENV/bin/python setup.py develop |
| | | |
| | | #. We add a call ``config.add_static_view in |
| | | #. We add a call ``config.add_static_view`` in |
| | | ``static_assets/tutorial/__init__.py``: |
| | | |
| | | .. literalinclude:: static_assets/tutorial/__init__.py |
| | |
| | | |
| | | We have 2 views, each leading to the other. If you start at |
| | | http://localhost:6543/, you get a response with a link to the next |
| | | view. The ``hello_view`` (available at the URL ``/howdy``) has a link |
| | | view. The ``hello`` view (available at the URL ``/howdy``) has a link |
| | | back to the first view. |
| | | |
| | | This step also shows that the name appearing in the URL, |
| | |
| | | |
| | | json_renderer_factory = JSON() # bw compat |
| | | |
| | | JSONP_VALID_CALLBACK = re.compile(r"^[a-zA-Z_$][0-9a-zA-Z_$]+$") |
| | | JSONP_VALID_CALLBACK = re.compile(r"^[$a-z_][$0-9a-z_\.\[\]]+[^.]$", re.I) |
| | | |
| | | class JSONP(JSON): |
| | | """ `JSONP <http://en.wikipedia.org/wiki/JSONP>`_ renderer factory helper |
| | |
| | | raise HTTPBadRequest('Invalid JSONP callback function name.') |
| | | |
| | | ct = 'application/javascript' |
| | | body = '%s(%s);' % (callback, val) |
| | | body = '/**/{0}({1});'.format(callback, val) |
| | | response = request.response |
| | | if response.content_type == response.default_content_type: |
| | | response.content_type = ct |
| | |
| | | request = testing.DummyRequest() |
| | | request.GET['callback'] = 'callback' |
| | | result = renderer({'a':'1'}, {'request':request}) |
| | | self.assertEqual(result, 'callback({"a": "1"});') |
| | | self.assertEqual(result, '/**/callback({"a": "1"});') |
| | | self.assertEqual(request.response.content_type, |
| | | 'application/javascript') |
| | | |
| | | def test_render_to_jsonp_with_dot(self): |
| | | renderer_factory = self._makeOne() |
| | | renderer = renderer_factory(None) |
| | | request = testing.DummyRequest() |
| | | request.GET['callback'] = 'angular.callbacks._0' |
| | | result = renderer({'a':'1'}, {'request':request}) |
| | | self.assertEqual(result, '/**/angular.callbacks._0({"a": "1"});') |
| | | self.assertEqual(request.response.content_type, |
| | | 'application/javascript') |
| | | |
| | |
| | | Sphinx >= 1.2.3 |
| | | repoze.sphinx.autointerface |
| | | repoze.lru |
| | | pylons_sphinx_latesturl |
| | | pylons-sphinx-themes |
| | | -e .[docs] |
| | |
| | | tests_require.append('zope.component>=3.11.0') |
| | | |
| | | docs_extras = [ |
| | | 'Sphinx >= 1.2.3', |
| | | 'Sphinx >= 1.3.1', |
| | | 'docutils', |
| | | 'repoze.sphinx.autointerface', |
| | | 'pylons-sphinx-themes >= 0.3', |
| | | 'pylons_sphinx_latesturl', |
| | | 'pylons-sphinx-themes', |
| | | ] |
| | | |
| | | testing_extras = tests_require + [ |