| 18 | |
| 19 | |
| 20 | class InformationSource(stix.Entity): |
| 21 | _binding = stix_common_binding |
| 22 | _binding_class = stix_common_binding.InformationSourceType |
| 23 | _namespace = 'http://docs.oasis-open.org/cti/ns/stix/common-1' |
| 24 | |
| 25 | identity = fields.TypedField("Identity", type_=Identity, factory=IdentityFactory) |
| 26 | descriptions = fields.TypedField("Description", StructuredTextList) |
| 27 | contributing_sources = fields.TypedField("Contributing_Sources", type_="stix.common.information_source.ContributingSources") |
| 28 | time = fields.TypedField("Time", cybox.common.Time) |
| 29 | roles = VocabField("Role", multiple=True, key_name="roles") |
| 30 | tools = fields.TypedField("Tools", ToolInformationList) |
| 31 | references = fields.TypedField("References", References) |
| 32 | |
| 33 | def __init__(self, description=None, identity=None, time=None, tools=None, contributing_sources=None, references=None): |
| 34 | super(InformationSource, self).__init__() |
| 35 | |
| 36 | self.identity = identity |
| 37 | self.descriptions = StructuredTextList(description) |
| 38 | self.contributing_sources = contributing_sources |
| 39 | self.time = time |
| 40 | self.tools = tools |
| 41 | self.references = references |
| 42 | #self.roles = None |
| 43 | |
| 44 | def add_contributing_source(self, value): |
| 45 | self.contributing_sources.append(value) |
| 46 | |
| 47 | |
| 48 | def add_reference(self, value): |
| 49 | if not value: |
| 50 | return |
| 51 | # TODO: Check if it's a valid URI? |
| 52 | self.references.append(value) |
| 53 | |
| 54 | @property |
| 55 | def description(self): |
| 56 | """A single description about the contents or purpose of this object. |
| 57 | |
| 58 | Default Value: ``None`` |
| 59 | |
| 60 | Note: |
| 61 | If this object has more than one description set, this will return |
| 62 | the description with the lowest ordinality value. |
| 63 | |
| 64 | Returns: |
| 65 | An instance of :class:`.StructuredText` |
| 66 | |
| 67 | """ |
| 68 | return next(iter(self.descriptions), None) |
| 69 | |
| 70 | @description.setter |
| 71 | def description(self, value): |
| 72 | from stix.common.structured_text import StructuredTextList |
| 73 | self.descriptions = StructuredTextList(value) |
| 74 | |
| 75 | def add_description(self, description): |
| 76 | """Adds a description to the ``descriptions`` collection. |
| 77 |
no test coverage detected