<commit_before>from hashlib import sha1
import hmac
import binascii
from time import strftime, gmtime
from urllib import urlencode
import urllib2
import json
from urllib2 import HTTPError

# This is the sole function that should be imported. It returns the EmailCenterPro object which will configure itself
def ecp_connect(key, secret, url):
    return EmailCenterPro(key, secret, url)


class EmailCenterPro(object):
    def __init__(self, key, secret, url):
        self._key = key
        self._secret = secret
        self._url = url

        self.clear()

        self.folder = folder(self)
        self.metrics = metrics(self)

    def makeRequest(self, content):
        #TODO Make this use a list and support the nested actions
        api_action = '/%s/%s' % (self._object, '/'.join(self._action))
        arguments = self._args
        arguments.update(content)

        content = urlencode(arguments)
        date = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
        body = '\n'.join(['POST', api_action, content, date])
        headers = {'Authorization': 'ECP ' + self._key + ':' +
                                    binascii.b2a_base64(hmac.new(self._secret, body, sha1).digest())[:-1], 'Date': date}
        action_url = self._url + api_action
        request = urllib2.Request(action_url, content, headers=headers)
        try:
            response = urllib2.urlopen(request)
            self._data = response.read()
        except HTTPError as e:
            self._data = urllib2.urlopen(e.filename).read()

    def clear(self):
        self._object = None
        self._action = []
        self._args = {}
        self._data = None

    def read(self):
        return self._data


# On methods where the end result is a reply from the API we enforce it with a decorator<commit_msg>Revise EmailCenterPro clear method to include a argument clearing non-None param and allow setting of persistant arguments via keywords in ecp_connect<commit_after>from hashlib import sha1
import hmac
import binascii
from time import strftime, gmtime
from urllib import urlencode
import urllib2
import json
from urllib2 import HTTPError

# This is the sole function that should be imported. It returns the EmailCenterPro object which will configure itself
def ecp_connect(key, secret, url, **kwargs):
    return EmailCenterPro(key, secret, url, **kwargs)


class EmailCenterPro(object):
    def __init__(self, key, secret, url, **kwargs):
        self._key = key
        self._secret = secret
        self._url = url

        self._args = {}
        for k, v in kwargs.items():
            self._args[k] = v

        self.clear()

        self.folder = folder(self)
        self.metrics = metrics(self)

    def makeRequest(self, content):
        #TODO Make this use a list and support the nested actions
        api_action = '/%s/%s' % (self._object, '/'.join(self._action))
        arguments = self._args
        arguments.update(content)

        content = urlencode(arguments)
        date = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
        body = '\n'.join(['POST', api_action, content, date])
        headers = {'Authorization': 'ECP ' + self._key + ':' +
                                    binascii.b2a_base64(hmac.new(self._secret, body, sha1).digest())[:-1], 'Date': date}
        action_url = self._url + api_action
        request = urllib2.Request(action_url, content, headers=headers)
        try:
            response = urllib2.urlopen(request)
            self._data = response.read()
        except HTTPError as e:
            self._data = urllib2.urlopen(e.filename).read()

    def clear(self, clear_args=None):
        """
        Clears last object, action and held return data.
        With first parameter being not None it clears the set arguments as well.
        """
        if clear_args is not None:
            self._args = {}

        self._object = None
        self._action = []
        self._data = None

    def read(self):
        return self._data


# On methods where the end result is a reply from the API we enforce it with a decorator
{'fraction_non_alphanumeric': 0.10193106819848448, 'fraction_numerical': 0.007333170373991689, 'mean_word_length': 2.479591836734694, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3552602', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1163, 'n_words': 381}