# Path: panflute/utils.py
# def check_type(value, oktypes):
#     # This allows 'Space' instead of 'Space()'
#     if callable(value):
#         value = value()
# 
#     if isinstance(value, oktypes):
#         return value
# 
#     # Invalid type
#     caller = get_caller_name()
#     tag = type(value).__name__
#     msg = '\n\nElement "{}" received "{}" but expected {}\n'.format(caller, tag, oktypes)
#     raise TypeError(msg)
# 
# def encode_dict(tag, content):
#     return {
#         "t": tag,
#         "c": content,
#     }
# 
# def debug(*args, **kwargs):
#     """
#     Same as print, but prints to ``stderr``
#     (which is not intercepted by Pandoc).
#     """
#     print(file=sys.stderr, *args, **kwargs)


from collections.abc import MutableSequence, MutableMapping
from .utils import check_type, encode_dict, debug

    def __delitem__(self, k):
        del self.dict[k]

    def __setitem__(self, k, v):
        v = check_type(v, self.oktypes)
        self.dict[k] = v

    def __str__(self):
        return self.__repr__()

    def __repr__(self):
        return 'DictContainer({})'.format(' '.join(repr(x) for x in self.dict))

    def __iter__(self):
        return self.dict.__iter__()

    def to_json(self):
        return {k: to_json_wrapper(v) for k, v in self.dict.items()}


# ---------------------------
# Functions
# ---------------------------

def attach(element, parent, location):
    if not isinstance(element, (int, str, bool)):
        element.parent = parent
        element.location = location
    else:

# Path: panflute/utils.py
# def check_type(value, oktypes):
#     # This allows 'Space' instead of 'Space()'
#     if callable(value):
#         value = value()
# 
#     if isinstance(value, oktypes):
#         return value
# 
#     # Invalid type
#     caller = get_caller_name()
#     tag = type(value).__name__
#     msg = '\n\nElement "{}" received "{}" but expected {}\n'.format(caller, tag, oktypes)
#     raise TypeError(msg)
# 
# def encode_dict(tag, content):
#     return {
#         "t": tag,
#         "c": content,
#     }
# 
# def debug(*args, **kwargs):
#     """
#     Same as print, but prints to ``stderr``
#     (which is not intercepted by Pandoc).
#     """
#     print(file=sys.stderr, *args, **kwargs)


# Path: panflute/containers.py
from collections.abc import MutableSequence, MutableMapping
from .utils import check_type, encode_dict, debug


    def __delitem__(self, k):
        del self.dict[k]

    def __setitem__(self, k, v):
        v = check_type(v, self.oktypes)
        self.dict[k] = v

    def __str__(self):
        return self.__repr__()

    def __repr__(self):
        return 'DictContainer({})'.format(' '.join(repr(x) for x in self.dict))

    def __iter__(self):
        return self.dict.__iter__()

    def to_json(self):
        return {k: to_json_wrapper(v) for k, v in self.dict.items()}


# ---------------------------
# Functions
# ---------------------------

def attach(element, parent, location):
    if not isinstance(element, (int, str, bool)):
        element.parent = parent
        element.location = location
    else:

        debug(f'Warning: element "{type(element)}" has no parent')