Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed BaseHandler.get_response() to take a single parameter (an Htt…

…pRequest object) rather than a URL and the HttpRequest object, which is redundant

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3875 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 15e7805ae4e5a1ae30ec240a3e1ad6b8a4e32269 1 parent 0cc1815
@adrianholovaty adrianholovaty authored
View
6 django/core/handlers/base.py
@@ -48,7 +48,7 @@ def load_middleware(self):
if hasattr(mw_instance, 'process_exception'):
self._exception_middleware.insert(0, mw_instance.process_exception)
- def get_response(self, path, request):
+ def get_response(self, request):
"Returns an HttpResponse object for the given HttpRequest"
from django.core import exceptions, urlresolvers
from django.core.mail import mail_admins
@@ -62,7 +62,7 @@ def get_response(self, path, request):
resolver = urlresolvers.RegexURLResolver(r'^/', settings.ROOT_URLCONF)
try:
- callback, callback_args, callback_kwargs = resolver.resolve(path)
+ callback, callback_args, callback_kwargs = resolver.resolve(request.path)
# Apply view middleware
for middleware_method in self._view_middleware:
@@ -105,7 +105,7 @@ def get_response(self, path, request):
exc_info = sys.exc_info()
receivers = dispatcher.send(signal=signals.got_request_exception)
# When DEBUG is False, send an error message to the admins.
- subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', ''))
+ subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
try:
request_repr = repr(request)
except:
View
2  django/core/handlers/modpython.py
@@ -150,7 +150,7 @@ def __call__(self, req):
dispatcher.send(signal=signals.request_started)
try:
request = ModPythonRequest(req)
- response = self.get_response(req.uri, request)
+ response = self.get_response(request)
# Apply response middleware
for middleware_method in self._response_middleware:
View
4 django/core/handlers/wsgi.py
@@ -74,7 +74,7 @@ class WSGIRequest(http.HttpRequest):
def __init__(self, environ):
self.environ = environ
self.path = environ['PATH_INFO']
- self.META = environ
+ self.META = environ
self.method = environ['REQUEST_METHOD'].upper()
def __repr__(self):
@@ -186,7 +186,7 @@ def __call__(self, environ, start_response):
dispatcher.send(signal=signals.request_started)
try:
request = WSGIRequest(environ)
- response = self.get_response(request.path, request)
+ response = self.get_response(request)
# Apply response middleware
for middleware_method in self._response_middleware:
View
56 django/test/client.py
@@ -8,7 +8,7 @@
class ClientHandler(BaseHandler):
"""
- A HTTP Handler that can be used for testing purposes.
+ A HTTP Handler that can be used for testing purposes.
Uses the WSGI interface to compose requests, but returns
the raw HttpResponse object
"""
@@ -24,7 +24,7 @@ def __call__(self, environ):
dispatcher.send(signal=signals.request_started)
try:
request = WSGIRequest(environ)
- response = self.get_response(request.path, request)
+ response = self.get_response(request)
# Apply response middleware
for middleware_method in self._response_middleware:
@@ -32,7 +32,7 @@ def __call__(self, environ):
finally:
dispatcher.send(signal=signals.request_finished)
-
+
return response
def store_rendered_templates(store, signal, sender, template, context):
@@ -44,7 +44,7 @@ def encode_multipart(boundary, data):
"""
A simple method for encoding multipart POST data from a dictionary of
form values.
-
+
The key will be used as the form data name; the value will be transmitted
as content. If the value is a file, the contents of the file will be sent
as an application/octet-stream; otherwise, str(value) will be sent.
@@ -69,7 +69,7 @@ def encode_multipart(boundary, data):
'',
str(value)
])
-
+
lines.extend([
'--' + boundary + '--',
'',
@@ -78,8 +78,8 @@ def encode_multipart(boundary, data):
class Client:
"""
- A class that can act as a client for testing purposes.
-
+ A class that can act as a client for testing purposes.
+
It allows the user to compose GET and POST requests, and
obtain the response that the server gave to those requests.
The server Response objects are annotated with the details
@@ -88,7 +88,7 @@ class Client:
Client objects are stateful - they will retain cookie (and
thus session) details for the lifetime of the Client instance.
-
+
This is not intended as a replacement for Twill/Selenium or
the like - it is here to allow testing against the
contexts and templates produced by a view, rather than the
@@ -98,10 +98,10 @@ def __init__(self, **defaults):
self.handler = ClientHandler()
self.defaults = defaults
self.cookie = SimpleCookie()
-
+
def request(self, **request):
"""
- The master request method. Composes the environment dictionary
+ The master request method. Composes the environment dictionary
and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
using the arguments to the request.
@@ -112,24 +112,24 @@ def request(self, **request):
'PATH_INFO': '/',
'QUERY_STRING': '',
'REQUEST_METHOD': 'GET',
- 'SCRIPT_NAME': None,
+ 'SCRIPT_NAME': None,
'SERVER_NAME': 'testserver',
'SERVER_PORT': 80,
'SERVER_PROTOCOL': 'HTTP/1.1',
- }
+ }
environ.update(self.defaults)
- environ.update(request)
+ environ.update(request)
# Curry a data dictionary into an instance of
# the template renderer callback function
data = {}
on_template_render = curry(store_rendered_templates, data)
dispatcher.connect(on_template_render, signal=signals.template_rendered)
-
+
response = self.handler(environ)
-
+
# Add any rendered template detail to the response
- # If there was only one template rendered (the most likely case),
+ # If there was only one template rendered (the most likely case),
# flatten the list to a single element
for detail in ('template', 'context'):
if data.get(detail):
@@ -139,12 +139,12 @@ def request(self, **request):
setattr(response, detail, data[detail])
else:
setattr(response, detail, None)
-
+
if response.cookies:
self.cookie.update(response.cookies)
return response
-
+
def get(self, path, data={}, **extra):
"Request a response from the server using GET."
r = {
@@ -155,12 +155,12 @@ def get(self, path, data={}, **extra):
'REQUEST_METHOD': 'GET',
}
r.update(extra)
-
+
return self.request(**r)
-
+
def post(self, path, data={}, **extra):
"Request a response from the server using POST."
-
+
BOUNDARY = 'BoUnDaRyStRiNg'
encoded = encode_multipart(BOUNDARY, data)
@@ -173,25 +173,25 @@ def post(self, path, data={}, **extra):
'wsgi.input': stream,
}
r.update(extra)
-
+
return self.request(**r)
def login(self, path, username, password, **extra):
"""
A specialized sequence of GET and POST to log into a view that
is protected by a @login_required access decorator.
-
+
path should be the URL of the page that is login protected.
-
- Returns the response from GETting the requested URL after
+
+ Returns the response from GETting the requested URL after
login is complete. Returns False if login process failed.
"""
- # First, GET the page that is login protected.
+ # First, GET the page that is login protected.
# This page will redirect to the login page.
response = self.get(path)
if response.status_code != 302:
return False
-
+
login_path, data = response['Location'].split('?')
next = data.split('=')[1]
@@ -199,7 +199,7 @@ def login(self, path, username, password, **extra):
response = self.get(login_path, **extra)
if response.status_code != 200:
return False
-
+
# Last, POST the login data.
form_data = {
'username': username,
Please sign in to comment.
Something went wrong with that request. Please try again.