Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Adrian Holovaty authored September 28, 2006
6  django/core/handlers/base.py
@@ -48,7 +48,7 @@ def load_middleware(self):
48 48
             if hasattr(mw_instance, 'process_exception'):
49 49
                 self._exception_middleware.insert(0, mw_instance.process_exception)
50 50
 
51  
-    def get_response(self, path, request):
  51
+    def get_response(self, request):
52 52
         "Returns an HttpResponse object for the given HttpRequest"
53 53
         from django.core import exceptions, urlresolvers
54 54
         from django.core.mail import mail_admins
@@ -62,7 +62,7 @@ def get_response(self, path, request):
62 62
 
63 63
         resolver = urlresolvers.RegexURLResolver(r'^/', settings.ROOT_URLCONF)
64 64
         try:
65  
-            callback, callback_args, callback_kwargs = resolver.resolve(path)
  65
+            callback, callback_args, callback_kwargs = resolver.resolve(request.path)
66 66
 
67 67
             # Apply view middleware
68 68
             for middleware_method in self._view_middleware:
@@ -105,7 +105,7 @@ def get_response(self, path, request):
105 105
                 exc_info = sys.exc_info()
106 106
                 receivers = dispatcher.send(signal=signals.got_request_exception)
107 107
                 # When DEBUG is False, send an error message to the admins.
108  
-                subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', ''))
  108
+                subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
109 109
                 try:
110 110
                     request_repr = repr(request)
111 111
                 except:
2  django/core/handlers/modpython.py
@@ -150,7 +150,7 @@ def __call__(self, req):
150 150
         dispatcher.send(signal=signals.request_started)
151 151
         try:
152 152
             request = ModPythonRequest(req)
153  
-            response = self.get_response(req.uri, request)
  153
+            response = self.get_response(request)
154 154
 
155 155
             # Apply response middleware
156 156
             for middleware_method in self._response_middleware:
4  django/core/handlers/wsgi.py
@@ -74,7 +74,7 @@ class WSGIRequest(http.HttpRequest):
74 74
     def __init__(self, environ):
75 75
         self.environ = environ
76 76
         self.path = environ['PATH_INFO']
77  
-        self.META = environ 
  77
+        self.META = environ
78 78
         self.method = environ['REQUEST_METHOD'].upper()
79 79
 
80 80
     def __repr__(self):
@@ -186,7 +186,7 @@ def __call__(self, environ, start_response):
186 186
         dispatcher.send(signal=signals.request_started)
187 187
         try:
188 188
             request = WSGIRequest(environ)
189  
-            response = self.get_response(request.path, request)
  189
+            response = self.get_response(request)
190 190
 
191 191
             # Apply response middleware
192 192
             for middleware_method in self._response_middleware:
56  django/test/client.py
@@ -8,7 +8,7 @@
8 8
 
9 9
 class ClientHandler(BaseHandler):
10 10
     """
11  
-    A HTTP Handler that can be used for testing purposes. 
  11
+    A HTTP Handler that can be used for testing purposes.
12 12
     Uses the WSGI interface to compose requests, but returns
13 13
     the raw HttpResponse object
14 14
     """
@@ -24,7 +24,7 @@ def __call__(self, environ):
24 24
         dispatcher.send(signal=signals.request_started)
25 25
         try:
26 26
             request = WSGIRequest(environ)
27  
-            response = self.get_response(request.path, request)
  27
+            response = self.get_response(request)
28 28
 
29 29
             # Apply response middleware
30 30
             for middleware_method in self._response_middleware:
@@ -32,7 +32,7 @@ def __call__(self, environ):
32 32
 
33 33
         finally:
34 34
             dispatcher.send(signal=signals.request_finished)
35  
-        
  35
+
36 36
         return response
37 37
 
38 38
 def store_rendered_templates(store, signal, sender, template, context):
@@ -44,7 +44,7 @@ def encode_multipart(boundary, data):
44 44
     """
45 45
     A simple method for encoding multipart POST data from a dictionary of
46 46
     form values.
47  
-    
  47
+
48 48
     The key will be used as the form data name; the value will be transmitted
49 49
     as content. If the value is a file, the contents of the file will be sent
50 50
     as an application/octet-stream; otherwise, str(value) will be sent.
@@ -69,7 +69,7 @@ def encode_multipart(boundary, data):
69 69
                 '',
70 70
                 str(value)
71 71
             ])
72  
-        
  72
+
73 73
     lines.extend([
74 74
         '--' + boundary + '--',
75 75
         '',
@@ -78,8 +78,8 @@ def encode_multipart(boundary, data):
78 78
 
79 79
 class Client:
80 80
     """
81  
-    A class that can act as a client for testing purposes. 
82  
-      
  81
+    A class that can act as a client for testing purposes.
  82
+
83 83
     It allows the user to compose GET and POST requests, and
84 84
     obtain the response that the server gave to those requests.
