@@ -202,7 +202,7 @@ def format(formatter, ns, target, label, fullmatch=None):
202
202
"""
203
203
204
204
205
- def parse_args (args , strict = True ):
205
+ def parse_args (args , strict = True , stripws = False ):
206
206
"""Utility for parsing macro "content" and splitting them into arguments.
207
207
208
208
The content is split along commas, unless they are escaped with a
@@ -211,6 +211,10 @@ def parse_args(args, strict=True):
211
211
:param args: a string containing macros arguments
212
212
:param strict: if `True`, only Python-like identifiers will be
213
213
recognized as keyword arguments
214
+ :param stripws: if `True`, leading and trailing whitespace is stripped from
215
+ the arguments. However, regardless of this parameter,
216
+ :param: strict always governs whether whitespace is allowed
217
+ between the kw and the `=` character.
214
218
215
219
Example usage::
216
220
@@ -222,6 +226,9 @@ def parse_args(args, strict=True):
222
226
(['Some text', ' some other arg, with a comma.'], {'mode': ' 3'})
223
227
>>> parse_args('milestone=milestone1,status!=closed', strict=False)
224
228
([], {'status!': 'closed', 'milestone': 'milestone1'})
229
+ >>> parse_args(' Some text, mode= 3, arg , othermode= on ', \
230
+ stripws=True)
231
+ (['Some text', 'arg'], {'othermode': 'on', 'mode': '3'})
225
232
226
233
"""
227
234
largs , kwargs = [], {}
@@ -236,8 +243,13 @@ def parse_args(args, strict=True):
236
243
kw = arg [:m .end ()- 1 ].strip ()
237
244
if strict :
238
245
kw = unicode (kw ).encode ('utf-8' )
239
- kwargs [kw ] = arg [m .end ():]
246
+ if stripws :
247
+ kwargs [kw ] = arg [m .end ():].strip ()
248
+ else :
249
+ kwargs [kw ] = arg [m .end ():]
240
250
else :
251
+ if stripws :
252
+ arg = arg .strip ()
241
253
largs .append (arg )
242
254
return largs , kwargs
243
255
0 commit comments