Move from str.format() to string.Template.
This commit is contained in:
parent
f1900f6a7b
commit
8ddc1f8977
@ -317,16 +317,19 @@ def visitor_statlink(specs, args):
|
|||||||
def visitor_print(specs, args):
|
def visitor_print(specs, args):
|
||||||
'Print a string for each spec using args.format.'
|
'Print a string for each spec using args.format.'
|
||||||
fmt = args.format[0]
|
fmt = args.format[0]
|
||||||
|
from string import Template
|
||||||
|
t = Template(fmt)
|
||||||
|
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
kwds = spec2dict(spec)
|
kwds = spec2dict(spec)
|
||||||
try:
|
try:
|
||||||
string = fmt.format(**kwds)
|
text = t.substitute(kwds)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
tty.error("Format error, use keywords: %s" % (', '.join(kwds.keys()), ))
|
tty.error("Format error, use keywords: %s" % (', '.join(kwds.keys()), ))
|
||||||
raise
|
raise
|
||||||
# argparser escapes these
|
# argparser escapes these
|
||||||
string = string.replace(r'\n', '\n').replace(r'\t', '\t')
|
text = text.replace(r'\n', '\n').replace(r'\t', '\t')
|
||||||
sys.stdout.write(string)
|
sys.stdout.write(text)
|
||||||
|
|
||||||
|
|
||||||
# Finally, the actual "view" command. There should be no need to
|
# Finally, the actual "view" command. There should be no need to
|
||||||
|
Loading…
Reference in New Issue
Block a user