<commit_before>import json
import logging
from StringIO import StringIO

import requests


class Client(requests.Session):
    def __init__(self, base_url="http://localhost:4243"):
        super(Client, self).__init__()
        self.base_url = base_url

    def _url(self, path):
        return self.base_url + path

    def _result(self, response, json=False):
        if response.status_code != 200 and response.status_code != 201:
            response.raise_for_status()
        if json:
            return response.json()
        return response.text

    def _container_config(self, image, command, hostname=None, user=None, detach=False,
        stdin_open=False, tty=False, mem_limit=0, ports=None, environment=None, dns=None,
        volumes=None, volumes_from=None):
        return {
            'Hostname':     hostname,
            'PortSpecs':    ports,
            'User':         user,
            'Tty':          tty,
            'OpenStdin':    stdin_open,
            'Memory':       mem_limit,
            'AttachStdin':  0,
            'AttachStdout': 0,
            'AttachStderr': 0,
            'Env':          environment,
            'Cmd':          command,
            'Dns':          dns,
            'Image':        image,
            'Volumes':      volumes,
            'VolumesFrom':  volumes_from,
        }

    def post_json(self, url, data, **kwargs):
        # Go <1.1 can't unserialize null to a string
        # so we do this disgusting thing here.
        data2 = {}
        if data is not None:
            for k, v in data.iteritems():
                if v is not None:
                    data2[k] = v

        return self.post(url, json.dumps(data2), **kwargs)

    def build(self, dockerfile):
        bc = BuilderClient(self)<commit_msg>minor json fixes that caused the docker server to return 500s<commit_after>import json
import logging
from StringIO import StringIO

import requests


class Client(requests.Session):
    def __init__(self, base_url="http://localhost:4243"):
        super(Client, self).__init__()
        self.base_url = base_url

    def _url(self, path):
        return self.base_url + path

    def _result(self, response, json=False):
        if response.status_code != 200 and response.status_code != 201:
            response.raise_for_status()
        if json:
            return response.json()
        return response.text

    def _container_config(self, image, command, hostname=None, user=None, detach=False,
        stdin_open=False, tty=False, mem_limit=0, ports=None, environment=None, dns=None,
        volumes=None, volumes_from=None):
        return {
            'Hostname':     hostname,
            'PortSpecs':    [ports],
            'User':         user,
            'Tty':          tty,
            'OpenStdin':    stdin_open,
            'Memory':       mem_limit,
            'AttachStdin':  False,
            'AttachStdout': False,
            'AttachStderr': False,
            'Env':          environment,
            'Cmd':          [command],
            'Dns':          dns,
            'Image':        image,
            'Volumes':      volumes,
            'VolumesFrom':  volumes_from,
        }

    def post_json(self, url, data, **kwargs):
        # Go <1.1 can't unserialize null to a string
        # so we do this disgusting thing here.
        data2 = {}
        if data is not None:
            for k, v in data.iteritems():
                if v is not None:
                    data2[k] = v

        return self.post(url, json.dumps(data2), **kwargs)

    def build(self, dockerfile):
        bc = BuilderClient(self)
{'fraction_non_alphanumeric': 0.10363836824696802, 'fraction_numerical': 0.010474090407938258, 'mean_word_length': 1.7723453017570665, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4776203', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1032, 'n_words': 279}