Format an argument spec from the 4 values returned by getargvalues. The first four arguments are (args, varargs, varkw, locals). The next four arguments are the corresponding optional formatting functions that are called to turn names and values into strings. The ninth argument is
(args, varargs, varkw, locals,
formatarg=str,
formatvarargs=lambda name: '*' + name,
formatvarkw=lambda name: '**' + name,
formatvalue=lambda value: '=' + repr(value),
join=joinseq)
| 167 | return '(' + ', '.join(specs) + ')' |
| 168 | |
| 169 | def formatargvalues(args, varargs, varkw, locals, |
| 170 | formatarg=str, |
| 171 | formatvarargs=lambda name: '*' + name, |
| 172 | formatvarkw=lambda name: '**' + name, |
| 173 | formatvalue=lambda value: '=' + repr(value), |
| 174 | join=joinseq): |
| 175 | """Format an argument spec from the 4 values returned by getargvalues. |
| 176 | |
| 177 | The first four arguments are (args, varargs, varkw, locals). The |
| 178 | next four arguments are the corresponding optional formatting functions |
| 179 | that are called to turn names and values into strings. The ninth |
| 180 | argument is an optional function to format the sequence of arguments. |
| 181 | |
| 182 | """ |
| 183 | def convert(name, locals=locals, |
| 184 | formatarg=formatarg, formatvalue=formatvalue): |
| 185 | return formatarg(name) + formatvalue(locals[name]) |
| 186 | specs = [strseq(arg, convert, join) for arg in args] |
| 187 | |
| 188 | if varargs: |
| 189 | specs.append(formatvarargs(varargs) + formatvalue(locals[varargs])) |
| 190 | if varkw: |
| 191 | specs.append(formatvarkw(varkw) + formatvalue(locals[varkw])) |
| 192 | return '(' + ', '.join(specs) + ')' |