<commit_before># -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

"""
topology_lib_scapy communication library implementation.
This library allows to send Scapy commands on host system that has Scapy
installed.
Packets can be defined using this library and then sent using Scapy.
Please refer to scapy documentation at
http://www.secdev.org/projects/scapy/doc/
to learn about Scapy

"""

from __future__ import unicode_literals, absolute_import
from __future__ import print_function, division
from .generator import createcdmline, protocol
import re
import threading


class ScapyApiTheard(threading.Thread):
    """
    This Class will create a thread and call all scapy library APIs directly
    TODO:

        Timeout happends when try to send the packets for longer interval.
        Need to discuss with maintainers to handle the timeout properly.
        This may require timeout param to be added explitcly for all functions
        and the command should be sent with low level apis to handle the
        timeout.
    Usage:

        ::

            hs1.libs.scapy.start_scapy()
            options = "iface='{}' ,count={}, inter={}".format(port1, 100, 0.2)
            scapy_thread = ScapyApiTheard(
                hs1, topology, hs1.libs.scapy.sendp,
                args=('ETH/IP', [eth, ip_pkt]), kwargs={"options": options}
            )
            scapy_thread.start()
            /*Do User defined operations if any*/
            scapy_thread.join()
            hs1.libs.scapy.exit_scapy()

    """
    def __init__(self, node, func, args=(), kwargs=None):
        """
        This method must be called while creating thread.
        : param object node: Modular framework topology node.
        : param func: Name of the function to be called.
        : param tuple args: Mandatory arugument to be passed for that func.
        : param dict kwargs: optional arugument to be passed for that func.

        Usage:

            ::

                scapy_thread = ScapyApiTheard(
                    hs1, topology, hs1.libs.scapy.sendp,
                    args=('ETH/IP', [eth, ip_pkt]), kwargs={"options": options}
                )

        """
        threading.Thread.__init__(self)
        self.func = func
        self.node = node
        self.args = args
        self.kwargs = kwargs

    def outresult(self):
        return self.res

    def run(self):
        self.res = self.func(*self.args, **self.kwargs)


class ScapyThread(threading.Thread):
    def __init__(
            self, func, enode, topology,
            proto_str='', packet_list=[], filter_str='',
            count=0, port_str='', timeout_int=0
               ):
        threading.Thread.__init__(self)<commit_msg>Typo corrected and removed unnecessary arguments<commit_after># -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

"""
topology_lib_scapy communication library implementation.
This library allows to send Scapy commands on host system that has Scapy
installed.
Packets can be defined using this library and then sent using Scapy.
Please refer to scapy documentation at
http://www.secdev.org/projects/scapy/doc/
to learn about Scapy

"""

from __future__ import unicode_literals, absolute_import
from __future__ import print_function, division
from .generator import createcdmline, protocol
import re
import threading


class ScapyApiThread(threading.Thread):
    """
    This Class will create a thread and call all scapy library APIs directly
    TODO:

        Timeout happends when try to send the packets for longer interval.
        Need to discuss with maintainers to handle the timeout properly.
        This may require timeout param to be added explitcly for all functions
        and the command should be sent with low level apis to handle the
        timeout.
    Usage:

        ::

            hs1.libs.scapy.start_scapy()
            options = "iface='{}' ,count={}, inter={}".format(port1, 100, 0.2)
            scapy_thread = ScapyApiThread(
                hs1.libs.scapy.sendp,
                args=('ETH/IP', [eth, ip_pkt]), kwargs={"options": options}
            )
            scapy_thread.start()
            /*Do User defined operations if any*/
            scapy_thread.join()
            hs1.libs.scapy.exit_scapy()

    """
    def __init__(self, func, args=(), kwargs=None):
        """
        This method must be called while creating thread.
        : param func: Name of the function to be called.
        : param tuple args: Mandatory arugument to be passed for that func.
        : param dict kwargs: optional arugument to be passed for that func.

        Usage:

            ::

                scapy_thread = ScapyApiThread(
                    hs1.libs.scapy.sendp,
                    args=('ETH/IP', [eth, ip_pkt]), kwargs={"options": options}
                )

        """
        threading.Thread.__init__(self)
        self.func = func
        self.args = args
        self.kwargs = kwargs

    def outresult(self):
        return self.res

    def run(self):
        self.res = self.func(*self.args, **self.kwargs)


class ScapyThread(threading.Thread):
    def __init__(
            self, func, enode, topology,
            proto_str='', packet_list=[], filter_str='',
            count=0, port_str='', timeout_int=0
               ):
        threading.Thread.__init__(self)
{'fraction_non_alphanumeric': 0.08561749307052664, 'fraction_numerical': 0.006775485063135201, 'mean_word_length': 2.5032362459546924, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7638841', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1770, 'n_words': 660}