##// 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 @staticmethod
248 @staticmethod
249 def formatdict(data, key, value, fmt, sep):
249 def formatdict(data, key, value, fmt, sep):
250 '''stringify key-value pairs separated by sep'''
250 '''stringify key-value pairs separated by sep'''
251 prefmt = pycompat.identity
251 if fmt is None:
252 if fmt is None:
252 fmt = '%s=%s'
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 @staticmethod
257 @staticmethod
255 def formatlist(data, name, fmt, sep):
258 def formatlist(data, name, fmt, sep):
256 '''stringify iterable separated by sep'''
259 '''stringify iterable separated by sep'''
260 prefmt = pycompat.identity
257 if fmt is None:
261 if fmt is None:
258 fmt = '%s'
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 class plainformatter(baseformatter):
266 class plainformatter(baseformatter):
262 '''the default text output scheme'''
267 '''the default text output scheme'''
@@ -99,16 +99,20 b' class _mappable(object):'
99
99
100 def hybriddict(data, key='key', value='value', fmt=None, gen=None):
100 def hybriddict(data, key='key', value='value', fmt=None, gen=None):
101 """Wrap data to support both dict-like and string-like operations"""
101 """Wrap data to support both dict-like and string-like operations"""
102 prefmt = pycompat.identity
102 if fmt is None:
103 if fmt is None:
103 fmt = '%s=%s'
104 fmt = '%s=%s'
105 prefmt = pycompat.bytestr
104 return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
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 def hybridlist(data, name, fmt=None, gen=None):
109 def hybridlist(data, name, fmt=None, gen=None):
108 """Wrap data to support both list-like and string-like operations"""
110 """Wrap data to support both list-like and string-like operations"""
111 prefmt = pycompat.identity
109 if fmt is None:
112 if fmt is None:
110 fmt = '%s'
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 def unwraphybrid(thing):
117 def unwraphybrid(thing):
114 """Return an object which can be stringified possibly by using a legacy
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