Ticket #5076: django_request_charset.2.diff
File django_request_charset.2.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 if self.META.has_key('CONTENT_TYPE'): 56 ct = self.META['CONTENT_TYPE'] 57 ct.lower() 58 ct.replace(' ', '') 59 i = ct.find('charset') 60 if i > 0: 61 self._encoding = ct[i+8:] 62 63 50 64 def _set_encoding(self, val): 51 65 """ 52 66 Sets the encoding used for GET/POST accesses. If the GET or POST … … 112 126 encoding = settings.DEFAULT_CHARSET 113 127 self.encoding = encoding 114 128 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')) 129 130 try: 131 for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True 132 self.appendlist(force_unicode(key, encoding, errors='strict'), force_unicode(value, encoding, errors='strict')) 133 except UnicodeDecodeError: 134 # cp1252 (Windows-1252) is ISO-8850-1 (latin-1) with additional 135 # common characters defined, this is chosen over latin-1 since 136 # most browsers say latin-1 when they really use Windows-1252 137 encoding = 'cp1252' 138 self.encoding = encoding 139 for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True 140 self.appendlist(force_unicode(key, encoding, errors='replace'), force_unicode(value, encoding, errors='replace')) 117 141 self._mutable = mutable 118 142 119 143 def _assert_mutable(self): 120 144 if not self._mutable: 121 145 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