<commit_before>from urllib import quote
from urllib2 import URLError, urlopen


class Request(object):
    """
    Methods for interacting with the Digital Ocean API.
    """

    @classmethod
    def build_url(cls, domain, path, params={}):
        """
        Build a URL from its components.

        :param domain: the domain name for the request
        :param path: the path for the request
        :param params: zero or more query string parameters
        :return: the described URL
        """
        return 'https://%s%s%s%s' % (domain, path, '?' if params else '', quote(params))

    @classmethod
    def send_request(cls, domain, path, params={}):
        """
        Send an HTTP request.

        :param domain: the domain name for the request
        :param path: the path for the request
        :param params: zero or more query string parameters
        :return: the HTTP response or None
        """
        try:
            data = urlopen(cls.build_url(domain, path, params)).read()
        except URLError:
            return None
        else:
            return data<commit_msg>Switched request module to using the Python requests package.<commit_after>from requests import request, Request, RequestException

from .exceptions import ConnectionError, MalformedResponseError


def build_url(domain, path, params={}):
    """
    Build a URL from its components.

    :param domain: the domain name for the request
    :param path: the path for the request
    :param params: zero or more query string parameters
    :return: the described URL
    """
    return Request('GET', 'https://%s%s' % (domain, path), params=params).prepare().url


def send_request(method, domain, path, params={}):
    """
    Send an HTTP request.

    :param domain: the domain name for the request
    :param path: the path for the request
    :param params: zero or more query string parameters
    :return: the HTTP response or None
    """
    try:
        return request(method, 'https://%s%s' % (domain, path), params=params).json()
    except RequestException:
        raise ConnectionError()
    except ValueError:
        raise MalformedResponseError()
{'fraction_non_alphanumeric': 0.09376443418013856, 'fraction_numerical': 0.00046189376443418013, 'mean_word_length': 2.7216494845360826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, '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': '1409866', 'n_tokens_mistral': 574, 'n_tokens_neox': 559, 'n_words': 231}