class Attributes

from dj_angles.attributes import Attributes
A list of attributes, usually inside a :obj:`~dj_angles.tags.Tag`.

Ancestors (MRO)

  1. builtins.object
  2. collections.abc.Container
  3. collections.abc.Iterable
  4. collections.abc.Sized
  5. collections.abc.Collection
  6. collections.abc.Reversible
  7. collections.abc.Sequence
  8. dj_angles.attributes.Attributes
AttributeTypeDefined in
AttributeValueDefined in
def __class_getitem__(self)
collections.abc.Iterable
collections.abc.Iterable
Represent a PEP 585 generic type

E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
collections.abc.Container
Represent a PEP 585 generic type

E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
def __contains__(self, value)
collections.abc.Sequence
collections.abc.Sequence
    def __contains__(self, value):
        for v in self:
            if v is value or v == value:
                return True
        return False
collections.abc.Container
    @abstractmethod
    def __contains__(self, x):
        return False
def __getitem__(self, index)
dj_angles.attributes.Attributes
dj_angles.attributes.Attributes
    def __getitem__(self, index):
        return self._attributes.__getitem__(index)
collections.abc.Sequence
    @abstractmethod
    def __getitem__(self, index):
        raise IndexError
def __init__(self)
dj_angles.attributes.Attributes
Initialize self.  See help(type(self)) for accurate signature.
    def __init__(self, template_tag_args: str):
        self._attributes: list[Attribute] = []

        self.template_tag_args = template_tag_args
        self.parse()
def __iter__(self)
dj_angles.attributes.Attributes
dj_angles.attributes.Attributes
    def __iter__(self):
        return self._attributes.__iter__()
collections.abc.Sequence
    def __iter__(self):
        i = 0
        try:
            while True:
                v = self[i]
                yield v
                i += 1
        except IndexError:
            return
collections.abc.Iterable
    @abstractmethod
    def __iter__(self):
        while False:
            yield None
def __len__(self)
dj_angles.attributes.Attributes
dj_angles.attributes.Attributes
    def __len__(self):
        return self._attributes.__len__()
collections.abc.Sized
    @abstractmethod
    def __len__(self):
        return 0
def __reversed__(self)
collections.abc.Sequence
collections.abc.Sequence
    def __reversed__(self):
        for i in reversed(range(len(self))):
            yield self[i]
collections.abc.Reversible
    @abstractmethod
    def __reversed__(self):
        while False:
            yield None
def __str__(self)
dj_angles.attributes.Attributes
Return str(self).
    def __str__(self):
        s = ""

        for attribute in self._attributes:
            s = f"{s} {attribute}"

        return s.strip()
def __subclasshook__(cls, C)
collections.abc.Reversible
collections.abc.Reversible
    @classmethod
    def __subclasshook__(cls, C):
        if cls is Reversible:
            return _check_methods(C, "__reversed__", "__iter__")
        return NotImplemented
collections.abc.Collection
    @classmethod
    def __subclasshook__(cls, C):
        if cls is Collection:
            return _check_methods(C,  "__len__", "__iter__", "__contains__")
        return NotImplemented
collections.abc.Sized
    @classmethod
    def __subclasshook__(cls, C):
        if cls is Sized:
            return _check_methods(C, "__len__")
        return NotImplemented
collections.abc.Iterable
    @classmethod
    def __subclasshook__(cls, C):
        if cls is Iterable:
            return _check_methods(C, "__iter__")
        return NotImplemented
collections.abc.Container
    @classmethod
    def __subclasshook__(cls, C):
        if cls is Container:
            return _check_methods(C, "__contains__")
        return NotImplemented
def append(self)
dj_angles.attributes.Attributes
Parse the attribute string as an `Attribute` and add it to the end of the list of attributes.

Args:
    param attribute_string: The attribute as a string.

Raises:
    :obj:`~dj_angles.exceptions.DuplicateAttributeError`: If the attribute conflicts with an existing attribute.
    def append(self, attribute_string: str) -> None:
        """Parse the attribute string as an `Attribute` and add it to the end of the list of attributes.

        Args:
            param attribute_string: The attribute as a string.

        Raises:
            :obj:`~dj_angles.exceptions.DuplicateAttributeError`: If the attribute conflicts with an existing attribute.
        """

        _attribute = Attribute(attribute_string)

        if self.get(_attribute.key):
            raise DuplicateAttributeError("Already existing attribute key")

        self._attributes.append(_attribute)
