Author: mtredinnick
Date: 2007-08-12 07:02:08 -0500 (Sun, 12 Aug 2007)
New Revision: 5874

Modified:
   django/trunk/AUTHORS
   django/trunk/django/http/__init__.py
   django/trunk/django/utils/datastructures.py
   django/trunk/tests/regressiontests/datastructures/tests.py
Log:
Fixed #4947 -- Avoid displaying uploaded file contents in the debug web page. 
Based on a patch from [EMAIL PROTECTED]


Modified: django/trunk/AUTHORS
===================================================================
--- django/trunk/AUTHORS        2007-08-12 12:01:31 UTC (rev 5873)
+++ django/trunk/AUTHORS        2007-08-12 12:02:08 UTC (rev 5874)
@@ -101,6 +101,7 @@
     [EMAIL PROTECTED]
     Andy Dustman <[EMAIL PROTECTED]>
     Clint Ecker
+    [EMAIL PROTECTED]
     enlight
     Enrico <[EMAIL PROTECTED]>
     A. Murat Eren <[EMAIL PROTECTED]>

Modified: django/trunk/django/http/__init__.py
===================================================================
--- django/trunk/django/http/__init__.py        2007-08-12 12:01:31 UTC (rev 
5873)
+++ django/trunk/django/http/__init__.py        2007-08-12 12:02:08 UTC (rev 
5874)
@@ -2,7 +2,7 @@
 from Cookie import SimpleCookie
 from pprint import pformat
 from urllib import urlencode
-from django.utils.datastructures import MultiValueDict
+from django.utils.datastructures import MultiValueDict, FileDict
 from django.utils.encoding import smart_str, iri_to_uri, force_unicode
 
 RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
@@ -88,11 +88,11 @@
                 # directory separator, which may not be the same as the
                 # client's one.)
                 filename = 
name_dict['filename'][name_dict['filename'].rfind("\\")+1:]
-                FILES.appendlist(name_dict['name'], {
+                FILES.appendlist(name_dict['name'], FileDict({
                     'filename': filename,
                     'content-type': 'Content-Type' in submessage and 
submessage['Content-Type'] or None,
                     'content': submessage.get_payload(),
-                })
+                }))
             else:
                 POST.appendlist(name_dict['name'], submessage.get_payload())
     return POST, FILES

Modified: django/trunk/django/utils/datastructures.py
===================================================================
--- django/trunk/django/utils/datastructures.py 2007-08-12 12:01:31 UTC (rev 
5873)
+++ django/trunk/django/utils/datastructures.py 2007-08-12 12:02:08 UTC (rev 
5874)
@@ -267,3 +267,16 @@
                 current[bits[-1]] = v
             except TypeError: # Special-case if current isn't a dict.
                 current = {bits[-1] : v}
+
+class FileDict(dict):
+    """
+    A dictionary used to hold uploaded file contents. The only special feature
+    here is that repr() of this object won't dump the entire contents of the
+    file to the output. A handy safeguard for a large file upload.
+    """
+    def __repr__(self):
+        if 'content' in self:
+            d = dict(self, content='<omitted>')
+            return dict.__repr__(d)
+        return dict.__repr__(self)
+

Modified: django/trunk/tests/regressiontests/datastructures/tests.py
===================================================================
--- django/trunk/tests/regressiontests/datastructures/tests.py  2007-08-12 
12:01:31 UTC (rev 5873)
+++ django/trunk/tests/regressiontests/datastructures/tests.py  2007-08-12 
12:02:08 UTC (rev 5874)
@@ -64,4 +64,13 @@
 ['Holovaty']
 >>> d['person']['2']['firstname']
 ['Adrian']
+
+### FileDict ################################################################
+
+>>> d = FileDict({'content': 'once upon a time...'})
+>>> repr(d)
+"{'content': '<omitted>'}"
+>>> d = FileDict({'other-key': 'once upon a time...'})
+>>> repr(d)
+"{'other-key': 'once upon a time...'}"
 """


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to