Used for storing descriptive text elements. Attributes: 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``.
| 18 | |
| 19 | |
| 20 | class StructuredText(stix.Entity): |
| 21 | """Used for storing descriptive text elements. |
| 22 | |
| 23 | Attributes: |
| 24 | id_: An id for the text element, typically used for controlled |
| 25 | structure xpath selectors. |
| 26 | value: The text value of this object. |
| 27 | structuring_format: The format of the text. For example, ``html5``. |
| 28 | """ |
| 29 | |
| 30 | _binding = stix_common_binding |
| 31 | _binding_class = _binding.StructuredTextType |
| 32 | _namespace = 'http://docs.oasis-open.org/cti/ns/stix/common-1' |
| 33 | |
| 34 | id_ = fields.IdField("id") |
| 35 | ordinality = fields.TypedField("ordinality") |
| 36 | value = fields.TypedField("valueOf_", key_name="value") |
| 37 | structuring_format = fields.TypedField("structuring_format") |
| 38 | |
| 39 | |
| 40 | def __init__(self, value=None, ordinality=None): |
| 41 | super(StructuredText, self).__init__() |
| 42 | |
| 43 | self.id_ = None |
| 44 | self.value = value |
| 45 | self.structuring_format = None |
| 46 | self.ordinality = ordinality |
| 47 | |
| 48 | def is_plain(self): |
| 49 | plain = ( |
| 50 | (not self.id_) and |
| 51 | (not self.structuring_format) and |
| 52 | (self.ordinality is None) |
| 53 | ) |
| 54 | |
| 55 | return plain |
| 56 | |
| 57 | def to_dict(self): |
| 58 | """Converts this object into a dictionary representation. |
| 59 | |
| 60 | Note: |
| 61 | If no properies or attributes are set other than ``value``, |
| 62 | this will return a string. |
| 63 | |
| 64 | """ |
| 65 | # Return a plain string if there is no format specified. |
| 66 | if self.is_plain(): |
| 67 | return self.value |
| 68 | else: |
| 69 | return super(StructuredText, self).to_dict() |
| 70 | |
| 71 | def __str__(self): |
| 72 | """Returns a UTF-8 encoded string representation of the ``value``. |
| 73 | |
| 74 | """ |
| 75 | if version_info < (3,): |
| 76 | return self.__unicode__().encode("utf-8") |
| 77 | else: |
no outgoing calls