##// END OF EJS Templates
templater: byte-stringify dict/list values before passing to default format...
Yuya Nishihara -
r36652:cafd0586 default
parent child Browse files
Show More
@@ -248,15 +248,20 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 prefmt = pycompat.identity
251 252 if fmt is None:
252 253 fmt = '%s=%s'
253 return sep.join(fmt % (k, v) for k, v in _iteritems(data))
254 prefmt = pycompat.bytestr
255 return sep.join(fmt % (prefmt(k), prefmt(v))
256 for k, v in _iteritems(data))
254 257 @staticmethod
255 258 def formatlist(data, name, fmt, sep):
256 259 '''stringify iterable separated by sep'''
260 prefmt = pycompat.identity
257 261 if fmt is None:
258 262 fmt = '%s'
259 return sep.join(fmt % e for e in data)
263 prefmt = pycompat.bytestr
264 return sep.join(fmt % prefmt(e) for e in data)
260 265
261 266 class plainformatter(baseformatter):
262 267 '''the default text output scheme'''
@@ -99,16 +99,20 b' class _mappable(object):'
99 99
100 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 prefmt = pycompat.identity
102 103 if fmt is None:
103 104 fmt = '%s=%s'
105 prefmt = pycompat.bytestr
104 106 return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
105 lambda k: fmt % (k, data[k]))
107 lambda k: fmt % (prefmt(k), prefmt(data[k])))
106 108
107 109 def hybridlist(data, name, fmt=None, gen=None):
108 110 """Wrap data to support both list-like and string-like operations"""
111 prefmt = pycompat.identity
109 112 if fmt is None:
110 113 fmt = '%s'
111 return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % x)
114 prefmt = pycompat.bytestr
115 return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % prefmt(x))
112 116
113 117 def unwraphybrid(thing):
114 118 """Return an object which can be stringified possibly by using a legacy
General Comments 0
You need to be logged in to leave comments. Login now