Coverage for skema/program_analysis/CAST/pythonAST/modules_list.py: 57%
21 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
1BUILTINS = [
2 "__future__",
3 "__main__",
4 "_thread",
5 "abc",
6 "aifc",
7 "argparse",
8 "array",
9 "ast",
10 "asynchat",
11 "asyncio",
12 "asyncore",
13 "atexit",
14 "audioop",
15 "base64",
16 "bdb",
17 "binascii",
18 "binhex",
19 "bisect",
20 "builtins",
21 "bz2",
22 "calendar",
23 "cgi",
24 "cgitb",
25 "chunk",
26 "cmath",
27 "cmd",
28 "code",
29 "codecs",
30 "codeop",
31 "collections",
32 "collections.abc",
33 "colorsys",
34 "compileall",
35 "concurrent.futures",
36 "configparser",
37 "contextlib",
38 "contextvars",
39 "copy",
40 "copyreg",
41 "cProfile",
42 "crypt",
43 "csv",
44 "ctypes",
45 "curses",
46 "curses.ascii",
47 "curses.panel",
48 "curses.textpad",
49 "dataclasses",
50 "datetime",
51 "dbm",
52 "dbm.dumb",
53 "dbm.gnu",
54 "dbm.ndbm",
55 "decimal",
56 "difflib",
57 "dis",
58 "distutils",
59 "doctest",
60 "email",
61 "email.charset",
62 "email.contentmanager",
63 "email.encoders",
64 "email.errors",
65 "email.generator",
66 "email.header",
67 "email.headerregistry",
68 "email.iterators",
69 "email.message",
70 "email.mime",
71 "email.parser",
72 "email.policy",
73 "email.utils",
74 "encodings.idna",
75 "encodings.mbcs",
76 "encodings.utf_8_sig",
77 "ensurepip",
78 "enum",
79 "errno",
80 "faulthandler",
81 "fcntl",
82 "filecmp",
83 "fileinput",
84 "fnmatch",
85 "fractions",
86 "ftplib",
87 "functools",
88 "gc",
89 "getopt",
90 "getpass",
91 "gettext",
92 "glob",
93 "graphlib",
94 "grp",
95 "gzip",
96 "hashlib",
97 "heapq",
98 "hmac",
99 "html",
100 "html.entities",
101 "html.parser",
102 "http",
103 "http.client",
104 "http.cookiejar",
105 "http.cookies",
106 "http.server",
107 "idlelib",
108 "imaplib",
109 "imghdr",
110 "imp",
111 "importlib",
112 "importlib.abc",
113 "importlib.machinery",
114 "importlib.metadata",
115 "importlib.resources",
116 "importlib.util",
117 "inspect",
118 "io",
119 "ipaddress",
120 "itertools",
121 "json",
122 "json.tool",
123 "keyword",
124 "lib2to3",
125 "linecache",
126 "locale",
127 "logging",
128 "logging.config",
129 "logging.handlers",
130 "lzma",
131 "mailbox",
132 "mailcap",
133 "marshal",
134 "math",
135 "mimetypes",
136 "mmap",
137 "modulefinder",
138 "msilib",
139 "msvcrt",
140 "multiprocessing",
141 "multiprocessing.connection",
142 "multiprocessing.dummy",
143 "multiprocessing.managers",
144 "multiprocessing.pool",
145 "multiprocessing.shared_memory",
146 "multiprocessing.sharedctypes",
147 "netrc",
148 "nis",
149 "nntplib",
150 "numbers",
151 "operator",
152 "optparse",
153 "os",
154 "os.path",
155 "ossaudiodev",
156 "pathlib",
157 "pdb",
158 "pickle",
159 "pickletools",
160 "pipes",
161 "pkgutil",
162 "platform",
163 "plistlib",
164 "poplib",
165 "posix",
166 "pprint",
167 "profile",
168 "pstats",
169 "pty",
170 "pwd",
171 "py_compile",
172 "pyclbr",
173 "pydoc",
174 "queue",
175 "quopri",
176 "random",
177 "re",
178 "readline",
179 "reprlib",
180 "resource",
181 "rlcompleter",
182 "runpy",
183 "sched",
184 "secrets",
185 "select",
186 "selectors",
187 "shelve",
188 "shlex",
189 "shutil",
190 "signal",
191 "site",
192 "smtpd",
193 "smtplib",
194 "sndhdr",
195 "socket",
196 "socketserver",
197 "spwd",
198 "sqlite3",
199 "ssl",
200 "stat",
201 "statistics",
202 "string",
203 "str",
204 "stringprep",
205 "struct",
206 "subprocess",
207 "sunau",
208 "symtable",
209 "sys",
210 "sysconfig",
211 "syslog",
212 "tabnanny",
213 "tarfile",
214 "telnetlib",
215 "tempfile",
216 "termios",
217 "test",
218 "test.support",
219 "test.support.bytecode_helper",
220 "test.support.import_helper",
221 "test.support.os_helper",
222 "test.support.script_helper",
223 "test.support.socket_helper",
224 "test.support.threading_helper",
225 "test.support.warnings_helper",
226 "textwrap",
227 "threading",
228 "time",
229 "timeit",
230 "tkinter",
231 "tkinter.colorchooser",
232 "tkinter.commondialog",
233 "tkinter.dnd",
234 "tkinter.filedialog",
235 "tkinter.font",
236 "tkinter.messagebox",
237 "tkinter.scrolledtext",
238 "tkinter.simpledialog",
239 "tkinter.tix",
240 "tkinter.ttk",
241 "token",
242 "tokenize",
243 "trace",
244 "traceback",
245 "tracemalloc",
246 "tty",
247 "turtle",
248 "turtledemo",
249 "types",
250 "typing",
251 "unicodedata",
252 "unittest",
253 "unittest.mock",
254 "urllib",
255 "urllib.error",
256 "urllib.parse",
257 "urllib.request",
258 "urllib.response",
259 "urllib.robotparser",
260 "uu",
261 "uuid",
262 "venv",
263 "warnings",
264 "wave",
265 "weakref",
266 "webbrowser",
267 "winreg",
268 "winsound",
269 "wsgiref",
270 "wsgiref.handlers",
271 "wsgiref.headers",
272 "wsgiref.simple_server",
273 "wsgiref.util",
274 "wsgiref.validate",
275 "xdrlib",
276 "xml",
277 "xml.dom",
278 "xml.dom.minidom",
279 "xml.dom.pulldom",
280 "xml.etree.ElementTree",
281 "xml.parsers.expat",
282 "xml.parsers.expat.errors",
283 "xml.parsers.expat.model",
284 "xml.sax",
285 "xml.sax.handler",
286 "xml.sax.saxutils",
287 "xml.sax.xmlreader",
288 "xmlrpc.client",
289 "xmlrpc.server",
290 "zipapp",
291 "zipfile",
292 "zipimport",
293 "zlib",
294 "zoneinfo",
295]
296import importlib
299def find_std_lib_module(module_name):
300 try:
301 library = importlib.util.find_spec(module_name)
302 if library == None:
303 return False
304 print(f"found {library.name}")
305 return True
306 except:
307 return False
310def find_func_in_module(module_name, func_name):
311 """When a module is imported using
312 'from x import *', all the functions for module x
313 then become bound to the namespace but don't have their attributes attached to the module x
314 That is, they're called using just their name as opposed to x.func_name().
315 This function attempts to find a function in such a module by importing it and then
316 using 'dir' to determine if func_name is within module_name's list of functions
317 """
318 # TODO: Metapath finder, find_spec
319 # TODO: cache the module objects to look back so we dont do multiple imports in a map
320 import os
321 import sys
323 sys.path.append(os.getcwd())
325 # TODO: Support find_func_in_module for Fortran source code as well
326 try:
327 module_import = importlib.import_module(module_name)
328 except:
329 return False
331 funcs = list(dir(module_import))
332 return func_name in funcs