Scan one logical line of Python and look up values of variables used.
(reader, frame, locals)
| 83 | return None, __UNDEF__ |
| 84 | |
| 85 | def scanvars(reader, frame, locals): |
| 86 | """Scan one logical line of Python and look up values of variables used.""" |
| 87 | vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__ |
| 88 | for ttype, token, start, end, line in tokenize.generate_tokens(reader): |
| 89 | if ttype == tokenize.NEWLINE: break |
| 90 | if ttype == tokenize.NAME and token not in keyword.kwlist: |
| 91 | if lasttoken == '.': |
| 92 | if parent is not __UNDEF__: |
| 93 | value = getattr(parent, token, __UNDEF__) |
| 94 | vars.append((prefix + token, prefix, value)) |
| 95 | else: |
| 96 | where, value = lookup(token, frame, locals) |
| 97 | vars.append((token, where, value)) |
| 98 | elif token == '.': |
| 99 | prefix += lasttoken + '.' |
| 100 | parent = value |
| 101 | else: |
| 102 | parent, prefix = None, '' |
| 103 | lasttoken = token |
| 104 | return vars |
| 105 | |
| 106 | def html(einfo, context=5): |
| 107 | """Return a nice HTML document describing a given traceback.""" |