# Path: wikitextparser/_spans.py
# ATTRS_PATTERN = ( # noqa
#     rb'(?<attr>'
#         rb'[' + SPACE_CHARS + rb']++(?>' + ATTR_NAME + ATTR_VAL + rb')'
#         # Invalid attribute. Todo: could the / be removed? see
#         # https://stackoverflow.com/a/3558200/2705757
#         + rb'|(?>[^>/]++|/(?!\s*+>))++'
#     rb')*+(?<attr_insert>)')
# 
# END_TAG_PATTERN = rb'(?<end_tag></{name}(?:>|[' + SPACE_CHARS + rb'][^>]*+>))'
# 
# SPACE_CHARS = rb' \t\n\u000C\r'  # \s - \v
# 
# Path: wikitextparser/_wikitext.py
# class SubWikiText(WikiText):
#     """Define a class to be inherited by some subclasses of WikiText.
# 
#     Allow to focus on a particular part of WikiText.
#     """
# 
#     __slots__ = '_type'
# 
#     def __init__(
#         self,
#         string: Union[str, MutableSequence[str]],
#         _type_to_spans: Optional[Dict[str, List[List[int]]]] = None,
#         _span: Optional[List[int]] = None,
#         _type: Optional[Union[str, int]] = None,
#     ) -> None:
#         """Initialize the object."""
#         if _type is None:
#             # assert _span is None
#             # assert _type_to_spans is None
#             self._type = _type = type(self).__name__
#             super().__init__(string)
#         else:
#             # assert _span is not None
#             # assert _type_to_spans is not None
#             self._type = _type
#             super().__init__(string, _type_to_spans)
#             self._span_data = _span
# 
#     def _subspans(self, _type: str) -> Generator[int, None, None]:
#         """Yield all the sub-span indices excluding self._span."""
#         ss, se, _, _ = self._span_data
#         spans = self._type_to_spans[_type]
#         # Do not yield self._span by bisecting for s < ss.
#         # The second bisect is an optimization and should be on [se + 1],
#         # but empty spans are not desired thus [se] is used.
#         b = bisect_left(spans, [ss])
#         for span in spans[b:bisect_right(spans, [se], b)]:
#             if span[1] <= se:
#                 yield span
# 
#     # noinspection PyProtectedMember
#     def ancestors(self, type_: Optional[str] = None) -> List['WikiText']:
#         """Return the ancestors of the current node.
# 
#         :param type_: the type of the desired ancestors as a string.
#             Currently the following types are supported: {Template,
#             ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
#             The default is None and means all the ancestors of any type above.
#         """
#         if type_ is None:
#             types = SPAN_PARSER_TYPES
#         else:
#             types = type_,
#         lststr = self._lststr
#         type_to_spans = self._type_to_spans
#         ss, se, _, _ = self._span_data
#         ancestors = []
#         ancestors_append = ancestors.append
#         for type_ in types:
#             cls = globals()[type_]
#             spans = type_to_spans[type_]
#             for span in spans[:bisect_right(spans, [ss])]:
#                 if se < span[1]:
#                     ancestors_append(cls(lststr, type_to_spans, span, type_))
#         return sorted(ancestors, key=lambda i: ss - i._span_data[0])
# 
#     def parent(self, type_: Optional[str] = None) -> Optional['WikiText']:
#         """Return the parent node of the current object.
# 
#         :param type_: the type of the desired parent object.
#             Currently the following types are supported: {Template,
#             ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
#             The default is None and means the first parent, of any type above.
#         :return: parent WikiText object or None if no parent with the desired
#             `type_` is found.
#         """
#         ancestors = self.ancestors(type_)
#         if ancestors:
#             return ancestors[0]
#         return None


from typing import Any, Dict, List, Optional
from regex import DOTALL, VERBOSE, compile as regex_compile
from ._spans import ATTRS_PATTERN, END_TAG_PATTERN, SPACE_CHARS
from ._wikitext import SubWikiText
            Set contents to a new value.
            Note that if the tag is self-closing, then it will be expanded to
            have a start tag and an end tag. For example:
            >>> t = Tag('<t/>')
            >>> t.contents = 'n'
            >>> t.string
            '<t>n</t>'
        """
        s, e = self._match.span('contents')
        return self(s, e)

    @contents.setter
    def contents(self, contents: str) -> None:
        match = self._match
        start, end = match.span('contents')
        if start != -1:
            self[start:end] = contents
        else:
            # This is a self-closing tag.
            s, e = match.span('self_closing')
            self[s:e] = '>{0}</{1}>'.format(contents, match['name'].decode())

    @property
    def parsed_contents(self) -> SubWikiText:
        """Return the contents as a SubWikiText object."""
        ss, _, _, byte_array = self._span_data
        s, e = self._match.span('contents')
        type_to_spans = self._type_to_spans
        span = type_to_spans.setdefault(
            'SubWikiText', [ss + s, ss + e, None, byte_array[s:e]])

# Path: wikitextparser/_spans.py
# ATTRS_PATTERN = ( # noqa
#     rb'(?<attr>'
#         rb'[' + SPACE_CHARS + rb']++(?>' + ATTR_NAME + ATTR_VAL + rb')'
#         # Invalid attribute. Todo: could the / be removed? see
#         # https://stackoverflow.com/a/3558200/2705757
#         + rb'|(?>[^>/]++|/(?!\s*+>))++'
#     rb')*+(?<attr_insert>)')
# 
# END_TAG_PATTERN = rb'(?<end_tag></{name}(?:>|[' + SPACE_CHARS + rb'][^>]*+>))'
# 
# SPACE_CHARS = rb' \t\n\u000C\r'  # \s - \v
# 
# Path: wikitextparser/_wikitext.py
# class SubWikiText(WikiText):
#     """Define a class to be inherited by some subclasses of WikiText.
# 
#     Allow to focus on a particular part of WikiText.
#     """
# 
#     __slots__ = '_type'
# 
#     def __init__(
#         self,
#         string: Union[str, MutableSequence[str]],
#         _type_to_spans: Optional[Dict[str, List[List[int]]]] = None,
#         _span: Optional[List[int]] = None,
#         _type: Optional[Union[str, int]] = None,
#     ) -> None:
#         """Initialize the object."""
#         if _type is None:
#             # assert _span is None
#             # assert _type_to_spans is None
#             self._type = _type = type(self).__name__
#             super().__init__(string)
#         else:
#             # assert _span is not None
#             # assert _type_to_spans is not None
#             self._type = _type
#             super().__init__(string, _type_to_spans)
#             self._span_data = _span
# 
#     def _subspans(self, _type: str) -> Generator[int, None, None]:
#         """Yield all the sub-span indices excluding self._span."""
#         ss, se, _, _ = self._span_data
#         spans = self._type_to_spans[_type]
#         # Do not yield self._span by bisecting for s < ss.
#         # The second bisect is an optimization and should be on [se + 1],
#         # but empty spans are not desired thus [se] is used.
#         b = bisect_left(spans, [ss])
#         for span in spans[b:bisect_right(spans, [se], b)]:
#             if span[1] <= se:
#                 yield span
# 
#     # noinspection PyProtectedMember
#     def ancestors(self, type_: Optional[str] = None) -> List['WikiText']:
#         """Return the ancestors of the current node.
# 
#         :param type_: the type of the desired ancestors as a string.
#             Currently the following types are supported: {Template,
#             ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
#             The default is None and means all the ancestors of any type above.
#         """
#         if type_ is None:
#             types = SPAN_PARSER_TYPES
#         else:
#             types = type_,
#         lststr = self._lststr
#         type_to_spans = self._type_to_spans
#         ss, se, _, _ = self._span_data
#         ancestors = []
#         ancestors_append = ancestors.append
#         for type_ in types:
#             cls = globals()[type_]
#             spans = type_to_spans[type_]
#             for span in spans[:bisect_right(spans, [ss])]:
#                 if se < span[1]:
#                     ancestors_append(cls(lststr, type_to_spans, span, type_))
#         return sorted(ancestors, key=lambda i: ss - i._span_data[0])
# 
#     def parent(self, type_: Optional[str] = None) -> Optional['WikiText']:
#         """Return the parent node of the current object.
# 
#         :param type_: the type of the desired parent object.
#             Currently the following types are supported: {Template,
#             ParserFunction, WikiLink, Comment, Parameter, ExtensionTag}.
#             The default is None and means the first parent, of any type above.
#         :return: parent WikiText object or None if no parent with the desired
#             `type_` is found.
#         """
#         ancestors = self.ancestors(type_)
#         if ancestors:
#             return ancestors[0]
#         return None


# Path: wikitextparser/_tag.py
from typing import Any, Dict, List, Optional
from regex import DOTALL, VERBOSE, compile as regex_compile
from ._spans import ATTRS_PATTERN, END_TAG_PATTERN, SPACE_CHARS
from ._wikitext import SubWikiText

            Set contents to a new value.
            Note that if the tag is self-closing, then it will be expanded to
            have a start tag and an end tag. For example:
            >>> t = Tag('<t/>')
            >>> t.contents = 'n'
            >>> t.string
            '<t>n</t>'
        """
        s, e = self._match.span('contents')
        return self(s, e)

    @contents.setter
    def contents(self, contents: str) -> None:
        match = self._match
        start, end = match.span('contents')
        if start != -1:
            self[start:end] = contents
        else:
            # This is a self-closing tag.
            s, e = match.span('self_closing')
            self[s:e] = '>{0}</{1}>'.format(contents, match['name'].decode())

    @property
    def parsed_contents(self) -> SubWikiText:
        """Return the contents as a SubWikiText object."""
        ss, _, _, byte_array = self._span_data
        s, e = self._match.span('contents')
        type_to_spans = self._type_to_spans
        span = type_to_spans.setdefault(
            'SubWikiText', [ss + s, ss + e, None, byte_array[s:e]])

        return SubWikiText(self._lststr, type_to_spans, span, 'SubWikiText')