<commit_before>import settings
import pprint
import json
import httplib
from urlparse import urlparse

logger = settings.get_logger('http')

def handle(r):
    text = r.read()
    logger.debug('handle', status=r.status, text=text, reason=r.reason)
    if 200 <= r.status <= 299:
        if text:
            return text
        else:
            return r.status
    elif 400 <= r.status <= 499:
        return None
    else:
        raise Blipp_HTTP_Error(r.status, text)

def make_request(rtype, rurl, headers, data,
                 ssl_cert=None, ssl_key=None, ssl_cafile = None):
    logger.debug('make_request', rtype=rtype, url=rurl, data=pprint.pformat(json.loads(data)))
    o = urlparse(rurl)
    if ssl_cert is not None and ssl_key is not None:
        conn = httplib.HTTPSConnection(o.hostname, o.port, ssl_key, ssl_cert)
    else:
        conn = httplib.HTTPConnection(o.hostname, o.port)

    if rtype.upper()=="GET":
        if headers:
            conn.request("GET", o.path + '?' + o.query, data, headers)
        else:
            conn.request("GET", o.path + '?' + o.query, data)
    else:
        if headers:
            conn.request(rtype.upper(), o.path, data, headers)
        else:
            conn.request(rtype.upper(), o.path, data)
    return handle(conn.getresponse())

def get(get_url, data=None, headers=None,
        ssl_cert=None, ssl_key=None, ssl_cafile = None):
    return make_request('get', get_url, headers, data, ssl_cert, ssl_key, ssl_cafile)

def post(post_url, data=None, headers=None,
         ssl_cert=None, ssl_key=None, ssl_cafile = None):
    return make_request('post', post_url, headers, data, ssl_cert, ssl_key, ssl_cafile)

def delete(delete_url, data=None, headers=None,
           ssl_cert=None, ssl_key=None, ssl_cafile = None):
    return make_request('delete', delete_url, headers, data, ssl_cert, ssl_key, ssl_cafile)


class Blipp_HTTP_Error(Exception):
    def __init__(self, code, text):
        self.code = code
        self.text = text
    def __str__(self):
        return "BLiPP Error - Response code: " + str(self.code) + " Message: " + str(self.text)<commit_msg>reverting httplib changes... going to try to get requests to work with verify=False<commit_after>import requests
import settings
import pprint
import json

logger = settings.get_logger('http')

def handle(resp):
    logger.debug('handle', status=resp.status_code, text=resp.text)
    if 200 <= resp.status_code <= 299:
        if resp.text:
            return resp.text
        else:
            return resp.status_code
    elif 400 <= resp.status_code <= 499:
        return None
    else:
        raise Blipp_HTTP_Error(resp.status_code, resp.text)

def make_request(rtype, rurl, headers, data,
                 ssl_cert=None, ssl_key=None, ssl_cafile = None):
    logger.debug('make_request', rtype=rtype, url=rurl, data=pprint.pformat(json.loads(data)))
    return handle(requests.request(rtype, rurl, headers=headers, data=data,
                                   cert=(ssl_cert, ssl_key), verify=ssl_cafile))

def get(get_url, data=None, headers=None,
        ssl_cert=None, ssl_key=None, ssl_cafile = None):
    return make_request('get', get_url, headers, data, ssl_cert, ssl_key, ssl_cafile)

def post(post_url, data=None, headers=None,
         ssl_cert=None, ssl_key=None, ssl_cafile = None):
    return make_request('post', post_url, headers, data, ssl_cert, ssl_key, ssl_cafile)

def delete(delete_url, data=None, headers=None,
           ssl_cert=None, ssl_key=None, ssl_cafile = None):
    return make_request('delete', delete_url, headers, data, ssl_cert, ssl_key, ssl_cafile)


class Blipp_HTTP_Error(Exception):
    def __init__(self, code, text):
        self.code = code
        self.text = text
    def __str__(self):
        return "BLiPP Error - Response code: " + str(self.code) + " Message: " + str(self.text)
{'fraction_non_alphanumeric': 0.11936820300362506, 'fraction_numerical': 0.006214396685655101, 'mean_word_length': 3.180735930735931, 'pattern_counts': {'":': 1, '<': 11, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '450403', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1321, 'n_words': 308}