import yaml


def load(stream, is_safe=True):
    """Converts a YAML document to a Python object.

    :param stream: the YAML document to convert into a Python object. Accepts
                   a byte string, a Unicode string, an open binary file object,
                   or an open text file object.
    :param is_safe: Turn off safe loading. True by default and only load
                    standard YAML. This option can be turned off by
                    passing ``is_safe=False`` if you need to load not only
                    standard YAML tags or if you need to construct an
                    arbitrary python object.

    Stream specifications:

    * An empty stream contains no documents.
    * Documents are separated with ``---``.
    * Documents may optionally end with ``...``.
    * A single document may or may not be marked with ``---``.

    Parses the given stream and returns a Python object constructed
    from the first document in the stream. If there are no documents
    in the stream, it returns None.
    """
    yaml_loader = yaml.Loader
    if is_safe:
        if hasattr(yaml, 'CSafeLoader'):
            yaml_loader = yaml.CSafeLoader
        else:
            yaml_loader = yaml.SafeLoader
    return yaml.load(stream, yaml_loader)