Kaydet (Commit) 39814eeb authored tarafından Malcolm Tredinnick's avatar Malcolm Tredinnick

Fixed #5487 -- Added deepcopying ability to lazy() objects, along with a test to…

Fixed #5487 -- Added deepcopying ability to lazy() objects, along with a test to demonstrate why the previous code failed. Debugging and patch from John Buchanan.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6276 bcc190cf-cafb-0310-a4f2-bffc1f526a37
üst b984505d
import copy
def curry(_curried_func, *args, **kwargs): def curry(_curried_func, *args, **kwargs):
def _curried(*moreargs, **morekwargs): def _curried(*moreargs, **morekwargs):
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs)) return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
...@@ -101,6 +103,11 @@ def lazy(func, *resultclasses): ...@@ -101,6 +103,11 @@ def lazy(func, *resultclasses):
else: else:
raise AssertionError('__mod__ not supported for non-string types') raise AssertionError('__mod__ not supported for non-string types')
def __deepcopy__(self, memo):
result = copy.copy(self)
memo[id(self)] = result
return result
def __wrapper__(*args, **kw): def __wrapper__(*args, **kw):
# Creates the proxy object, instead of the actual value. # Creates the proxy object, instead of the actual value.
return __proxy__(args, kw) return __proxy__(args, kw)
......
...@@ -60,6 +60,12 @@ Translated error messages used to be buggy. ...@@ -60,6 +60,12 @@ Translated error messages used to be buggy.
u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>' u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
>>> deactivate() >>> deactivate()
Deep copying translated text shouldn't raise an error
>>> from django.utils.translation import gettext_lazy
>>> class CopyForm(Form):
... degree = IntegerField(widget=Select(choices=((1, gettext_lazy('test')),)))
>>> f = CopyForm()
####################### #######################
# Miscellaneous Tests # # Miscellaneous Tests #
####################### #######################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment