# 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 __init__(self, *args, oktypes=object, parent=None):
        self.oktypes = oktypes
        self.parent = parent
        self.location = None  # Cannot be set through __init__

        self.list = []
        self.extend(args)  # self.oktypes must be set first

    def __contains__(self, item):
        return item in self.list

    def __len__(self):
        return len(self.list)

    def __getitem__(self, i):
        if isinstance(i, int):
            return attach(self.list[i], self.parent, self.location)
        else:
            newlist = self.list.__getitem__(i)
            obj = ListContainer(*newlist,
                                oktypes=self.oktypes, parent=self.parent)
            obj.location = self.location
            return obj

    def __delitem__(self, i):
        del self.list[i]

    def __setitem__(self, i, v):
        if isinstance(i, slice):

# 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 __init__(self, *args, oktypes=object, parent=None):
        self.oktypes = oktypes
        self.parent = parent
        self.location = None  # Cannot be set through __init__

        self.list = []
        self.extend(args)  # self.oktypes must be set first

    def __contains__(self, item):
        return item in self.list

    def __len__(self):
        return len(self.list)

    def __getitem__(self, i):
        if isinstance(i, int):
            return attach(self.list[i], self.parent, self.location)
        else:
            newlist = self.list.__getitem__(i)
            obj = ListContainer(*newlist,
                                oktypes=self.oktypes, parent=self.parent)
            obj.location = self.location
            return obj

    def __delitem__(self, i):
        del self.list[i]

    def __setitem__(self, i, v):
        if isinstance(i, slice):

            v = (check_type(x, self.oktypes) for x in v)