# Path: exdir/core/mode.py
# def assert_file_open(file_object):
#     """
#     Decorator to check if the file is not closed.
#     """
#     if file_object.io_mode == OpenMode.FILE_CLOSED:
#         raise IOError("Unable to operate on closed File instance.")
# 
# class OpenMode(Enum):
#     READ_WRITE = 1
#     READ_ONLY = 2
#     FILE_CLOSED = 3
# 
# def assert_file_writable(file_object):
#     """
#     Decorator to check if the file is not closed,
#     and that it is not in read only mode.
#     """
#     if file_object.io_mode == OpenMode.FILE_CLOSED:
#         raise IOError("Unable to operate on closed File instance.")
#     if file_object.io_mode == OpenMode.READ_ONLY:
#         raise IOError("Cannot change data on file in read only 'r' mode")


from enum import Enum
from .mode import assert_file_open, OpenMode, assert_file_writable
import os
import numpy as np
import exdir
    import ruamel_yaml as yaml
    import ruamel.yaml as yaml

        with self.filename.open("w", encoding="utf-8") as attribute_file:
            yaml.dump(
                attribute_data_quoted,
                attribute_file,
                default_flow_style=False,
                allow_unicode=True,
                Dumper=yaml.RoundTripDumper
            )

    # TODO only needs filename, make into free function
    def _open_or_create(self):
        assert_file_open(self.file)
        attrs = {}
        if self.filename.exists():  # NOTE str for Python 3.5 support
            with self.filename.open("r", encoding="utf-8") as meta_file:
                attrs = yaml.safe_load(meta_file)
        return attrs

    def __iter__(self):
        for key in self.keys():
            yield key

    @property
    def filename(self):
        """
        Returns
        -------
        The filename of the :code:`attributes.yaml` file.
        """

# Path: exdir/core/mode.py
# def assert_file_open(file_object):
#     """
#     Decorator to check if the file is not closed.
#     """
#     if file_object.io_mode == OpenMode.FILE_CLOSED:
#         raise IOError("Unable to operate on closed File instance.")
# 
# class OpenMode(Enum):
#     READ_WRITE = 1
#     READ_ONLY = 2
#     FILE_CLOSED = 3
# 
# def assert_file_writable(file_object):
#     """
#     Decorator to check if the file is not closed,
#     and that it is not in read only mode.
#     """
#     if file_object.io_mode == OpenMode.FILE_CLOSED:
#         raise IOError("Unable to operate on closed File instance.")
#     if file_object.io_mode == OpenMode.READ_ONLY:
#         raise IOError("Cannot change data on file in read only 'r' mode")


# Path: exdir/core/attribute.py
from enum import Enum
from .mode import assert_file_open, OpenMode, assert_file_writable
import os
import numpy as np
import exdir
    import ruamel_yaml as yaml
    import ruamel.yaml as yaml


        with self.filename.open("w", encoding="utf-8") as attribute_file:
            yaml.dump(
                attribute_data_quoted,
                attribute_file,
                default_flow_style=False,
                allow_unicode=True,
                Dumper=yaml.RoundTripDumper
            )

    # TODO only needs filename, make into free function
    def _open_or_create(self):
        assert_file_open(self.file)
        attrs = {}
        if self.filename.exists():  # NOTE str for Python 3.5 support
            with self.filename.open("r", encoding="utf-8") as meta_file:
                attrs = yaml.safe_load(meta_file)
        return attrs

    def __iter__(self):
        for key in self.keys():
            yield key

    @property
    def filename(self):
        """
        Returns
        -------
        The filename of the :code:`attributes.yaml` file.
        """

        assert_file_open(self.file)