Django

Code

Changeset 5874

Show
Ignore:
Timestamp:
08/12/07 07:02:08 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4947 -- Avoid displaying uploaded file contents in the debug web page. Based on a patch from eibaan@gmail.com.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r5868 r5874  
    102102    Andy Dustman <farcepest@gmail.com> 
    103103    Clint Ecker 
     104    eibaan@gmail.com 
    104105    enlight 
    105106    Enrico <rico.bl@gmail.com> 
  • django/trunk/django/http/__init__.py

    r5873 r5874  
    33from pprint import pformat 
    44from urllib import urlencode 
    5 from django.utils.datastructures import MultiValueDict 
     5from django.utils.datastructures import MultiValueDict, FileDict 
    66from django.utils.encoding import smart_str, iri_to_uri, force_unicode 
    77 
     
    8989                # client's one.) 
    9090                filename = name_dict['filename'][name_dict['filename'].rfind("\\")+1:] 
    91                 FILES.appendlist(name_dict['name'],
     91                FILES.appendlist(name_dict['name'], FileDict(
    9292                    'filename': filename, 
    9393                    'content-type': 'Content-Type' in submessage and submessage['Content-Type'] or None, 
    9494                    'content': submessage.get_payload(), 
    95                 }) 
     95                })) 
    9696            else: 
    9797                POST.appendlist(name_dict['name'], submessage.get_payload()) 
  • django/trunk/django/utils/datastructures.py

    r5091 r5874  
    268268            except TypeError: # Special-case if current isn't a dict. 
    269269                current = {bits[-1] : v} 
     270 
     271class FileDict(dict): 
     272    """ 
     273    A dictionary used to hold uploaded file contents. The only special feature 
     274    here is that repr() of this object won't dump the entire contents of the 
     275    file to the output. A handy safeguard for a large file upload. 
     276    """ 
     277    def __repr__(self): 
     278        if 'content' in self: 
     279            d = dict(self, content='<omitted>') 
     280            return dict.__repr__(d) 
     281        return dict.__repr__(self) 
     282 
  • django/trunk/tests/regressiontests/datastructures/tests.py

    r5069 r5874  
    6565>>> d['person']['2']['firstname'] 
    6666['Adrian'] 
     67 
     68### FileDict ################################################################ 
     69 
     70>>> d = FileDict({'content': 'once upon a time...'}) 
     71>>> repr(d) 
     72"{'content': '<omitted>'}" 
     73>>> d = FileDict({'other-key': 'once upon a time...'}) 
     74>>> repr(d) 
     75"{'other-key': 'once upon a time...'}" 
    6776"""