# Path: htmlgen/attribute.py
# class int_html_attribute:
#     """Add an attribute to an HTML element that accepts only integers.
# 
#         >>> from htmlgen import Element
#         >>> class MyElement(Element):
#         ...     value = int_html_attribute("data-value")
#         >>> element = MyElement("div")
#         >>> element.value
#         >>> str(element)
#         '<div></div>'
#         >>> element.value = 42
#         >>> str(element)
#         '<div data-value="42"></div>'
# 
#     If the optional default argument is given, the attribute will not be
#     included if the value matches it.
# 
#         >>> class MyElement(Element):
#         ...     value = int_html_attribute("data-value", default=0)
#         >>> element = MyElement("div")
#         >>> element.value
#         0
#         >>> str(element)
#         '<div></div>'
# 
#     """
# 
#     def __init__(self, attribute_name, default=None):
#         self._attribute_name = attribute_name
#         self._default = default
# 
#     def __get__(self, obj, _=None):
#         value = obj.get_attribute(self._attribute_name, default=self._default)
#         if value is None:
#             return None
#         return int(value)
# 
#     def __set__(self, obj, value):
#         if value is None or value == self._default:
#             obj.remove_attribute(self._attribute_name)
#         else:
#             obj.set_attribute(self._attribute_name, str(value))
# 
# Path: htmlgen/element.py
# class Element(NonVoidElement):
# 
#     """Base generator for HTML elements with children.
# 
#     This includes most elements, like <body>, <div>, <span>, <strong>, etc.
# 
#         >>> link = Element("a")
#         >>> link.set_attribute("href", "http://www.example.com/")
#         >>> link.append("Test Link")
#         >>> str(link)
#         '<a href="http://www.example.com/">Test Link</a>'
# 
#     append() and extend() escape reserved HTML characters in string, but
#     not in sub-generators:
# 
#         >>> span = Element("span")
#         >>> span.add_css_classes("my-css")
#         >>> span.set_style("color", "red")
#         >>> span.append("Test & Test")
#         >>> str(span)
#         '<span class="my-css" style="color: red">Test &amp; Test</span>'
# 
#     append_raw() and extend_raw() do not do any escaping. Do not use these
#     methods with strings from untrusted sources!
# 
#         >>> span = Element("span")
#         >>> span.append_raw("Test<br/>Test")
#         >>> str(span)
#         '<span>Test<br/>Test</span>'
# 
#     Instead of appending children to elements, the generate_children()
#     method can be overwritten. This is generally preferred for element
#     sub-classes that are not meant to be extended by users, since it avoids
#     constructing the HTML tree in memory.
# 
#         >>> class MyElement(Element):
#         ...     def generate_children(self):
#         ...         yield "Hello, "
#         ...         child = Element("strong")
#         ...         child.append("World!")
#         ...         yield child
#         >>> str(MyElement("div"))
#         '<div>Hello, <strong>World!</strong></div>'
# 
#     """
# 
#     def __init__(self, element_name):
#         super().__init__(element_name)
#         self.children = HTMLChildGenerator()
# 
#     def __bool__(self):
#         return True
# 
#     def __getattr__(self, item):
#         return getattr(self.children, item)
# 
#     def __len__(self):
#         """Return the number of children.
# 
#         A sub-generator is counted as one child.
# 
#         """
#         return len(self.children)
# 
#     def __nonzero__(self):
#         return True
# 
#     def generate_children(self):
#         """Return an iterator over the children of this element.
# 
#         This method can be overridden by sub-classes.
# 
#         """
#         return self.children


from htmlgen.attribute import int_html_attribute
from htmlgen.element import Element

class DescriptionList(Element):
    """An HTML description list (<dl>) element.

    This used to be known as a "definition list" and is a list of terms and
    their descriptions.

        >>> dl = DescriptionList()
        >>> term, definition = dl.create_item("Term", "Long description.")
        >>> term.add_css_classes("my-term")
        >>> str(dl)
        '<dl><dt class="my-term">Term</dt><dd>Long description.</dd></dl>'
    """

    def __init__(self):
        super().__init__("dl")

    def create_item(self, term, description):
        """Create term and definition elements and add them to the list.

        Returns a (term element, description element) tuple.

        """
        dt = DescriptionTerm(term)
        dd = DescriptionDefinition(description)
        self.append(dt)
        self.append(dd)
        return dt, dd



