• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This is a stub package designed to roughly emulate the _yaml
2# extension module, which previously existed as a standalone module
3# and has been moved into the `yaml` package namespace.
4# It does not perfectly mimic its old counterpart, but should get
5# close enough for anyone who's relying on it even when they shouldn't.
6import yaml
7
8# in some circumstances, the yaml module we imoprted may be from a different version, so we need
9# to tread carefully when poking at it here (it may not have the attributes we expect)
10if not getattr(yaml, '__with_libyaml__', False):
11    from sys import version_info
12
13    exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError
14    raise exc("No module named '_yaml'")
15else:
16    from yaml._yaml import *
17    import warnings
18    warnings.warn(
19        'The _yaml extension module is now located at yaml._yaml'
20        ' and its location is subject to change.  To use the'
21        ' LibYAML-based parser and emitter, import from `yaml`:'
22        ' `from yaml import CLoader as Loader, CDumper as Dumper`.',
23        DeprecationWarning
24    )
25    del warnings
26    # Don't `del yaml` here because yaml is actually an existing
27    # namespace member of _yaml.
28
29__name__ = '_yaml'
30# If the module is top-level (i.e. not a part of any specific package)
31# then the attribute should be set to ''.
32# https://docs.python.org/3.8/library/types.html
33__package__ = ''
34