Ticket #17235: t17235.patch
File t17235.patch, 3.7 KB (added by , 12 years ago) |
---|
-
django/http/multipartparser.py
diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py index 070874f..fa11488 100644
a b import cgi 11 11 12 12 from django.conf import settings 13 13 from django.core.exceptions import SuspiciousOperation 14 from django.utils.datastructures import MultiValueDict14 from django.utils.datastructures import ImmutableMultiValueDict 15 15 from django.utils.encoding import force_text 16 16 from django.utils import six 17 17 from django.utils.text import unescape_entities … … class MultiPartParser(object): 110 110 # HTTP spec says that Content-Length >= 0 is valid 111 111 # handling content-length == 0 before continuing 112 112 if self._content_length == 0: 113 return QueryDict('', encoding=self._encoding),MultiValueDict()113 return QueryDict('', mutable=True, encoding=self._encoding), ImmutableMultiValueDict() 114 114 115 115 # See if the handler will want to take care of the parsing. 116 116 # This allows overriding everything if somebody wants it. … … class MultiPartParser(object): 125 125 126 126 # Create the data structures to be used later. 127 127 self._post = QueryDict('', mutable=True) 128 self._files = MultiValueDict()128 self._files = ImmutableMultiValueDict(mutable=True) 129 129 130 130 # Instantiate the parser and stream: 131 131 stream = LazyStream(ChunkIter(self._input_data, self._chunk_size)) … … class MultiPartParser(object): 242 242 if retval: 243 243 break 244 244 245 self._post._mutable = self._files._mutable = False 246 245 247 return self._post, self._files 246 248 247 249 def handle_file_complete(self, old_field_name, counters): -
django/utils/datastructures.py
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index 64c218f..a8652cd 100644
a b class MultiValueDict(dict): 443 443 return dict((key, self[key]) for key in self) 444 444 445 445 446 class ImmutableMultiValueDict(MultiValueDict): 447 _mutbale = False 448 449 def __init__(self, key_to_list_mapping=(), mutable=False): 450 super(ImmutableMultiValueDict, self).__init__(key_to_list_mapping) 451 self._mutable = mutable 452 453 def _assert_mutable(self): 454 if not self._mutable: 455 raise AttributeError("This ImmutableMultiValueDict instance is immutable") 456 457 def __setitem__(self, key, value): 458 self._assert_mutable() 459 super(ImmutableMultiValueDict, self).__setitem__(key, value) 460 461 def __delitem__(self, key): 462 self._assert_mutable() 463 super(ImmutableMultiValueDict, self).__delitem__(key) 464 465 def setlist(self, key, list_): 466 self._assert_mutable() 467 super(ImmutableMultiValueDict, self).setlist(key, list_) 468 469 def setlistdefault(self, key, default_list=None): 470 self._assert_mutable() 471 return super(ImmutableMultiValueDict, self).setlistdefault(key, default_list) 472 473 def appendlist(self, key, value): 474 self._assert_mutable() 475 super(ImmutableMultiValueDict, self).appendlist(key, value) 476 477 def pop(self, key, *args): 478 self._assert_mutable() 479 return super(ImmutableMultiValueDict, self).pop(key, *args) 480 481 def popitem(self): 482 self._assert_mutable() 483 return super(ImmutableMultiValueDict, self).popitem() 484 485 def clear(self): 486 self._assert_mutable() 487 super(ImmutableMultiValueDict, self).clear() 488 489 def setdefault(self, key, default=None): 490 self._assert_mutable() 491 return super(ImmutableMultiValueDict, self).setdefault(key, default) 492 493 446 494 class ImmutableList(tuple): 447 495 """ 448 496 A tuple-like object that raises useful errors when it is asked to mutate.