<commit_before># -*- coding: utf-8 -*-
import os
import signal
import subprocess
import time


def create_ssh_tunnel(beaver_config, logger=None):
    """Returns a BeaverSshTunnel object if the current config requires us to"""
    if not beaver_config.use_ssh_tunnel():
        return None

    logger.info("Proxying transport using through local ssh tunnel")
    return BeaverSshTunnel(beaver_config)


class BeaverSubprocess(object):
    """General purpose subprocess wrapper"""

    def __init__(self, beaver_config):
        """Child classes should build a subprocess via the following method:

           self._subprocess = subprocess.Popen(cmd, stdout=subprocess.PIPE, preexec_fn=os.setsid)

        This will allow us to attach a session id to the spawned child, allowing
        us to send a SIGTERM to the process on close
        """
        self._beaver_config = beaver_config
        self._subprocess = None

    def poll(self):
        """Poll attached subprocess until it is available"""
        if self._subprocess is not None:
            self._subprocess.poll()

        time.sleep(self._beaver_config.get('subprocess_poll_sleep'))

    def close(self):
        """Close child subprocess"""
        if self._subprocess is not None:
            os.killpg(self._subprocess.pid, signal.SIGTERM)
            self._subprocess = None


class BeaverSshTunnel(BeaverSubprocess):
    """SSH Tunnel Subprocess Wrapper"""

    def __init__(self, beaver_config):
        super(BeaverSshTunnel, self).__init__(beaver_config)

        key_file = beaver_config.get('ssh_key_file')
        tunnel = beaver_config.get('ssh_tunnel')<commit_msg>Subclass the BaseLog class in BeaverSubprocess. Refs #142<commit_after># -*- coding: utf-8 -*-
import os
import signal
import subprocess
import time

from beaver.base_log import BaseLog


def create_ssh_tunnel(beaver_config, logger=None):
    """Returns a BeaverSshTunnel object if the current config requires us to"""
    if not beaver_config.use_ssh_tunnel():
        return None

    logger.info("Proxying transport using through local ssh tunnel")
    return BeaverSshTunnel(beaver_config, logger=logger)


class BeaverSubprocess(BaseLog):
    """General purpose subprocess wrapper"""

    def __init__(self, beaver_config, logger=None):
        """Child classes should build a subprocess via the following method:

           self._subprocess = subprocess.Popen(cmd, stdout=subprocess.PIPE, preexec_fn=os.setsid)

        This will allow us to attach a session id to the spawned child, allowing
        us to send a SIGTERM to the process on close
        """
        super(BeaverSubprocess, self).__init__(logger=logger)
        self._log_template = '[BeaverSubprocess] - {0}'

        self._beaver_config = beaver_config
        self._subprocess = None
        self._logger = logger

    def poll(self):
        """Poll attached subprocess until it is available"""
        if self._subprocess is not None:
            self._subprocess.poll()

        time.sleep(self._beaver_config.get('subprocess_poll_sleep'))

    def close(self):
        """Close child subprocess"""
        if self._subprocess is not None:
            os.killpg(self._subprocess.pid, signal.SIGTERM)
            self._subprocess = None


class BeaverSshTunnel(BeaverSubprocess):
    """SSH Tunnel Subprocess Wrapper"""

    def __init__(self, beaver_config, logger=None):
        super(BeaverSshTunnel, self).__init__(beaver_config, logger=logger)
        self._log_template = '[BeaverSshTunnel] - {0}'

        key_file = beaver_config.get('ssh_key_file')
        tunnel = beaver_config.get('ssh_tunnel')
{'fraction_non_alphanumeric': 0.09045780474351903, 'fraction_numerical': 0.0019305019305019305, 'mean_word_length': 3.222351571594878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4782372', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1044, 'n_words': 294}