<commit_before>from rackattack import api
import threading
from rackattack.tcp import allocation
from rackattack.tcp import heartbeat
from rackattack.tcp import subscribe
from rackattack.tcp import suicide
from rackattack.tcp import transport
import urllib2
import os


class Client(api.Client):
    def __init__(self,
                 providerRequestLocation,
                 providerSubscribeLocation,
                 providerHTTPLocation):
        self._providerSubscribeLocation = providerSubscribeLocation
        self._providerHTTPLocation = providerHTTPLocation
        self._request = transport.Transport(providerRequestLocation)
        self._lock = threading.Lock()
        self._closed = False
        self._activeAllocations = []
        self.call("handshake", versionInfo=dict(RACKATTACK_VERSION=api.VERSION))
        self._subscribe = None
        self._connectionToProviderInterrupted = self._connectionToProviderInterruptedDefaultCallback
        self._heartbeat = heartbeat.HeartBeat(self)
        self._skipSuicide = bool(os.getenv("SKIP_SUICIDE", None))

    def allocate(self, requirements, allocationInfo):
        assert len(requirements) > 0
        jsonableRequirements = {
            name: requirement.__dict__ for name, requirement in requirements.iteritems()}
        if self._subscribe is None:
            self._subscribe = subscribe.Subscribe(amqpURL=self._providerSubscribeLocation,
                                                  skipSuicide=self._skipSuicide)
        allocationID = self.call(
            cmd='allocate',
            requirements=jsonableRequirements,
            allocationInfo=allocationInfo.__dict__)
        return self._getAllocationInstance(requirements, allocationID)

    def allocateExisting(self, requirements, allocationID):
        return self._getAllocationInstance(requirements, allocationID)

    def _getAllocationInstance(self, requirements, allocationID):
        allocationInstance = allocation.Allocation(
            id=allocationID, requirements=requirements, ipcClient=self,
            subscribe=self._subscribe, heartbeat=self._heartbeat)
        self._activeAllocations.append(allocationInstance)<commit_msg>SI-859 - Monkey | add pre-baked functionality<commit_after>from rackattack import api
import threading
from rackattack.tcp import allocation
from rackattack.tcp import heartbeat
from rackattack.tcp import subscribe
from rackattack.tcp import suicide
from rackattack.tcp import transport
import urllib2
import os


class Client(api.Client):
    def __init__(self,
                 providerRequestLocation,
                 providerSubscribeLocation,
                 providerHTTPLocation):
        self._providerSubscribeLocation = providerSubscribeLocation
        self._providerHTTPLocation = providerHTTPLocation
        self._request = transport.Transport(providerRequestLocation)
        self._lock = threading.Lock()
        self._closed = False
        self._activeAllocations = []
        self.call("handshake", versionInfo=dict(RACKATTACK_VERSION=api.VERSION))
        self._subscribe = None
        self._connectionToProviderInterrupted = self._connectionToProviderInterruptedDefaultCallback
        self._heartbeat = heartbeat.HeartBeat(self)
        self._skipSuicide = bool(os.getenv("SKIP_SUICIDE", None))

    def allocate(self, requirements, allocationInfo):
        assert len(requirements) > 0
        jsonableRequirements = {
            name: requirement.__dict__ for name, requirement in requirements.iteritems()}
        if self._subscribe is None:
            self._subscribe = subscribe.Subscribe(amqpURL=self._providerSubscribeLocation,
                                                  skipSuicide=self._skipSuicide)
        allocationID = self.call(
            cmd='allocate',
            requirements=jsonableRequirements,
            allocationInfo=allocationInfo.__dict__)
        return self._getAllocationInstance(requirements, allocationID)

    def allocateExisting(self, requirements, allocationID):
        return self._getAllocationInstance(requirements, allocationID)

    def _getAllocationInstance(self, requirements, allocationID):
        if self._subscribe is None:
            self._subscribe = subscribe.Subscribe(amqpURL=self._providerSubscribeLocation,
                                                  skipSuicide=self._skipSuicide)
        allocationInstance = allocation.Allocation(
            id=allocationID, requirements=requirements, ipcClient=self,
            subscribe=self._subscribe, heartbeat=self._heartbeat)
        self._activeAllocations.append(allocationInstance)
{'fraction_non_alphanumeric': 0.0671286271113036, 'fraction_numerical': 0.0015158077089649198, 'mean_word_length': 3.0696035242290747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5601045', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1069, 'n_words': 226}