def add(self, value): """Adds the :class:`.StructuredText` `value` to the collection. If `value` is not a :class:`.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. Args: value: A :class:`.StructuredText` object. """ if not self._is_valid(value): value = self._fix_value(value) if value.ordinality is None: value.ordinality = self.next_ordinality # Remove the existing item if there is one. with utils.ignored(KeyError): del self[value.ordinality] self._inner.append(value)
def _apply_input_schemalocations(self, tree, entity): """Attaches an __input_schemalocations__ dictionary to the input entity. Args: tree: The input etree instance entity: The entity to attach the schemlocation dictionary to """ root = get_etree_root(tree) with ignored(KeyError): pairs = get_schemaloc_pairs(root) entity.__input_schemalocations__ = dict(pairs)
def from_dict(cls, d, return_obj=None): if not d: return None if not return_obj: return_obj = cls() super(MAECInstance, cls).from_dict(d, return_obj) with utils.ignored(KeyError): maec = d['maec'] if isinstance(maec, dict): return_obj.maec = cls._maec_from_dict(maec) else: parser = mixbox.xml.get_xml_parser() return_obj.maec = etree.parse(StringIO(maec), parser=parser) return return_obj
def from_dict(cls, d, return_obj=None): if not d: return None if not return_obj: return_obj = cls() super(MAECInstance, cls).from_dict(d, return_obj) with utils.ignored(KeyError): maec = d["maec"] if isinstance(maec, dict): return_obj.maec = cls._maec_from_dict(maec) else: parser = mixbox.xml.get_xml_parser() return_obj.maec = etree.parse(StringIO(maec), parser=parser) return return_obj
'urn:oasis:names:tc:ciq:xnl:3': 'xnl' } DEFAULT_CYBOX_NAMESPACES = dict( (ns, alias) for (ns, alias, _) in cybox_nsparser.NS_LIST) DEFAULT_STIX_NAMESPACES = dict( itertools.chain(DEFAULT_CYBOX_NAMESPACES.iteritems(), XML_NAMESPACES.iteritems(), DEFAULT_STIX_NS_TO_PREFIX.iteritems(), DEFAULT_EXT_TO_PREFIX.iteritems())) DEFAULT_STIX_SCHEMALOCATIONS = dict( itertools.chain( STIX_NS_TO_SCHEMALOCATION.iteritems(), EXT_NS_TO_SCHEMALOCATION.iteritems(), CYBOX_NS_TO_SCHEMALOCATION.iteritems(), )) # python-maec support code with ignored(ImportError): from maec.utils.nsparser import NS_LIST DEFAULT_MAEC_NAMESPACES = dict((ns, alias) for (ns, alias, _) in NS_LIST) del DEFAULT_MAEC_NAMESPACES['http://maec.mitre.org/default_vocabularies-1'] MAEC_NS_TO_SCHEMALOCATION = dict( (ns, schemaloc) for ns, _, schemaloc in NS_LIST if schemaloc) DEFAULT_STIX_NAMESPACES.update(DEFAULT_MAEC_NAMESPACES) DEFAULT_STIX_SCHEMALOCATIONS.update(MAEC_NS_TO_SCHEMALOCATION)
DEFAULT_STIX_NAMESPACES = dict( itertools.chain( DEFAULT_CYBOX_NAMESPACES.iteritems(), XML_NAMESPACES.iteritems(), DEFAULT_STIX_NS_TO_PREFIX.iteritems(), DEFAULT_EXT_TO_PREFIX.iteritems() ) ) DEFAULT_STIX_SCHEMALOCATIONS = dict( itertools.chain( STIX_NS_TO_SCHEMALOCATION.iteritems(), EXT_NS_TO_SCHEMALOCATION.iteritems(), CYBOX_NS_TO_SCHEMALOCATION.iteritems(), ) ) # python-maec support code with ignored(ImportError): from maec.utils.nsparser import NS_LIST DEFAULT_MAEC_NAMESPACES = dict((ns, alias) for (ns, alias, _) in NS_LIST) del DEFAULT_MAEC_NAMESPACES['http://maec.mitre.org/default_vocabularies-1'] MAEC_NS_TO_SCHEMALOCATION = dict( (ns, schemaloc) for ns, _, schemaloc in NS_LIST if schemaloc ) DEFAULT_STIX_NAMESPACES.update(DEFAULT_MAEC_NAMESPACES) DEFAULT_STIX_SCHEMALOCATIONS.update(MAEC_NS_TO_SCHEMALOCATION)