Merge pull request #285 from michr/012b9762
fix up all the ..note and ..warnings.
| | |
| | | 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 |
| | |
| | | * :ref:`glossary` |
| | | * :ref:`genindex` |
| | | * :ref:`search` |
| | | |
| | | |
| | | .. add glossary in hidden toc tree so it does not complain its not included |
| | | |
| | | .. toctree:: |
| | | :hidden: |
| | | |
| | | glossary |
| | | |
| | |
| | | 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 |
| | | .. 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`. |
| | |
| | | :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 |
| | |
| | | def notfound_view(request): |
| | | return HTTPNotFound() |
| | | |
| | | .. note:: When a NotFound view callable is invoked, it is passed a |
| | | .. 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 |
| | |
| | | ``pyramid.debug_notfound`` environment setting is true than it is when it |
| | | is false. |
| | | |
| | | .. warning:: When a NotFound view callable accepts an argument list as |
| | | .. 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 |
| | |
| | | def forbidden_view(request): |
| | | return Response('forbidden') |
| | | |
| | | .. note:: When a forbidden view callable is invoked, it is passed a |
| | | .. 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 |
| | |
| | | declared directly "below" it, ad infinitum. The "main" Pyramid request |
| | | handler is implicit, and always "at the bottom". |
| | | |
| | | .. note:: Pyramid's own :term:`exception view` handling logic is implemented |
| | | .. note:: |
| | | |
| | | Pyramid's own :term:`exception view` handling logic is implemented |
| | | as a tween factory function: :func:`pyramid.tweens.excview_tween_factory`. |
| | | If Pyramid exception view handling is desired, and tween factories are |
| | | specified via the ``pyramid.tweens`` configuration setting, the |
| | |
| | | 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`. |
| | | |
| | |
| | | New python executable in env/bin/python |
| | | Installing setuptools.............done. |
| | | |
| | | .. warning:: Using ``--no-site-packages`` when generating your |
| | | .. 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``, |
| | |
| | | :mod:`logging` module. This chapter describes how to configure logging and |
| | | how to send log messages to loggers that you've configured. |
| | | |
| | | .. warning:: This chapter assumes you've used a :term:`scaffold` to create a |
| | | .. warning:: |
| | | |
| | | This chapter assumes you've used a :term:`scaffold` to create a |
| | | project which contains ``development.ini`` and ``production.ini`` files |
| | | which help configure logging. All of the scaffolds which ship along with |
| | | :app:`Pyramid` do this. If you're not using a scaffold, or if you've used |
| | |
| | | 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` |
| | | .. 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 |
| | |
| | | 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 |
| | | .. warning:: |
| | | |
| | | If your root resource has a ``__name__`` argument that is not |
| | | ``None`` or the empty string, URLs returned by the |
| | | :func:`~pyramid.request.Request.resource_url` function and paths generated |
| | | by the :func:`~pyramid.traversal.resource_path` and |
| | |
| | | {'foo':1, 'bar':2}, |
| | | request=request) |
| | | |
| | | .. warning:: Earlier iterations of this documentation |
| | | .. 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 |
| | |
| | | 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. |
| | |
| | | exception to this rule is use of the ``pregenerator`` argument, which is not |
| | | ignored when ``static`` is ``True``. |
| | | |
| | | .. note:: the ``static`` argument to |
| | | .. note:: |
| | | |
| | | the ``static`` argument to |
| | | :meth:`~pyramid.config.Configurator.add_route` is new as of :app:`Pyramid` |
| | | 1.1. |
| | | |
| | |
| | | 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 |
| | | .. note:: |
| | | |
| | | See :ref:`security_chapter` for more information about |
| | | :app:`Pyramid` security and ACLs. |
| | | |
| | | .. index:: |
| | |
| | | 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 |
| | | .. 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 |
| | |
| | | .. literalinclude:: src/views/tutorial/templates/view.pt |
| | | :language: xml |
| | | |
| | | .. note:: The names available for our use in a template are always those that |
| | | .. 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". |
| | |
| | | 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 |
| | | .. 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 |
| | |
| | | package-relative path, an absolute path, or a :term:`asset |
| | | specification`. |
| | | |
| | | .. 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.get_renderer` instead. |
| | | """ |
| | | package = caller_package() |
| | |
| | | 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 |
| | | .. 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. |
| | | """ |
| | |
| | | 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() |
| | |
| | | package-relative path, an absolute path, or a :term:`asset |
| | | specification`. |
| | | |
| | | .. 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.get_renderer` instead. |
| | | """ |
| | | package = caller_package() |
| | |
| | | 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 |
| | | .. 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. |
| | | """ |
| | |
| | | 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() |
| | |
| | | same. 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 |
| | |
| | | |
| | | if debug_logger is None: |
| | | debug_logger = logging.getLogger(self.package_name) |
| | | |
| | | |
| | | registry.registerUtility(debug_logger, IDebugLogger) |
| | | |
| | | for name, renderer in DEFAULT_RENDERERS: |
| | |
| | | tweens = aslist(registry.settings.get('pyramid.tweens', [])) |
| | | for factory in tweens: |
| | | self._add_tween(factory, explicit=True) |
| | | |
| | | |
| | | includes = aslist(registry.settings.get('pyramid.includes', [])) |
| | | for inc in includes: |
| | | self.include(inc) |
| | |
| | | ``route_prefix``. This can be used to help mount a set of routes at a |
| | | different location than the included callable's author intended while |
| | | still maintaining the same route names. For example: |
| | | |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | |
| | |
| | | |
| | | def included(config): |
| | | config.add_route('show_users', '/show') |
| | | |
| | | |
| | | def main(global_config, **settings): |
| | | config = Configurator() |
| | | config.include(included, route_prefix='/users') |
| | |
| | | configurator.basepath = os.path.dirname(sourcefile) |
| | | configurator.includepath = self.includepath + (spec,) |
| | | c(configurator) |
| | | |
| | | |
| | | def add_directive(self, name, directive, action_wrap=True): |
| | | """ |
| | | Add a directive method to the configurator. |
| | |
| | | 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. |
| | | """ |
| | |
| | | state. If the ``factory`` argument is ``None`` a default root |
| | | factory will be registered. |
| | | |
| | | .. note:: Using the ``root_factory`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | .. note:: |
| | | |
| | | Using the ``root_factory`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor can be used to |
| | | achieve the same purpose. |
| | | """ |
| | | factory = self.maybe_dotted(factory) |
| | | if factory is None: |
| | |
| | | method is called, the ``session_factory`` argument must be a session |
| | | factory callable or a :term:`dotted Python name` to that factory. |
| | | |
| | | .. 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. |
| | | """ |
| | | session_factory = self.maybe_dotted(session_factory) |
| | | def register(): |
| | |
| | | :class:`pyramid.request.Request` class (particularly |
| | | ``__call__``, and ``blank``). |
| | | |
| | | .. note:: Using the ``request_factory`` argument to the |
| | | .. note:: |
| | | |
| | | Using the ``request_factory`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | """ |
| | |
| | | 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. |
| | | """ |
| | | def register(): |
| | | self._set_locale_negotiator(negotiator) |
| | |
| | | # 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 = '' |
| | | def register(): |
| | | self.registry.registerUtility(factory, IRendererFactory, name=name) |
| | |
| | | dictionary, and therefore will be made available to the code |
| | | which uses the renderer. |
| | | |
| | | .. warning:: This method is deprecated as of Pyramid 1.1. |
| | | .. warning:: |
| | | |
| | | .. note:: Using the ``renderer_globals_factory`` argument |
| | | This method is deprecated as of Pyramid 1.1. |
| | | |
| | | .. note:: |
| | | |
| | | Using the ``renderer_globals_factory`` argument |
| | | to the :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | """ |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | of an authentication policy or a :term:`dotted Python name` |
| | | that points at an instance of an authentication policy. |
| | | |
| | | .. note:: Using the ``authentication_policy`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | |
| | | .. note:: |
| | | |
| | | Using the ``authentication_policy`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor can be used to |
| | | achieve the same purpose. |
| | | |
| | | """ |
| | | def register(): |
| | | self._set_authentication_policy(policy) |
| | |
| | | of an authorization policy or a :term:`dotted Python name` that points |
| | | at an instance of an authorization policy. |
| | | |
| | | .. note:: Using the ``authorization_policy`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | .. note:: |
| | | |
| | | Using the ``authorization_policy`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor can be used to |
| | | achieve the same purpose. |
| | | """ |
| | | def register(): |
| | | self._set_authorization_policy(policy) |
| | |
| | | 'Cannot configure an authorization policy without ' |
| | | 'also configuring an authentication policy ' |
| | | '(use the set_authorization_policy method)') |
| | | |
| | | |
| | | # authorization policy used by view config (phase 3) and |
| | | # authentication policy (phase 2) |
| | | self.action(IAuthorizationPolicy, register, order=PHASE1_CONFIG) |
| | |
| | | |
| | | 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 (phase 3) |
| | | def register(): |
| | |
| | | val = (val,) |
| | | val = tuple(sorted(val)) |
| | | return val |
| | | |
| | | |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | discriminator.extend(sorted(custom_predicates)) |
| | | discriminator = tuple(discriminator) |
| | | self.action(discriminator, register) |
| | | |
| | | |
| | | def derive_view(self, view, attr=None, renderer=None): |
| | | """ |
| | | Create a :term:`view callable` using the function, instance, |
| | | or class (or :term:`dotted Python name` referring to the same) |
| | | provided as ``view`` object. |
| | | |
| | | .. warning:: This method is typically only used by :app:`Pyramid` |
| | | framework extension authors, not by :app:`Pyramid` application |
| | | developers. |
| | | .. warning:: |
| | | |
| | | This method is typically only used by :app:`Pyramid` framework |
| | | extension authors, not by :app:`Pyramid` application developers. |
| | | |
| | | This is API is useful to framework extenders who create |
| | | pluggable systems which need to register 'proxy' view |
| | |
| | | mapper=mapper, |
| | | decorator=decorator, |
| | | http_cache=http_cache) |
| | | |
| | | |
| | | return deriver(view) |
| | | |
| | | @action_method |
| | |
| | | """ 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. |
| | |
| | | |
| | | See also :ref:`using_a_view_mapper`. |
| | | |
| | | .. note:: Using the ``default_view_mapper`` argument to the |
| | | .. note:: |
| | | |
| | | Using the ``default_view_mapper`` argument to the |
| | | :class:`pyramid.config.Configurator` constructor |
| | | can be used to achieve the same purpose. |
| | | """ |
| | |
| | | |
| | | 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 |
| | | if config.route_prefix: |
| | |
| | | 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) |
| | | def __init__(self, app): |
| | |
| | | documentation attached to :class:`pyramid.events.ContextFound` |
| | | for more information. |
| | | |
| | | .. note:: For backwards compatibility with versions of |
| | | .. note:: |
| | | |
| | | For backwards compatibility with versions of |
| | | :app:`Pyramid` before 1.0, this event interface can also be |
| | | imported as :class:`pyramid.interfaces.IAfterTraversal`. |
| | | """ |
| | |
| | | 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` |
| | | .. note:: |
| | | |
| | | For backwards compatibility with :app:`Pyramid` |
| | | versions before 1.0, this interface can also be imported as |
| | | :class:`pyramid.interfaces.IWSGIApplicationCreatedEvent`. |
| | | """ |
| | |
| | | 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.""") |
| | | |
| | |
| | | |
| | | def __setitem__(k, value): |
| | | """ Set a key/value pair into the dictionary""" |
| | | |
| | | |
| | | def __delitem__(k): |
| | | """ Delete an item from the dictionary which is passed to the |
| | | renderer as the renderer globals dictionary.""" |
| | | |
| | | |
| | | def __getitem__(k): |
| | | """ Return the value for key ``k`` from the dictionary or raise a |
| | | KeyError if the key doesn't exist""" |
| | | |
| | | def __iter__(): |
| | | """ Return an iterator over the keys of this dictionary """ |
| | | |
| | | |
| | | def get(k, default=None): |
| | | """ Return the value for key ``k`` from the renderer dictionary, or |
| | | the default if no such value exists.""" |
| | |
| | | value into the dictionary under the k name passed. If a value already |
| | | existed in the dictionary, return it. If a value did not exist in |
| | | the dictionary, return the default""" |
| | | |
| | | |
| | | def update(d): |
| | | """ Update the renderer dictionary with another dictionary ``d``.""" |
| | | |
| | |
| | | The event object itself provides a dictionary-like interface for adding |
| | | and removing :term:`renderer globals`. The keys and values of the |
| | | dictionary are those globals. For example:: |
| | | |
| | | |
| | | from repoze.events import subscriber |
| | | from pyramid.interfaces import IBeforeRender |
| | | |
| | |
| | | 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 |
| | |
| | | The ``request`` argument will be an instance of an object that |
| | | provides IRequest.""" |
| | | |
| | | 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 """ |
| | |
| | | that may be called when your script is complete (it pops a threadlocal |
| | | stack). |
| | | |
| | | .. note:: Most operations within :app:`Pyramid` expect to be invoked |
| | | within the context of a WSGI request, thus it's important when |
| | | loading your application to anchor it when executing scripts |
| | | and other code that is not normally invoked during active WSGI |
| | | requests. |
| | | .. note:: |
| | | |
| | | .. 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`. |
| | | Most operations within :app:`Pyramid` expect to be invoked within the |
| | | context of a WSGI request, thus it's important when loading your |
| | | application to anchor it when executing scripts 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`. |
| | | |
| | | ``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) |
| | |
| | | using an explicit tweens ordering (will be true when the |
| | | ``pyramid.tweens`` setting is used) or an implicit tweens ordering (will |
| | | be true when the ``pyramid.tweens`` setting is *not* used). |
| | | |
| | | |
| | | This command accepts one positional argument: |
| | | |
| | | ``config_uri`` -- specifies the PasteDeploy config file to use for the |
| | |
| | | if new_path_info != '/': # don't want a sole double-slash |
| | | if path_info != '/': # if orig path_info is '/', we're already done |
| | | if path_info.endswith('/'): |
| | | # readd trailing slash stripped by subpath (traversal) |
| | | # readd trailing slash stripped by subpath (traversal) |
| | | # conversion |
| | | new_path_info += '/' |
| | | |
| | |
| | | # to end of script_name |
| | | while workback and (workback[-1] == ''): |
| | | workback = workback[:-1] |
| | | |
| | | |
| | | new_script_name = '/'.join(workback) |
| | | |
| | | new_request = request.copy() |
| | |
| | | :mod:`pyramid.security.Everyone` (the special principal |
| | | identifier representing all principals). |
| | | |
| | | .. note:: even if an :term:`authorization policy` is in effect, |
| | | .. 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 |
| | |
| | | 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 |
| | |
| | | content_length = getsize(path) |
| | | self.app_iter = _FileIter(open(path, 'rb'), content_length) |
| | | # assignment of content_length must come after assignment of app_iter |
| | | self.content_length = content_length |
| | | self.content_length = content_length |
| | | if cache_max_age is not None: |
| | | self.cache_expires = cache_max_age |
| | | |
| | |
| | | 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, index='index.html'): |
| | |
| | | |
| | | 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:: |
| | | |
| | | .. note:: The :term:`root` resource *must* have a ``__name__`` |
| | | attribute with a value of either ``None`` or the empty |
| | | string for paths to be generated properly. If the root |
| | | resource has a non-null ``__name__`` attribute, its name |
| | | will be prepended to the generated path rather than a |
| | | single leading '/' character. |
| | | 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:: For backwards compatibility purposes, this function can also |
| | | .. note:: |
| | | |
| | | The :term:`root` resource *must* have a ``__name__`` attribute with a |
| | | value of either ``None`` or the empty string for paths to be generated |
| | | properly. If the root resource has a non-null ``__name__`` attribute, |
| | | its name will be prepended to the generated path rather than a single |
| | | leading '/' character. |
| | | |
| | | .. note:: |
| | | |
| | | For backwards compatibility purposes, this function can also |
| | | be imported as ``model_path``, although doing so will cause |
| | | a deprecation warning to be emitted. |
| | | """ |
| | |
| | | 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:: |
| | | |
| | | .. note:: The :term:`root` resource *must* have a ``__name__`` |
| | | attribute with a value of either ``None`` or the empty |
| | | string for path tuples to be generated properly. If |
| | | the root resource has a non-null ``__name__`` attribute, |
| | | its name will be the first element in the generated |
| | | path tuple rather than the empty string. |
| | | 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:: For backwards compatibility purposes, this function can also be |
| | | imported as ``model_path_tuple``, although doing so will cause a |
| | | deprecation warning to be emitted. |
| | | .. note:: |
| | | |
| | | The :term:`root` resource *must* have a ``__name__`` attribute with a |
| | | value of either ``None`` or the empty string for path tuples to be |
| | | generated properly. If the root resource has a non-null ``__name__`` |
| | | attribute, its name will be the first element in the generated path tuple |
| | | rather than the empty string. |
| | | |
| | | .. note:: |
| | | |
| | | For backwards compatibility purposes, this function can also be imported |
| | | as ``model_path_tuple``, although doing so will cause a deprecation |
| | | warning to be emitted. |
| | | """ |
| | | return tuple(_resource_path_list(resource, *elements)) |
| | | |
| | |
| | | |
| | | (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 |
| | |
| | | ``http://example.com/route/url``, the resulting generated URL will |
| | | be ``http://example.com/route/url#foo``). |
| | | |
| | | .. note:: If ``_anchor`` is passed as a string, it should be UTF-8 |
| | | encoded. If ``_anchor`` is passed as a Unicode object, it |
| | | will be converted to UTF-8 before being appended to the |
| | | URL. The anchor value is not quoted in any way before |
| | | being appended to the generated URL. |
| | | .. note:: |
| | | |
| | | If ``_anchor`` is passed as a string, it should be UTF-8 encoded. If |
| | | ``_anchor`` is passed as a Unicode object, it will be converted to |
| | | UTF-8 before being appended to the URL. The anchor value is not |
| | | quoted in any way before being appended to the generated URL. |
| | | |
| | | If both ``_anchor`` and ``_query`` are specified, the anchor |
| | | element will always follow the query element, |
| | |
| | | |
| | | Will return the string ``/1/2``. |
| | | |
| | | .. note:: Calling ``request.route_path('route')`` is the same as |
| | | calling ``request.route_url('route', |
| | | _app_url=request.script_name)``. |
| | | :meth:`pyramid.request.Request.route_path` is, in fact, |
| | | implemented in terms of `:meth:`pyramid.request.Request.route_url` |
| | | in just this way. As a result, any ``_app_url`` passed within the |
| | | ``**kw`` values to ``route_path`` will be ignored. |
| | | .. note:: |
| | | |
| | | Calling ``request.route_path('route')`` is the same as calling |
| | | ``request.route_url('route', _app_url=request.script_name)``. |
| | | :meth:`pyramid.request.Request.route_path` is, in fact, implemented |
| | | in terms of `:meth:`pyramid.request.Request.route_url` in just this |
| | | way. As a result, any ``_app_url`` passed within the ``**kw`` values |
| | | to ``route_path`` will be ignored. |
| | | """ |
| | | kw['_app_url'] = self.script_name |
| | | return self.route_url(route_name, *elements, **kw) |
| | |
| | | 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 |
| | |
| | | ``http://example.com/resource/url``, the resulting generated URL will |
| | | be ``http://example.com/resource/url#foo``). |
| | | |
| | | .. note:: If ``anchor`` is passed as a string, it should be UTF-8 |
| | | encoded. If ``anchor`` is passed as a Unicode object, it |
| | | will be converted to UTF-8 before being appended to the |
| | | URL. The anchor value is not quoted in any way before |
| | | being appended to the generated URL. |
| | | .. note:: |
| | | |
| | | If ``anchor`` is passed as a string, it should be UTF-8 encoded. If |
| | | ``anchor`` is passed as a Unicode object, it will be converted to |
| | | UTF-8 before being appended to the URL. The anchor value is not |
| | | quoted in any way before being appended to the generated URL. |
| | | |
| | | If both ``anchor`` and ``query`` are specified, the anchor element |
| | | will always follow the query element, |
| | |
| | | the base 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:: For backwards compatibility purposes, this method is also |
| | | .. 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 method is also |
| | | aliased as the ``model_url`` method of request. |
| | | """ |
| | | try: |
| | |
| | | suffix = '' |
| | | |
| | | return resource_url + suffix + qs + anchor |
| | | |
| | | |
| | | model_url = resource_url # b/w compat forever |
| | | |
| | | def static_url(self, path, **kw): |
| | |
| | | |
| | | /static/foo.css |
| | | |
| | | .. note:: Calling ``request.static_path(apath)`` is the same |
| | | as calling ``request.static_url(apath, |
| | | _app_url=request.script_name)``. |
| | | :meth:`pyramid.request.Request.static_path` is, in fact, |
| | | implemented in terms of |
| | | `:meth:`pyramid.request.Request.static_url` in just this |
| | | way. As a result, any ``_app_url`` passed within the ``**kw`` |
| | | values to ``static_path`` will be ignored. |
| | | .. note:: |
| | | |
| | | Calling ``request.static_path(apath)`` is the same as calling |
| | | ``request.static_url(apath, _app_url=request.script_name)``. |
| | | :meth:`pyramid.request.Request.static_path` is, in fact, implemented |
| | | in terms of `:meth:`pyramid.request.Request.static_url` in just this |
| | | way. As a result, any ``_app_url`` passed within the ``**kw`` values |
| | | to ``static_path`` will be ignored. |
| | | """ |
| | | if not os.path.isabs(path): |
| | | if not ':' in path: |
| | |
| | | |
| | | Will return the string ``/1/2``. |
| | | |
| | | .. note:: Calling ``request.current_route_path('route')`` is the same |
| | | .. note:: |
| | | |
| | | Calling ``request.current_route_path('route')`` is the same |
| | | as calling ``request.current_route_url('route', |
| | | _app_url=request.script_name)``. |
| | | :meth:`pyramid.request.Request.current_route_path` is, in fact, |
| | |
| | | """ |
| | | kw['_app_url'] = self.script_name |
| | | return self.current_route_url(*elements, **kw) |
| | | |
| | | |
| | | |
| | | |
| | | def route_url(route_name, request, *elements, **kw): |
| | | """ |
| | | This is a backwards compatibility function. Its result is the same as |
| | |
| | | |
| | | _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 |
| | | .. 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 |