Skip to content

Commit

Permalink
Merge branch 'master' into feature.re-entrant-config
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerickel committed Feb 6, 2015
2 parents d35a916 + 4b13e0d commit b63f0c5
Show file tree
Hide file tree
Showing 43 changed files with 1,298 additions and 224 deletions.
33 changes: 33 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ Features
via ``request.static_url('myapp:static/foo.png')``.
See https://github.com/Pylons/pyramid/issues/1252

- Added ``pyramid.config.Configurator.set_response_factory`` and the
``response_factory`` keyword argument to the ``Configurator`` for defining
a factory that will return a custom ``Response`` class.
See https://github.com/Pylons/pyramid/pull/1499

- Allow an iterator to be returned from a renderer. Previously it was only
possible to return bytes or unicode.
See https://github.com/Pylons/pyramid/pull/1417

- ``pserve`` can now take a ``-b`` or ``--browser`` option to open the server
URL in a web browser. See https://github.com/Pylons/pyramid/pull/1533

- Overall improvments for the ``proutes`` command. Added ``--format`` and
``--glob`` arguments to the command, introduced the ``method``
column for displaying available request methods, and improved the ``view``
output by showing the module instead of just ``__repr__``.
See https://github.com/Pylons/pyramid/pull/1488

- Support keyword-only arguments and function annotations in views in
Python 3. See https://github.com/Pylons/pyramid/pull/1556

Bug Fixes
---------

Expand Down Expand Up @@ -105,6 +126,11 @@ Bug Fixes
- Fix route generation for static view asset specifications having no path.
See https://github.com/Pylons/pyramid/pull/1377