# Path: htmlgen/attribute.py
# class int_html_attribute:
#     """Add an attribute to an HTML element that accepts only integers.
# 
#         >>> from htmlgen import Element
#         >>> class MyElement(Element):
#         ...     value = int_html_attribute("data-value")
#         >>> element = MyElement("div")
#         >>> element.value
#         >>> str(element)
#         '<div></div>'
#         >>> element.value = 42
#         >>> str(element)
#         '<div data-value="42"></div>'
# 
#     If the optional default argument is given, the attribute will not be
#     included if the value matches it.
# 
#         >>> class MyElement(Element):
#         ...     value = int_html_attribute("data-value", default=0)
#         >>> element = MyElement("div")
#         >>> element.value
#         0
#         >>> str(element)
#         '<div></div>'
# 
#     """
# 
#     def __init__(self, attribute_name, default=None):
#         self._attribute_name = attribute_name
#         self._default = default
# 
#     def __get__(self, obj, _=None):
#         value = obj.get_attribute(self._attribute_name, default=self._default)
#         if value is None:
#             return None
#         return int(value)
# 
#     def __set__(self, obj, value):
#         if value is None or value == self._default:
#             obj.remove_attribute(self._attribute_name)
#         else:
#             obj.set_attribute(self._attribute_name, str(value))
# 
# Path: htmlgen/element.py
# class Element(NonVoidElement):
# 
#     """Base generator for HTML elements with children.
# 
#     This includes most elements, like <body>, <div>, <span>, <strong>, etc.
# 
#         >>> link = Element("a")
#         >>> link.set_attribute("href", "http://www.example.com/")
#         >>> link.append("Test Link")
#         >>> str(link)
#         '<a href="http://www.example.com/">Test Link</a>'
# 
#     append() and extend() escape reserved HTML characters in string, but
#     not in sub-generators:
# 
#         >>> span = Element("span")
#         >>> span.add_css_classes("my-css")
#         >>> span.set_style("color", "red")
#         >>> span.append("Test & Test")
#         >>> str(span)
#         '<span class="my-css" style="color: red">Test &amp; Test</span>'
# 
#     append_raw() and extend_raw() do not do any escaping. Do not use these
#     methods with strings from untrusted sources!
# 
#         >>> span = Element("span")
#         >>> span.append_raw("Test<br/>Test")
#         >>> str(span)
#         '<span>Test<br/>Test</span>'
# 
#     Instead of appending children to elements, the generate_children()
#     method can be overwritten. This is generally preferred for element
#     sub-classes that are not meant to be extended by users, since it avoids
#     constructing the HTML tree in memory.
# 
#         >>> class MyElement(Element):
#         ...     def generate_children(self):
#         ...         yield "Hello, "
#         ...         child = Element("strong")
#         ...         child.append("World!")
#         ...         yield child
#         >>> str(MyElement("div"))
#         '<div>Hello, <strong>World!</strong></div>'
# 
#     """
# 
#     def __init__(self, element_name):
#         super().__init__(element_name)
#         self.children = HTMLChildGenerator()
# 
#     def __bool__(self):
#         return True
# 
#     def __getattr__(self, item):
#         return getattr(self.children, item)
# 
#     def __len__(self):
#         """Return the number of children.
# 
#         A sub-generator is counted as one child.
# 
#         """
#         return len(self.children)
# 
#     def __nonzero__(self):
#         return True
# 
#     def generate_children(self):
#         """Return an iterator over the children of this element.
# 
#         This method can be overridden by sub-classes.
# 
#         """
#         return self.children


# Path: htmlgen/list.py
from htmlgen.attribute import int_html_attribute
from htmlgen.element import Element


class DescriptionList(Element):
    """An HTML description list (<dl>) element.

    This used to be known as a "definition list" and is a list of terms and
    their descriptions.

        >>> dl = DescriptionList()
        >>> term, definition = dl.create_item("Term", "Long description.")
        >>> term.add_css_classes("my-term")
        >>> str(dl)
        '<dl><dt class="my-term">Term</dt><dd>Long description.</dd></dl>'
    """

    def __init__(self):
        super().__init__("dl")

    def create_item(self, term, description):
        """Create term and definition elements and add them to the list.

        Returns a (term element, description element) tuple.

        """
        dt = DescriptionTerm(term)
        dd = DescriptionDefinition(description)
        self.append(dt)
        self.append(dd)
        return dt, dd



class DescriptionTerm(Element):