diff options
| author | Wyatt L Baldwin <wyatt.lee.baldwin@gmail.com> | 2012-10-09 19:19:13 -0700 |
|---|---|---|
| committer | Wyatt L Baldwin <wyatt.lee.baldwin@gmail.com> | 2012-10-09 19:19:13 -0700 |
| commit | c4e3f4fe37003f9ad30883a31b3946ed78439506 (patch) | |
| tree | d8037cc4fffa08b19d8e6548b46a6fb581dc0d08 | |
| parent | 1273d56ee5c038f447dce0525844cd3ea6c15e4d (diff) | |
| download | pyramid-c4e3f4fe37003f9ad30883a31b3946ed78439506.tar.gz pyramid-c4e3f4fe37003f9ad30883a31b3946ed78439506.tar.bz2 pyramid-c4e3f4fe37003f9ad30883a31b3946ed78439506.zip | |
Get rid of monkeypatch of Request and Response in pyramid.__init__
Added `request.default_request_factory()`, which is now used as the default
request factory in the `Router` constructor instead of using the `Request`
class directly as the default request factory.
Fixes #702
| -rw-r--r-- | pyramid/__init__.py | 5 | ||||
| -rw-r--r-- | pyramid/request.py | 7 | ||||
| -rw-r--r-- | pyramid/router.py | 5 |
3 files changed, 10 insertions, 7 deletions
diff --git a/pyramid/__init__.py b/pyramid/__init__.py index 473d5e1c6..e69de29bb 100644 --- a/pyramid/__init__.py +++ b/pyramid/__init__.py @@ -1,5 +0,0 @@ -from pyramid.request import Request -from pyramid.response import Response -Response.RequestClass = Request -Request.ResponseClass = Response -del Request, Response diff --git a/pyramid/request.py b/pyramid/request.py index af3310829..0abf87dbb 100644 --- a/pyramid/request.py +++ b/pyramid/request.py @@ -9,6 +9,7 @@ from webob import BaseRequest from pyramid.interfaces import ( IRequest, + IRequestFactory, IResponse, ISessionFactory, IResponseFactory, @@ -28,6 +29,12 @@ from pyramid.response import Response from pyramid.url import URLMethodsMixin from pyramid.util import InstancePropertyMixin + +@implementer(IRequestFactory) +def default_request_factory(environ): + return Request(environ, ResponseClass=Response) + + class TemplateContext(object): pass diff --git a/pyramid/router.py b/pyramid/router.py index 0c7f61071..f1318ec3c 100644 --- a/pyramid/router.py +++ b/pyramid/router.py @@ -25,7 +25,8 @@ from pyramid.events import ( ) from pyramid.httpexceptions import HTTPNotFound -from pyramid.request import Request +from pyramid.request import default_request_factory +from pyramid.response import Response from pyramid.threadlocal import manager from pyramid.traversal import ( @@ -48,7 +49,7 @@ class Router(object): self.logger = q(IDebugLogger) self.root_factory = q(IRootFactory, default=DefaultRootFactory) self.routes_mapper = q(IRoutesMapper) - self.request_factory = q(IRequestFactory, default=Request) + self.request_factory = q(IRequestFactory, default=default_request_factory) self.request_extensions = q(IRequestExtensions) tweens = q(ITweens) if tweens is None: |
