From f433a63c9958124ba4e955e42cb1b8c1eeb8fae6 Mon Sep 17 00:00:00 2001
From: Denver Coneybeare <denver@sleepydragon.org>
Date: Tue, 7 Jan 2014 00:17:10 -0500
Subject: [PATCH] django/test/client.py: replace mutable default arguments with
immutable objects (ie. the None object)
---
django/test/client.py | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/django/test/client.py b/django/test/client.py
index 9197a5a..11b9b23 100644
a
|
b
|
class RequestFactory(object):
|
277 | 277 | path = path.encode('utf-8').decode('iso-8859-1') |
278 | 278 | return path |
279 | 279 | |
280 | | def get(self, path, data={}, secure=False, **extra): |
| 280 | def get(self, path, data=None, secure=False, **extra): |
281 | 281 | "Construct a GET request." |
282 | 282 | |
| 283 | if data is None: |
| 284 | data = {} |
| 285 | |
283 | 286 | r = { |
284 | 287 | 'QUERY_STRING': urlencode(data, doseq=True), |
285 | 288 | } |
286 | 289 | r.update(extra) |
287 | 290 | return self.generic('GET', path, secure=secure, **r) |
288 | 291 | |
289 | | def post(self, path, data={}, content_type=MULTIPART_CONTENT, |
| 292 | def post(self, path, data=None, content_type=MULTIPART_CONTENT, |
290 | 293 | secure=False, **extra): |
291 | 294 | "Construct a POST request." |
292 | 295 | |
| 296 | if data is None: |
| 297 | data = {} |
| 298 | |
293 | 299 | post_data = self._encode_data(data, content_type) |
294 | 300 | |
295 | 301 | return self.generic('POST', path, post_data, content_type, |
296 | 302 | secure=secure, **extra) |
297 | 303 | |
298 | | def head(self, path, data={}, secure=False, **extra): |
| 304 | def head(self, path, data=None, secure=False, **extra): |
299 | 305 | "Construct a HEAD request." |
300 | 306 | |
| 307 | if data is None: |
| 308 | data = {} |
| 309 | |
301 | 310 | r = { |
302 | 311 | 'QUERY_STRING': urlencode(data, doseq=True), |
303 | 312 | } |
… |
… |
class Client(RequestFactory):
|
461 | 470 | signals.template_rendered.disconnect(dispatch_uid=signal_uid) |
462 | 471 | got_request_exception.disconnect(dispatch_uid="request-exception") |
463 | 472 | |
464 | | def get(self, path, data={}, follow=False, secure=False, **extra): |
| 473 | def get(self, path, data=None, follow=False, secure=False, **extra): |
465 | 474 | """ |
466 | 475 | Requests a response from the server using GET. |
467 | 476 | """ |
| 477 | if data is None: |
| 478 | data = {} |
| 479 | |
468 | 480 | response = super(Client, self).get(path, data=data, secure=secure, |
469 | 481 | **extra) |
470 | 482 | if follow: |
471 | 483 | response = self._handle_redirects(response, **extra) |
472 | 484 | return response |
473 | 485 | |
474 | | def post(self, path, data={}, content_type=MULTIPART_CONTENT, |
| 486 | def post(self, path, data=None, content_type=MULTIPART_CONTENT, |
475 | 487 | follow=False, secure=False, **extra): |
476 | 488 | """ |
477 | 489 | Requests a response from the server using POST. |
478 | 490 | """ |
| 491 | if data is None: |
| 492 | data = {} |
| 493 | |
479 | 494 | response = super(Client, self).post(path, data=data, |
480 | 495 | content_type=content_type, |
481 | 496 | secure=secure, **extra) |
… |
… |
class Client(RequestFactory):
|
483 | 498 | response = self._handle_redirects(response, **extra) |
484 | 499 | return response |
485 | 500 | |
486 | | def head(self, path, data={}, follow=False, secure=False, **extra): |
| 501 | def head(self, path, data=None, follow=False, secure=False, **extra): |
487 | 502 | """ |
488 | 503 | Request a response from the server using HEAD. |
489 | 504 | """ |
| 505 | if data is None: |
| 506 | data = {} |
| 507 | |
490 | 508 | response = super(Client, self).head(path, data=data, secure=secure, |
491 | 509 | **extra) |
492 | 510 | if follow: |