本文整理匯總了Python中yaml.__version__方法的典型用法代碼示例。如果您正苦於以下問題:Python yaml.__version__方法的具體用法?Python yaml.__version__怎麽用?Python yaml.__version__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yaml
的用法示例。
在下文中一共展示了yaml.__version__方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: read_yaml
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import __version__ [as 別名]
def read_yaml(filepath: str, default_value: Optional[Any] = None, strict: bool = False) -> Dict:
"""Read a YAML file in. If no file is found and default value is set, return that instead. Otherwise error
:param filepath: str, A file to load
:param default_value: If the file doesn't exist, return return this. Defaults to an empty dict.
:param strict: bool, If true raise an error on file not found.
:return: dict, The read yaml object
"""
if not os.path.exists(filepath):
if strict:
raise IOError("No file {} found".format(filepath))
return default_value if default_value is not None else {}
with open(filepath) as f:
import yaml
from distutils.version import LooseVersion
if LooseVersion(yaml.__version__) >= LooseVersion("5.1"):
return yaml.load(f, Loader=yaml.FullLoader)
return yaml.load(f)
示例2: yaml_load
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import __version__ [as 別名]
def yaml_load(f: typing.Union[str, typing.IO[str]]) -> typing.Any:
"""Wrapper over yaml.load using the C loader if possible."""
start = datetime.datetime.now()
# WORKAROUND for https://github.com/yaml/pyyaml/pull/181
with log.ignore_py_warnings(
category=DeprecationWarning,
message=r"Using or importing the ABCs from 'collections' instead "
r"of from 'collections\.abc' is deprecated.*"):
data = yaml.load(f, Loader=YamlLoader)
end = datetime.datetime.now()
delta = (end - start).total_seconds()
deadline = 10 if 'CI' in os.environ else 2
if delta > deadline: # pragma: no cover
log.misc.warning(
"YAML load took unusually long, please report this at "
"https://github.com/qutebrowser/qutebrowser/issues/2777\n"
"duration: {}s\n"
"PyYAML version: {}\n"
"C extension: {}\n"
"Stack:\n\n"
"{}".format(
delta, yaml.__version__, YAML_C_EXT,
''.join(traceback.format_stack())))
return data
示例3: default_params
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import __version__ [as 別名]
def default_params():
'''Return default configuration
'''
default_params_yaml = open("config.yaml", "r")
if(yaml.__version__[0]>=5):
params = yaml.safe_load(default_params_yaml)
else:
params = yaml.load(default_params_yaml)
params['image_format'] = get_img_format(params['base_dir'])
return params
示例4: test_datetimes
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import __version__ [as 別名]
def test_datetimes(self):
self.assertEqual(self.run_yq("- 2016-12-20T22:07:36Z\n", ["."]), "")
if yaml.__version__ < '5.3':
self.assertEqual(self.run_yq("- 2016-12-20T22:07:36Z\n", ["-y", "."]), "- '2016-12-20T22:07:36'\n")
else:
self.assertEqual(self.run_yq("- 2016-12-20T22:07:36Z\n", ["-y", "."]), "- '2016-12-20T22:07:36+00:00'\n")
self.assertEqual(self.run_yq("2016-12-20", ["."]), "")
self.assertEqual(self.run_yq("2016-12-20", ["-y", "."]), "'2016-12-20'\n")
示例5: get_version
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import __version__ [as 別名]
def get_version(pkg):
s = ".".join(pkg.__version__.split(".")[:2])
return float(s)
示例6: get_platform_info
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import __version__ [as 別名]
def get_platform_info():
from gi.repository import GObject
from gi.repository import Gtk
import yaml
functions = [
platform.machine,
platform.platform,
platform.processor,
platform.python_version,
platform.release,
platform.system,
]
names_values = [(func.__name__, func()) for func in functions]
names_values.extend(
[
(
"GTK",
(
Gtk.get_major_version(),
Gtk.get_minor_version(),
Gtk.get_micro_version(),
),
),
("Glib", GObject.glib_version),
("PyGObject", GObject.pygobject_version),
("YAML", yaml.__version__),
]
)
vals = ["{}: {}".format(name, val) for name, val in names_values]
return "System info: " + ", ".join(vals)