Django

Code

Show
Ignore:
Timestamp:
07/01/08 10:49:08 (6 months ago)
Author:
brosner
Message:

newforms-admin: Merged from trunk up to [7814].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin

    • Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7808 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7814
  • django/branches/newforms-admin/django/utils/datastructures.py

    r7770 r7815  
    333333                current = {bits[-1]: v} 
    334334 
    335 class FileDict(dict): 
    336     """ 
    337     A dictionary used to hold uploaded file contents. The only special feature 
    338     here is that repr() of this object won't dump the entire contents of the 
    339     file to the output. A handy safeguard for a large file upload. 
    340     """ 
    341     def __repr__(self): 
    342         if 'content' in self: 
    343             d = dict(self, content='<omitted>') 
    344             return dict.__repr__(d) 
    345         return dict.__repr__(self) 
     335class ImmutableList(tuple): 
     336    """ 
     337    A tuple-like object that raises useful errors when it is asked to mutate. 
     338 
     339    Example:: 
     340 
     341        >>> a = ImmutableList(range(5), warning="You cannot mutate this.") 
     342        >>> a[3] = '4' 
     343        Traceback (most recent call last): 
     344            ... 
     345        AttributeError: You cannot mutate this. 
     346    """ 
     347 
     348    def __new__(cls, *args, **kwargs): 
     349        if 'warning' in kwargs: 
     350            warning = kwargs['warning'] 
     351            del kwargs['warning'] 
     352        else: 
     353            warning = 'ImmutableList object is immutable.' 
     354        self = tuple.__new__(cls, *args, **kwargs) 
     355        self.warning = warning 
     356        return self 
     357 
     358    def complain(self, *wargs, **kwargs): 
     359        if isinstance(self.warning, Exception): 
     360            raise self.warning 
     361        else: 
     362            raise AttributeError, self.warning 
     363 
     364    # All list mutation functions complain. 
     365    __delitem__  = complain 
     366    __delslice__ = complain 
     367    __iadd__     = complain 
     368    __imul__     = complain 
     369    __setitem__  = complain 
     370    __setslice__ = complain 
     371    append       = complain 
     372    extend       = complain 
     373    insert       = complain 
     374    pop          = complain 
     375    remove       = complain 
     376    sort         = complain 
     377    reverse      = complain 
    346378 
    347379class DictWrapper(dict):