85 85
     The server Response objects are annotated with the details
@@ -88,7 +88,7 @@ class Client:
88 88
 
89 89
     Client objects are stateful - they will retain cookie (and
90 90
     thus session) details for the lifetime of the Client instance.
91  
-    
  91
+
92 92
     This is not intended as a replacement for Twill/Selenium or
93 93
     the like - it is here to allow testing against the
94 94
     contexts and templates produced by a view, rather than the
@@ -98,10 +98,10 @@ def __init__(self, **defaults):
98 98
         self.handler = ClientHandler()
99 99
         self.defaults = defaults
100 100
         self.cookie = SimpleCookie()
101  
-        
  101
+
102 102
     def request(self, **request):
103 103
         """
104  
-        The master request method. Composes the environment dictionary 
  104
+        The master request method. Composes the environment dictionary
105 105
         and passes to the handler, returning the result of the handler.
106 106
         Assumes defaults for the query environment, which can be overridden
107 107
         using the arguments to the request.
@@ -112,24 +112,24 @@ def request(self, **request):
112 112
             'PATH_INFO':         '/',
113 113
             'QUERY_STRING':      '',
114 114
             'REQUEST_METHOD':    'GET',
115  
-            'SCRIPT_NAME':       None, 
  115
+            'SCRIPT_NAME':       None,
116 116
             'SERVER_NAME':       'testserver',
117 117
             'SERVER_PORT':       80,
118 118
             'SERVER_PROTOCOL':   'HTTP/1.1',
119  
-        }        
  119
+        }
120 120
         environ.update(self.defaults)
121  
-        environ.update(request)        
  121
+        environ.update(request)
122 122
 
123 123
         # Curry a data dictionary into an instance of
124 124
         # the template renderer callback function
125 125
         data = {}
126 126
         on_template_render = curry(store_rendered_templates, data)
127 127
         dispatcher.connect(on_template_render, signal=signals.template_rendered)
128  
-        
  128
+
129 129
         response = self.handler(environ)
130  
-        
  130
+
131 131
         # Add any rendered template detail to the response
132  
-        # If there was only one template rendered (the most likely case), 
  132
+        # If there was only one template rendered (the most likely case),
133 133
         # flatten the list to a single element
134 134
         for detail in ('template', 'context'):
135 135
             if data.get(detail):
@@ -139,12 +139,12 @@ def request(self, **request):
139 139
                     setattr(response, detail, data[detail])
140 140
             else:
141 141
                 setattr(response, detail, None)
142  
-        
  142
+
143 143
         if response.cookies:
144 144
             self.cookie.update(response.cookies)
145 145
 
146 146
         return response
147  
-        
  147
+
148 148
     def get(self, path, data={}, **extra):
149 149
         "Request a response from the server using GET."
150 150
         r = {
@@ -155,12 +155,12 @@ def get(self, path, data={}, **extra):
155 155
             'REQUEST_METHOD': 'GET',
156 156
         }
157 157
         r.update(extra)
158  
-        
  158
+
159 159
         return self.request(**r)
160  
-    
  160
+
161 161
     def post(self, path, data={}, **extra):
162 162
         "Request a response from the server using POST."
163  
-        
  163
+
164 164
         BOUNDARY = 'BoUnDaRyStRiNg'
165 165
 
166 166
         encoded = encode_multipart(BOUNDARY, data)
@@ -173,25 +173,25 @@ def post(self, path, data={}, **extra):
173 173
             'wsgi.input':     stream,
174 174
         }
175 175
         r.update(extra)
176  
-        
  176
+
177 177
         return self.request(**r)
178 178
 
179 179
     def login(self, path, username, password, **extra):
180 180
         """
181 181
         A specialized sequence of GET and POST to log into a view that
182 182
         is protected by a @login_required access decorator.
183  
-        
  183
+
184 184
         path should be the URL of the page that is login protected.
185  
-        
186  
-        Returns the response from GETting the requested URL after 
  185
+
  186
+        Returns the response from GETting the requested URL after
187 187
         login is complete. Returns False if login process failed.
188 188
         """
189  
-        # First, GET the page that is login protected. 
  189
+        # First, GET the page that is login protected.
190 190
         # This page will redirect to the login page.
191 191
         response = self.get(path)
192 192
         if response.status_code != 302:
193 193
             return False
194  
-            
  194
+
195 195
         login_path, data = response['Location'].split('?')
196 196
         next = data.split('=')[1]
197 197
 
@@ -199,7 +199,7 @@ def login(self, path, username, password, **extra):
199 199
         response = self.get(login_path, **extra)
200 200
         if response.status_code != 200:
201 201
             return False
202  
-            
  202
+
203 203
         # Last, POST the login data.
204 204
         form_data = {
205 205
             'username': username,

0 notes on commit 15e7805

Please sign in to comment.
Something went wrong with that request. Please try again.