mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	[1.5.x] Fixed #19487 -- Used str in the test client's WSGI environ.
This regression was introduced by the unicode_literals patch. The WSGI
spec mandates that environ contains native strings.
Backport of d9a0b6a.
			
			
This commit is contained in:
		| @@ -21,7 +21,7 @@ from django.http import SimpleCookie, HttpRequest, QueryDict | ||||
| from django.template import TemplateDoesNotExist | ||||
| from django.test import signals | ||||
| from django.utils.functional import curry | ||||
| from django.utils.encoding import force_bytes | ||||
| from django.utils.encoding import force_bytes, force_str | ||||
| from django.utils.http import urlencode | ||||
| from django.utils.importlib import import_module | ||||
| from django.utils.itercompat import is_iterable | ||||
| @@ -205,15 +205,15 @@ class RequestFactory(object): | ||||
|         # See http://www.python.org/dev/peps/pep-3333/#environ-variables | ||||
|         environ = { | ||||
|             'HTTP_COOKIE':       self.cookies.output(header='', sep='; '), | ||||
|             'PATH_INFO':         '/', | ||||
|             'REMOTE_ADDR':       '127.0.0.1', | ||||
|             'REQUEST_METHOD':    'GET', | ||||
|             'SCRIPT_NAME':       '', | ||||
|             'SERVER_NAME':       'testserver', | ||||
|             'SERVER_PORT':       '80', | ||||
|             'SERVER_PROTOCOL':   'HTTP/1.1', | ||||
|             'PATH_INFO':         str('/'), | ||||
|             'REMOTE_ADDR':       str('127.0.0.1'), | ||||
|             'REQUEST_METHOD':    str('GET'), | ||||
|             'SCRIPT_NAME':       str(''), | ||||
|             'SERVER_NAME':       str('testserver'), | ||||
|             'SERVER_PORT':       str('80'), | ||||
|             'SERVER_PROTOCOL':   str('HTTP/1.1'), | ||||
|             'wsgi.version':      (1, 0), | ||||
|             'wsgi.url_scheme':   'http', | ||||
|             'wsgi.url_scheme':   str('http'), | ||||
|             'wsgi.input':        FakePayload(b''), | ||||
|             'wsgi.errors':       self.errors, | ||||
|             'wsgi.multiprocess': True, | ||||
| @@ -241,21 +241,21 @@ class RequestFactory(object): | ||||
|             return force_bytes(data, encoding=charset) | ||||
|  | ||||
|     def _get_path(self, parsed): | ||||
|         path = force_str(parsed[2]) | ||||
|         # If there are parameters, add them | ||||
|         if parsed[3]: | ||||
|             return unquote(parsed[2] + ";" + parsed[3]) | ||||
|         else: | ||||
|             return unquote(parsed[2]) | ||||
|             path += str(";") + force_str(parsed[3]) | ||||
|         return unquote(path) | ||||
|  | ||||
|     def get(self, path, data={}, **extra): | ||||
|         "Construct a GET request." | ||||
|  | ||||
|         parsed = urlparse(path) | ||||
|         r = { | ||||
|             'CONTENT_TYPE':    'text/html; charset=utf-8', | ||||
|             'CONTENT_TYPE':    str('text/html; charset=utf-8'), | ||||
|             'PATH_INFO':       self._get_path(parsed), | ||||
|             'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4], | ||||
|             'REQUEST_METHOD': 'GET', | ||||
|             'QUERY_STRING':    urlencode(data, doseq=True) or force_str(parsed[4]), | ||||
|             'REQUEST_METHOD':  str('GET'), | ||||
|         } | ||||
|         r.update(extra) | ||||
|         return self.request(**r) | ||||
| @@ -271,8 +271,8 @@ class RequestFactory(object): | ||||
|             'CONTENT_LENGTH': len(post_data), | ||||
|             'CONTENT_TYPE':   content_type, | ||||
|             'PATH_INFO':      self._get_path(parsed), | ||||
|             'QUERY_STRING':   parsed[4], | ||||
|             'REQUEST_METHOD': 'POST', | ||||
|             'QUERY_STRING':   force_str(parsed[4]), | ||||
|             'REQUEST_METHOD': str('POST'), | ||||
|             'wsgi.input':     FakePayload(post_data), | ||||
|         } | ||||
|         r.update(extra) | ||||
| @@ -283,10 +283,10 @@ class RequestFactory(object): | ||||
|  | ||||
|         parsed = urlparse(path) | ||||
|         r = { | ||||
|             'CONTENT_TYPE':    'text/html; charset=utf-8', | ||||
|             'CONTENT_TYPE':    str('text/html; charset=utf-8'), | ||||
|             'PATH_INFO':       self._get_path(parsed), | ||||
|             'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4], | ||||
|             'REQUEST_METHOD': 'HEAD', | ||||
|             'QUERY_STRING':    urlencode(data, doseq=True) or force_str(parsed[4]), | ||||
|             'REQUEST_METHOD':  str('HEAD'), | ||||
|         } | ||||
|         r.update(extra) | ||||
|         return self.request(**r) | ||||
| @@ -312,13 +312,13 @@ class RequestFactory(object): | ||||
|         data = force_bytes(data, settings.DEFAULT_CHARSET) | ||||
|         r = { | ||||
|             'PATH_INFO':      self._get_path(parsed), | ||||
|             'QUERY_STRING':   parsed[4], | ||||
|             'REQUEST_METHOD': method, | ||||
|             'QUERY_STRING':   force_str(parsed[4]), | ||||
|             'REQUEST_METHOD': str(method), | ||||
|         } | ||||
|         if data: | ||||
|             r.update({ | ||||
|                 'CONTENT_LENGTH': len(data), | ||||
|                 'CONTENT_TYPE':   content_type, | ||||
|                 'CONTENT_TYPE':   str(content_type), | ||||
|                 'wsgi.input':     FakePayload(data), | ||||
|             }) | ||||
|         r.update(extra) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user