- Allow the ``pyramid.renderers.JSONP`` renderer to work even if there is no
valid request object. In this case it will not wrap the object in a
callback and thus behave just like the ``pyramid.renderers.JSON` renderer.
See https://github.com/Pylons/pyramid/pull/1561

Deprecations
------------

Expand All @@ -115,6 +141,13 @@ Deprecations
Docs
----

- Moved the documentation for ``accept`` on ``Configurator.add_view`` to no
longer be part of the predicate list. See
https://github.com/Pylons/pyramid/issues/1391 for a bug report stating
``not_`` was failing on ``accept``. Discussion with @mcdonc led to the
conclusion that it should not be documented as a predicate.
See https://github.com/Pylons/pyramid/pull/1487 for this PR

- Removed logging configuration from Quick Tutorial ini files except for
scaffolding- and logging-related chapters to avoid needing to explain it too
early.
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,5 @@ Contributors
- Hugo Branquinho, 2014/11/25

- Adrian Teng, 2014/12/17

- Ilja Everila, 2015/02/05
2 changes: 1 addition & 1 deletion HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ Bug Fixes
- Make test suite pass on 32-bit systems; closes #286. closes #306.
See also https://github.com/Pylons/pyramid/issues/286

- The ``pryamid.view.view_config`` decorator did not accept a ``match_params``
- The ``pyramid.view.view_config`` decorator did not accept a ``match_params``
predicate argument. See https://github.com/Pylons/pyramid/pull/308

- The AuthTktCookieHelper could potentially generate Unicode headers
Expand Down
2 changes: 1 addition & 1 deletion docs/_themes
Submodule _themes updated 1 files
+ pylons/static/in_progress.png
4 changes: 4 additions & 0 deletions docs/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Glossary
An object which, provided a :term:`WSGI` environment as a single
positional argument, returns a Pyramid-compatible request.

response factory
An object which, provided a :term:`request` as a single positional
argument, returns a Pyramid-compatible response.

response
An object returned by a :term:`view callable` that represents response
data returned to the requesting user agent. It must implement the
Expand Down
56 changes: 46 additions & 10 deletions docs/narr/commandline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,24 +312,60 @@ For example:
:linenos:
$ $VENV/bin/proutes development.ini
Name Pattern View
---- ------- ----
home / <function my_view>
home2 / <function my_view>
another /another None
static/ static/*subpath <static_view object>
catchall /*subpath <function static_view>
``proutes`` generates a table with three columns: *Name*, *Pattern*,
Name Pattern View
---- ------- ----
debugtoolbar /_debug_toolbar/*subpath <wsgiapp> *
__static/ /static/*subpath dummy_starter:static/ *
__static2/ /static2/*subpath /var/www/static/ *
__pdt_images/ /pdt_images/*subpath pyramid_debugtoolbar:static/img/ *
a / <unknown> *
no_view_attached / <unknown> *
route_and_view_attached / app1.standard_views.route_and_view_attached *
method_conflicts /conflicts app1.standard_conflicts <route mismatch>
multiview /multiview app1.standard_views.multiview GET,PATCH
not_post /not_post app1.standard_views.multview !POST,*
``proutes`` generates a table with four columns: *Name*, *Pattern*, *Method*,
and *View*. The items listed in the
Name column are route names, the items listed in the Pattern column are route
patterns, and the items listed in the View column are representations of the
view callable that will be invoked when a request matches the associated
route pattern. The view column may show ``None`` if no associated view
route pattern. The view column may show ``<unknown>`` if no associated view
callable could be found. If no routes are configured within your
application, nothing will be printed to the console when ``proutes``
is executed.

It is convenient when using the ``proutes`` often to configure which columns
and the order you would like to view them. To facilitate this, ``proutes`` will
look for a special ``[proutes]`` section in your INI file and use those as
defaults.

For example you may remove request method and place the view first:

.. code-block:: text
:linenos:
[proutes]
format = view
name
pattern
You can also separate the formats with commas or spaces:

.. code-block:: text
:linenos:
[proutes]
format = view name pattern
[proutes]
format = view, name, pattern
If you want to temporarily configure the columns and order there is the
``--format`` which is a comma separated list of columns you want to include. The
current available formats are ``name``, ``pattern``, ``view``, and ``method``.


.. index::
pair: tweens; printing
single: ptweens
Expand Down
48 changes: 47 additions & 1 deletion docs/narr/hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,52 @@ We attach and cache an object named ``extra`` to the ``request`` object.
>>> request.extra.prop
the property

.. index::
single: response factory

.. _changing_the_response_factory:

Changing the Response Factory
-------------------------------

.. versionadded:: 1.6

Whenever :app:`Pyramid` returns a response from a view it creates a
:term:`response` object. By default, an instance of the
:class:`pyramid.response.Response` class is created to represent the response
object.

The factory that :app:`Pyramid` uses to create a response object instance can be
changed by passing a ``response_factory`` argument to the constructor of the
:term:`configurator`. This argument can be either a callable or a
:term:`dotted Python name` representing a callable.

.. code-block:: python
:linenos:
from pyramid.response import Response
class MyResponse(Response):
pass
config = Configurator(response_factory=lambda r: MyResponse())
If you're doing imperative configuration, and you'd rather do it after you've
already constructed a :term:`configurator` it can also be registered via the
:meth:`pyramid.config.Configurator.set_response_factory` method:

.. code-block:: python
:linenos:
from pyramid.config import Configurator
from pyramid.response import Response
class MyResponse(Response):
pass
config = Configurator()
config.set_response_factory(lambda r: MyResponse())
.. index::
single: before render event
single: adding renderer globals
Expand Down Expand Up @@ -730,7 +776,7 @@ If you want to implement your own Response object instead of using the
:class:`pyramid.response.Response` object in any capacity at all, you'll have
to make sure the object implements every attribute and method outlined in
:class:`pyramid.interfaces.IResponse` and you'll have to ensure that it uses
``zope.interface.implementer(IResponse)`` as a class decoratoror.
``zope.interface.implementer(IResponse)`` as a class decorator.

.. code-block:: python
:linenos:
Expand Down
2 changes: 1 addition & 1 deletion docs/narr/hybrid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ commonly in route declarations that look like this:
.. code-block:: python
:linenos:
from pryamid.static import static_view
from pyramid.static import static_view
www = static_view('mypackage:static', use_subpath=True)
Expand Down
16 changes: 8 additions & 8 deletions docs/narr/introspector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ introspectables in categories not described here.
``subscriber``

The subscriber callable object (the resolution of the ``subscriber``
argument passed to ``add_susbcriber``).
argument passed to ``add_subscriber``).

``interfaces``

Expand All @@ -137,12 +137,12 @@ introspectables in categories not described here.
``predicates``

The predicate objects created as the result of passing predicate arguments
to ``add_susbcriber``
to ``add_subscriber``

``derived_predicates``

Wrappers around the predicate objects created as the result of passing
predicate arguments to ``add_susbcriber`` (to be used when predicates take
predicate arguments to ``add_subscriber`` (to be used when predicates take
only one value but must be passed more than one).

``response adapters``
Expand Down Expand Up @@ -450,9 +450,9 @@ introspectables in categories not described here.
The :class:`pyramid.interfaces.IRendererInfo` object which represents
this template's renderer.

``view mapper``
``view mappers``

Each introspectable in the ``permissions`` category represents a call to
Each introspectable in the ``view mappers`` category represents a call to
:meth:`pyramid.config.Configurator.add_view` that has an explicit
``mapper`` argument to *or* a call to
:meth:`pyramid.config.Configurator.set_view_mapper`; each will have
Expand Down Expand Up @@ -481,8 +481,8 @@ introspectables in categories not described here.

``translation directories``

Each introspectable in the ``asset overrides`` category represents an
individual element in a ``specs`` argument passed to
Each introspectable in the ``translation directories`` category represents
an individual element in a ``specs`` argument passed to
:meth:`pyramid.config.Configurator.add_translation_dirs`; each will have
the following data.

Expand Down Expand Up @@ -511,7 +511,7 @@ introspectables in categories not described here.

``type``

``implict`` or ``explicit`` as a string.
``implicit`` or ``explicit`` as a string.

``under``

Expand Down
18 changes: 9 additions & 9 deletions docs/narr/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,15 @@ level unless they're explicitly set differently. Meaning the ``myapp.views``,
``myapp.models`` (and all your app's modules') loggers by default have an
effective level of ``DEBUG`` too.

For more advanced filtering, the logging module provides a `Filter
<http://docs.python.org/lib/node423.html>`_ object; however it cannot be used
directly from the configuration file.
For more advanced filtering, the logging module provides a
:class:`logging.Filter` object; however it cannot be used directly from the
configuration file.

