~ubuntu-branches/ubuntu/utopic/python-django/utopic

« back to all changes in this revision

Viewing changes to django/utils/functional.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-08-13 16:49:39 UTC
  • mfrom: (1.1.22) (4.4.28 sid)
  • Revision ID: package-import@ubuntu.com-20130813164939-ct6oweybhkuyq4tt
* New upstream security release.
  https://www.djangoproject.com/weblog/2013/aug/13/security-releases-issued/
  - Cross-site scripting (XSS) in admin interface
  - Possible XSS via is_safe_url

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import sys
5
5
 
6
6
from django.utils import six
 
7
from django.utils.six.moves import copyreg
 
8
 
7
9
 
8
10
# You can't trivially replace this `functools.partial` because this binds to
9
11
# classes and returns bound instances, whereas functools.partial (on CPython)
294
296
            self._setup()
295
297
        return self._wrapped.__dict__
296
298
 
297
 
    # Python 3.3 will call __reduce__ when pickling; these methods are needed
298
 
    # to serialize and deserialize correctly. They are not called in earlier
299
 
    # versions of Python.
 
299
    # Python 3.3 will call __reduce__ when pickling; this method is needed
 
300
    # to serialize and deserialize correctly.
300
301
    @classmethod
301
302
    def __newobj__(cls, *args):
302
303
        return cls.__new__(cls, *args)
303
304
 
304
 
    def __reduce__(self):
305
 
        return (self.__newobj__, (self.__class__,), self.__getstate__())
 
305
    def __reduce_ex__(self, proto):
 
306
        if proto >= 2:
 
307
            # On Py3, since the default protocol is 3, pickle uses the
 
308
            # ``__newobj__`` method (& more efficient opcodes) for writing.
 
309
            return (self.__newobj__, (self.__class__,), self.__getstate__())
 
310
        else:
 
311
            # On Py2, the default protocol is 0 (for back-compat) & the above
 
312
            # code fails miserably (see regression test). Instead, we return
 
313
            # exactly what's returned if there's no ``__reduce__`` method at
 
314
            # all.
 
315
            return (copyreg._reconstructor, (self.__class__, object, None), self.__getstate__())
306
316
 
307
317
    # Need to pretend to be the wrapped class, for the sake of objects that care
308
318
    # about this (especially in equality tests)