From 354e0ea288d678e5f199f11e98b6b5deea04fef2 Mon Sep 17 00:00:00 2001 From: Phil Price Date: Wed, 30 Oct 2019 13:23:13 +1100 Subject: [PATCH] Allow decrypting of modules on different drive letter to the working directory under Windows. (Full path is required in key) --- pyce/_imports.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyce/_imports.py b/pyce/_imports.py index 246ad31..fbf0eec 100644 --- a/pyce/_imports.py +++ b/pyce/_imports.py @@ -69,8 +69,14 @@ def get_code(self, fullname: str) -> Any: path = self.get_filename(fullname) data = self.get_data(path) + # Relative paths are impossible on Windows if the target file is on a different drive letter to the working directory + try: + r_path = relpath(path) + except: + # well, we tried + r_path = path # It is important to normalize path case for platforms like Windows - data = decrypt(data, PYCEPathFinder.KEYS[normcase(relpath(path))]) + data = decrypt(data, PYCEPathFinder.KEYS[normcase(r_path)]) # Call _classify_pyc to do basic validation of the pyc but ignore the # result. There's no source to check against.