summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/core/validators.py5
-rw-r--r--django/utils/functional.py10
2 files changed, 12 insertions, 3 deletions
diff --git a/django/core/validators.py b/django/core/validators.py
index b68fc0ade8..9889fadfd1 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -27,6 +27,7 @@ url_re = re.compile(r'^http://\S+$')
from django.conf.settings import JING_PATH
from django.utils.translation import gettext_lazy, ngettext
+from django.utils.functional import Promise
class ValidationError(Exception):
def __init__(self, message):
@@ -34,7 +35,7 @@ class ValidationError(Exception):
if isinstance(message, list):
self.messages = message
else:
- assert isinstance(message, basestring), ("%s should be a string" % repr(message))
+ assert isinstance(message, (basestring, Promise)), ("%s should be a string" % repr(message))
self.messages = [message]
def __str__(self):
# This is needed because, without a __str__(), printing an exception
@@ -49,7 +50,7 @@ class CriticalValidationError(Exception):
if isinstance(message, list):
self.messages = message
else:
- assert isinstance(message, basestring), ("'%s' should be a string" % message)
+ assert isinstance(message, (basestring, Promise)), ("'%s' should be a string" % message)
self.messages = [message]
def __str__(self):
return str(self.messages)
diff --git a/django/utils/functional.py b/django/utils/functional.py
index f2ea12b1b2..69aeb81850 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -3,6 +3,14 @@ def curry(*args, **kwargs):
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))
return _curried
+class Promise:
+ """
+ This is just a base class for the proxy class created in
+ the closure of the lazy function. It can be used to recognize
+ promises in code.
+ """
+ pass
+
def lazy(func, *resultclasses):
"""
Turns any callable into a lazy evaluated callable. You need to give result
@@ -10,7 +18,7 @@ def lazy(func, *resultclasses):
the lazy evaluation code is triggered. Results are not memoized; the
function is evaluated on every access.
"""
- class __proxy__:
+ class __proxy__(Promise):
# This inner class encapsulates the code that should be evaluated
# lazily. On calling of one of the magic methods it will force
# the evaluation and store the result. Afterwards, the result