Show More
@@ -321,8 +321,8 b' class _templateconverter(object):' | |||||
321 | data = util.sortdict(_iteritems(data)) |
|
321 | data = util.sortdict(_iteritems(data)) | |
322 | def f(): |
|
322 | def f(): | |
323 | yield _plainconverter.formatdict(data, key, value, fmt, sep) |
|
323 | yield _plainconverter.formatdict(data, key, value, fmt, sep) | |
324 |
return templatekw. |
|
324 | return templatekw.hybriddict(data, key=key, value=value, fmt=fmt, | |
325 |
|
|
325 | gen=f()) | |
326 | @staticmethod |
|
326 | @staticmethod | |
327 | def formatlist(data, name, fmt, sep): |
|
327 | def formatlist(data, name, fmt, sep): | |
328 | '''build object that can be evaluated as either plain string or list''' |
|
328 | '''build object that can be evaluated as either plain string or list''' |
@@ -62,6 +62,11 b' class _hybrid(object):' | |||||
62 | raise AttributeError(name) |
|
62 | raise AttributeError(name) | |
63 | return getattr(self._values, name) |
|
63 | return getattr(self._values, name) | |
64 |
|
64 | |||
|
65 | def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None): | |||
|
66 | """Wrap data to support both dict-like and string-like operations""" | |||
|
67 | return _hybrid(gen, data, lambda k: {key: k, value: data[k]}, | |||
|
68 | lambda d: fmt % (d[key], d[value])) | |||
|
69 | ||||
65 | def hybridlist(data, name, fmt='%s', gen=None): |
|
70 | def hybridlist(data, name, fmt='%s', gen=None): | |
66 | """Wrap data to support both list-like and string-like operations""" |
|
71 | """Wrap data to support both list-like and string-like operations""" | |
67 | return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name]) |
|
72 | return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name]) |
General Comments 0
You need to be logged in to leave comments.
Login now