this repo has no description
at trunk 110 lines 2.0 kB view raw
1#!/usr/bin/env python3 2# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 3"""_imp provides basic importlib support.""" 4 5import sys 6 7from _builtins import ( 8 _builtin, 9 _code_check, 10 _code_guard, 11 _code_set_filename, 12 _str_guard, 13 _str_rpartition, 14 _unimplemented, 15) 16 17 18check_hash_based_pycs = "default" 19 20 21def create_builtin(spec): 22 _builtin() 23 24 25def _create_dynamic(name, path): 26 _builtin() 27 28 29def create_dynamic(spec): 30 _str_guard(spec.name) 31 _str_guard(spec.origin) 32 spec_name = spec.name 33 # Remove the import path from the extension module name 34 # TODO(T69088495): Encode in ASCII/punycode and replace '-' with '_' 35 if "." in spec_name: 36 short_name = _str_rpartition(spec_name, ".")[-1] 37 else: 38 short_name = spec_name 39 result = _create_dynamic(short_name, spec.origin) 40 sys.modules[spec_name] = result 41 return result 42 43 44def exec_builtin(module): 45 _builtin() 46 47 48def acquire_lock(): 49 _builtin() 50 51 52def exec_dynamic(mod): 53 # TODO(T39542987): Enable multi-phase module initialization 54 pass 55 56 57def extension_suffixes(): 58 return [".pyro.so", ".abi3.so", ".so"] 59 60 61def _code_update_filenames_recursive(code, old_name, new_name): 62 _code_set_filename(code, new_name) 63 for const in code.co_consts: 64 if _code_check(const): 65 _code_update_filenames_recursive(const, old_name, new_name) 66 67 68def _import_fastpath(name, fromlist, level): 69 _builtin() 70 71 72def _fix_co_filename(code, path): 73 _code_guard(code) 74 _str_guard(path) 75 old_name = code.co_filename 76 if old_name == path: 77 return 78 _code_update_filenames_recursive(code, old_name, path) 79 80 81def get_frozen_object(name): 82 _builtin() 83 84 85def init_frozen(name): 86 _unimplemented() 87 88 89def is_builtin(name): 90 _builtin() 91 92 93def is_frozen(name): 94 _builtin() 95 96 97def is_frozen_package(name): 98 _builtin() 99 100 101def lock_held(): 102 _builtin() 103 104 105def release_lock(): 106 _builtin() 107 108 109def source_hash(key, source): 110 _builtin()