diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-09-28 10:07:55 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-09-28 10:07:55 -0400 |
commit | a9739749d841818a31ae956fe02e0b3f03a82a31 (patch) | |
tree | 807180ce6c7df203b926d414322c9d0c84b71dff /coverage/parser.py | |
parent | 702d355f9bd2c218a7932e33fe3f587a8f7e3035 (diff) | |
download | python-coveragepy-a9739749d841818a31ae956fe02e0b3f03a82a31.tar.gz |
More abstractions for bytes objects. Cleans up some version checks in the real code.
Diffstat (limited to 'coverage/parser.py')
-rw-r--r-- | coverage/parser.py | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index 2d777a5..d531d12 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -5,6 +5,7 @@ import dis, re, sys, token, tokenize from coverage.backward import set, sorted, StringIO # pylint: disable=W0622 from coverage.backward import open_source, range # pylint: disable=W0622 from coverage.backward import reversed # pylint: disable=W0622 +from coverage.backward import bytes_to_ints from coverage.bytecode import ByteCodes, CodeObjects from coverage.misc import nice_pair, expensive, join_regex from coverage.misc import CoverageException, NoSource, NotPython @@ -367,18 +368,6 @@ class ByteParser(object): children = CodeObjects(self.code) return [ByteParser(code=c, text=self.text) for c in children] - # Getting numbers from the lnotab value changed in Py3.0. - if sys.version_info >= (3, 0): - def _lnotab_increments(self, lnotab): - """Produce ints from the lnotab bytes in 3.x""" - # co_lnotab is a bytes object, which iterates as ints. - return lnotab - else: - def _lnotab_increments(self, lnotab): - """Produce ints from the lnotab string in 2.x""" - for c in lnotab: - yield ord(c) - def _bytes_lines(self): """Map byte offsets to line numbers in `code`. @@ -390,8 +379,8 @@ class ByteParser(object): """ # Adapted from dis.py in the standard library. - byte_increments = self._lnotab_increments(self.code.co_lnotab[0::2]) - line_increments = self._lnotab_increments(self.code.co_lnotab[1::2]) + byte_increments = bytes_to_ints(self.code.co_lnotab[0::2]) + line_increments = bytes_to_ints(self.code.co_lnotab[1::2]) last_line_num = None line_num = self.code.co_firstlineno |