(data, doc_name, t_stamp, source, reference, use_hdr_src,
                     analyst, import_now=False, top_name=None)
Take the data for a STIX document, decode if necessary, and save in the DB.

    :param data: The STIX document data
    :type data: :class:`django.core.files.uploadedfile.InMemoryUploadedFile`
                OR :class:`zipfile.ZipExtFile`
    :param doc_name: The filename of the STIX document
    :type doc_name: string
    :param t_stamp: Timestamp representing when this data was uploaded
    :type t_stamp: :class:`datetime.datetime`
    :param source: The analyst provided source name of the data
    :type source: string
    :param reference: A reference to the source of the data
    :type reference: string
    :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 analyst: Userid of the analyst who uploaded the data
    :type analyst: string
    :param import_now: If True, import all STIX data into CRITs
    :type import_now: boolean
    :param top_name: The filename of the STIX document or parent ZIP file
    :type top_name: string
    :returns: if import_now is True, returns result of import_content function
Take the data for a STIX document, decode if necessary, and save in the DB.
Take the data for a STIX document decode if necessary and save in the DB .
def process_stix_doc(data, doc_name, t_stamp, source, reference, use_hdr_src,
                     analyst, import_now=False, top_name=None):
    """
    Take the data for a STIX document, decode if necessary, and save in the DB.

    :param data: The STIX document data
    :type data: :class:`django.core.files.uploadedfile.InMemoryUploadedFile`
                OR :class:`zipfile.ZipExtFile`
    :param doc_name: The filename of the STIX document
    :type doc_name: string
    :param t_stamp: Timestamp representing when this data was uploaded
    :type t_stamp: :class:`datetime.datetime`
    :param source: The analyst provided source name of the data
    :type source: string
    :param reference: A reference to the source of the data
    :type reference: string
    :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 analyst: Userid of the analyst who uploaded the data
    :type analyst: string
    :param import_now: If True, import all STIX data into CRITs
    :type import_now: boolean
    :param top_name: The filename of the STIX document or parent ZIP file
    :type top_name: string
    :returns: if import_now is True, returns result of import_content function
    """

    if not top_name:
        top_name = doc_name

    decoded = u''
    checked = False
    encoding = 'utf-8'
    ## search and extract encoding string
    ptrn = r"""^<\?xml.+?encoding=["'](?P<encstr>[^"']+)["'].*?\?>"""

    for line in data:
        if not checked:
            match = re.search(ptrn, line)
            checked = True
            if match:
                encoding = match.group("encstr")
        decoded += line.decode(encoding, 'replace')

    content = taxii.TaxiiContent()
    content.populate(decoded, analyst, reference, source, top_name, doc_name,
                     poll_time=t_stamp, use_hdr_src=use_hdr_src)

    if import_now: # Do not save if we're importing right now
        result = import_content([content], analyst)
        return result
    else: # save for later
        content.save()
def process_stix_doc ( data , doc_name , t_stamp , source , reference , use_hdr_src , analyst , import_now = False , top_name = None ) : if not top_name : top_name = doc_name decoded = u'' checked = False encoding = 'utf-8' ## search and extract encoding string ptrn = r"""^<\?xml.+?encoding=["'](?P<encstr>[^"']+)["'].*?\?>""" for line in data : if not checked : match = re . search ( ptrn , line ) checked = True if match : encoding = match . group ( "encstr" ) decoded += line . decode ( encoding , 'replace' ) content = taxii . TaxiiContent ( ) content . populate ( decoded , analyst , reference , source , top_name , doc_name , poll_time = t_stamp , use_hdr_src = use_hdr_src ) if import_now : # Do not save if we're importing right now result = import_content ( [ content ] , analyst ) return result else : # save for later content . save ( )