fix up all the ..note and ..warning sphinx errors
excluded _themes/README.rst from being looked ed
| | |
| | | # List of documents that shouldn't be included in the build. |
| | | #unused_docs = [] |
| | | |
| | | # List of patterns, relative to source directory, that match files and |
| | | # directories to ignore when looking for source files. |
| | | exclude_patterns = ['_themes/README.rst',] |
| | | |
| | | # List of directories, relative to source directories, that shouldn't be searched |
| | | # for source files. |
| | | #exclude_dirs = [] |
| | |
| | | abandoned and it is not used in :app:`Pyramid`. We continued to use a ZCA |
| | | registry within :app:`Pyramid` because it ultimately proved a better fit. |
| | | |
| | | .. note:: We continued using ZCA registry rather than disusing it in |
| | | .. note:: |
| | | |
| | | We continued using ZCA registry rather than disusing it in |
| | | favor of using the registry implementation in |
| | | :mod:`repoze.component` largely because the ZCA concept of |
| | | interfaces provides for use of an interface hierarchy, which is |
| | |
| | | :linenos: |
| | | |
| | | from pyramid.view import view_config |
| | | @view_config(name='post_view', request_method='POST', |
| | | @view_config(name='post_view', request_method='POST', |
| | | accept='application/json', renderer='json') |
| | | def post_view(request): |
| | | return 'POSTed' |
| | |
| | | often via a registered handler or callback and converts the event |
| | | into appropriate user action, understandable for the model. |
| | | |
| | | The controller notifies the model of the user action, possibly |
| | | The controller notifies the model of the user action, possibly |
| | | resulting in a change in the model's state. (For example, the |
| | | controller updates the user's shopping cart.)[5] |
| | | |
| | | A view queries the model in order to generate an appropriate |
| | | user interface (for example, the view lists the shopping cart's |
| | | user interface (for example, the view lists the shopping cart's |
| | | contents). Note that the view gets its own data from the model. |
| | | |
| | | The controller may (in some implementations) issue a general |
| | |
| | | |
| | | .. code-block:: text |
| | | |
| | | [chrism@thinko]$ python app.py |
| | | [chrism@thinko]$ python app.py |
| | | [<function foo at 0x7f4ea41ab1b8>, |
| | | <function foo at 0x7f4ea41ab230>, |
| | | <function bar at 0x7f4ea41ab2a8>] |
| | |
| | | else: |
| | | error = 'Invalid username/password' |
| | | # this is executed if the request method was GET or the |
| | | # credentials were invalid |
| | | # credentials were invalid |
| | | |
| | | The `Pylons 1.X <http://pylonsproject.org>`_ web framework uses a similar |
| | | strategy. It calls these things "Stacked Object Proxies", so, for purposes |
| | |
| | | |
| | | def hello_world(request): # accepts a request; no request thread local reqd |
| | | # explicit response object means no response threadlocal |
| | | return Response('Hello world!') |
| | | return Response('Hello world!') |
| | | |
| | | if __name__ == '__main__': |
| | | from pyramid.config import Configurator |
| | |
| | | include that can be used outside of one (such as |
| | | :meth:`~pyramid.config.Configurator.add_view`, etc). |
| | | |
| | | Pyramid has a conflict detection system that will throw an error if two |
| | | included externals try to add "the same" configuration in a conflicting |
| | | way (such as both externals trying to add a route using the same name, |
| | | or both externals trying to add a view with the same set of predicates). |
| | | It's awful tempting to call this set of features something that can be |
| | | used to compose a system out of "pluggable applications". But in |
| | | reality, there are a number of problems with claiming this: |
| | | Pyramid has a conflict detection system that will throw an error if two |
| | | included externals try to add "the same" configuration in a conflicting |
| | | way (such as both externals trying to add a route using the same name, |
| | | or both externals trying to add a view with the same set of predicates). |
| | | It's awful tempting to call this set of features something that can be |
| | | used to compose a system out of "pluggable applications". But in |
| | | reality, there are a number of problems with claiming this: |
| | | |
| | | - The terminology is strained. Pyramid really has no notion of a |
| | | plurality of "applications", just a way to compose configuration |
| | | from multiple sources to create a single WSGI application. That |
| | | WSGI application may gain behavior by including or disincluding |
| | | configuration, but once it's all composed together, Pyramid |
| | | doesn't really provide any machinery which can be used to demarcate |
| | | the boundaries of one "application" (in the sense of configuration |
| | | from an external that adds routes, views, etc) from another. |
| | | - The terminology is strained. Pyramid really has no notion of a |
| | | plurality of "applications", just a way to compose configuration |
| | | from multiple sources to create a single WSGI application. That |
| | | WSGI application may gain behavior by including or disincluding |
| | | configuration, but once it's all composed together, Pyramid |
| | | doesn't really provide any machinery which can be used to demarcate |
| | | the boundaries of one "application" (in the sense of configuration |
| | | from an external that adds routes, views, etc) from another. |
| | | |
| | | - Pyramid doesn't provide enough "rails" to make it possible to |
| | | integrate truly honest-to-god, download-an-app-from-a-random-place |
| | | and-plug-it-in-to-create-a-system "pluggable" applications. |
| | | Because Pyramid itself isn't opinionated (it doesn't mandate a |
| | | particular kind of database, it offers multiple ways to map URLs |
| | | to code, etc), it's unlikely that someone who creates something |
| | | "application-like" will be able to casually redistribute it |
| | | to J. Random Pyramid User and have it "just work" by asking him |
| | | to config.include a function from the package. |
| | | This is particularly true of very high level components such |
| | | as blogs, wikis, twitter clones, commenting systems, etc. |
| | | The "integrator" (the Pyramid developer who has downloaded a |
| | | package advertised as a "pluggable app") will almost certainly |
| | | have made different choices about e.g. what type of persistence |
| | | system he's using, and for the integrator to appease the |
| | | requirements of the "pluggable application", he may be required |
| | | to set up a different database, make changes to his own code |
| | | to prevent his application from "shadowing" the pluggable |
| | | app (or vice versa), and any other number of arbitrary |
| | | changes. |
| | | - Pyramid doesn't provide enough "rails" to make it possible to |
| | | integrate truly honest-to-god, download-an-app-from-a-random-place |
| | | and-plug-it-in-to-create-a-system "pluggable" applications. |
| | | Because Pyramid itself isn't opinionated (it doesn't mandate a |
| | | particular kind of database, it offers multiple ways to map URLs |
| | | to code, etc), it's unlikely that someone who creates something |
| | | "application-like" will be able to casually redistribute it |
| | | to J. Random Pyramid User and have it "just work" by asking him |
| | | to config.include a function from the package. |
| | | This is particularly true of very high level components such |
| | | as blogs, wikis, twitter clones, commenting systems, etc. |
| | | The "integrator" (the Pyramid developer who has downloaded a |
| | | package advertised as a "pluggable app") will almost certainly |
| | | have made different choices about e.g. what type of persistence |
| | | system he's using, and for the integrator to appease the |
| | | requirements of the "pluggable application", he may be required |
| | | to set up a different database, make changes to his own code |
| | | to prevent his application from "shadowing" the pluggable |
| | | app (or vice versa), and any other number of arbitrary |
| | | changes. |
| | | |
| | | For this reason, we claim that Pyramid has "extensible" applications, |
| | | not pluggable applications. Any Pyramid application can be extended |
| | | without forking it as long as its configuration statements have been |
| | | composed into things that can be pulled in via "config.include". |
| | | For this reason, we claim that Pyramid has "extensible" applications, |
| | | not pluggable applications. Any Pyramid application can be extended |
| | | without forking it as long as its configuration statements have been |
| | | composed into things that can be pulled in via "config.include". |
| | | |
| | | It's also perfectly reasonable for a single developer or team to create a set |
| | | of interoperating components which can be enabled or disabled by using |
| | |
| | | mechanism makes a directory of static files available at a name relative to |
| | | the application root URL, e.g. ``/static`` or as an external URL. |
| | | |
| | | .. note:: :meth:`~pyramid.config.Configurator.add_static_view` cannot serve a |
| | | single file, nor can it serve a directory of static files directly |
| | | relative to the root URL of a :app:`Pyramid` application. For these |
| | | features, see :ref:`advanced_static`. |
| | | .. note:: |
| | | |
| | | :meth:`~pyramid.config.Configurator.add_static_view` cannot serve a single |
| | | file, nor can it serve a directory of static files directly relative to the |
| | | root URL of a :app:`Pyramid` application. For these features, see |
| | | :ref:`advanced_static`. |
| | | |
| | | Here's an example of a use of |
| | | :meth:`~pyramid.config.Configurator.add_static_view` that will serve files up |
| | |
| | | :linenos: |
| | | |
| | | # config is an instance of pyramid.config.Configurator |
| | | config.add_static_view(name='http://example.com/images', |
| | | config.add_static_view(name='http://example.com/images', |
| | | path='mypackage:images') |
| | | |
| | | Because :meth:`~pyramid.config.Configurator.add_static_view` is provided with |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | config.add_static_view(name='http://example.com/images', |
| | | config.add_static_view(name='http://example.com/images', |
| | | path='mypackage:images') |
| | | |
| | | Under such a configuration, the URL generated by ``static_url`` for |
| | |
| | | :meth:`~pyramid.config.Configurator.add_static_view` configuration method, so |
| | | its behavior is almost exactly the same once it's configured. |
| | | |
| | | .. warning:: The following example *will not work* for applications that use |
| | | .. warning:: |
| | | |
| | | The following example *will not work* for applications that use |
| | | :term:`traversal`, it will only work if you use :term:`URL dispatch` |
| | | exclusively. The root-relative route we'll be registering will always be |
| | | matched before traversal takes place, subverting any views registered via |
| | | ``add_view`` (at least those without a ``route_name``). A |
| | | :class:`~pyramid.static.static_view` static view cannot be made |
| | | root-relative when you use traversal unless it's registered as a |
| | | :term:`Not Found view`. |
| | | :class:`~pyramid.static.static_view` static view cannot be made root-relative |
| | | when you use traversal unless it's registered as a :term:`Not Found view`. |
| | | |
| | | To serve files within a directory located on your filesystem at |
| | | ``/path/to/static/dir`` as the result of a "catchall" route hanging from the |
| | |
| | | passed to the ``Response`` constructor as the *body* of the response. In the |
| | | ``goodbye_world`` function, the string ``'Goodbye world!'`` is passed. |
| | | |
| | | .. note:: As we'll see in later chapters, returning a literal |
| | | :term:`response` object from a view callable is not always required; we |
| | | can instead use a :term:`renderer` in our view configurations. If we use |
| | | a renderer, our view callable is allowed to return a value that the |
| | | renderer understands, and the renderer generates a response on our behalf. |
| | | .. note:: |
| | | |
| | | As we'll see in later chapters, returning a literal :term:`response` object |
| | | from a view callable is not always required; we can instead use a |
| | | :term:`renderer` in our view configurations. If we use a renderer, our view |
| | | callable is allowed to return a value that the renderer understands, and the |
| | | renderer generates a response on our behalf. |
| | | |
| | | .. index:: |
| | | single: imperative configuration |
| | |
| | | def notfound_view(request): |
| | | return HTTPNotFound() |
| | | |
| | | .. note:: When a NotFound view callable is invoked, it is passed a |
| | | :term:`request`. The ``exception`` attribute of the request will be an |
| | | instance of the :exc:`~pyramid.httpexceptions.HTTPNotFound` exception that |
| | | caused the not found view to be called. The value of |
| | | ``request.exception.message`` will be a value explaining why the not found |
| | | error was raised. This message will be different when the |
| | | ``debug_notfound`` environment setting is true than it is when it is |
| | | false. |
| | | .. note:: |
| | | |
| | | .. warning:: When a NotFound view callable accepts an argument list as |
| | | described in :ref:`request_and_context_view_definitions`, the ``context`` |
| | | passed as the first argument to the view callable will be the |
| | | When a NotFound view callable is invoked, it is passed a :term:`request`. |
| | | The ``exception`` attribute of the request will be an instance of the |
| | | :exc:`~pyramid.httpexceptions.HTTPNotFound` exception that caused the not |
| | | found view to be called. The value of ``request.exception.message`` will be |
| | | a value explaining why the not found error was raised. This message will be |
| | | different when the ``debug_notfound`` environment setting is true than it is |
| | | when it is false. |
| | | |
| | | .. warning:: |
| | | |
| | | When a NotFound view callable accepts an argument list as described in |
| | | :ref:`request_and_context_view_definitions`, the ``context`` passed as the |
| | | first argument to the view callable will be the |
| | | :exc:`~pyramid.httpexceptions.HTTPNotFound` exception instance. If |
| | | available, the resource context will still be available as |
| | | ``request.context``. |
| | |
| | | def forbidden_view(request): |
| | | return Response('forbidden') |
| | | |
| | | .. note:: When a forbidden view callable is invoked, it is passed a |
| | | :term:`request`. The ``exception`` attribute of the request will be an |
| | | instance of the :exc:`~pyramid.httpexceptions.HTTPForbidden` exception |
| | | that caused the forbidden view to be called. The value of |
| | | ``request.exception.message`` will be a value explaining why the forbidden |
| | | was raised and ``request.exception.result`` will be extended information |
| | | about the forbidden exception. These messages will be different when the |
| | | ``debug_authorization`` environment setting is true than it is when it is |
| | | false. |
| | | .. note:: |
| | | |
| | | When a forbidden view callable is invoked, it is passed a :term:`request`. |
| | | The ``exception`` attribute of the request will be an instance of the |
| | | :exc:`~pyramid.httpexceptions.HTTPForbidden` exception that caused the |
| | | forbidden view to be called. The value of ``request.exception.message`` will |
| | | be a value explaining why the forbidden was raised and |
| | | ``request.exception.result`` will be extended information about the forbidden |
| | | exception. These messages will be different when the ``debug_authorization`` |
| | | environment setting is true than it is when it is false. |
| | | |
| | | .. index:: |
| | | single: request factory |
| | |
| | | |
| | | class MyResponse(object): |
| | | implements(IResponse) |
| | | # ... an implementation of every method and attribute |
| | | # ... an implementation of every method and attribute |
| | | # documented in IResponse should follow ... |
| | | |
| | | When an alternate response object implementation is returned by a view |
| | |
| | | def aview(request): |
| | | locale = get_localizer(request) |
| | | |
| | | .. note:: If you need to create a localizer for a locale use the |
| | | .. note:: |
| | | |
| | | If you need to create a localizer for a locale use the |
| | | :func:`pyramid.i18n.make_localizer` function. |
| | | |
| | | .. index:: |
| | |
| | | ``domain`` attribute of the provided translation string as well as the |
| | | locale of the localizer. |
| | | |
| | | .. note:: If you're using :term:`Chameleon` templates, you don't need |
| | | .. note:: |
| | | |
| | | If you're using :term:`Chameleon` templates, you don't need |
| | | to pre-translate translation strings this way. See |
| | | :ref:`chameleon_translation_strings`. |
| | | |
| | |
| | | ------------------ |
| | | |
| | | You will need `Python <http://python.org>`_ version 2.5 or better to |
| | | run :app:`Pyramid`. |
| | | run :app:`Pyramid`. |
| | | |
| | | .. sidebar:: Python Versions |
| | | |
| | |
| | | .. code-block:: text |
| | | |
| | | [chrism@vitaminf pyramid]$ python |
| | | Python 2.6.5 (r265:79063, Apr 29 2010, 00:31:32) |
| | | Python 2.6.5 (r265:79063, Apr 29 2010, 00:31:32) |
| | | [GCC 4.4.3] on linux2 |
| | | Type "help", "copyright", "credits" or "license" for more information. |
| | | >>> import setuptools |
| | |
| | | New python executable in env/bin/python |
| | | Installing setuptools.............done. |
| | | |
| | | .. warning:: Using ``--no-site-packages`` when generating your |
| | | virtualenv is *very important*. This flag provides the necessary |
| | | isolation for running the set of packages required by |
| | | :app:`Pyramid`. If you do not specify ``--no-site-packages``, |
| | | it's possible that :app:`Pyramid` will not install properly into |
| | | the virtualenv, or, even if it does, may not run properly, |
| | | depending on the packages you've already got installed into your |
| | | Python's "main" site-packages dir. |
| | | .. warning:: |
| | | |
| | | Using ``--no-site-packages`` when generating your virtualenv is *very |
| | | important*. This flag provides the necessary isolation for running the set of |
| | | packages required by :app:`Pyramid`. If you do not specify |
| | | ``--no-site-packages``, it's possible that :app:`Pyramid` will not install |
| | | properly into the virtualenv, or, even if it does, may not run properly, |
| | | depending on the packages you've already got installed into your Python's |
| | | "main" site-packages dir. |
| | | |
| | | .. warning:: If you're on UNIX, *do not* use ``sudo`` to run the |
| | | ``virtualenv`` script. It's perfectly acceptable (and desirable) |
| | |
| | | PasteDeploy libraries are installed. |
| | | |
| | | Additionally, as chronicled in :ref:`project_narr`, scaffolds will be registered, |
| | | which make it easy to start a new :app:`Pyramid` project. |
| | | which make it easy to start a new :app:`Pyramid` project. |
| | | |
| | |
| | | :app:`Pyramid` applications to map URLs to code. |
| | | |
| | | .. note:: |
| | | |
| | | |
| | | Ex-Zope users whom are already familiar with traversal and view lookup |
| | | conceptually may want to skip directly to the :ref:`traversal_chapter` |
| | | chapter, which discusses technical details. This chapter is mostly aimed |
| | |
| | | .. code-block:: text |
| | | :linenos: |
| | | |
| | | Python 2.4.6 (#2, Apr 29 2010, 00:31:48) |
| | | Python 2.4.6 (#2, Apr 29 2010, 00:31:48) |
| | | [GCC 4.4.3] on linux2 |
| | | Type "help", "copyright", "credits" or "license" for more information. |
| | | >>> adict = {} |
| | |
| | | using :app:`Pyramid` and you ever find that you *do* need to support one of |
| | | these use cases, you'll be glad you have traversal in your toolkit. |
| | | |
| | | .. note:: It is even possible to mix and match :term:`traversal` with |
| | | .. note:: |
| | | |
| | | It is even possible to mix and match :term:`traversal` with |
| | | :term:`URL dispatch` in the same :app:`Pyramid` application. See the |
| | | :ref:`hybrid_chapter` chapter for details. |
| | |
| | | URL mapping via :term:`traversal` and persistence via |
| | | :term:`SQLAlchemy` |
| | | |
| | | .. note:: At this time, each of these scaffolds uses the :term:`Chameleon` |
| | | templating system, which is incompatible with Jython. To use scaffolds to |
| | | build applications which will run on Jython, you can try the |
| | | .. note:: |
| | | |
| | | At this time, each of these scaffolds uses the :term:`Chameleon` templating |
| | | system, which is incompatible with Jython. To use scaffolds to build |
| | | applications which will run on Jython, you can try the |
| | | ``pyramid_jinja2_starter`` scaffold which ships as part of the |
| | | :term:`pyramid_jinja2` package. You can also just use any above scaffold |
| | | and replace the Chameleon template it includes with a :term:`Mako` |
| | | analogue. |
| | | :term:`pyramid_jinja2` package. You can also just use any above scaffold and |
| | | replace the Chameleon template it includes with a :term:`Mako` analogue. |
| | | |
| | | Rather than use any of the above scaffolds, Pylons 1 users may feel more |
| | | comfortable installing the :term:`Akhet` development environment, which |
| | |
| | | just like if you keep executing the ``cd ..`` filesystem command, eventually |
| | | you will reach the filesystem root directory. |
| | | |
| | | .. warning:: If your root resource has a ``__name__`` argument |
| | | that is not ``None`` or the empty string, URLs returned by the |
| | | :func:`~pyramid.url.resource_url` function and paths generated by |
| | | the :func:`~pyramid.traversal.resource_path` and |
| | | :func:`~pyramid.traversal.resource_path_tuple` APIs will be |
| | | generated improperly. The value of ``__name__`` will be prepended |
| | | to every path and URL generated (as opposed to a single leading |
| | | slash or empty tuple element). |
| | | .. warning:: |
| | | |
| | | If your root resource has a ``__name__`` argument that is not ``None`` or the |
| | | empty string, URLs returned by the :func:`~pyramid.url.resource_url` function |
| | | and paths generated by the :func:`~pyramid.traversal.resource_path` and |
| | | :func:`~pyramid.traversal.resource_path_tuple` APIs will be generated |
| | | improperly. The value of ``__name__`` will be prepended to every path and |
| | | URL generated (as opposed to a single leading slash or empty tuple element). |
| | | |
| | | .. sidebar:: Using :mod:`pyramid_traversalwrapper` |
| | | |
| | |
| | | from pyramid.renderers import render_to_response |
| | | |
| | | def sample_view(request): |
| | | return render_to_response('templates/foo.pt', |
| | | {'foo':1, 'bar':2}, |
| | | return render_to_response('templates/foo.pt', |
| | | {'foo':1, 'bar':2}, |
| | | request=request) |
| | | |
| | | .. warning:: Earlier iterations of this documentation |
| | | (pre-version-1.3) encouraged the application developer to use |
| | | ZPT-specific APIs such as |
| | | .. warning:: |
| | | |
| | | Earlier iterations of this documentation (pre-version-1.3) encouraged the |
| | | application developer to use ZPT-specific APIs such as |
| | | :func:`pyramid.chameleon_zpt.render_template_to_response` and |
| | | :func:`pyramid.chameleon_zpt.render_template` to render templates |
| | | directly. This style of rendering still works, but at least for |
| | | purposes of this documentation, those functions are deprecated. |
| | | Application developers are encouraged instead to use the functions |
| | | available in the :mod:`pyramid.renderers` module to perform |
| | | rendering tasks. This set of functions works to render templates |
| | | for all renderer extensions registered with :app:`Pyramid`. |
| | | :func:`pyramid.chameleon_zpt.render_template` to render templates directly. |
| | | This style of rendering still works, but at least for purposes of this |
| | | documentation, those functions are deprecated. Application developers are |
| | | encouraged instead to use the functions available in the |
| | | :mod:`pyramid.renderers` module to perform rendering tasks. This set of |
| | | functions works to render templates for all renderer extensions registered |
| | | with :app:`Pyramid`. |
| | | |
| | | The ``sample_view`` :term:`view callable` function above returns a |
| | | :term:`response` object which contains the body of the |
| | |
| | | which use a :term:`renderer` named via view configuration (which we'll |
| | | see shortly). The :func:`pyramid.renderers.render_to_response` |
| | | function is a shortcut function that actually returns a response |
| | | object. This allows the example view above to simply return the result |
| | | of its call to ``render_to_response()`` directly. |
| | | object. This allows the example view above to simply return the result |
| | | of its call to ``render_to_response()`` directly. |
| | | |
| | | Obviously not all APIs you might call to get response data will return a |
| | | response object. For example, you might render one or more templates to |
| | |
| | | from pyramid.response import Response |
| | | |
| | | def sample_view(request): |
| | | result = render('mypackage:templates/foo.pt', |
| | | {'foo':1, 'bar':2}, |
| | | result = render('mypackage:templates/foo.pt', |
| | | {'foo':1, 'bar':2}, |
| | | request=request) |
| | | response = Response(result) |
| | | return response |
| | |
| | | |
| | | def sample_view(request): |
| | | result = render('mypackage:templates/foo.pt', |
| | | {'foo':1, 'bar':2}, |
| | | {'foo':1, 'bar':2}, |
| | | request=request) |
| | | response = Response(result) |
| | | response.content_type = 'text/plain' |
| | |
| | | The renderer name used to perform the rendering, |
| | | e.g. ``mypackage:templates/foo.pt``. |
| | | |
| | | ``renderer_info`` |
| | | ``renderer_info`` |
| | | An object implementing the :class:`pyramid.interfaces.IRendererInfo` |
| | | interface. Basically, an object with the following attributes: |
| | | ``name``, ``package`` and ``type``. |
| | |
| | | An alternative to using :func:`~pyramid.renderers.render_to_response` |
| | | to render templates manually in your view callable code, is |
| | | to specify the template as a :term:`renderer` in your |
| | | *view configuration*. This can be done with any of the |
| | | *view configuration*. This can be done with any of the |
| | | templating languages supported by :app:`Pyramid`. |
| | | |
| | | To use a renderer via view configuration, specify a template |
| | |
| | | templates is available from `the Chameleon website |
| | | <http://chameleon.repoze.org/>`_. |
| | | |
| | | .. warning:: |
| | | .. warning:: |
| | | |
| | | :term:`Chameleon` only works on :term:`CPython` platforms and |
| | | :term:`Google App Engine`. On :term:`Jython` and other non-CPython |
| | |
| | | .. code-block:: xml |
| | | :linenos: |
| | | |
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| | | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| | | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:tal="http://xml.zope.org/namespaces/tal"> |
| | |
| | | .. code-block:: xml |
| | | :linenos: |
| | | |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:tal="http://xml.zope.org/namespaces/tal" |
| | | xmlns:metal="http://xml.zope.org/namespaces/metal"> |
| | | <span metal:define-macro="hello"> |
| | |
| | | .. code-block:: xml |
| | | :linenos: |
| | | |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | <html xmlns="http://www.w3.org/1999/xhtml" |
| | | xmlns:tal="http://xml.zope.org/namespaces/tal" |
| | | xmlns:metal="http://xml.zope.org/namespaces/metal"> |
| | | <span metal:use-macro="main.macros['hello']"> |
| | |
| | | |
| | | Jinja2 template bindings are available for :app:`Pyramid` in the |
| | | ``pyramid_jinja2`` package. You can get the latest release of |
| | | this package from the |
| | | this package from the |
| | | `Python package index <http://pypi.python.org/pypi/pyramid_jinja2>`_ |
| | | (pypi). |
| | | |
| | |
| | | To capture both segments, two replacement markers can be used: |
| | | |
| | | .. code-block:: text |
| | | |
| | | |
| | | foo/{name}.{ext} |
| | | |
| | | The literal path ``/foo/biz.html`` will match the above route pattern, and |
| | |
| | | |
| | | .. code-block:: text |
| | | |
| | | foo/1/2/ -> |
| | | foo/1/2/ -> |
| | | {'baz':u'1', 'bar':u'2', 'fizzle':()} |
| | | |
| | | foo/abc/def/a/b/c -> |
| | | foo/abc/def/a/b/c -> |
| | | {'baz':u'abc', 'bar':u'def', 'fizzle':(u'a', u'b', u'c')} |
| | | |
| | | Note that when a ``*stararg`` remainder match is matched, the value put into |
| | |
| | | also capture the remainder of the URL, for example: |
| | | |
| | | .. code-block:: text |
| | | |
| | | |
| | | foo/{baz}/{bar}{fizzle:.*} |
| | | |
| | | The above pattern will match these URLs, generating the following matchdicts: |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | config.add_route('abc', '/abc', |
| | | config.add_route('abc', '/abc', |
| | | factory='myproject.resources.root_factory') |
| | | config.add_view('myproject.views.theview', route_name='abc') |
| | | |
| | |
| | | Other arguments are ``name`` and ``factory``. These arguments represent |
| | | neither predicates nor view configuration information. |
| | | |
| | | .. warning:: Some arguments are view-configuration related arguments, such as |
| | | .. warning:: |
| | | |
| | | Some arguments are view-configuration related arguments, such as |
| | | ``view_renderer``. These only have an effect when the route configuration |
| | | names a ``view`` and these arguments have been deprecated as of |
| | | :app:`Pyramid` 1.1. |
| | |
| | | |
| | | num_one_two_or_three = any_of('num', 'one', 'two', 'three') |
| | | |
| | | config.add_route('route_to_num', '/{num}', |
| | | config.add_route('route_to_num', '/{num}', |
| | | custom_predicates=(num_one_two_or_three,)) |
| | | |
| | | The above ``any_of`` function generates a predicate which ensures that the |
| | |
| | | |
| | | ymd_to_int = integers('year', 'month', 'day') |
| | | |
| | | config.add_route('ymd', '/{year}/{month}/{day}', |
| | | config.add_route('ymd', '/{year}/{month}/{day}', |
| | | custom_predicates=(ymd_to_int,)) |
| | | |
| | | Note that a conversion predicate is still a predicate so it must return |
| | |
| | | |
| | | ymd_to_int = integers('year', 'month', 'day') |
| | | |
| | | config.add_route('ymd', '/{year:\d+}/{month:\d+}/{day:\d+}', |
| | | config.add_route('ymd', '/{year:\d+}/{month:\d+}/{day:\d+}', |
| | | custom_predicates=(ymd_to_int,)) |
| | | |
| | | Now the try/except is no longer needed because the route will not match at |
| | |
| | | |
| | | config.add_route('y', '/{year}', custom_predicates=(twenty_ten,)) |
| | | config.add_route('ym', '/{year}/{month}', custom_predicates=(twenty_ten,)) |
| | | config.add_route('ymd', '/{year}/{month}/{day}', |
| | | config.add_route('ymd', '/{year}/{month}/{day}', |
| | | custom_predicates=(twenty_ten,)) |
| | | |
| | | The above predicate, when added to a number of route configurations ensures |
| | |
| | | exception to this rule is use of the ``pregenerator`` argument, which is not |
| | | ignored when ``static`` is ``True``. |
| | | |
| | | .. note:: the ``static`` argument to |
| | | :meth:`~pyramid.config.Configurator.add_route` is new as of :app:`Pyramid` |
| | | 1.1. |
| | | .. note:: |
| | | |
| | | the ``static`` argument to :meth:`~pyramid.config.Configurator.add_route` is |
| | | new as of :app:`Pyramid` 1.1. |
| | | |
| | | .. index:: |
| | | single: redirecting to slash-appended routes |
| | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | | config.add_view('pyramid.view.append_slash_notfound_view', |
| | | config.add_view('pyramid.view.append_slash_notfound_view', |
| | | context='pyramid.httpexceptions.HTTPNotFound') |
| | | |
| | | See :ref:`view_module` and :ref:`changing_the_notfound_view` for more |
| | |
| | | --------------------------- |
| | | |
| | | Sometimes it's required that some cleanup be performed at the end of a |
| | | request when a database connection is involved. |
| | | request when a database connection is involved. |
| | | |
| | | For example, let's say you have a ``mypackage`` :app:`Pyramid` application |
| | | package that uses SQLAlchemy, and you'd like the current SQLAlchemy database |
| | |
| | | match dict to see if the ``article`` argument matches a particular string; |
| | | our sample ``Article`` factory class is not very ambitious. |
| | | |
| | | .. note:: See :ref:`security_chapter` for more information about |
| | | :app:`Pyramid` security and ACLs. |
| | | .. note:: |
| | | |
| | | See :ref:`security_chapter` for more information about :app:`Pyramid` |
| | | security and ACLs. |
| | | |
| | | .. index:: |
| | | pair: debugging; route matching |
| | |
| | | :linenos: |
| | | |
| | | [chrism@thinko pylonsbasic]$ PYRAMID_DEBUG_ROUTEMATCH=true \ |
| | | bin/paster serve development.ini |
| | | bin/paster serve development.ini |
| | | Starting server in PID 13586. |
| | | serving on 0.0.0.0:6543 view at http://127.0.0.1:6543 |
| | | 2010-12-16 14:45:19,956 no route matched for url \ |
| | |
| | | parameters: :term:`context` and :term:`request`. A view callable is |
| | | assumed to return a :term:`response` object. |
| | | |
| | | .. note:: A :app:`Pyramid` view can also be defined as callable |
| | | which accepts *only* a :term:`request` argument. You'll see |
| | | this one-argument pattern used in other :app:`Pyramid` tutorials |
| | | and applications. Either calling convention will work in any |
| | | :app:`Pyramid` application; the calling conventions can be used |
| | | interchangeably as necessary. In :term:`traversal` based applications, |
| | | URLs are mapped to a context :term:`resource`, and since our |
| | | :term:`resource tree` also represents our application's |
| | | "domain model", we're often interested in the context, because |
| | | it represents the persistent storage of our application. For |
| | | this reason, in this tutorial we define views as callables that |
| | | accept ``context`` in the callable argument list. If you do |
| | | need the ``context`` within a view function that only takes |
| | | the request as a single argument, you can obtain it via |
| | | ``request.context``. |
| | | .. note:: |
| | | |
| | | A :app:`Pyramid` view can also be defined as callable which accepts *only* a |
| | | :term:`request` argument. You'll see this one-argument pattern used in other |
| | | :app:`Pyramid` tutorials and applications. Either calling convention will |
| | | work in any :app:`Pyramid` application; the calling conventions can be used |
| | | interchangeably as necessary. In :term:`traversal` based applications, URLs |
| | | are mapped to a context :term:`resource`, and since our :term:`resource tree` |
| | | also represents our application's "domain model", we're often interested in |
| | | the context, because it represents the persistent storage of our application. |
| | | For this reason, in this tutorial we define views as callables that accept |
| | | ``context`` in the callable argument list. If you do need the ``context`` |
| | | within a view function that only takes the request as a single argument, you |
| | | can obtain it via ``request.context``. |
| | | |
| | | We're going to define several :term:`view callable` functions, then wire them |
| | | into :app:`Pyramid` using some :term:`view configuration`. |
| | |
| | | .. literalinclude:: src/views/tutorial/templates/view.pt |
| | | :language: xml |
| | | |
| | | .. note:: The names available for our use in a template are always those that |
| | | are present in the dictionary returned by the view callable. But our |
| | | templates make use of a ``request`` object that none of our tutorial views |
| | | return in their dictionary. This value appears as if "by magic". |
| | | However, ``request`` is one of several names that are available "by |
| | | default" in a template when a template renderer is used. See |
| | | :ref:`chameleon_template_renderers` for more information about other names |
| | | that are available by default in a template when a template is used as a |
| | | renderer. |
| | | .. note:: |
| | | |
| | | The names available for our use in a template are always those that are |
| | | present in the dictionary returned by the view callable. But our templates |
| | | make use of a ``request`` object that none of our tutorial views return in |
| | | their dictionary. This value appears as if "by magic". However, ``request`` |
| | | is one of several names that are available "by default" in a template when a |
| | | template renderer is used. See :ref:`chameleon_template_renderers` for more |
| | | information about other names that are available by default in a template |
| | | when a template is used as a renderer. |
| | | |
| | | The ``edit.pt`` Template |
| | | ------------------------ |
| | |
| | | parameter named :term:`request`. A view callable is assumed to return a |
| | | :term:`response` object. |
| | | |
| | | .. note:: A :app:`Pyramid` view can also be defined as callable |
| | | which accepts *two* arguments: a :term:`context` and a |
| | | :term:`request`. You'll see this two-argument pattern used in |
| | | other :app:`Pyramid` tutorials and applications. Either calling |
| | | convention will work in any :app:`Pyramid` application; the |
| | | calling conventions can be used interchangeably as necessary. In |
| | | :term:`url dispatch` based applications, however, the context |
| | | object is rarely used in the view body itself, so within this |
| | | tutorial we define views as callables that accept only a request to |
| | | avoid the visual "noise". If you do need the ``context`` within a |
| | | view function that only takes the request as a single argument, you |
| | | can obtain it via ``request.context``. |
| | | .. note:: |
| | | |
| | | A :app:`Pyramid` view can also be defined as callable which accepts *two* |
| | | arguments: a :term:`context` and a :term:`request`. You'll see this |
| | | two-argument pattern used in other :app:`Pyramid` tutorials and applications. |
| | | Either calling convention will work in any :app:`Pyramid` application; the |
| | | calling conventions can be used interchangeably as necessary. In :term:`url |
| | | dispatch` based applications, however, the context object is rarely used in |
| | | the view body itself, so within this tutorial we define views as callables |
| | | that accept only a request to avoid the visual "noise". If you do need the |
| | | ``context`` within a view function that only takes the request as a single |
| | | argument, you can obtain it via ``request.context``. |
| | | |
| | | The request passed to every view that is called as the result of a route |
| | | match has an attribute named ``matchdict`` that contains the elements placed |
| | |
| | | try: |
| | | from chameleon.zpt.template import PageTextTemplateFile |
| | | # prevent pyflakes complaining about a redefinition below |
| | | PageTextTemplateFile |
| | | PageTextTemplateFile |
| | | except ImportError: # pragma: no cover |
| | | exc_class, exc, tb = sys.exc_info() |
| | | # Chameleon doesn't work on non-CPython platforms |
| | |
| | | |
| | | def implementation(self): |
| | | return self.template |
| | | |
| | | |
| | | def __call__(self, value, system): |
| | | try: |
| | | system.update(value) |
| | |
| | | ``path`` argument. The ``path`` argument may be a |
| | | package-relative path, an absolute path, or a :term:`asset |
| | | specification`. |
| | | |
| | | |
| | | .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | :func:`pyramid.renderers.get_renderer` instead. |
| | | """ |
| | |
| | | The ``path`` argument may be a package-relative path, an absolute |
| | | path, or a :term:`asset specification`. |
| | | |
| | | .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | the ``implementation()`` method of a template renderer retrieved via |
| | | .. warning:: |
| | | |
| | | This API is deprecated in :app:`Pyramid` 1.0. Use the |
| | | ``implementation()`` method of a template renderer retrieved via |
| | | :func:`pyramid.renderers.get_renderer` instead. |
| | | """ |
| | | package = caller_package() |
| | |
| | | names to the template, and so may be used within the template |
| | | itself. Returns a string. |
| | | |
| | | .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | .. warning:: |
| | | |
| | | This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | :func:`pyramid.renderers.render` instead. |
| | | """ |
| | | package = caller_package() |
| | |
| | | itself. Returns a :term:`Response` object with the body as the |
| | | template result. |
| | | |
| | | .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | .. warning:: |
| | | |
| | | This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | :func:`pyramid.renderers.render_to_response` instead. |
| | | """ |
| | | package = caller_package() |
| | |
| | | from pyramid import renderers |
| | | |
| | | registry_lock = threading.Lock() |
| | | |
| | | |
| | | def renderer_factory(info, lock=registry_lock): |
| | | return renderers.template_renderer_factory(info, ZPTTemplateRenderer) |
| | | |
| | |
| | | |
| | | def implementation(self): |
| | | return self.template |
| | | |
| | | |
| | | def __call__(self, value, system): |
| | | try: |
| | | system.update(value) |
| | |
| | | ``path`` argument. The ``path`` argument may be a |
| | | package-relative path, an absolute path, or a :term:`asset |
| | | specification`. |
| | | |
| | | |
| | | .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | :func:`pyramid.renderers.get_renderer` instead. |
| | | """ |
| | |
| | | The ``path`` argument may be a package-relative path, an absolute |
| | | path, or a :term:`asset specification`. |
| | | |
| | | .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | the ``implementation()`` method of a template renderer retrieved via |
| | | .. warning:: |
| | | |
| | | This API is deprecated in :app:`Pyramid` 1.0. Use the |
| | | ``implementation()`` method of a template renderer retrieved via |
| | | :func:`pyramid.renderers.get_renderer` instead. |
| | | """ |
| | | package = caller_package() |
| | |
| | | names to the template, and so may be used within the template |
| | | itself. Returns a string. |
| | | |
| | | .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | .. warning:: |
| | | |
| | | This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | :func:`pyramid.renderers.render` instead. |
| | | """ |
| | | package = caller_package() |
| | |
| | | itself. Returns a :term:`Response` object with the body as the |
| | | template result. |
| | | |
| | | .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | .. warning:: |
| | | |
| | | This API is deprecated in :app:`Pyramid` 1.0. Use |
| | | :func:`pyramid.renderers.render_to_response` instead. |
| | | """ |
| | | package = caller_package() |
| | |
| | | except TypeError: # pragma: no cover |
| | | pass # pypy |
| | | |
| | | try: |
| | | try: |
| | | from pyramid import chameleon_zpt |
| | | DEFAULT_RENDERERS += (('.pt', chameleon_zpt.renderer_factory),) |
| | | except TypeError: # pragma: no cover |
| | |
| | | See :ref:`adding_renderer_globals`. By default, it is ``None``, which |
| | | means use no renderer globals factory. |
| | | |
| | | .. warning:: as of Pyramid 1.1, ``renderer_globals_factory`` is |
| | | deprecated. Instead, use a BeforeRender event subscriber as per |
| | | :ref:`beforerender_event`. |
| | | .. warning:: |
| | | |
| | | as of Pyramid 1.1, ``renderer_globals_factory`` is deprecated. Instead, |
| | | use a BeforeRender event subscriber as per :ref:`beforerender_event`. |
| | | |
| | | If ``default_permission`` is passed, it should be a |
| | | :term:`permission` string to be used as the default permission for |
| | |
| | | policy = self.maybe_dotted(policy) |
| | | self.registry.registerUtility(policy, IAuthorizationPolicy) |
| | | self.action(IAuthorizationPolicy, None) |
| | | |
| | | |
| | | def _make_spec(self, path_or_spec): |
| | | package, filename = resolve_asset_spec(path_or_spec, |
| | | self.package_name) |
| | |
| | | mapper=mapper, |
| | | decorator=decorator, |
| | | http_cache=http_cache) |
| | | |
| | | |
| | | return deriver(view) |
| | | |
| | | @action_method |
| | |
| | | Python :term:`module`, in which case, the module will be searched for |
| | | a callable named ``includeme``, which will be treated as the |
| | | configuration callable. |
| | | |
| | | |
| | | For example, if the ``includeme`` function below lives in a module |
| | | named ``myapp.myconfig``: |
| | | |
| | |
| | | discriminators. ``action_wrap`` will cause the directive to be |
| | | wrapped in a decorator which provides more accurate conflict |
| | | cause information. |
| | | |
| | | |
| | | ``add_directive`` does not participate in conflict detection, and |
| | | later calls to ``add_directive`` will override earlier calls. |
| | | """ |
| | |
| | | if default_view_mapper is not None: |
| | | self.set_view_mapper(default_view_mapper) |
| | | self.commit() |
| | | |
| | | |
| | | def hook_zca(self): |
| | | """ Call :func:`zope.component.getSiteManager.sethook` with |
| | | the argument |
| | |
| | | accept ``(context, request)``. The decorator must return a |
| | | replacement view callable which also accepts ``(context, |
| | | request)``. |
| | | |
| | | |
| | | mapper |
| | | |
| | | A Python object or :term:`dotted Python name` which refers to a |
| | |
| | | plug-point is useful for Pyramid extension developers, but it's not |
| | | very useful for 'civilians' who are just developing stock Pyramid |
| | | applications. Pay no attention to the man behind the curtain. |
| | | |
| | | |
| | | Predicate Arguments |
| | | |
| | | name |
| | |
| | | pattern doesn't match the current URL, route matching |
| | | continues. |
| | | |
| | | .. note:: For backwards compatibility purposes (as of |
| | | :app:`Pyramid` 1.0), a ``path`` keyword argument passed |
| | | to this function will be used to represent the pattern |
| | | value if the ``pattern`` argument is ``None``. If both |
| | | ``path`` and ``pattern`` are passed, ``pattern`` wins. |
| | | |
| | | .. note:: |
| | | |
| | | For backwards compatibility purposes (as of :app:`Pyramid` 1.0), a |
| | | ``path`` keyword argument passed to this function will be used to |
| | | represent the pattern value if the ``pattern`` argument is |
| | | ``None``. If both ``path`` and ``pattern`` are passed, ``pattern`` |
| | | wins. |
| | | |
| | | xhr |
| | | |
| | | This value should be either ``True`` or ``False``. If this |
| | |
| | | |
| | | View-Related Arguments |
| | | |
| | | .. warning:: The arguments described below have been deprecated as of |
| | | .. warning:: |
| | | |
| | | The arguments described below have been deprecated as of |
| | | :app:`Pyramid` 1.1. *Do not use these for new development; they |
| | | should only be used to support older code bases which depend upon |
| | | them.* Use a separate call to |
| | | :meth:`pyramid.config.Configurator.add_view` to associate a view |
| | | with a route using the ``route_name`` argument. |
| | | :meth:`pyramid.config.Configurator.add_view` to associate a view with |
| | | a route using the ``route_name`` argument. |
| | | |
| | | view |
| | | |
| | |
| | | view_context |
| | | |
| | | .. warning:: Deprecated as of :app:`Pyramid` 1.1. |
| | | |
| | | |
| | | A class or an :term:`interface` or :term:`dotted Python |
| | | name` to the same object which the :term:`context` of the |
| | | view should match for the view named by the route to be |
| | |
| | | # if name is None or the empty string, we're trying to register |
| | | # a default renderer, but registerUtility is too dumb to accept None |
| | | # as a name |
| | | if not name: |
| | | if not name: |
| | | name = '' |
| | | # we need to register renderers eagerly because they are used during |
| | | # view configuration |
| | |
| | | override_package, override_prefix = override_with.split(':', 1) |
| | | |
| | | # *_isdir = override is package or directory |
| | | overridden_isdir = path=='' or path.endswith('/') |
| | | overridden_isdir = path=='' or path.endswith('/') |
| | | override_isdir = override_prefix=='' or override_prefix.endswith('/') |
| | | |
| | | if overridden_isdir and (not override_isdir): |
| | |
| | | """ Add a default forbidden view to the current configuration |
| | | state. |
| | | |
| | | .. warning:: This method has been deprecated in :app:`Pyramid` |
| | | 1.0. *Do not use it for new development; it should only be |
| | | used to support older code bases which depend upon it.* See |
| | | :ref:`changing_the_forbidden_view` to see how a forbidden |
| | | view should be registered in new projects. |
| | | .. warning:: |
| | | |
| | | This method has been deprecated in :app:`Pyramid` 1.0. *Do not use |
| | | it for new development; it should only be used to support older code |
| | | bases which depend upon it.* See :ref:`changing_the_forbidden_view` |
| | | to see how a forbidden view should be registered in new projects. |
| | | |
| | | The ``view`` argument should be a :term:`view callable` or a |
| | | :term:`dotted Python name` which refers to a view callable. |
| | |
| | | """ Add a default not found view to the current configuration |
| | | state. |
| | | |
| | | .. warning:: This method has been deprecated in |
| | | :app:`Pyramid` 1.0. *Do not use it for new development; |
| | | it should only be used to support older code bases which |
| | | depend upon it.* See :ref:`changing_the_notfound_view` to |
| | | see how a not found view should be registered in new |
| | | projects. |
| | | .. warning:: |
| | | |
| | | This method has been deprecated in :app:`Pyramid` 1.0. *Do not use |
| | | it for new development; it should only be used to support older code |
| | | bases which depend upon it.* See :ref:`changing_the_notfound_view` to |
| | | see how a not found view should be registered in new projects. |
| | | |
| | | The ``view`` argument should be a :term:`view callable` or a |
| | | :term:`dotted Python name` which refers to a view callable. |
| | |
| | | :class:`pyramid.request.Request` class (particularly |
| | | ``__call__``, and ``blank``). |
| | | |
| | | .. note:: Using the ``request_factory`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | .. note:: |
| | | |
| | | Using the ``request_factory`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor can be used to |
| | | achieve the same purpose. |
| | | """ |
| | | factory = self.maybe_dotted(factory) |
| | | def register(): |
| | |
| | | application. See :ref:`activating_translation` for more |
| | | information. |
| | | |
| | | .. note:: Using the ``locale_negotiator`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | .. note:: |
| | | |
| | | Using the ``locale_negotiator`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor can be used to |
| | | achieve the same purpose. |
| | | """ |
| | | negotiator = self.maybe_dotted(negotiator) |
| | | def register(): |
| | |
| | | |
| | | See also :ref:`setting_a_default_permission`. |
| | | |
| | | .. note:: Using the ``default_permission`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | .. note:: |
| | | |
| | | Using the ``default_permission`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor can be used to |
| | | achieve the same purpose. |
| | | """ |
| | | # default permission used during view registration |
| | | self.registry.registerUtility(permission, IDefaultPermission) |
| | |
| | | used by all subsequent :term:`view configuration` registrations, as |
| | | if you had passed a ``default_view_mapper`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor. |
| | | |
| | | |
| | | See also :ref:`using_a_view_mapper`. |
| | | """ |
| | | mapper = self.maybe_dotted(mapper) |
| | |
| | | this method is called, the ``session_factory`` argument must |
| | | be a session factory callable. |
| | | |
| | | .. note:: Using the ``session_factory`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | .. note:: |
| | | |
| | | Using the ``session_factory`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor can be used to |
| | | achieve the same purpose. |
| | | """ |
| | | def register(): |
| | | self.registry.registerUtility(session_factory, ISessionFactory) |
| | |
| | | # if this happens the predicate is probably a classmethod |
| | | if hasattr(predicate, '__func__'): |
| | | predicate.__func__.__text__ = text |
| | | else: # # pragma: no cover ; 2.5 doesn't have __func__ |
| | | else: # # pragma: no cover ; 2.5 doesn't have __func__ |
| | | predicate.im_func.__text__ = text |
| | | predicates.append(predicate) |
| | | # using hash() here rather than id() is intentional: we |
| | |
| | | def http_cached_view(self, view): |
| | | if self.registry.settings.get('prevent_http_cache', False): |
| | | return view |
| | | |
| | | |
| | | seconds = self.kw.get('http_cache') |
| | | |
| | | if seconds is None: |
| | |
| | | elif self.attr: |
| | | mapped_view = self.map_nonclass_attr(view) |
| | | return mapped_view |
| | | |
| | | |
| | | def map_class_requestonly(self, view): |
| | | # its a class that has an __init__ which only accepts request |
| | | attr = self.attr |
| | |
| | | For example: |
| | | |
| | | .. code-block:: python |
| | | |
| | | |
| | | from pyramid.events import NewRequest |
| | | from pyramid.events import subscriber |
| | | |
| | |
| | | |
| | | More than one event type can be passed as a construtor argument. The |
| | | decorated subscriber will be called for each event type. |
| | | |
| | | |
| | | .. code-block:: python |
| | | |
| | | |
| | | from pyramid.events import NewRequest, NewResponse |
| | | from pyramid.events import subscriber |
| | | |
| | |
| | | the function it decorates is called for every event sent: |
| | | |
| | | .. code-block:: python |
| | | |
| | | |
| | | from pyramid.events import subscriber |
| | | |
| | | @subscriber() |
| | |
| | | against the package or module which contains it, ala: |
| | | |
| | | .. code-block:: python |
| | | |
| | | |
| | | from pyramid.config import Configurator |
| | | config = Configurator() |
| | | config.scan('somepackage_containing_subscribers') |
| | |
| | | This class implements the |
| | | :class:`pyramid.interfaces.IContextFound` interface. |
| | | |
| | | .. note:: As of :app:`Pyramid` 1.0, for backwards compatibility |
| | | purposes, this event may also be imported as |
| | | :class:`pyramid.events.AfterTraversal`. |
| | | .. note:: |
| | | |
| | | As of :app:`Pyramid` 1.0, for backwards compatibility purposes, this |
| | | event may also be imported as :class:`pyramid.events.AfterTraversal`. |
| | | """ |
| | | implements(IContextFound) |
| | | def __init__(self, request): |
| | | self.request = request |
| | | |
| | | AfterTraversal = ContextFound # b/c as of 1.0 |
| | | |
| | | class ApplicationCreated(object): |
| | | |
| | | class ApplicationCreated(object): |
| | | """ An instance of this class is emitted as an :term:`event` when |
| | | the :meth:`pyramid.config.Configurator.make_wsgi_app` is |
| | | called. The instance has an attribute, ``app``, which is an |
| | |
| | | This class implements the |
| | | :class:`pyramid.interfaces.IApplicationCreated` interface. |
| | | |
| | | .. note:: For backwards compatibility purposes, this class can |
| | | also be imported as |
| | | :class:`pyramid.events.WSGIApplicationCreatedEvent`. This |
| | | was the name of the event class before :app:`Pyramid` 1.0. |
| | | .. note:: |
| | | |
| | | For backwards compatibility purposes, this class can also be imported as |
| | | :class:`pyramid.events.WSGIApplicationCreatedEvent`. This was the name |
| | | of the event class before :app:`Pyramid` 1.0. |
| | | |
| | | """ |
| | | implements(IApplicationCreated) |
| | |
| | | """ Return the value for key ``k`` from the renderer globals |
| | | dictionary, or the default if no such value exists.""" |
| | | return self._system.get(k) |
| | | |
| | | |
| | |
| | | documentation attached to :class:`pyramid.events.ContextFound` |
| | | for more information. |
| | | |
| | | .. note:: For backwards compatibility with versions of |
| | | :app:`Pyramid` before 1.0, this event interface can also be |
| | | imported as :class:`pyramid.interfaces.IAfterTraversal`. |
| | | .. note:: |
| | | |
| | | For backwards compatibility with versions of :app:`Pyramid` before 1.0, |
| | | this event interface can also be imported as |
| | | :class:`pyramid.interfaces.IAfterTraversal`. |
| | | """ |
| | | request = Attribute('The request object') |
| | | |
| | |
| | | begins to process a new request. See the documentation attached |
| | | to :class:`pyramid.events.NewRequest` for more information.""" |
| | | request = Attribute('The request object') |
| | | |
| | | |
| | | class INewResponse(Interface): |
| | | """ An event type that is emitted whenever any :app:`Pyramid` |
| | | view returns a response. See the |
| | |
| | | :class:`pyramid.events.ApplicationCreated` for more |
| | | information. |
| | | |
| | | .. note:: For backwards compatibility with :app:`Pyramid` |
| | | versions before 1.0, this interface can also be imported as |
| | | .. note:: |
| | | |
| | | For backwards compatibility with :app:`Pyramid` versions before 1.0, this |
| | | interface can also be imported as |
| | | :class:`pyramid.interfaces.IWSGIApplicationCreatedEvent`. |
| | | """ |
| | | app = Attribute(u"Created application") |
| | |
| | | otherwise they will be preserved.""") |
| | | |
| | | content_type_params = Attribute( |
| | | """A dictionary of all the parameters in the content type. This is |
| | | """A dictionary of all the parameters in the content type. This is |
| | | not a view, set to change, modifications of the dict would not |
| | | be applied otherwise.""") |
| | | |
| | |
| | | principal named ``principal`` when set in a response. An |
| | | individual authentication policy and its consumers can decide |
| | | on the composition and meaning of ``**kw.`` """ |
| | | |
| | | |
| | | def forget(request): |
| | | """ Return a set of headers suitable for 'forgetting' the |
| | | current user on subsequent requests. """ |
| | |
| | | """ Return ``True`` if any of the ``principals`` is allowed the |
| | | ``permission`` in the current ``context``, else return ``False`` |
| | | """ |
| | | |
| | | |
| | | def principals_allowed_by_permission(context, permission): |
| | | """ Return a set of principal identifiers allowed by the |
| | | ``permission`` in ``context``. This behavior is optional; if you |
| | |
| | | class IRequest(Interface): |
| | | """ Request type interface attached to all request objects """ |
| | | |
| | | IRequest.combined = IRequest # for exception view lookups |
| | | IRequest.combined = IRequest # for exception view lookups |
| | | |
| | | class IRouteRequest(Interface): |
| | | """ *internal only* interface used as in a utility lookup to find |
| | |
| | | a view registry.""" |
| | | registry = Attribute( |
| | | """Component architecture registry local to this application.""") |
| | | |
| | | |
| | | class ISettings(Interface): |
| | | """ Runtime settings utility for pyramid; represents the |
| | | deployment settings for the application. Implements a mapping |
| | | interface.""" |
| | | |
| | | |
| | | # this interface, even if it becomes unused within Pyramid, is |
| | | # imported by other packages (such as traversalwrapper) |
| | | class ILocation(Interface): |
| | |
| | | |
| | | class ILocalizer(Interface): |
| | | """ Localizer for a specific language """ |
| | | |
| | | |
| | | class ILocaleNegotiator(Interface): |
| | | def __call__(request): |
| | | """ Return a locale name """ |
| | |
| | | """ |
| | | |
| | | # mapping methods |
| | | |
| | | |
| | | def __getitem__(key): |
| | | """Get a value for a key |
| | | |
| | |
| | | |
| | | def clear(): |
| | | "delete all items" |
| | | |
| | | |
| | | def update(d): |
| | | " Update D from E: for k in E.keys(): D[k] = E[k]" |
| | | |
| | | |
| | | def setdefault(key, default=None): |
| | | " D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D " |
| | | |
| | | |
| | | def pop(k, *args): |
| | | """remove specified key and return the corresponding value |
| | | ``*args`` may contain a single default value, or may not be supplied. |
| | | If key is not found, default is returned if given, otherwise |
| | | If key is not found, default is returned if given, otherwise |
| | | ``KeyError`` is raised""" |
| | | |
| | | |
| | | def popitem(): |
| | | """remove and return some (key, value) pair as a |
| | | 2-tuple; but raise ``KeyError`` if mapping is empty""" |
| | |
| | | 'renderer was created') |
| | | settings = Attribute('The deployment settings dictionary related ' |
| | | 'to the current application') |
| | | |
| | | |
| | |
| | | and other code that is not normally invoked during active WSGI |
| | | requests. |
| | | |
| | | .. note:: For a complex config file containing multiple :app:`Pyramid` |
| | | applications, this function will setup the environment under |
| | | the context of the last-loaded :app:`Pyramid` application. You |
| | | may load a specific application yourself by using the |
| | | lower-level functions :meth:`pyramid.paster.get_app` and |
| | | :meth:`pyramid.scripting.prepare` in conjunction with |
| | | :attr:`pyramid.config.global_registries`. |
| | | .. note:: |
| | | |
| | | For a complex config file containing multiple :app:`Pyramid` |
| | | applications, this function will setup the environment under the context |
| | | of the last-loaded :app:`Pyramid` application. You may load a specific |
| | | application yourself by using the lower-level functions |
| | | :meth:`pyramid.paster.get_app` and :meth:`pyramid.scripting.prepare` in |
| | | conjunction with :attr:`pyramid.config.global_registries`. |
| | | |
| | | ``config_uri`` -- specifies the PasteDeploy config file to use for the |
| | | interactive shell. The format is ``inifile#name``. If the name is left |
| | |
| | | |
| | | def out(self, msg): # pragma: no cover |
| | | print msg |
| | | |
| | | |
| | | def command(self): |
| | | from pyramid.interfaces import IRouteRequest |
| | | from pyramid.interfaces import IViewClassifier |
| | |
| | | |
| | | def out(self, msg): # pragma: no cover |
| | | print msg |
| | | |
| | | |
| | | def _find_multi_routes(self, mapper, request): |
| | | infos = [] |
| | | path = request.environ['PATH_INFO'] |
| | |
| | | from pyramid.request import Request |
| | | from pyramid.traversal import DefaultRootFactory |
| | | from pyramid.traversal import ResourceTreeTraverser |
| | | |
| | | |
| | | q = registry.queryUtility |
| | | root_factory = q(IRootFactory, default=DefaultRootFactory) |
| | | routes_mapper = q(IRoutesMapper) |
| | |
| | | :mod:`pyramid.security.Everyone` (the special principal |
| | | identifier representing all principals). |
| | | |
| | | .. note:: even if an :term:`authorization policy` is in effect, |
| | | some (exotic) authorization policies may not implement the |
| | | required machinery for this function; those will cause a |
| | | :exc:`NotImplementedError` exception to be raised when this |
| | | function is invoked. |
| | | .. note:: |
| | | |
| | | even if an :term:`authorization policy` is in effect, some (exotic) |
| | | authorization policies may not implement the required machinery for this |
| | | function; those will cause a :exc:`NotImplementedError` exception to be |
| | | raised when this function is invoked. |
| | | """ |
| | | reg = get_current_registry() |
| | | policy = reg.queryUtility(IAuthorizationPolicy) |
| | |
| | | return [] |
| | | else: |
| | | return policy.forget(request) |
| | | |
| | | |
| | | class PermitsResult(int): |
| | | def __new__(cls, s, *args): |
| | | inst = int.__new__(cls, cls.boolval) |
| | | inst.s = s |
| | | inst.args = args |
| | | return inst |
| | | |
| | | |
| | | @property |
| | | def msg(self): |
| | | return self.s % self.args |
| | |
| | | cache_max_age=self.cache_max_age)(environ, start_response) |
| | | pi = environ.get('PATH_INFO') |
| | | if pi and pi != '/': |
| | | return self.error_extra_path(environ, start_response) |
| | | return self.error_extra_path(environ, start_response) |
| | | full = pkg_resources.resource_filename(self.package_name, resource) |
| | | if_none_match = environ.get('HTTP_IF_NONE_MATCH') |
| | | if if_none_match: |
| | |
| | | |
| | | attr = extra.pop('view_attr', None) |
| | | |
| | | # register a route using the computed view, permission, and |
| | | # register a route using the computed view, permission, and |
| | | # pattern, plus any extras passed to us via add_static_view |
| | | pattern = "%s*subpath" % name # name already ends with slash |
| | | self.config.add_route(name, pattern, **extra) |
| | |
| | | the static application will consider request.path_info as ``PATH_INFO`` |
| | | input. By default, this is ``False``. |
| | | |
| | | .. note:: If the ``root_dir`` is relative to a :term:`package`, or |
| | | is a :term:`asset specification` the :app:`Pyramid` |
| | | :class:`pyramid.config.Configurator` method can be |
| | | used to override assets within the named ``root_dir`` |
| | | package-relative directory. However, if the ``root_dir`` is |
| | | absolute, configuration will not be able to |
| | | override the assets it contains. """ |
| | | |
| | | .. note:: |
| | | |
| | | If the ``root_dir`` is relative to a :term:`package`, or is a |
| | | :term:`asset specification` the :app:`Pyramid` |
| | | :class:`pyramid.config.Configurator` method can be used to override |
| | | assets within the named ``root_dir`` package-relative directory. |
| | | However, if the ``root_dir`` is absolute, configuration will not be able |
| | | to override the assets it contains. """ |
| | | |
| | | def __init__(self, root_dir, cache_max_age=3600, package_name=None, |
| | | use_subpath=False): |
| | | # package_name is for bw compat; it is preferred to pass in a |
| | |
| | | |
| | | The ``resource`` passed in *must* be :term:`location`-aware. |
| | | |
| | | .. note:: Each segment in the path string returned will use the |
| | | ``__name__`` attribute of the resource it represents within |
| | | the resource tree. Each of these segments *should* be a unicode |
| | | or string object (as per the contract of |
| | | :term:`location`-awareness). However, no conversion or |
| | | safety checking of resource names is performed. For |
| | | instance, if one of the resources in your tree has a |
| | | ``__name__`` which (by error) is a dictionary, the |
| | | :func:`pyramid.traversal.resource_path` function will |
| | | attempt to append it to a string and it will cause a |
| | | :exc:`pyramid.exceptions.URLDecodeError`. |
| | | .. note:: |
| | | |
| | | Each segment in the path string returned will use the ``__name__`` |
| | | attribute of the resource it represents within the resource tree. Each |
| | | of these segments *should* be a unicode or string object (as per the |
| | | contract of :term:`location`-awareness). However, no conversion or |
| | | safety checking of resource names is performed. For instance, if one of |
| | | the resources in your tree has a ``__name__`` which (by error) is a |
| | | dictionary, the :func:`pyramid.traversal.resource_path` function will |
| | | attempt to append it to a string and it will cause a |
| | | :exc:`pyramid.exceptions.URLDecodeError`. |
| | | |
| | | .. note:: The :term:`root` resource *must* have a ``__name__`` |
| | | attribute with a value of either ``None`` or the empty |
| | |
| | | resource = find_root(resource) |
| | | |
| | | reg = get_current_registry() |
| | | |
| | | |
| | | request_factory = reg.queryUtility(IRequestFactory) |
| | | if request_factory is None: |
| | | from pyramid.request import Request # avoid circdep |
| | |
| | | |
| | | The ``resource`` passed in *must* be :term:`location`-aware. |
| | | |
| | | .. note:: Each segment in the path tuple returned will equal the |
| | | ``__name__`` attribute of the resource it represents within |
| | | the resource tree. Each of these segments *should* be a unicode |
| | | or string object (as per the contract of |
| | | :term:`location`-awareness). However, no conversion or |
| | | safety checking of resource names is performed. For |
| | | instance, if one of the resources in your tree has a |
| | | ``__name__`` which (by error) is a dictionary, that |
| | | dictionary will be placed in the path tuple; no warning |
| | | or error will be given. |
| | | .. note:: |
| | | |
| | | Each segment in the path tuple returned will equal the ``__name__`` |
| | | attribute of the resource it represents within the resource tree. Each |
| | | of these segments *should* be a unicode or string object (as per the |
| | | contract of :term:`location`-awareness). However, no conversion or |
| | | safety checking of resource names is performed. For instance, if one of |
| | | the resources in your tree has a ``__name__`` which (by error) is a |
| | | dictionary, that dictionary will be placed in the path tuple; no warning |
| | | or error will be given. |
| | | |
| | | .. note:: The :term:`root` resource *must* have a ``__name__`` |
| | | attribute with a value of either ``None`` or the empty |
| | |
| | | |
| | | (u'archives', u'<unprintable unicode>') |
| | | |
| | | .. note:: This function does not generate the same type of tuples |
| | | that :func:`pyramid.traversal.resource_path_tuple` does. |
| | | In particular, the leading empty string is not present |
| | | in the tuple it returns, unlike tuples returned by |
| | | :func:`pyramid.traversal.resource_path_tuple`. As a |
| | | result, tuples generated by ``traversal_path`` are not |
| | | resolveable by the |
| | | :func:`pyramid.traversal.find_resource` API. |
| | | ``traversal_path`` is a function mostly used by the |
| | | internals of :app:`Pyramid` and by people writing |
| | | their own traversal machinery, as opposed to users |
| | | writing applications in :app:`Pyramid`. |
| | | .. note:: |
| | | |
| | | This function does not generate the same type of tuples that |
| | | :func:`pyramid.traversal.resource_path_tuple` does. In particular, the |
| | | leading empty string is not present in the tuple it returns, unlike |
| | | tuples returned by :func:`pyramid.traversal.resource_path_tuple`. As a |
| | | result, tuples generated by ``traversal_path`` are not resolveable by the |
| | | :func:`pyramid.traversal.find_resource` API. ``traversal_path`` is a |
| | | function mostly used by the internals of :app:`Pyramid` and by people |
| | | writing their own traversal machinery, as opposed to users writing |
| | | applications in :app:`Pyramid`. |
| | | """ |
| | | if isinstance(path, unicode): |
| | | path = path.encode('ascii') |
| | |
| | | data is turned into a query string, a leading ``?`` is prepended, |
| | | and the resulting string is appended to the generated URL. |
| | | |
| | | .. note:: Python data structures that are passed as ``_query`` |
| | | which are sequences or dictionaries are turned into a |
| | | string under the same rules as when run through |
| | | :func:`urllib.urlencode` with the ``doseq`` argument |
| | | equal to ``True``. This means that sequences can be |
| | | passed as values, and a k=v pair will be placed into the |
| | | query string for each value. |
| | | .. note:: |
| | | |
| | | Python data structures that are passed as ``_query`` which are sequences |
| | | or dictionaries are turned into a string under the same rules as when run |
| | | through :func:`urllib.urlencode` with the ``doseq`` argument equal to |
| | | ``True``. This means that sequences can be passed as values, and a k=v |
| | | pair will be placed into the query string for each value. |
| | | |
| | | If a keyword argument ``_anchor`` is present, its string |
| | | representation will be used as a named anchor in the generated URL |
| | |
| | | turned into a query string, a leading ``?`` is prepended, and the |
| | | resulting string is appended to the generated URL. |
| | | |
| | | .. note:: Python data structures that are passed as ``query`` |
| | | which are sequences or dictionaries are turned into a |
| | | string under the same rules as when run through |
| | | :func:`urllib.urlencode` with the ``doseq`` argument |
| | | equal to ``True``. This means that sequences can be |
| | | passed as values, and a k=v pair will be placed into the |
| | | query string for each value. |
| | | .. note:: |
| | | |
| | | Python data structures that are passed as ``query`` which are sequences |
| | | or dictionaries are turned into a string under the same rules as when run |
| | | through :func:`urllib.urlencode` with the ``doseq`` argument equal to |
| | | ``True``. This means that sequences can be passed as values, and a k=v |
| | | pair will be placed into the query string for each value. |
| | | |
| | | If a keyword argument ``anchor`` is present, its string |
| | | representation will be used as a named anchor in the generated URL |
| | |
| | | resource which is operated upon by this function. See also |
| | | :ref:`overriding_resource_url_generation`. |
| | | |
| | | .. note:: If the :term:`resource` used is the result of a |
| | | :term:`traversal`, it must be :term:`location`-aware. |
| | | The resource can also be the context of a :term:`URL |
| | | dispatch`; contexts found this way do not need to be |
| | | location-aware. |
| | | .. note:: |
| | | |
| | | .. note:: If a 'virtual root path' is present in the request |
| | | environment (the value of the WSGI environ key |
| | | ``HTTP_X_VHM_ROOT``), and the resource was obtained via |
| | | :term:`traversal`, the URL path will not include the |
| | | virtual root prefix (it will be stripped off the |
| | | left hand side of the generated URL). |
| | | If the :term:`resource` used is the result of a :term:`traversal`, it |
| | | must be :term:`location`-aware. The resource can also be the context of |
| | | a :term:`URL dispatch`; contexts found this way do not need to be |
| | | location-aware. |
| | | |
| | | .. note:: |
| | | |
| | | If a 'virtual root path' is present in the request environment (the value |
| | | of the WSGI environ key ``HTTP_X_VHM_ROOT``), and the resource was |
| | | obtained via :term:`traversal`, the URL path will not include the virtual |
| | | root prefix (it will be stripped off the left hand side of the generated |
| | | URL). |
| | | |
| | | .. note:: For backwards compatibility purposes, this function can also be |
| | | imported as ``model_url``, although doing so will emit a deprecation |
| | |
| | | reg = request.registry |
| | | except AttributeError: |
| | | reg = get_current_registry() # b/c |
| | | |
| | | |
| | | context_url = reg.queryMultiAdapter((resource, request), IContextURL) |
| | | if context_url is None: |
| | | context_url = TraversalContextURL(resource, request) |
| | |
| | | reg = request.registry |
| | | except AttributeError: |
| | | reg = get_current_registry() # b/c |
| | | |
| | | |
| | | info = reg.queryUtility(IStaticURLInfo) |
| | | if info is None: |
| | | raise ValueError('No static URL definition matching %s' % path) |
| | | |
| | | |
| | | return info.generate(path, request, **kw) |
| | | |
| | | def current_route_url(request, *elements, **kw): |
| | | """Generates a fully qualified URL for a named :app:`Pyramid` |
| | | :term:`route configuration` based on the 'current route'. |
| | | |
| | | |
| | | This function supplements :func:`pyramid.url.route_url`. It presents an |
| | | easy way to generate a URL for the 'current route' (defined as the route |
| | | which matched when the request was generated). |
| | |
| | | current url path is ``/foo/1``, the matchdict will be |
| | | ``{'page':'1'}``. The result of ``current_route_url(request, page='2')`` |
| | | in this situation will be ``/foo/2``. |
| | | |
| | | |
| | | Usage of the ``_route_name`` keyword argument: if our routing table |
| | | defines routes ``/foo/{action}`` named 'foo' and ``/foo/{action}/{page}`` |
| | | named ``fooaction``, and the current url pattern is ``/foo/view`` (which |
| | |
| | | |
| | | _marker = object() |
| | | |
| | | class static(static_view): |
| | | class static(static_view): |
| | | """ Backwards compatibility alias for |
| | | :class:`pyramid.static.static_view`; it overrides that class' constructor |
| | | to pass ``use_subpath=True`` by default. This class is deprecated as of |
| | |
| | | """ Return ``True`` if ``ob`` implements the interface implied by |
| | | :ref:`the_response`. ``False`` if not. |
| | | |
| | | .. warning:: This function is deprecated as of :app:`Pyramid` 1.1. New |
| | | code should not use it. Instead, new code should use the |
| | | .. warning:: |
| | | |
| | | This function is deprecated as of :app:`Pyramid` 1.1. New code should |
| | | not use it. Instead, new code should use the |
| | | :func:`pyramid.request.Request.is_response` method.""" |
| | | if ( hasattr(ob, 'app_iter') and hasattr(ob, 'headerlist') and |
| | | hasattr(ob, 'status') ): |