Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templatefuncs.py @ 37227:e70a90a72b80
templatefuncs: use evaldate() where seems appropriate
This means date("today") is allowed.
Also fixes evaldate() to forcibly use the custom error message if specified.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 18 Mar 2018 15:58:22 +0900 |
parents | 67efce231633 |
children | 3685a79ea51b |
comparison
equal
deleted
inserted
replaced
37226:67efce231633 | 37227:e70a90a72b80 |
---|---|
50 "Mon Sep 04 15:13:13 2006 0700".""" | 50 "Mon Sep 04 15:13:13 2006 0700".""" |
51 if not (1 <= len(args) <= 2): | 51 if not (1 <= len(args) <= 2): |
52 # i18n: "date" is a keyword | 52 # i18n: "date" is a keyword |
53 raise error.ParseError(_("date expects one or two arguments")) | 53 raise error.ParseError(_("date expects one or two arguments")) |
54 | 54 |
55 date = evalfuncarg(context, mapping, args[0]) | 55 date = evaldate(context, mapping, args[0], |
56 # i18n: "date" is a keyword | |
57 _("date expects a date information")) | |
56 fmt = None | 58 fmt = None |
57 if len(args) == 2: | 59 if len(args) == 2: |
58 fmt = evalstring(context, mapping, args[1]) | 60 fmt = evalstring(context, mapping, args[1]) |
59 try: | 61 if fmt is None: |
60 if fmt is None: | 62 return dateutil.datestr(date) |
61 return dateutil.datestr(date) | 63 else: |
62 else: | 64 return dateutil.datestr(date, fmt) |
63 return dateutil.datestr(date, fmt) | |
64 except (TypeError, ValueError): | |
65 # i18n: "date" is a keyword | |
66 raise error.ParseError(_("date expects a date information")) | |
67 | 65 |
68 @templatefunc('dict([[key=]value...])', argspec='*args **kwargs') | 66 @templatefunc('dict([[key=]value...])', argspec='*args **kwargs') |
69 def dict_(context, mapping, args): | 67 def dict_(context, mapping, args): |
70 """Construct a dict from key-value pairs. A key may be omitted if | 68 """Construct a dict from key-value pairs. A key may be omitted if |
71 a value expression can provide an unambiguous name.""" | 69 a value expression can provide an unambiguous name.""" |