MCPcopy Index your code
hub / github.com/python/cpython / entry_ok

Method entry_ok

Lib/idlelib/query.py:196–226  ·  view source on GitHub ↗

Return entered module name as file path or None.

(self)

Source from the content-addressed store, hash-verified

194 _htest=_htest, _utest=_utest)
195
196 def entry_ok(self):
197 "Return entered module name as file path or None."
198 name = self.entry.get().strip()
199 if not name:
200 self.showerror('no name specified.')
201 return None
202 # XXX Ought to insert current file's directory in front of path.
203 try:
204 spec = importlib.util.find_spec(name)
205 except (ValueError, ImportError) as msg:
206 self.showerror(str(msg))
207 return None
208 if spec is None:
209 self.showerror("module not found.")
210 return None
211 if not isinstance(spec.loader, importlib.abc.SourceLoader):
212 self.showerror("not a source-based module.")
213 return None
214 try:
215 file_path = spec.loader.get_filename(name)
216 except AttributeError:
217 self.showerror("loader does not support get_filename.")
218 return None
219 except ImportError:
220 # Some special modules require this (e.g. os.path)
221 try:
222 file_path = spec.loader.get_filename()
223 except TypeError:
224 self.showerror("loader failed to get filename.")
225 return None
226 return file_path
227
228
229class Goto(Query):

Callers

nothing calls this directly

Calls 6

strFunction · 0.85
stripMethod · 0.45
getMethod · 0.45
showerrorMethod · 0.45
find_specMethod · 0.45
get_filenameMethod · 0.45

Tested by

no test coverage detected