<commit_before>'''
Created on Dec 16, 2009

@author: <NAME>
'''
try:
    import simplejson as json
except ImportError:
    import json

from octopus.core.communication.http import Http404, Http400, HttpConflict
from octopus.core.framework import BaseResource, queue
from octopus.dispatcher.model.pool import PoolShare, PoolShareCreationException

__all__ = []


class PoolSharesResource(BaseResource):
    @queue
    def get(self):
        poolShares = self.getDispatchTree().poolShares.values()
        self.writeCallback({
            'poolshares': dict(((poolShare.id, poolShare.to_json()) for poolShare in poolShares))
            })

    @queue
    def post(self):
        dct = self.getBodyAsJSON()
        for key in ('poolName', 'nodeId', 'maxRN'):
            if not key in dct:
                return Http400("Missing key %r" % key)
        poolName = str(dct['poolName'])
        nodeId = int(dct['nodeId'])
        maxRN = int(dct['maxRN'])
        # get the pool object
        if not poolName in self.getDispatchTree().pools:
            return HttpConflict("Pool %s is not registered" % poolName)
        pool = self.getDispatchTree().pools[poolName]
        # get the node object
        if not nodeId in self.getDispatchTree().nodes:
            return HttpConflict("No such node %r" % nodeId)
        node = self.getDispatchTree().nodes[nodeId]
        # create the poolShare
        try:<commit_msg>Resource to fetch poolshares based on id list<commit_after>'''
Created on Dec 16, 2009

@author: <NAME>
'''
try:
    import simplejson as json
except ImportError:
    import json

from octopus.core.communication.http import Http404, Http400, HttpConflict
from octopus.core.framework import BaseResource, queue
from octopus.dispatcher.model.pool import PoolShare, PoolShareCreationException

__all__ = []


class PoolSharesResource(BaseResource):
    @queue
    def get(self):
        poolShares = self.getDispatchTree().poolShares.values()
        self.writeCallback({'poolshares': dict(((poolShare.id, poolShare.to_json()) for poolShare in poolShares))})

    @queue
    def put(self):
        dct = self.getBodyAsJSON()
        if "pslist" in dct:
            pslist = dct['pslist']
            poolShares = []
            for psId in pslist:
                poolShares.append(self.getDispatchTree().poolShares[int(psId)])
            self.writeCallback({'poolshares': dict(((poolShare.node.id, poolShare.to_json()) for poolShare in poolShares))})

    @queue
    def post(self):
        dct = self.getBodyAsJSON()
        for key in ('poolName', 'nodeId', 'maxRN'):
            if not key in dct:
                return Http400("Missing key %r" % key)
        poolName = str(dct['poolName'])
        nodeId = int(dct['nodeId'])
        maxRN = int(dct['maxRN'])
        # get the pool object
        if not poolName in self.getDispatchTree().pools:
            return HttpConflict("Pool %s is not registered" % poolName)
        pool = self.getDispatchTree().pools[poolName]
        # get the node object
        if not nodeId in self.getDispatchTree().nodes:
            return HttpConflict("No such node %r" % nodeId)
        node = self.getDispatchTree().nodes[nodeId]
        # create the poolShare
        try:
{'fraction_non_alphanumeric': 0.10970333745364648, 'fraction_numerical': 0.009270704573547589, 'mean_word_length': 2.7335640138408306, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '671340', 'n_tokens_mistral': 990, 'n_tokens_neox': 938, 'n_words': 259}