comparison mercurial/templater.py @ 36544:a16fceb686a7

py3: fix join(), min(), and max() template functions over string It's silly to split a string into characters and concatenate them, but that should work and test-command-template.t has one. min() and max() had the same issue on Python 3, so fixed too.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 01 Mar 2018 16:42:24 -0500
parents 638c012a87ef
children ab7f86a748e6
comparison
equal deleted inserted replaced
36543:3e458c583d2c 36544:a16fceb686a7
906 joiner = " " 906 joiner = " "
907 if len(args) > 1: 907 if len(args) > 1:
908 joiner = evalstring(context, mapping, args[1]) 908 joiner = evalstring(context, mapping, args[1])
909 909
910 first = True 910 first = True
911 for x in joinset: 911 for x in pycompat.maybebytestr(joinset):
912 if first: 912 if first:
913 first = False 913 first = False
914 else: 914 else:
915 yield joiner 915 yield joiner
916 yield joinfmt(x) 916 yield joinfmt(x)
989 # i18n: "max" is a keyword 989 # i18n: "max" is a keyword
990 raise error.ParseError(_("max expects one argument")) 990 raise error.ParseError(_("max expects one argument"))
991 991
992 iterable = evalfuncarg(context, mapping, args[0]) 992 iterable = evalfuncarg(context, mapping, args[0])
993 try: 993 try:
994 x = max(iterable) 994 x = max(pycompat.maybebytestr(iterable))
995 except (TypeError, ValueError): 995 except (TypeError, ValueError):
996 # i18n: "max" is a keyword 996 # i18n: "max" is a keyword
997 raise error.ParseError(_("max first argument should be an iterable")) 997 raise error.ParseError(_("max first argument should be an iterable"))
998 return templatekw.wraphybridvalue(iterable, x, x) 998 return templatekw.wraphybridvalue(iterable, x, x)
999 999
1004 # i18n: "min" is a keyword 1004 # i18n: "min" is a keyword
1005 raise error.ParseError(_("min expects one argument")) 1005 raise error.ParseError(_("min expects one argument"))
1006 1006
1007 iterable = evalfuncarg(context, mapping, args[0]) 1007 iterable = evalfuncarg(context, mapping, args[0])
1008 try: 1008 try:
1009 x = min(iterable) 1009 x = min(pycompat.maybebytestr(iterable))
1010 except (TypeError, ValueError): 1010 except (TypeError, ValueError):
1011 # i18n: "min" is a keyword 1011 # i18n: "min" is a keyword
1012 raise error.ParseError(_("min first argument should be an iterable")) 1012 raise error.ParseError(_("min first argument should be an iterable"))
1013 return templatekw.wraphybridvalue(iterable, x, x) 1013 return templatekw.wraphybridvalue(iterable, x, x)
1014 1014