78 """Set sys.path properly. |
78 """Set sys.path properly. |
79 |
79 |
80 This needs to happen before any importing, and without importing anything. |
80 This needs to happen before any importing, and without importing anything. |
81 """ |
81 """ |
82 if self.as_module: |
82 if self.as_module: |
83 if env.PYBEHAVIOR.actual_syspath0_dash_m: |
83 path0 = os.getcwd() |
84 path0 = os.getcwd() |
|
85 else: |
|
86 path0 = "" |
|
87 elif os.path.isdir(self.arg0): |
84 elif os.path.isdir(self.arg0): |
88 # Running a directory means running the __main__.py file in that |
85 # Running a directory means running the __main__.py file in that |
89 # directory. |
86 # directory. |
90 path0 = self.arg0 |
87 path0 = self.arg0 |
91 else: |
88 else: |
293 # match or we won't run the file. |
290 # match or we won't run the file. |
294 magic = fpyc.read(4) |
291 magic = fpyc.read(4) |
295 if magic != PYC_MAGIC_NUMBER: |
292 if magic != PYC_MAGIC_NUMBER: |
296 raise NoCode(f"Bad magic number in .pyc file: {magic!r} != {PYC_MAGIC_NUMBER!r}") |
293 raise NoCode(f"Bad magic number in .pyc file: {magic!r} != {PYC_MAGIC_NUMBER!r}") |
297 |
294 |
298 date_based = True |
295 flags = struct.unpack('<L', fpyc.read(4))[0] |
299 if env.PYBEHAVIOR.hashed_pyc_pep552: |
296 hash_based = flags & 0x01 |
300 flags = struct.unpack('<L', fpyc.read(4))[0] |
297 if hash_based: |
301 hash_based = flags & 0x01 |
298 fpyc.read(8) # Skip the hash. |
302 if hash_based: |
299 else: |
303 fpyc.read(8) # Skip the hash. |
|
304 date_based = False |
|
305 if date_based: |
|
306 # Skip the junk in the header that we don't need. |
300 # Skip the junk in the header that we don't need. |
307 fpyc.read(4) # Skip the moddate. |
301 fpyc.read(4) # Skip the moddate. |
308 # 3.3 added another long to the header (size), skip it. |
302 fpyc.read(4) # Skip the size. |
309 fpyc.read(4) |
|
310 |
303 |
311 # The rest of the file is the code object we want. |
304 # The rest of the file is the code object we want. |
312 code = marshal.load(fpyc) |
305 code = marshal.load(fpyc) |
313 |
306 |
314 return code |
307 return code |