<commit_before>from functools import partial
from httplib import HTTPConnection, HTTPSConnection
from itertools import chain
from urlparse import urlparse

import multipart


def request(method, url, data, headers, callback=None):
    url = urlparse(url)

    # Connect
    if url.scheme == 'https':
        request = HTTPSConnection(url.netloc)
    else:
        request = HTTPConnection(url.netloc)

    request.connect()

    # Initiate request
    request.putrequest(method, url.path)

    encoded_data = multipart.encode(data)
    encoded_data_headers = encoded_data.get_headers()
    all_headers = chain(
        encoded_data_headers.iteritems(),
        headers.iteritems()
    )

    # Send headers
    for name, value in all_headers:
        request.putheader(name, value)

    request.endheaders()

    # Send body
    bytes_sent = 0
    for chunk in encoded_data:
        request.send(chunk)
        bytes_sent += len(chunk)

        if callback is not None:
            callback(bytes_sent, encoded_data_headers['Content-Length'])

    # TODO: Wrap the response in a container to allow chunked reading.
    response = request.getresponse()

    response_status = response.status
    response_data = response.read()

    request.close()

    return response_status, response_data

get = partial(request, 'GET')
post = partial(request, 'POST')
<commit_msg>Comparison between string/int always return false<commit_after>from functools import partial
from httplib import HTTPConnection, HTTPSConnection
from itertools import chain
from urlparse import urlparse

import multipart


def request(method, url, data, headers, callback=None):
    url = urlparse(url)

    # Connect
    if url.scheme == 'https':
        request = HTTPSConnection(url.netloc)
    else:
        request = HTTPConnection(url.netloc)

    request.connect()

    # Initiate request
    request.putrequest(method, url.path)

    encoded_data = multipart.encode(data)
    encoded_data_headers = encoded_data.get_headers()
    all_headers = chain(
        encoded_data_headers.iteritems(),
        headers.iteritems()
    )

    # Send headers
    for name, value in all_headers:
        request.putheader(name, value)

    request.endheaders()

    # Send body
    bytes_sent = 0
    bytes_total = int(encoded_data_headers['Content-Length'])
    for chunk in encoded_data:
        request.send(chunk)
        bytes_sent += len(chunk)

        if callable(callback):
            callback(bytes_sent, bytes_total)

    # TODO: Wrap the response in a container to allow chunked reading.
    response = request.getresponse()

    response_status = response.status
    response_data = response.read()

    request.close()

    return response_status, response_data

get = partial(request, 'GET')
post = partial(request, 'POST')
{'fraction_non_alphanumeric': 0.085, 'fraction_numerical': 0.0007142857142857143, 'mean_word_length': 3.2183734939759034, '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': '2110521', 'n_tokens_mistral': 805, 'n_tokens_neox': 778, 'n_words': 212}