summaryrefslogtreecommitdiff
path: root/lab
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 /lab
parent6155d7f3f6f658719edd0e418268263c34c5874a (diff)
downloadpython-coveragepy-392d901aba3930243c516ee2a9ef00a090357ac6.tar.gz
Python 3.7 tweaked the layout of .pyc files
Diffstat (limited to 'lab')
-rw-r--r--lab/show_pyc.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/lab/show_pyc.py b/lab/show_pyc.py
index 0a28e4f..525797a 100644
--- a/lab/show_pyc.py
+++ b/lab/show_pyc.py
@@ -13,14 +13,25 @@ import types
def show_pyc_file(fname):
f = open(fname, "rb")
magic = f.read(4)
- moddate = f.read(4)
- modtime = time.asctime(time.localtime(struct.unpack('<L', moddate)[0]))
print("magic %s" % (binascii.hexlify(magic)))
- print("moddate %s (%s)" % (binascii.hexlify(moddate), modtime))
- if sys.version_info >= (3, 3):
- # 3.3 added another long to the header (size).
- size = f.read(4)
- print("pysize %s (%d)" % (binascii.hexlify(size), struct.unpack('<L', size)[0]))
+ read_date_and_size = True
+ if sys.version_info >= (3, 7):
+ # 3.7 added a flags word
+ flags = struct.unpack('<L', f.read(4))[0]
+ hash_based = flags & 0x01
+ check_source = flags & 0x02
+ print("flags 0x%08x" % (flags,))
+ if hash_based:
+ source_hash = f.read(8)
+ read_date_and_size = False
+ if read_date_and_size:
+ moddate = f.read(4)
+ modtime = time.asctime(time.localtime(struct.unpack('<L', moddate)[0]))
+ print("moddate %s (%s)" % (binascii.hexlify(moddate), modtime))
+ if sys.version_info >= (3, 3):
+ # 3.3 added another long to the header (size).
+ size = f.read(4)
+ print("pysize %s (%d)" % (binascii.hexlify(size), struct.unpack('<L', size)[0]))
code = marshal.load(f)
show_code(code)