Code

Ticket #19160: 19160-poc.diff

File 19160-poc.diff, 1.0 KB (added by claudep, 18 months ago)

Proof of concept

Line 
1diff --git a/django/utils/functional.py b/django/utils/functional.py
2index 085a8fc..ad64802 100644
3--- a/django/utils/functional.py
4+++ b/django/utils/functional.py
5@@ -1,6 +1,8 @@
6 import copy
7+import inspect
8 import operator
9 from functools import wraps, update_wrapper
10+import re
11 import sys
12 
13 from django.utils import six
14@@ -153,6 +155,13 @@ def lazy(func, *resultclasses):
15         __hash__ = object.__hash__
16 
17         def __mod__(self, rhs):
18+            if len(inspect.getargspec(func)[0]) > len(self.__args) and isinstance(rhs, dict):
19+                # Complete missing argument by looking for '%(var)d' in rhs,
20+                # used mainly by ungettext_lazy
21+                m = re.search('%\(([^)]*)\)d', self.__args[0])
22+                key = m.groups()[0] if m else None
23+                if key and key in rhs:
24+                    self.__args = self.__args + (rhs[key],)
25             if self._delegate_bytes and not six.PY3:
26                 return bytes(self) % rhs
27             elif self._delegate_text: