<commit_before>#
# Copyright (c) 2014 Palo Alto Networks, Inc. <<EMAIL>>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

import sys
import getopt
import logging
import pan.xapi

import datetime
import dateutil.tz

import panstix.utils
import panstix.packaging

def _set_logging_debug(options):
    if options['debug']:
        logger = logging.getLogger()
        if options['debug'] == 3:
            logger.setLevel(pan.xapi.DEBUG3)
        elif options['debug'] == 2:
            logger.setLevel(pan.xapi.DEBUG2)
        elif options['debug'] == 1:
            logger.setLevel(pan.xapi.DEBUG1)
    
        handler = logging.StreamHandler()
        logger.addHandler(handler)

def dump_report_to_stix(options):
    panstix.utils.set_id_namespace("https://github.com/PaloAltoNetworks-BD/pan-stix", "pan-stix")

    _set_logging_debug(options)

    subargs = {k: v for k,v in options.iteritems() if k in ['hash', 'tag', 'sample', 'pcap']}
    if 'inreport' in options:
        subargs['report'] = options['inreport']

    sp = panstix.packaging.get_stix_package_from_wfreport(**options)
    if options['outfile'] is not None:
        f = open(options['outfile'], 'w')
        f.write(sp.to_xml())
        f.close()
    else:
        sys.stdout.write(sp.to_xml())

def dump_report_to_maec(options):
    panstix.utils.set_id_namespace("https://github.com/PaloAltoNetworks-BD/pan-stix", "pan-stix")

    _set_logging_debug(options)

    subargs = {k: v for k,v in options.iteritems() if k in ['hash', 'tag', 'sample', 'pcap']}
    if 'inreport' in options:
        subargs['report'] = options['inreport']

    mp = panstix.packaging.get_maec_package_from_wfreport(**options)
    if options['outfile'] is not None:
        f = open(options['outfile'], 'w')
        f.write(mp.to_xml())
        f.close()
    else:
        sys.stdout.write(mpp.to_xml())

def parse_opts():
    options = {
        'tag': None,
        'debug': 0,
        'hash': None,
        'pcap': 'network',
        'sample': 'network',
        'report': None,
        'outfmt': 'stix',
        'outfile': None
    }

    valid_outfmt = ['stix', 'maec']
    short_options = 't:Dh:i:o:f:'
    long_options = ['no-pcap', 'no-sample']<commit_msg>Removed typo<commit_after>#
# Copyright (c) 2014 Palo Alto Networks, Inc. <<EMAIL>>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

import sys
import getopt
import logging
import pan.xapi

import datetime
import dateutil.tz

import panstix.utils
import panstix.packaging

def _set_logging_debug(options):
    if options['debug']:
        logger = logging.getLogger()
        if options['debug'] == 3:
            logger.setLevel(pan.xapi.DEBUG3)
        elif options['debug'] == 2:
            logger.setLevel(pan.xapi.DEBUG2)
        elif options['debug'] == 1:
            logger.setLevel(pan.xapi.DEBUG1)
    
        handler = logging.StreamHandler()
        logger.addHandler(handler)

def dump_report_to_stix(options):
    panstix.utils.set_id_namespace("https://github.com/PaloAltoNetworks-BD/pan-stix", "pan-stix")

    _set_logging_debug(options)

    sp = panstix.packaging.get_stix_package_from_wfreport(**options)
    if options['outfile'] is not None:
        f = open(options['outfile'], 'w')
        f.write(sp.to_xml())
        f.close()
    else:
        sys.stdout.write(sp.to_xml())

def dump_report_to_maec(options):
    panstix.utils.set_id_namespace("https://github.com/PaloAltoNetworks-BD/pan-stix", "pan-stix")

    _set_logging_debug(options)

    mp = panstix.packaging.get_maec_package_from_wfreport(**options)
    if options['outfile'] is not None:
        f = open(options['outfile'], 'w')
        f.write(mp.to_xml())
        f.close()
    else:
        sys.stdout.write(mpp.to_xml())

def parse_opts():
    options = {
        'tag': None,
        'debug': 0,
        'hash': None,
        'pcap': 'network',
        'sample': 'network',
        'report': None,
        'outfmt': 'stix',
        'outfile': None
    }

    valid_outfmt = ['stix', 'maec']
    short_options = 't:Dh:i:o:f:'
    long_options = ['no-pcap', 'no-sample']
{'fraction_non_alphanumeric': 0.12073103193649622, 'fraction_numerical': 0.004061288536090087, 'mean_word_length': 3.2196261682242993, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4398394', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1705, 'n_words': 484}