From 1ffb8e3cc21603b29ccd78152f82cca7f61a09b1 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 16 May 2011 02:11:56 -0400 Subject: - Added API docs for ``pyramid.httpexceptions.abort`` and ``pyramid.httpexceptions.redirect``. - Added "HTTP Exceptions" section to Views narrative chapter including a description of ``pyramid.httpexceptions.abort``; adjusted redirect section to note ``pyramid.httpexceptions.redirect``. - A default exception view for the context ``webob.exc.HTTPException`` (aka ``pyramid.httpexceptions.HTTPException``) is now registered by default. This means that an instance of any exception class imported from ``pyramid.httpexceptions`` (such as ``HTTPFound``) can now be raised from within view code; when raised, this exception view will render the exception to a response. - New functions named ``pyramid.httpexceptions.abort`` and ``pyramid.httpexceptions.redirect`` perform the equivalent of their Pylons brethren when an HTTP exception handler is registered. These functions take advantage of the newly registered exception view for ``webob.exc.HTTPException``. - The Configurator now accepts an additional keyword argument named ``httpexception_view``. By default, this argument is populated with a default exception view function that will be used when an HTTP exception is raised. When ``None`` is passed for this value, an exception view for HTTP exceptions will not be registered. Passing ``None`` returns the behavior of raising an HTTP exception to that of Pyramid 1.0 (the exception will propagate to middleware and to the WSGI server). --- CHANGES.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'CHANGES.txt') diff --git a/CHANGES.txt b/CHANGES.txt index 0992af9ef..756d1345c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -37,6 +37,13 @@ Documentation - Added "What's New in Pyramid 1.1" to HTML rendering of documentation. +- Added API docs for ``pyramid.httpexceptions.abort`` and + ``pyramid.httpexceptions.redirect``. + +- Added "HTTP Exceptions" section to Views narrative chapter including a + description of ``pyramid.httpexceptions.abort``; adjusted redirect section + to note ``pyramid.httpexceptions.redirect``. + Features -------- @@ -97,6 +104,27 @@ Features section entitled "Static Routes" in the URL Dispatch narrative chapter for more information. +- A default exception view for the context ``webob.exc.HTTPException`` (aka + ``pyramid.httpexceptions.HTTPException``) is now registered by default. + This means that an instance of any exception class imported from + ``pyramid.httpexceptions`` (such as ``HTTPFound``) can now be raised from + within view code; when raised, this exception view will render the + exception to a response. + +- New functions named ``pyramid.httpexceptions.abort`` and + ``pyramid.httpexceptions.redirect`` perform the equivalent of their Pylons + brethren when an HTTP exception handler is registered. These functions + take advantage of the newly registered exception view for + ``webob.exc.HTTPException``. + +- The Configurator now accepts an additional keyword argument named + ``httpexception_view``. By default, this argument is populated with a + default exception view function that will be used when an HTTP exception is + raised. When ``None`` is passed for this value, an exception view for HTTP + exceptions will not be registered. Passing ``None`` returns the behavior + of raising an HTTP exception to that of Pyramid 1.0 (the exception will + propagate to middleware and to the WSGI server). + Bug Fixes --------- -- cgit v1.2.3 From 966b5cfe03009069d7bbe92cc047b32a5e3cd4e6 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 30 May 2011 03:23:31 -0400 Subject: - Fix older CHANGES entries. - The ``pyramid.request.Request`` class now has a ``ResponseClass`` interface which points at ``pyramid.response.Response``. - The ``pyramid.request.Response`` class now has a ``RequestClass`` interface which points at ``pyramid.response.Request``. - ``pyramid.response.Response`` is now a *subclass* of ``webob.response.Response``. It also inherits from the built-in Python ``Exception`` class and implements the ``pyramid.interfaces.IExceptionResponse`` class so it can be raised as an exception from view code. --- CHANGES.txt | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'CHANGES.txt') diff --git a/CHANGES.txt b/CHANGES.txt index 756d1345c..15c86c13c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -104,12 +104,13 @@ Features section entitled "Static Routes" in the URL Dispatch narrative chapter for more information. -- A default exception view for the context ``webob.exc.HTTPException`` (aka - ``pyramid.httpexceptions.HTTPException``) is now registered by default. - This means that an instance of any exception class imported from - ``pyramid.httpexceptions`` (such as ``HTTPFound``) can now be raised from - within view code; when raised, this exception view will render the - exception to a response. +- A default exception view for the context + ``pyramid.interfaces.IExceptionResponse`` (aka + ``pyramid.response.Response`` or ``pyramid.httpexceptions.HTTPException``) + is now registered by default. This means that an instance of any exception + response class imported from ``pyramid.httpexceptions`` (such as + ``HTTPFound``) can now be raised from within view code; when raised, this + exception view will render the exception to a response. - New functions named ``pyramid.httpexceptions.abort`` and ``pyramid.httpexceptions.redirect`` perform the equivalent of their Pylons @@ -118,12 +119,18 @@ Features ``webob.exc.HTTPException``. - The Configurator now accepts an additional keyword argument named - ``httpexception_view``. By default, this argument is populated with a - default exception view function that will be used when an HTTP exception is - raised. When ``None`` is passed for this value, an exception view for HTTP - exceptions will not be registered. Passing ``None`` returns the behavior - of raising an HTTP exception to that of Pyramid 1.0 (the exception will - propagate to middleware and to the WSGI server). + ``exceptionresponse_view``. By default, this argument is populated with a + default exception view function that will be used when a response is raised + as an exception. When ``None`` is passed for this value, an exception view + for responses will not be registered. Passing ``None`` returns the + behavior of raising an HTTP exception to that of Pyramid 1.0 (the exception + will propagate to middleware and to the WSGI server). + +- The ``pyramid.request.Request`` class now has a ``ResponseClass`` interface + which points at ``pyramid.response.Response``. + +- The ``pyramid.request.Response`` class now has a ``RequestClass`` interface + which points at ``pyramid.response.Request``. Bug Fixes --------- @@ -289,6 +296,12 @@ Behavior Changes implements its own ``__getattr__``, ``__setattr__`` or ``__delattr__`` as a result. +- ``pyramid.response.Response`` is now a *subclass* of + ``webob.response.Response``. It also inherits from the built-in Python + ``Exception`` class and implements the + ``pyramid.interfaces.IExceptionResponse`` class so it can be raised as an + exception from view code. + Dependencies ------------ -- cgit v1.2.3 From df15ed98612e7962e3122da52d8d5f5b9d8882b2 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 4 Jun 2011 18:43:25 -0400 Subject: - It is now possible to control how the Pyramid router calls the WSGI ``start_response`` callable and obtains the WSGI ``app_iter`` based on adapting the response object to the new ``pyramid.interfaces.IResponder`` interface. The default ``IResponder`` uses Pyramid 1.0's logic to do this. To override the responder:: from pyramid.interfaces import IResponder from pyramid.response import Response from myapp import MyResponder config.registry.registerAdapter(MyResponder, (Response,), IResponder, name='') This makes it possible to reuse response object implementations which have, for example, their own ``__call__`` expected to be used as a WSGI application (like ``pyramid.response.Response``), e.g.: class MyResponder(object): def __init__(self, response): """ Obtain a reference to the response """ self.response = response def __call__(self, request, start_response): """ Call start_response and return an app_iter """ app_iter = self.response(request.environ, start_response) return app_iter --- CHANGES.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'CHANGES.txt') diff --git a/CHANGES.txt b/CHANGES.txt index 15c86c13c..7840bc525 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -132,6 +132,32 @@ Features - The ``pyramid.request.Response`` class now has a ``RequestClass`` interface which points at ``pyramid.response.Request``. +- It is now possible to control how the Pyramid router calls the WSGI + ``start_response`` callable and obtains the WSGI ``app_iter`` based on + adapting the response object to the new ``pyramid.interfaces.IResponder`` + interface. The default ``IResponder`` uses Pyramid 1.0's logic to do this. + To override the responder:: + + from pyramid.interfaces import IResponder + from pyramid.response import Response + from myapp import MyResponder + + config.registry.registerAdapter(MyResponder, (Response,), + IResponder, name='') + + This makes it possible to reuse response object implementations which have, + for example, their own ``__call__`` expected to be used as a WSGI + application (like ``pyramid.response.Response``), e.g.: + + class MyResponder(object): + def __init__(self, response): + """ Obtain a reference to the response """ + self.response = response + def __call__(self, request, start_response): + """ Call start_response and return an app_iter """ + app_iter = self.response(request.environ, start_response) + return app_iter + Bug Fixes --------- -- cgit v1.2.3 From 99edc51a3b05309c7f5d98ff96289ec51b1d7660 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 11 Jun 2011 05:35:27 -0400 Subject: - Pyramid now expects Response objects to have a __call__ method which implements the WSGI application interface instead of the three webob attrs status, headerlist and app_iter. Backwards compatibility exists for code which returns response objects that do not have a __call__. - pyramid.response.Response is no longer an exception (and therefore cannot be raised in order to generate a response). - Changed my mind about moving stuff from pyramid.httpexceptions to pyramid.response. The stuff I moved over has been moved back to pyramid.httpexceptions. --- CHANGES.txt | 79 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 42 deletions(-) (limited to 'CHANGES.txt') diff --git a/CHANGES.txt b/CHANGES.txt index 7840bc525..e413f0657 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -37,12 +37,10 @@ Documentation - Added "What's New in Pyramid 1.1" to HTML rendering of documentation. -- Added API docs for ``pyramid.httpexceptions.abort`` and - ``pyramid.httpexceptions.redirect``. +- Added API docs for ``pyramid.httpexceptions.responsecode``. - Added "HTTP Exceptions" section to Views narrative chapter including a - description of ``pyramid.httpexceptions.abort``; adjusted redirect section - to note ``pyramid.httpexceptions.redirect``. + description of ``pyramid.httpexceptions.responsecode``. Features -------- @@ -105,18 +103,15 @@ Features more information. - A default exception view for the context - ``pyramid.interfaces.IExceptionResponse`` (aka - ``pyramid.response.Response`` or ``pyramid.httpexceptions.HTTPException``) - is now registered by default. This means that an instance of any exception - response class imported from ``pyramid.httpexceptions`` (such as - ``HTTPFound``) can now be raised from within view code; when raised, this - exception view will render the exception to a response. - -- New functions named ``pyramid.httpexceptions.abort`` and - ``pyramid.httpexceptions.redirect`` perform the equivalent of their Pylons - brethren when an HTTP exception handler is registered. These functions - take advantage of the newly registered exception view for - ``webob.exc.HTTPException``. + ``pyramid.interfaces.IExceptionResponse`` is now registered by default. + This means that an instance of any exception response class imported from + ``pyramid.httpexceptions`` (such as ``HTTPFound``) can now be raised from + within view code; when raised, this exception view will render the + exception to a response. + +- A function named ``pyramid.httpexceptions.responsecode`` is a shortcut that + can be used to create HTTP exception response objects using an HTTP integer + status code. - The Configurator now accepts an additional keyword argument named ``exceptionresponse_view``. By default, this argument is populated with a @@ -135,28 +130,13 @@ Features - It is now possible to control how the Pyramid router calls the WSGI ``start_response`` callable and obtains the WSGI ``app_iter`` based on adapting the response object to the new ``pyramid.interfaces.IResponder`` - interface. The default ``IResponder`` uses Pyramid 1.0's logic to do this. - To override the responder:: - - from pyramid.interfaces import IResponder - from pyramid.response import Response - from myapp import MyResponder - - config.registry.registerAdapter(MyResponder, (Response,), - IResponder, name='') - - This makes it possible to reuse response object implementations which have, - for example, their own ``__call__`` expected to be used as a WSGI - application (like ``pyramid.response.Response``), e.g.: + interface. See the section in the Hooks chapter of the documentation + entitled "Changing How Pyramid Treats Response Objects". - class MyResponder(object): - def __init__(self, response): - """ Obtain a reference to the response """ - self.response = response - def __call__(self, request, start_response): - """ Call start_response and return an app_iter """ - app_iter = self.response(request.environ, start_response) - return app_iter +- The Pyramid router will now, by default, call the ``__call__`` method of + WebOb response objects when returning a WSGI response. This means that, + among other things, the ``conditional_response`` feature of WebOb response + objects will now behave properly. Bug Fixes --------- @@ -291,7 +271,7 @@ Deprecations Behavior Changes ---------------- -- A custom request factory is now required to return a response object that +- A custom request factory is now required to return a request object that has a ``response`` attribute (or "reified"/lazy property) if they the request is meant to be used in a view that uses a renderer. This ``response`` attribute should be an instance of the class @@ -323,10 +303,25 @@ Behavior Changes result. - ``pyramid.response.Response`` is now a *subclass* of - ``webob.response.Response``. It also inherits from the built-in Python - ``Exception`` class and implements the - ``pyramid.interfaces.IExceptionResponse`` class so it can be raised as an - exception from view code. + ``webob.response.Response`` (in order to directly implement the + ``pyramid.interfaces.IResponse`` interface). + +- The ``pyramid.interfaces.IResponse`` interface now includes a ``__call__`` + method which has the WSGI application call signature (and which expects an + iterable as a result). + +- The Pyramid router now, by default, expects response objects returned from + views to implement the WSGI application interface (a ``__call__`` method + that accepts ``environ`` and ``start_response``, and which returns an + ``app_iter`` iterable). If such a method exists, Pyramid will now call it + in order to satisfy the WSGI request. Backwards compatibility code in the + default responder exists which will fall back to the older behavior, but + Pyramid will raise a deprecation warning if it is reached. See the section + in the Hooks chapter of the documentation entitled "Changing How Pyramid + Treats Response Objects" to default back to the older behavior, where the + ``app_iter``, ``headerlist``, and ``status`` attributes of the object were + consulted directly (without any indirection through ``__call__``) to + silence the deprecation warnings. Dependencies ------------ -- cgit v1.2.3 From d868fff7597c5a05acd1f5c024fc45dde9880413 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 13 Jun 2011 06:17:00 -0400 Subject: - Remove IResponder abstraction in favor of more general IResponse abstraction. - It is now possible to return an arbitrary object from a Pyramid view callable even if a renderer is not used, as long as a suitable adapter to ``pyramid.interfaces.IResponse`` is registered for the type of the returned object. See the section in the Hooks chapter of the documentation entitled "Changing How Pyramid Treats View Responses". - The Pyramid router now, by default, expects response objects returned from view callables to implement the ``pyramid.interfaces.IResponse`` interface. Unlike the Pyramid 1.0 version of this interface, objects which implement IResponse now must define a ``__call__`` method that accepts ``environ`` and ``start_response``, and which returns an ``app_iter`` iterable, among other things. Previously, it was possible to return any object which had the three WebOb ``app_iter``, ``headerlist``, and ``status`` attributes as a response, so this is a backwards incompatibility. It is possible to get backwards compatibility back by registering an adapter to IResponse from the type of object you're now returning from view callables. See the section in the Hooks chapter of the documentation entitled "Changing How Pyramid Treats View Responses". - The ``pyramid.interfaces.IResponse`` interface is now much more extensive. Previously it defined only ``app_iter``, ``status`` and ``headerlist``; now it is basically intended to directly mirror the ``webob.Response`` API, which has many methods and attributes. - Documentation changes to support above. --- CHANGES.txt | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'CHANGES.txt') diff --git a/CHANGES.txt b/CHANGES.txt index e413f0657..5e8df1a0b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -127,11 +127,11 @@ Features - The ``pyramid.request.Response`` class now has a ``RequestClass`` interface which points at ``pyramid.response.Request``. -- It is now possible to control how the Pyramid router calls the WSGI - ``start_response`` callable and obtains the WSGI ``app_iter`` based on - adapting the response object to the new ``pyramid.interfaces.IResponder`` - interface. See the section in the Hooks chapter of the documentation - entitled "Changing How Pyramid Treats Response Objects". +- It is now possible to return an arbitrary object from a Pyramid view + callable even if a renderer is not used, as long as a suitable adapter to + ``pyramid.interfaces.IResponse`` is registered for the type of the returned + object. See the section in the Hooks chapter of the documentation entitled + "Changing How Pyramid Treats View Responses". - The Pyramid router will now, by default, call the ``__call__`` method of WebOb response objects when returning a WSGI response. This means that, @@ -306,22 +306,26 @@ Behavior Changes ``webob.response.Response`` (in order to directly implement the ``pyramid.interfaces.IResponse`` interface). -- The ``pyramid.interfaces.IResponse`` interface now includes a ``__call__`` - method which has the WSGI application call signature (and which expects an - iterable as a result). +Backwards Incompatibilities +--------------------------- - The Pyramid router now, by default, expects response objects returned from - views to implement the WSGI application interface (a ``__call__`` method - that accepts ``environ`` and ``start_response``, and which returns an - ``app_iter`` iterable). If such a method exists, Pyramid will now call it - in order to satisfy the WSGI request. Backwards compatibility code in the - default responder exists which will fall back to the older behavior, but - Pyramid will raise a deprecation warning if it is reached. See the section - in the Hooks chapter of the documentation entitled "Changing How Pyramid - Treats Response Objects" to default back to the older behavior, where the - ``app_iter``, ``headerlist``, and ``status`` attributes of the object were - consulted directly (without any indirection through ``__call__``) to - silence the deprecation warnings. + view callables to implement the ``pyramid.interfaces.IResponse`` interface. + Unlike the Pyramid 1.0 version of this interface, objects which implement + IResponse now must define a ``__call__`` method that accepts ``environ`` + and ``start_response``, and which returns an ``app_iter`` iterable, among + other things. Previously, it was possible to return any object which had + the three WebOb ``app_iter``, ``headerlist``, and ``status`` attributes as + a response, so this is a backwards incompatibility. It is possible to get + backwards compatibility back by registering an adapter to IResponse from + the type of object you're now returning from view callables. See the + section in the Hooks chapter of the documentation entitled "Changing How + Pyramid Treats View Responses". + +- The ``pyramid.interfaces.IResponse`` interface is now much more extensive. + Previously it defined only ``app_iter``, ``status`` and ``headerlist``; now + it is basically intended to directly mirror the ``webob.Response`` API, + which has many methods and attributes. Dependencies ------------ -- cgit v1.2.3 From 1a6fc7062f803b9f15b7677db9a9257a4f00bfcb Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 14 Jun 2011 02:36:07 -0400 Subject: - Added new add_response_adapter method to Configurator. - Fix Configurator docstring wrt exception responses. - Speed up registry.queryAdapterOrSelf --- CHANGES.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'CHANGES.txt') diff --git a/CHANGES.txt b/CHANGES.txt index 5e8df1a0b..c7ca3794d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -130,8 +130,10 @@ Features - It is now possible to return an arbitrary object from a Pyramid view callable even if a renderer is not used, as long as a suitable adapter to ``pyramid.interfaces.IResponse`` is registered for the type of the returned - object. See the section in the Hooks chapter of the documentation entitled - "Changing How Pyramid Treats View Responses". + object by using the new + ``pyramid.config.Configurator.add_response_adapter`` API. See the section + in the Hooks chapter of the documentation entitled "Changing How Pyramid + Treats View Responses". - The Pyramid router will now, by default, call the ``__call__`` method of WebOb response objects when returning a WSGI response. This means that, -- cgit v1.2.3 From 92099080859976ce78882de477ddc2c01bc880b2 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 14 Jun 2011 03:37:08 -0400 Subject: - New method named ``pyramid.request.Request.is_response``. This method should be used instead of the ``pyramid.view.is_response`` function, which has been deprecated. - Deprecated ``pyramid.view.is_response`` function in favor of (newly-added) ``pyramid.request.Request.is_response`` method. Determining if an object is truly a valid response object now requires access to the registry, which is only easily available as a request attribute. The ``pyramid.view.is_response`` function will still work until it is removed, but now may return an incorrect answer under some (very uncommon) circumstances. --- CHANGES.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'CHANGES.txt') diff --git a/CHANGES.txt b/CHANGES.txt index c7ca3794d..ea4bedc7e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -140,6 +140,10 @@ Features among other things, the ``conditional_response`` feature of WebOb response objects will now behave properly. +- New method named ``pyramid.request.Request.is_response``. This method + should be used instead of the ``pyramid.view.is_response`` function, which + has been deprecated. + Bug Fixes --------- @@ -270,6 +274,14 @@ Deprecations 1.0 and before). In a future version, these methods will be removed entirely. +- Deprecated ``pyramid.view.is_response`` function in favor of (newly-added) + ``pyramid.request.Request.is_response`` method. Determining if an object + is truly a valid response object now requires access to the registry, which + is only easily available as a request attribute. The + ``pyramid.view.is_response`` function will still work until it is removed, + but now may return an incorrect answer under some (very uncommon) + circumstances. + Behavior Changes ---------------- -- cgit v1.2.3 From 53d11e7793317eee0f756b1e77b853ae7e1e6726 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 14 Jun 2011 04:31:26 -0400 Subject: - Move default app_iter generation logic into __call__ for exception responses. - Add note about why we've created a shadow exception hierarchy parallel to that of webob.exc. --- CHANGES.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'CHANGES.txt') diff --git a/CHANGES.txt b/CHANGES.txt index ea4bedc7e..a2976d1a2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -320,6 +320,25 @@ Behavior Changes ``webob.response.Response`` (in order to directly implement the ``pyramid.interfaces.IResponse`` interface). +- The "exception response" objects importable from ``pyramid.httpexceptions`` + (e.g. ``HTTPNotFound``) are no longer just import aliases for classes that + actually live in ``webob.exc``. Instead, we've defined our own exception + classes within the module that mirror and emulate the ``webob.exc`` + exception response objects almost entirely. We do this in order to a) + allow the exception responses to subclass ``pyramid.response.Response``, + which speeds up response generation slightly due to the way the Pyramid + router works, b) allows us to provide alternate __call__ logic which also + speeds up response generation, c) allows the exception classes to provide + for the proper value of ``self.RequestClass`` (pyramid.request.Request), d) + allows us freedom from having to think about backwards compatibility code + present in ``webob.exc`` having to do with Python 2.4, which we no longer + support, e) We change the behavior of two classes (HTTPNotFound and + HTTPForbidden) in the module so that they can be used internally for + notfound and forbidden exceptions, f) allows us to influence the docstrings + of the exception classes to provide Pyramid-specific documentation, and g) + allows us to silence a stupid deprecation warning under Python 2.6 when the + response objects are used as exceptions (related to ``self.message``). + Backwards Incompatibilities --------------------------- -- cgit v1.2.3