def count(self, value)
collections.abc.Sequence
S.count(value) -> integer -- return number of occurrences of value
    def count(self, value):
        'S.count(value) -> integer -- return number of occurrences of value'
        return sum(1 for v in self if v is value or v == value)
def get(self)
dj_angles.attributes.Attributes
Get an :obj:`~dj_angles.attributes.Attribute` by name. Returns `None` if the attribute is missing.

Args:
    param name: The name of the attribute.
    param default: What to return if the attribute is not available. Defaults to `None`.
    def get(self, name: str) -> Optional[Attribute]:
        """Get an :obj:`~dj_angles.attributes.Attribute` by name. Returns `None` if the attribute is missing.

        Args:
            param name: The name of the attribute.
            param default: What to return if the attribute is not available. Defaults to `None`.
        """

        for attribute in self._attributes:
            if attribute.key == name:
                return attribute

        return None
def index(self, value, start=0, stop=None)
collections.abc.Sequence
S.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but
recommended.
    def index(self, value, start=0, stop=None):
        '''S.index(value, [start, [stop]]) -> integer -- return first index of value.
           Raises ValueError if the value is not present.

           Supporting start and stop arguments is optional, but
           recommended.
        '''
        if start is not None and start < 0:
            start = max(len(self) + start, 0)
        if stop is not None and stop < 0:
            stop += len(self)

        i = start
        while stop is None or i < stop:
            try:
                v = self[i]
                if v is value or v == value:
                    return i
            except IndexError:
                break
            i += 1
        raise ValueError
def parse(self)
dj_angles.attributes.Attributes
Parse the attributes string to generate a list of :obj:`~dj_angles.attributes.Attribute` objects.
    def parse(self):
        """Parse the attributes string to generate a list of :obj:`~dj_angles.attributes.Attribute` objects."""

        attribute_keys = set()

        for arg in yield_tokens(self.template_tag_args, " "):
            attribute = Attribute(arg)

            if attribute.key not in attribute_keys:
                self._attributes.append(attribute)
                attribute_keys.add(attribute.key)
def pop(self)
dj_angles.attributes.Attributes
Remove and return the last attribute.
    def pop(self, index: SupportsIndex) -> Attribute:
        """Remove and return the last attribute."""

        return self._attributes.pop(index)
def prepend(self)
dj_angles.attributes.Attributes
Parse the attribute string as an `Attribute` and add it to the beginning of the list of attributes.

Args:
    param attribute_string: The attribute as a string.

Raises:
    :obj:`~dj_angles.exceptions.DuplicateAttributeError`: If the attribute conflicts with an existing attribute.
    def prepend(self, attribute_string: str) -> None:
        """Parse the attribute string as an `Attribute` and add it to the beginning of the list of attributes.

        Args:
            param attribute_string: The attribute as a string.

        Raises:
            :obj:`~dj_angles.exceptions.DuplicateAttributeError`: If the attribute conflicts with an existing attribute.
        """

        _attribute = Attribute(attribute_string)

        if self.get(_attribute.key):
            raise DuplicateAttributeError("Already existing attribute key")

        self._attributes.insert(0, _attribute)
def remove(self)
dj_angles.attributes.Attributes
Removes an attribute from the list.

Args:
    param key: The key of the attribute to remove.

Raises:
    :obj:`~dj_angles.exceptions.MissingAttributeError`: If the attribute is missing.
    def remove(self, key: str) -> None:
        """Removes an attribute from the list.

        Args:
            param key: The key of the attribute to remove.

        Raises:
            :obj:`~dj_angles.exceptions.MissingAttributeError`: If the attribute is missing.
        """

        _attributes = []

        for attribute in self._attributes:
            if attribute.key != key:
                _attributes.append(attribute)

        if self._attributes == _attributes:
            raise MissingAttributeError("Attribute was not found.")

        self._attributes = _attributes