Show More
@@ -29,7 +29,11 b' class TemplateNotFound(error.Abort):' | |||
|
29 | 29 | |
|
30 | 30 | class wrapped(object): |
|
31 | 31 | """Object requiring extra conversion prior to displaying or processing |
|
32 |
as value |
|
|
32 | as value | |
|
33 | ||
|
34 | Use unwrapvalue(), unwrapastype(), or unwraphybrid() to obtain the inner | |
|
35 | object. | |
|
36 | """ | |
|
33 | 37 | |
|
34 | 38 | __metaclass__ = abc.ABCMeta |
|
35 | 39 | |
@@ -42,6 +46,13 b' class wrapped(object):' | |||
|
42 | 46 | not printable. |
|
43 | 47 | """ |
|
44 | 48 | |
|
49 | @abc.abstractmethod | |
|
50 | def tovalue(self, context, mapping): | |
|
51 | """Move the inner value object out or create a value representation | |
|
52 | ||
|
53 | A returned value must be serializable by templaterfilters.json(). | |
|
54 | """ | |
|
55 | ||
|
45 | 56 | # stub for representing a date type; may be a real date type that can |
|
46 | 57 | # provide a readable string value |
|
47 | 58 | class date(object): |
@@ -85,6 +96,10 b' class hybrid(wrapped):' | |||
|
85 | 96 | return gen() |
|
86 | 97 | return gen |
|
87 | 98 | |
|
99 | def tovalue(self, context, mapping): | |
|
100 | # TODO: return self._values and get rid of proxy methods | |
|
101 | return self | |
|
102 | ||
|
88 | 103 | def __contains__(self, x): |
|
89 | 104 | return x in self._values |
|
90 | 105 | def __getitem__(self, key): |
@@ -108,8 +123,7 b' class mappable(wrapped):' | |||
|
108 | 123 | - "{manifest.rev}" |
|
109 | 124 | |
|
110 | 125 | Unlike a hybrid, this does not simulate the behavior of the underling |
|
111 | value. Use unwrapvalue(), unwrapastype(), or unwraphybrid() to obtain | |
|
112 | the inner object. | |
|
126 | value. | |
|
113 | 127 | """ |
|
114 | 128 | |
|
115 | 129 | def __init__(self, gen, key, value, makemap): |
@@ -133,6 +147,9 b' class mappable(wrapped):' | |||
|
133 | 147 | return gen() |
|
134 | 148 | return gen |
|
135 | 149 | |
|
150 | def tovalue(self, context, mapping): | |
|
151 | return _unthunk(context, mapping, self._value) | |
|
152 | ||
|
136 | 153 | def hybriddict(data, key='key', value='value', fmt=None, gen=None): |
|
137 | 154 | """Wrap data to support both dict-like and string-like operations""" |
|
138 | 155 | prefmt = pycompat.identity |
@@ -159,9 +176,9 b' def unwraphybrid(context, mapping, thing' | |||
|
159 | 176 | |
|
160 | 177 | def unwrapvalue(context, mapping, thing): |
|
161 | 178 | """Move the inner value object out of the wrapper""" |
|
162 |
if not |
|
|
179 | if not isinstance(thing, wrapped): | |
|
163 | 180 | return thing |
|
164 |
return thing. |
|
|
181 | return thing.tovalue(context, mapping) | |
|
165 | 182 | |
|
166 | 183 | def wraphybridvalue(container, key, value): |
|
167 | 184 | """Wrap an element of hybrid container to be mappable |
General Comments 0
You need to be logged in to leave comments.
Login now