402 """Return the max of an iterable""" |
401 """Return the max of an iterable""" |
403 if len(args) != 1: |
402 if len(args) != 1: |
404 # i18n: "max" is a keyword |
403 # i18n: "max" is a keyword |
405 raise error.ParseError(_("max expects one argument")) |
404 raise error.ParseError(_("max expects one argument")) |
406 |
405 |
407 iterable = evalfuncarg(context, mapping, args[0]) |
406 iterable = evalwrapped(context, mapping, args[0]) |
408 try: |
407 try: |
409 x = max(pycompat.maybebytestr(iterable)) |
408 return iterable.getmax(context, mapping) |
410 except (TypeError, ValueError): |
409 except error.ParseError as err: |
411 # i18n: "max" is a keyword |
410 # i18n: "max" is a keyword |
412 raise error.ParseError(_("max first argument should be an iterable")) |
411 hint = _("max first argument should be an iterable") |
413 return templateutil.wraphybridvalue(iterable, x, x) |
412 raise error.ParseError(bytes(err), hint=hint) |
414 |
413 |
415 @templatefunc('min(iterable)') |
414 @templatefunc('min(iterable)') |
416 def min_(context, mapping, args, **kwargs): |
415 def min_(context, mapping, args, **kwargs): |
417 """Return the min of an iterable""" |
416 """Return the min of an iterable""" |
418 if len(args) != 1: |
417 if len(args) != 1: |
419 # i18n: "min" is a keyword |
418 # i18n: "min" is a keyword |
420 raise error.ParseError(_("min expects one argument")) |
419 raise error.ParseError(_("min expects one argument")) |
421 |
420 |
422 iterable = evalfuncarg(context, mapping, args[0]) |
421 iterable = evalwrapped(context, mapping, args[0]) |
423 try: |
422 try: |
424 x = min(pycompat.maybebytestr(iterable)) |
423 return iterable.getmin(context, mapping) |
425 except (TypeError, ValueError): |
424 except error.ParseError as err: |
426 # i18n: "min" is a keyword |
425 # i18n: "min" is a keyword |
427 raise error.ParseError(_("min first argument should be an iterable")) |
426 hint = _("min first argument should be an iterable") |
428 return templateutil.wraphybridvalue(iterable, x, x) |
427 raise error.ParseError(bytes(err), hint=hint) |
429 |
428 |
430 @templatefunc('mod(a, b)') |
429 @templatefunc('mod(a, b)') |
431 def mod(context, mapping, args): |
430 def mod(context, mapping, args): |
432 """Calculate a mod b such that a / b + a mod b == a""" |
431 """Calculate a mod b such that a / b + a mod b == a""" |
433 if not len(args) == 2: |
432 if not len(args) == 2: |