Show More
@@ -176,10 +176,10 b' class baseformatter(object):' | |||
|
176 | 176 | def formatdate(self, date, fmt='%a %b %d %H:%M:%S %Y %1%2'): |
|
177 | 177 | '''convert date tuple to appropriate format''' |
|
178 | 178 | return self._converter.formatdate(date, fmt) |
|
179 |
def formatdict(self, data, key='key', value='value', fmt= |
|
|
179 | def formatdict(self, data, key='key', value='value', fmt=None, sep=' '): | |
|
180 | 180 | '''convert dict or key-value pairs to appropriate dict format''' |
|
181 | 181 | return self._converter.formatdict(data, key, value, fmt, sep) |
|
182 |
def formatlist(self, data, name, fmt= |
|
|
182 | def formatlist(self, data, name, fmt=None, sep=' '): | |
|
183 | 183 | '''convert iterable to appropriate list format''' |
|
184 | 184 | # name is mandatory argument for now, but it could be optional if |
|
185 | 185 | # we have default template keyword, e.g. {item} |
@@ -248,10 +248,14 b' class _plainconverter(object):' | |||
|
248 | 248 | @staticmethod |
|
249 | 249 | def formatdict(data, key, value, fmt, sep): |
|
250 | 250 | '''stringify key-value pairs separated by sep''' |
|
251 | if fmt is None: | |
|
252 | fmt = '%s=%s' | |
|
251 | 253 | return sep.join(fmt % (k, v) for k, v in _iteritems(data)) |
|
252 | 254 | @staticmethod |
|
253 | 255 | def formatlist(data, name, fmt, sep): |
|
254 | 256 | '''stringify iterable separated by sep''' |
|
257 | if fmt is None: | |
|
258 | fmt = '%s' | |
|
255 | 259 | return sep.join(fmt % e for e in data) |
|
256 | 260 | |
|
257 | 261 | class plainformatter(baseformatter): |
@@ -97,13 +97,17 b' class _mappable(object):' | |||
|
97 | 97 | def itermaps(self): |
|
98 | 98 | yield self.tomap() |
|
99 | 99 | |
|
100 |
def hybriddict(data, key='key', value='value', fmt= |
|
|
100 | def hybriddict(data, key='key', value='value', fmt=None, gen=None): | |
|
101 | 101 | """Wrap data to support both dict-like and string-like operations""" |
|
102 | if fmt is None: | |
|
103 | fmt = '%s=%s' | |
|
102 | 104 | return _hybrid(gen, data, lambda k: {key: k, value: data[k]}, |
|
103 | 105 | lambda k: fmt % (k, data[k])) |
|
104 | 106 | |
|
105 |
def hybridlist(data, name, fmt= |
|
|
107 | def hybridlist(data, name, fmt=None, gen=None): | |
|
106 | 108 | """Wrap data to support both list-like and string-like operations""" |
|
109 | if fmt is None: | |
|
110 | fmt = '%s' | |
|
107 | 111 | return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % x) |
|
108 | 112 | |
|
109 | 113 | def unwraphybrid(thing): |
@@ -137,7 +141,7 b' def wraphybridvalue(container, key, valu' | |||
|
137 | 141 | return _mappable(None, key, value, makemap) |
|
138 | 142 | |
|
139 | 143 | def compatdict(context, mapping, name, data, key='key', value='value', |
|
140 |
fmt= |
|
|
144 | fmt=None, plural=None, separator=' '): | |
|
141 | 145 | """Wrap data like hybriddict(), but also supports old-style list template |
|
142 | 146 | |
|
143 | 147 | This exists for backward compatibility with the old-style template. Use |
@@ -148,7 +152,7 b' def compatdict(context, mapping, name, d' | |||
|
148 | 152 | f = _showlist(name, c, t, mapping, plural, separator) |
|
149 | 153 | return hybriddict(data, key=key, value=value, fmt=fmt, gen=f) |
|
150 | 154 | |
|
151 |
def compatlist(context, mapping, name, data, element=None, fmt= |
|
|
155 | def compatlist(context, mapping, name, data, element=None, fmt=None, | |
|
152 | 156 | plural=None, separator=' '): |
|
153 | 157 | """Wrap data like hybridlist(), but also supports old-style list template |
|
154 | 158 | |
@@ -160,7 +164,7 b' def compatlist(context, mapping, name, d' | |||
|
160 | 164 | return hybridlist(data, name=element or name, fmt=fmt, gen=f) |
|
161 | 165 | |
|
162 | 166 | def showdict(name, data, mapping, plural=None, key='key', value='value', |
|
163 |
fmt= |
|
|
167 | fmt=None, separator=' '): | |
|
164 | 168 | ui = mapping.get('ui') |
|
165 | 169 | if ui: |
|
166 | 170 | ui.deprecwarn("templatekw.showdict() is deprecated, use compatdict()", |
General Comments 0
You need to be logged in to leave comments.
Login now