summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-01-10 21:47:09 -0500
committerNed Batchelder <ned@nedbatchelder.com>2018-01-10 21:47:09 -0500
commit392d901aba3930243c516ee2a9ef00a090357ac6 (patch)
treed09d27d9ba4fc4552615e3a2be30b1a40e0f7748 /coverage/execfile.py
parent6155d7f3f6f658719edd0e418268263c34c5874a (diff)
downloadpython-coveragepy-392d901aba3930243c516ee2a9ef00a090357ac6.tar.gz
Python 3.7 tweaked the layout of .pyc files
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 693f54f..ffe3ca1 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -5,6 +5,7 @@
import marshal
import os
+import struct
import sys
import types
@@ -253,11 +254,19 @@ def make_code_from_pyc(filename):
if magic != PYC_MAGIC_NUMBER:
raise NoCode("Bad magic number in .pyc file")
- # Skip the junk in the header that we don't need.
- fpyc.read(4) # Skip the moddate.
- if sys.version_info >= (3, 3):
- # 3.3 added another long to the header (size), skip it.
- fpyc.read(4)
+ date_based = True
+ if sys.version_info >= (3, 7):
+ flags = struct.unpack('<L', fpyc.read(4))[0]
+ hash_based = flags & 0x01
+ if hash_based:
+ fpyc.read(8) # Skip the hash.
+ date_based = False
+ if date_based:
+ # Skip the junk in the header that we don't need.
+ fpyc.read(4) # Skip the moddate.
+ if sys.version_info >= (3, 3):
+ # 3.3 added another long to the header (size), skip it.
+ fpyc.read(4)
# The rest of the file is the code object we want.
code = marshal.load(fpyc)