Advanced Configuration
Advanced Configuration
----------------------

To capture log output to a separate file, use a `FileHandler
<http://docs.python.org/lib/node412.html>`_ (or a `RotatingFileHandler
<http://docs.python.org/lib/node413.html>`_):
To capture log output to a separate file, use :class:`logging.FileHandler` (or
:class:`logging.handlers.RotatingFileHandler`):

.. code-block:: ini
Expand Down Expand Up @@ -317,8 +316,9 @@ output, etc., but not web traffic. For web traffic logging Paste provides the
:term:`middleware`. TransLogger produces logs in the `Apache Combined Log
Format <http://httpd.apache.org/docs/2.2/logs.html#combined>`_. But
TransLogger does not write to files, the Python logging system must be
configured to do this. The Python FileHandler_ logging handler can be used
alongside TransLogger to create an ``access.log`` file similar to Apache's.
configured to do this. The Python :class:`logging.FileHandler` logging
handler can be used alongside TransLogger to create an ``access.log`` file
similar to Apache's.

Like any standard :term:`middleware` with a Paste entry point, TransLogger can
be configured to wrap your application using ``.ini`` file syntax. First,
Expand Down
4 changes: 2 additions & 2 deletions docs/narr/sessions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ It is digitally signed, however, and thus its data cannot easily be
tampered with.

You can configure this session factory in your :app:`Pyramid` application
by using the :meth:`pyramid.config.Configurator.set_session_factory`` method.
by using the :meth:`pyramid.config.Configurator.set_session_factory` method.

.. code-block:: python
:linenos:
Expand Down Expand Up @@ -380,7 +380,7 @@ Checking CSRF Tokens Manually
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In request handling code, you can check the presence and validity of a CSRF
token with :func:`pyramid.session.check_csrf_token(request)``. If the token is
token with :func:`pyramid.session.check_csrf_token`. If the token is
valid, it will return ``True``, otherwise it will raise ``HTTPBadRequest``.
Optionally, you can specify ``raises=False`` to have the check return ``False``
instead of raising an exception.
Expand Down
6 changes: 6 additions & 0 deletions pyramid/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ def unquote_bytes_to_wsgi(bytestring):
def is_bound_method(ob):
return inspect.ismethod(ob) and getattr(ob, im_self, None) is not None

# support annotations and keyword-only arguments in PY3
if PY3: # pragma: no cover
from inspect import getfullargspec as getargspec
else:
from inspect import getargspec

if PY3: # pragma: no cover
from itertools import zip_longest
else:
Expand Down
Loading

0 comments on commit b63f0c5

Please sign in to comment.