(self, reference='', hdr_events=False, source='',
                   use_hdr_src=False, obs_as_ind=False)
Parse the document.

        :param reference: The reference to the data.
        :type reference: str
        :param hdr_events: Whether to create an Event for each Package Header.
        :type hdr_events: bool
        :param source: The source of this document.
        :type source: str
        :param use_hdr_src: If True, try to use the STIX Header Information
                             Source instead of the value in "source" parameter
        :type use_hdr_src: boolean
        :param obs_as_ind: If True, create indicators for all qualifying
                           observables instead of Domain and IP TLOs
        :type obs_as_ind: boolean
        :raises: :class:`taxii_service.parsers.STIXParserException`

        Until we have a way to map source strings in a STIX document to
        a source in CRITs, we are being safe and using the source provided
        as the true source.
Parse the document.
Parse the document .
def parse_stix(self, reference='', hdr_events=False, source='',
                   use_hdr_src=False, obs_as_ind=False):
        """
        Parse the document.

        :param reference: The reference to the data.
        :type reference: str
        :param hdr_events: Whether to create an Event for each Package Header.
        :type hdr_events: bool
        :param source: The source of this document.
        :type source: str
        :param use_hdr_src: If True, try to use the STIX Header Information
                             Source instead of the value in "source" parameter
        :type use_hdr_src: boolean
        :param obs_as_ind: If True, create indicators for all qualifying
                           observables instead of Domain and IP TLOs
        :type obs_as_ind: boolean
        :raises: :class:`taxii_service.parsers.STIXParserException`

        Until we have a way to map source strings in a STIX document to
        a source in CRITs, we are being safe and using the source provided
        as the true source.
        """

        self.obs_as_ind = obs_as_ind
        if isinstance(self.data, unicode): # BytesIO requires str
            self.data = self.data.encode('utf-8')
            encoding = 'utf-8'
        else: # String has unknown encoding
            encoding = None
        with closing(BytesIO(self.data)) as f:
            try:
                try:
                    self.package = STIXPackage.from_xml(f, encoding)
                    if not self.package:
                        raise STIXParserException("STIX package failure")
                except UnsupportedVersionError:
                    v = stix.__version__
                    if len(v.split('.')) > 3:
                        v = v[0:-2]
                        if v[-1] == '0':
                            v = v[0:-2]
                    updated = ramrod.update(f, to_=v)
                    doc = updated.document.as_stringio()
                    self.package = STIXPackage.from_xml(doc)
                except XMLSyntaxError:
                    self.package = STIXPackage.from_json(f)
            except Exception as e:
                msg = "Failed to create STIX/CybOX from XML or JSON"
                self.failed.append((e.message,
                                    "STIX Package (%s)" % msg,
                                    '')) # note for display in UI
                return

            # Parse any related packages
            if self.package.related_packages:
                for rel_pkg in self.package.related_packages:
                    pkg = rel_pkg.item
                    self.pkg_rels[pkg.id_] = (str(rel_pkg.relationship),
                                              str(rel_pkg.confidence))
                    self.imported = self.importedByPkg.setdefault(pkg.id_, {})
                    self.parse_package(pkg, reference, hdr_events, source,
                                       use_hdr_src)

            self.imported = self.importedByPkg.setdefault(self.package.id_, {})
            self.parse_package(self.package, reference, hdr_events, source,
                               use_hdr_src) # parse the top-level package
            self.imported = {k: v for d in self.importedByPkg.itervalues() for k, v in d.items()}
def parse_stix ( self , reference = '' , hdr_events = False , source = '' , use_hdr_src = False , obs_as_ind = False ) : self . obs_as_ind = obs_as_ind if isinstance ( self . data , unicode ) : # BytesIO requires str self . data = self . data . encode ( 'utf-8' ) encoding = 'utf-8' else : # String has unknown encoding encoding = None with closing ( BytesIO ( self . data ) ) as f : try : try : self . package = STIXPackage . from_xml ( f , encoding ) if not self . package : raise STIXParserException ( "STIX package failure" ) except UnsupportedVersionError : v = stix . __version__ if len ( v . split ( '.' ) ) > 3 : v = v [ 0 : - 2 ] if v [ - 1 ] == '0' : v = v [ 0 : - 2 ] updated = ramrod . update ( f , to_ = v ) doc = updated . document . as_stringio ( ) self . package = STIXPackage . from_xml ( doc ) except XMLSyntaxError : self . package = STIXPackage . from_json ( f ) except Exception as e : msg = "Failed to create STIX/CybOX from XML or JSON" self . failed . append ( ( e . message , "STIX Package (%s)" % msg , '' ) ) # note for display in UI return # Parse any related packages if self . package . related_packages : for rel_pkg in self . package . related_packages : pkg = rel_pkg . item self . pkg_rels [ pkg . id_ ] = ( str ( rel_pkg . relationship ) , str ( rel_pkg . confidence ) ) self . imported = self . importedByPkg . setdefault ( pkg . id_ , { } ) self . parse_package ( pkg , reference , hdr_events , source , use_hdr_src ) self . imported = self . importedByPkg . setdefault ( self . package . id_ , { } ) self . parse_package ( self . package , reference , hdr_events , source , use_hdr_src ) # parse the top-level package self . imported = { k : v for d in self . importedByPkg . itervalues ( ) for k , v in d . items ( ) }