<commit_before>from __future__ import absolute_import

import jsonpickle
import requests

from .Config import Config
from .Utilities import RemoveFromJson


class Request (object):

    def __getstate__(self):
        body = RemoveFromJson(self.__dict__.copy())
        return body

    def __init__(self, category, proxy, endpoint, method):
        self.queryParams = {}
        self.url = ("https://%s/%s/sp2/%s/v%s/%s" %
                    (Config.baseEndpoint, category,
                     proxy, Config.version, endpoint))
        self.method = method

    def send(self):
        if (Config.doNotSend):
            body = jsonpickle.encode(self, unpicklable=False)
            if (Config.printRequest):
                print(body)
            return body
        else:
            queryParamString = ''
            if (self.queryParams):
                queryParamString = "?"
                for key, value in self.queryParams.iteritems():
                    queryParamString += key + "=" + value + "&"
                queryParamString = queryParamString[:-1]
            url = self.url + queryParamString
            body = jsonpickle.encode(self, unpicklable=False)
            if (Config.printRequest):
                print (body)
            try:
                headers = {'Authorization':
                           'VANTIV license='+"\""+Config.license+"\"",
                           'Content-Type': 'application/json'}
                response = requests.get(url,
                                        proxies=Config.proxy,
                                        data=body,
                                        headers=headers)
                code = response.status_code
                import ipdb; ipdb.set_trace() # DEBUG
                contents = response.json
            except Exception as error:
                contents = error.read()
            if (Config.printResponse):
                print(contents)

            return contents
<commit_msg>Change back to urllib/urllib2<commit_after>
from .Config import Config
from .Utilities import RemoveFromJson
import jsonpickle
import ssl
import sys

if sys.version_info.major < 3:
    import urllib2 as urllib
else:
    import urllib.request, urllib.error, urllib.parse


class Request (object):
    def __getstate__(self):
        body = RemoveFromJson(self.__dict__.copy())
        return body

    def __init__(self, category, proxy, endpoint, method):
        self.queryParams = {}

        self.url = ("https://%s/%s/sp2/%s/v%s/%s" %
                    (Config.baseEndpoint,
                     category,
                     proxy,
                     Config.version,
                     endpoint))
        self.method = method

    def send(self):
        if (Config.doNotSend):
            body = jsonpickle.encode(self, unpicklable=False)
            if (Config.printRequest):
                print(body)
            return body
        else:
            queryParamString = ''
            if (self.queryParams):
                queryParamString = "?"
                for key, value in self.queryParams.items():
                    queryParamString += key + "=" + value + "&"
                queryParamString = queryParamString[:-1]
            url = self.url + queryParamString
            body = jsonpickle.encode(self, unpicklable=False)
            if (Config.printRequest):
                print (body)
            if(Config.proxy):
                proxy = urllib.request.ProxyHandler(Config.proxy)
                auth = urllib.request.HTTPBasicAuthHandler()
                opener = urllib.request.build_opener(proxy,
                                                     auth,
                                                     urllib.request.HTTPHandler)
                urllib.request.install_opener(opener)
            req = urllib.request.Request(url)
            req.add_header('Authorization',
                           'VANTIV license=' + "\"" + Config.license + "\"")
            req.add_header('Content-Type', 'application/json')
            context = ssl._create_unverified_context()
            try:
                resp = urllib.request.urlopen(req,
                                              body.encode('UTF-8'),
                                              context=context)
                code = resp.getcode()
                contents = resp.read()
            except urllib.error.HTTPError as error:
                contents = error.read()
            if (Config.printResponse):
                print(contents)

            return contents

{'fraction_non_alphanumeric': 0.09409190371991247, 'fraction_numerical': 0.00175054704595186, 'mean_word_length': 1.3881922675026124, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1742551', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1100, 'n_words': 241}