From c4e3f4fe37003f9ad30883a31b3946ed78439506 Mon Sep 17 00:00:00 2001 From: Wyatt L Baldwin Date: Tue, 9 Oct 2012 19:19:13 -0700 Subject: 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 --- pyramid/__init__.py | 5 ----- pyramid/request.py | 7 +++++++ 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: -- cgit v1.2.3