MCPcopy Create free account
hub / github.com/EasyIME/PIME / parse_config_file

Method parse_config_file

python/python3/tornado/options.py:369–436  ·  view source on GitHub ↗

Parses and loads the config file at the given path. The config file contains Python code that will be executed (so it is **not safe** to use untrusted config files). Anything in the global namespace that matches a defined option will be used to set that option's valu

(self, path: str, final: bool = True)

Source from the content-addressed store, hash-verified

367 return remaining
368
369 def parse_config_file(self, path: str, final: bool = True) -> None:
370 """Parses and loads the config file at the given path.
371
372 The config file contains Python code that will be executed (so
373 it is **not safe** to use untrusted config files). Anything in
374 the global namespace that matches a defined option will be
375 used to set that option's value.
376
377 Options may either be the specified type for the option or
378 strings (in which case they will be parsed the same way as in
379 `.parse_command_line`)
380
381 Example (using the options defined in the top-level docs of
382 this module)::
383
384 port = 80
385 mysql_host = 'mydb.example.com:3306'
386 # Both lists and comma-separated strings are allowed for
387 # multiple=True.
388 memcache_hosts = ['cache1.example.com:11011',
389 'cache2.example.com:11011']
390 memcache_hosts = 'cache1.example.com:11011,cache2.example.com:11011'
391
392 If ``final`` is ``False``, parse callbacks will not be run.
393 This is useful for applications that wish to combine configurations
394 from multiple sources.
395
396 .. note::
397
398 `tornado.options` is primarily a command-line library.
399 Config file support is provided for applications that wish
400 to use it, but applications that prefer config files may
401 wish to look at other libraries instead.
402
403 .. versionchanged:: 4.1
404 Config files are now always interpreted as utf-8 instead of
405 the system default encoding.
406
407 .. versionchanged:: 4.4
408 The special variable ``__file__`` is available inside config
409 files, specifying the absolute path to the config file itself.
410
411 .. versionchanged:: 5.1
412 Added the ability to set options via strings in config files.
413
414 """
415 config = {"__file__": os.path.abspath(path)}
416 with open(path, "rb") as f:
417 exec_in(native_str(f.read()), config, config)
418 for name in config:
419 normalized = self._normalize_name(name)
420 if normalized in self._options:
421 option = self._options[normalized]
422 if option.multiple:
423 if not isinstance(config[name], (list, str)):
424 raise Error(
425 "Option %r is required to be a list of %s "
426 "or a comma-separated string"

Callers 4

parse_config_fileFunction · 0.80

Calls 7

_normalize_nameMethod · 0.95
run_parse_callbacksMethod · 0.95
exec_inFunction · 0.90
ErrorClass · 0.85
typeEnum · 0.50
parseMethod · 0.45
setMethod · 0.45

Tested by 3