Method: flask.config.Config.from_pyfile
Calls: 9, Exceptions: 4, Paths: 3Back
Path 1: 5 calls (0.56)
'/Users/andrehora/Documents/git/projects-pathspotter/flask/tests/test_config.py' (2) '/Users/andrehora/Documents/git/projects-pathspotter/flask/.tox/t...
False (5)
True (5)
1def from_pyfile(self, filename: str | os.PathLike, silent: bool = False) -> bool:
2 """Updates the values in the config from a Python file. This function
3 behaves as if the file was imported as module with the
4 :meth:`from_object` function.
5
6 :param filename: the filename of the config. This can either be an
7 absolute filename or a filename relative to the
8 root path.
9 :param silent: set to ``True`` if you want silent failure for missing
10 files.
11 :return: ``True`` if the file was loaded successfully.
12
13 .. versionadded:: 0.7
14 `silent` parameter.
15 """
16 filename = os.path.join(self.root_path, filename)
17 d = types.ModuleType("config")
18 d.__file__ = filename
19 try:
20 with open(filename, mode="rb") as config_file:
21 exec(compile(config_file.read(), filename, "exec"), d.__dict__)
22 except OSError as e:
23 if silent and e.errno in (errno.ENOENT, errno.EISDIR, errno.ENOTDIR):
24 return False
25 e.strerror = f"Unable to load configuration file ({e.strerror})"
26 raise
27 self.from_object(d)
28 return True
Path 2: 2 calls (0.22)
'missing.cfg' (2)
False (2)
FileNotFoundError (2)
1def from_pyfile(self, filename: str | os.PathLike, silent: bool = False) -> bool:
2 """Updates the values in the config from a Python file. This function
3 behaves as if the file was imported as module with the
4 :meth:`from_object` function.
5
6 :param filename: the filename of the config. This can either be an
7 absolute filename or a filename relative to the
8 root path.
9 :param silent: set to ``True`` if you want silent failure for missing
10 files.
11 :return: ``True`` if the file was loaded successfully.
12
13 .. versionadded:: 0.7
14 `silent` parameter.
15 """
16 filename = os.path.join(self.root_path, filename)
17 d = types.ModuleType("config")
18 d.__file__ = filename
19 try:
20 with open(filename, mode="rb") as config_file:
21 exec(compile(config_file.read(), filename, "exec"), d.__dict__)
22 except OSError as e:
23 if silent and e.errno in (errno.ENOENT, errno.EISDIR, errno.ENOTDIR):
24 return False
25 e.strerror = f"Unable to load configuration file ({e.strerror})"
26 raise
27 self.from_object(d)
28 return True
Path 3: 2 calls (0.22)
'missing.cfg' (2)
True (2)
False (2)
FileNotFoundError (2)
1def from_pyfile(self, filename: str | os.PathLike, silent: bool = False) -> bool:
2 """Updates the values in the config from a Python file. This function
3 behaves as if the file was imported as module with the
4 :meth:`from_object` function.
5
6 :param filename: the filename of the config. This can either be an
7 absolute filename or a filename relative to the
8 root path.
9 :param silent: set to ``True`` if you want silent failure for missing
10 files.
11 :return: ``True`` if the file was loaded successfully.
12
13 .. versionadded:: 0.7
14 `silent` parameter.
15 """
16 filename = os.path.join(self.root_path, filename)
17 d = types.ModuleType("config")
18 d.__file__ = filename
19 try:
20 with open(filename, mode="rb") as config_file:
21 exec(compile(config_file.read(), filename, "exec"), d.__dict__)
22 except OSError as e:
23 if silent and e.errno in (errno.ENOENT, errno.EISDIR, errno.ENOTDIR):
24 return False
25 e.strerror = f"Unable to load configuration file ({e.strerror})"
26 raise
27 self.from_object(d)
28 return True