Version: 1.2.0.10

stix.common.structured_text Module

Classes

class stix.common.structured_text.StructuredText(value=None, ordinality=None)

Bases: stix.base.Entity

Used for storing descriptive text elements.

id_

An id for the text element, typically used for controlled structure xpath selectors.

value

The text value of this object.

structuring_format

The format of the text. For example, html5.

__str__()

Returns a UTF-8 encoded string representation of the value.

__unicode__()

Returns a unicode string representation of the value.

to_dict()

Converts this object into a dictionary representation.

Note

If no properies or attributes are set other than value, this will return a string.

to_obj(ns_info=None)

Convert to a GenerateDS binding object.

Subclasses can override this function.

Returns:An instance of this Entity’s _binding_class with properties set from this Entity.
class stix.common.structured_text.StructuredTextList(*args)

Bases: stix.base.TypedCollection, _abcoll.Sequence

A sequence type used to store StructureText objects.

Parameters:*args – A variable-length argument list which can contain single StructuredText objects or sequences of objects.
__delitem__(key)

Removes the item with a given ordinality.

Parameters:key – An ordinality value.
Raises:KeyError – If the key does not match the ordinality for any object in the collection.
__getitem__(key)

Returns the StructuredText object with a matching ordinality.

Parameters:key – An ordinality value.
Raises:KeyError – If key does not match the ordinality of any StructuredText object.
__iter__()

Returns an iterator for the collection sorted by ordinality.

add(value)

Adds the StructuredText value to the collection.

If value is not a StructuredText object, an attempt will be made to convert it to one.

Note

If value does not have an ordinality set, one will be assigned. If value has an ordinality which matches one already in the collection, value will replace the existing item.

Parameters:value – A StructuredText object.
insert(value)

Inserts value into the collection.

If value has an ordinality which conflicts with an existing value, the existing value (and any contiguous values) will have their ordinality values incremented by one.

next_ordinality

Returns the “+1” of the highest ordinality in the collection.

remove(value)

Removes the value from the collection.

reset()

Assigns sequential ordinality values to each of the sorted StructuredText objects, starting with 1 and ending at len(self).

sorted

Returns a copy of the collection of internal StructuredText objects, sorted by their ordinality.

to_dict()

Returns a list of dictionary representations of the contained objects.

An attempt is made to flatten out the returned list when there is only one item in the collection. This is to support backwards compatibility with previous versions of python-stix.

  • If the list repr has more than one item, return the list.
  • If there is only one item, inspect it.
    • If the item is not a dictionary, return it.
    • If its ordinality key has a corresponding value of 1, remove it from the dictionary since it’s assumed if there is only one item.
    • After removing ordinality, if the only key left is value, just return the value of value (a string).
to_obj(ns_info=None)

Returns a binding object list for the StructuredTextList.

If the list has a length of 1, and its member has an ordinality of 1, the ordinality will be unset.

update(iterable)

Adds each item of iterable to the collection.

Note

Any existing objects with conflicting ordinality values will be overwritten.

Parameters:iterable – An iterable collection of StructuredText objects to add to this collection.