class Attribute

from dj_angles.attributes import Attribute
Encapsulates an attribute in an element. Attributes are a key-value pair, but the value can be
`None`.

Examples:
    - `<dj-include 'partial.html'>` has 1 attribute: `'partial.html'`. The value is `None`.
    - `<dj-include 'partial.html' shadow>` has 2 attributes: `'partial.html'` and `shadow`. The value is `None`.
    - `<dj-include 'partial.html' shadow test=True>` has 3 attributes: `'partial.html'`, `shadow`, `test`.            The first 2 attributes have a value of `None`, but `test` has a value of `True`.

Ancestors (MRO)

  1. builtins.object
  2. dj_angles.attributes.Attribute
AttributeTypeDefined in
AttributeValueDefined in
def __init__(self)
dj_angles.attributes.Attribute
Initialize self.  See help(type(self)) for accurate signature.
    def __init__(self, attribute: str):
        tokens = tuple(yield_tokens(attribute, "="))

        if not tokens:
            raise Exception("Invalid attribute")
        elif len(tokens) > VALID_ATTRIBUTE_TOKEN_COUNT:
            raise AssertionError(f"Invalid number of tokens in attribute: '{attribute}'")

        self.key = tokens[0]

        if len(tokens) > 1:
            self.value = tokens[1]
            self.has_value = True
def __str__(self)
dj_angles.attributes.Attribute
Return the attribute as a string.
    def __str__(self):
        """Return the attribute as a string."""

        if self.value is None:
            return self.key

        return f"{self.key}={self.value}"