diff options
author | Trent Nelson <trent.nelson@snakebite.org> | 2008-03-18 22:41:35 (GMT) |
---|---|---|
committer | Trent Nelson <trent.nelson@snakebite.org> | 2008-03-18 22:41:35 (GMT) |
commit | 428de65ca99492436130165bfbaeb56d6d1daec7 (patch) | |
tree | d6c11516a28d8ca658e1f35ac6d7cc802958e336 /Lib/inspect.py | |
parent | 112367a980481d54f8c21802ee2538a3485fdd41 (diff) | |
download | cpython-428de65ca99492436130165bfbaeb56d6d1daec7.zip cpython-428de65ca99492436130165bfbaeb56d6d1daec7.tar.gz cpython-428de65ca99492436130165bfbaeb56d6d1daec7.tar.bz2 |
- Issue #719888: Updated tokenize to use a bytes API. generate_tokens has been
renamed tokenize and now works with bytes rather than strings. A new
detect_encoding function has been added for determining source file encoding
according to PEP-0263. Token sequences returned by tokenize always start
with an ENCODING token which specifies the encoding used to decode the file.
This token is used to encode the output of untokenize back to bytes.
Credit goes to Michael "I'm-going-to-name-my-first-child-unittest" Foord from Resolver Systems for this work.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index ceaea5a..5cb958b 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -657,7 +657,9 @@ def getblock(lines): """Extract the block of code at the top of the given list of lines.""" blockfinder = BlockFinder() try: - tokenize.tokenize(iter(lines).__next__, blockfinder.tokeneater) + tokens = tokenize.generate_tokens(iter(lines).__next__) + for _token in tokens: + blockfinder.tokeneater(*_token) except (EndOfBlock, IndentationError): pass return lines[:blockfinder.last] |