dj_angles.attributes ==================== .. py:module:: dj_angles.attributes Module Contents --------------- .. py:data:: VALID_ATTRIBUTE_TOKEN_COUNT :value: 2 .. py:class:: Attribute(attribute: str) Encapsulates an attribute in an element. Attributes are a key-value pair, but the value can be `None`. .. rubric:: Examples - `` has 1 attribute: `'partial.html'`. The value is `None`. - `` has 2 attributes: `'partial.html'` and `shadow`. The value is `None`. - `` has 3 attributes: `'partial.html'`, `shadow`, `test`. The first 2 attributes have a value of `None`, but `test` has a value of `True`. .. py:attribute:: key :type: str Key of the attribute. Always defined. .. py:attribute:: value :type: Optional[str] :value: None Optional value of the attribute. Defaults to `None`. .. py:attribute:: has_value :type: bool :value: False Whether or not the attribute has a value. .. py:class:: Attributes(template_tag_args: str) Bases: :py:obj:`collections.abc.Sequence` A list of attributes, usually inside a :obj:`~dj_angles.tags.Tag`. .. py:attribute:: template_tag_args :type: str The original attributes as an unparsed string. .. py:method:: parse() Parse the attributes string to generate a list of :obj:`~dj_angles.attributes.Attribute` objects. .. py:method:: get(name: str) -> Optional[Attribute] Get an :obj:`~dj_angles.attributes.Attribute` by name. Returns `None` if the attribute is missing. :param param name: The name of the attribute. :param param default: What to return if the attribute is not available. Defaults to `None`. .. py:method:: remove(key: str) -> None Removes an attribute from the list. :param param key: The key of the attribute to remove. :raises ~dj_angles.exceptions.MissingAttributeError: If the attribute is missing. .. py:method:: pop(index: SupportsIndex) -> Attribute Remove and return the last attribute. .. py:method:: prepend(attribute_string: str) -> None Parse the attribute string as an `Attribute` and add it to the beginning of the list of attributes. :param param attribute_string: The attribute as a string. :raises ~dj_angles.exceptions.DuplicateAttributeError: If the attribute conflicts with an existing attribute. .. py:method:: append(attribute_string: str) -> None Parse the attribute string as an `Attribute` and add it to the end of the list of attributes. :param param attribute_string: The attribute as a string. :raises ~dj_angles.exceptions.DuplicateAttributeError: If the attribute conflicts with an existing attribute.