Ticket #5076: django_request_charset.diff
File django_request_charset.diff, 2.6 KB (added by , 17 years ago) |
---|
-
django/http/__init__.py
47 47 def is_secure(self): 48 48 return os.environ.get("HTTPS") == "on" 49 49 50 def detect_charset(self): 51 """ 52 Try to determine the encoding of the data by examining the 53 Content-Type header. To be called by classes inheriting HttpRequest. 54 """ 55 ct = self.META['CONTENT_TYPE'] 56 ct.lower() 57 ct.replace(' ', '') 58 i = ct.find('charset') 59 if i > 0: 60 self._encoding = ct[i+8:] 61 62 50 63 def _set_encoding(self, val): 51 64 """ 52 65 Sets the encoding used for GET/POST accesses. If the GET or POST … … 112 125 encoding = settings.DEFAULT_CHARSET 113 126 self.encoding = encoding 114 127 self._mutable = True 115 for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True 116 self.appendlist(force_unicode(key, encoding, errors='replace'), force_unicode(value, encoding, errors='replace')) 128 129 try: 130 for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True 131 self.appendlist(force_unicode(key, encoding, errors='strict'), force_unicode(value, encoding, errors='strict')) 132 except UnicodeDecodeError: 133 # cp1252 (Windows-1252) is ISO-8850-1 (latin-1) with additional 134 # common characters defined, this is chosen over latin-1 since 135 # most browsers say latin-1 when they really use Windows-1252 136 encoding = 'cp1252' 137 self.encoding = encoding 138 for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True 139 self.appendlist(force_unicode(key, encoding, errors='replace'), force_unicode(value, encoding, errors='replace')) 117 140 self._mutable = mutable 118 141 119 142 def _assert_mutable(self): 120 143 if not self._mutable: 121 144 raise AttributeError, "This QueryDict instance is immutable" -
django/core/handlers/wsgi.py
77 77 self.path = force_unicode(environ['PATH_INFO']) 78 78 self.META = environ 79 79 self.method = environ['REQUEST_METHOD'].upper() 80 self.detect_charset() 80 81 81 82 def __repr__(self): 82 83 # Since this is called as part of error handling, we need to be very