def get_namespace_schemalocation_str(self): '''Get the namespace/schemalocation declaration string''' output_string = '\n ' schemalocs = [] #Add the XSI, MAEC, and CybOX Core/Common namespaces and schemalocation output_string += 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \n ' if isinstance(self.maec_entity, package_binding.PackageType): output_string += 'xmlns:maecPackage="http://maec.mitre.org/XMLSchema/maec-package-2" \n ' output_string += 'xmlns:maecBundle="http://maec.mitre.org/XMLSchema/maec-bundle-4" \n ' output_string += 'xmlns:maecVocabs="http://maec.mitre.org/default_vocabularies-1" \n ' output_string += 'xmlns:mmdef="http://xml/metadataSharing.xsd" \n ' schemalocs.append('http://maec.mitre.org/default_vocabularies-1 http://maec.mitre.org/language/version4.0/maec_default_vocabularies.xsd') schemalocs.append(' http://maec.mitre.org/XMLSchema/maec-package-2 http://maec.mitre.org/language/version4.0/maec_package_schema.xsd') elif isinstance(self.maec_entity, bundle_binding.BundleType): output_string += 'xmlns:maecVocabs="http://maec.mitre.org/default_vocabularies-1" \n ' output_string += 'xmlns:maecBundle="http://maec.mitre.org/XMLSchema/maec-bundle-4" \n ' output_string += 'xmlns:mmdef="http://xml/metadataSharing.xsd" \n ' schemalocs.append('http://maec.mitre.org/default_vocabularies-1 http://maec.mitre.org/language/version4.0/maec_default_vocabularies.xsd') schemalocs.append(' http://maec.mitre.org/XMLSchema/maec-bundle-4 http://maec.mitre.org/language/version4.0/maec_bundle_schema.xsd') output_string += 'xmlns:cybox="http://cybox.mitre.org/cybox-2" \n ' output_string += 'xmlns:cyboxCommon="http://cybox.mitre.org/common-2" \n ' output_string += 'xmlns:cyboxVocabs="http://cybox.mitre.org/default_vocabularies-2" \n ' schemalocs.append(' http://cybox.mitre.org/cybox-2 http://cybox.mitre.org/XMLSchema/core/2.0/cybox_core.xsd') schemalocs.append(' http://maec.mitre.org/default_vocabularies-1 http://cybox.mitre.org/XMLSchema/default_vocabularies/2.0.0/cybox_default_vocabularies.xsd') for object_type in self.object_types: namespace = META.lookup_object(object_type).namespace namespace_prefix = META.lookup_namespace(namespace).prefix output_string += ('xmlns:' + namespace_prefix + '=' + '"' + namespace + '"' + ' \n ') for object_type_dependency in self.object_type_dependencies: if object_type_dependency not in self.object_types: namespace = META.lookup_object(object_type_dependency).namespace namespace_prefix = META.lookup_namespace(namespace).prefix output_string += ('xmlns:' + namespace_prefix + '=' + '"' + namespace + '"' + ' \n ') output_string += 'xsi:schemaLocation="' for object_type in self.object_types: namespace = META.lookup_object(object_type).namespace schemalocation = META.lookup_namespace(namespace).schema_location schemalocs.append(' ' + namespace + ' ' + schemalocation) for schemalocation_string in schemalocs: if schemalocs.index(schemalocation_string) == (len(schemalocs) - 1): output_string += (schemalocation_string + '"') else: output_string += (schemalocation_string + '\n') return output_string
def _get_namespaces(self, recurse=True): nsset = set() # Get all _namespaces for parent classes namespaces = [x._namespace for x in self.__class__.__mro__ if hasattr(x, '_namespace')] nsset.update([maecMETA.lookup_namespace(ns) for ns in namespaces]) #In case of recursive relationships, don't process this item twice self.touched = True if recurse: for x in self._get_children(): if not hasattr(x, 'touched'): nsset.update(x._get_namespaces()) del self.touched # Add any additional namespaces that may be included in the entity entity_dict = self.__dict__ input_ns = entity_dict.get("__input_namespaces__", {}) for namespace, alias in input_ns.items(): maec_ns = maecMETA.lookup_namespace(namespace) cybox_ns = META.lookup_namespace(namespace) if not maec_ns and not cybox_ns: nsset.add(Namespace(namespace, alias)) return nsset
def _get_namespaces(self, recurse=True): ns = set() # If this raises an AttributeError, it's because the object doesn't # have a "_namespace" element. All subclasses should define this. ns.update([META.lookup_namespace(self._namespace)]) #In case of recursive relationships, don't process this item twice self.touched = True if recurse: for x in self._get_children(): if not hasattr(x, 'touched'): ns.update(x._get_namespaces()) del self.touched return ns
def _get_namespaces(self, recurse=True): nsset = set() # Get all _namespaces for parent classes namespaces = [x._namespace for x in self.__class__.__mro__ if hasattr(x, "_namespace")] nsset.update([META.lookup_namespace(ns) for ns in namespaces]) # In case of recursive relationships, don't process this item twice self.touched = True if recurse: for x in self._get_children(): if not hasattr(x, "touched"): nsset.update(x._get_namespaces()) del self.touched return nsset
def _get_namespaces(self, recurse=True): nsset = set() # Get all _namespaces for parent classes namespaces = [ x._namespace for x in self.__class__.__mro__ if hasattr(x, '_namespace') ] nsset.update([META.lookup_namespace(ns) for ns in namespaces]) #In case of recursive relationships, don't process this item twice self.touched = True if recurse: for x in self._get_children(): if not hasattr(x, 'touched'): nsset.update(x._get_namespaces()) del self.touched return nsset