##// END OF EJS Templates
revset: add function to build dict of positional and keyword arguments...
Yuya Nishihara -
r25705:48919d24 default
parent child Browse files
Show More
@@ -91,6 +91,38 b' class parser(object):'
91 91 return self.eval(t)
92 92 return t
93 93
94 def buildargsdict(trees, funcname, keys, keyvaluenode, keynode):
95 """Build dict from list containing positional and keyword arguments
96
97 Invalid keywords or too many positional arguments are rejected, but
98 missing arguments are just omitted.
99 """
100 if len(trees) > len(keys):
101 raise error.ParseError(_("%(func)s takes at most %(nargs)d arguments")
102 % {'func': funcname, 'nargs': len(keys)})
103 args = {}
104 # consume positional arguments
105 for k, x in zip(keys, trees):
106 if x[0] == keyvaluenode:
107 break
108 args[k] = x
109 # remainder should be keyword arguments
110 for x in trees[len(args):]:
111 if x[0] != keyvaluenode or x[1][0] != keynode:
112 raise error.ParseError(_("%(func)s got an invalid argument")
113 % {'func': funcname})
114 k = x[1][1]
115 if k not in keys:
116 raise error.ParseError(_("%(func)s got an unexpected keyword "
117 "argument '%(key)s'")
118 % {'func': funcname, 'key': k})
119 if k in args:
120 raise error.ParseError(_("%(func)s got multiple values for keyword "
121 "argument '%(key)s'")
122 % {'func': funcname, 'key': k})
123 args[k] = x[2]
124 return args
125
94 126 def _prettyformat(tree, leafnodes, level, lines):
95 127 if not isinstance(tree, tuple) or tree[0] in leafnodes:
96 128 lines.append((level, str(tree)))
@@ -282,6 +282,10 b' def getargs(x, min, max, err):'
282 282 raise error.ParseError(err)
283 283 return l
284 284
285 def getkwargs(x, funcname, keys):
286 return parser.buildargsdict(getlist(x), funcname, keys.split(),
287 keyvaluenode='keyvalue', keynode='symbol')
288
285 289 def isvalidsymbol(tree):
286 290 """Examine whether specified ``tree`` is valid ``symbol`` or not
287 291 """
General Comments 0
You need to be logged in to leave comments. Login now