MCPcopy Create free account
hub / github.com/cdgriffith/Box / from_yaml

Method from_yaml

box/box.py:1416–1449  ·  view source on GitHub ↗

Transform a yaml object string into a Box object. By default will use SafeLoader. :param yaml_string: string to pass to `yaml.load` :param filename: filename to open and pass to `yaml.load` :param encoding: File encoding :param errors: Ho

(
            cls,
            yaml_string: str | None = None,
            filename: str | PathLike | None = None,
            encoding: str = "utf-8",
            errors: str = "strict",
            **kwargs,
        )

Source from the content-addressed store, hash-verified

1414
1415 @classmethod
1416 def from_yaml(
1417 cls,
1418 yaml_string: str | None = None,
1419 filename: str | PathLike | None = None,
1420 encoding: str = "utf-8",
1421 errors: str = "strict",
1422 **kwargs,
1423 ) -> Box:
1424 """
1425 Transform a yaml object string into a Box object. By default will use SafeLoader.
1426
1427 :param yaml_string: string to pass to `yaml.load`
1428 :param filename: filename to open and pass to `yaml.load`
1429 :param encoding: File encoding
1430 :param errors: How to handle encoding errors
1431 :param kwargs: parameters to pass to `Box()` or `yaml.load`
1432 :return: Box object from yaml data
1433 """
1434 box_args = {}
1435 for arg in kwargs.copy():
1436 if arg in BOX_PARAMETERS:
1437 box_args[arg] = kwargs.pop(arg)
1438
1439 data, comments = _from_yaml_with_comments(
1440 yaml_string=yaml_string, filename=filename, encoding=encoding, errors=errors, **kwargs
1441 )
1442 if not data:
1443 result = cls(**box_args)
1444 elif not isinstance(data, dict):
1445 raise BoxError(f"yaml data not returned as a dictionary but rather a {type(data).__name__}")
1446 else:
1447 result = cls(data, **box_args)
1448 _comments.apply_comments(result, comments)
1449 return result
1450
1451 else:
1452

Calls 4

_from_yaml_with_commentsFunction · 0.90
BoxErrorClass · 0.90
copyMethod · 0.80
popMethod · 0.45