<commit_before>from datetime import datetime
from datetime import timedelta
import hashlib
import hmac
import json

import requests

from pytransloadit.api import assemblies
from pytransloadit.api import templates

DEFAULT_BASE_URL = 'https://api2.transloadit.com'


class TransloadItClient(object):
    """HTTP REST client for transloadit APIs."""

    def __init__(self, key, secret,
                 duration=300,
                 max_size=None,
                 base_url=DEFAULT_BASE_URL, **kwargs):
        self.key = key
        self.secret = secret
        self.duration = duration
        self.max_size = max_size
        self.base_url = base_url
        self.headers = {
            'User-Agent': 'Python Transloadit 0.0.0'
        }
        self._client_kwargs = kwargs

    def _sign_request(self, params):
        return hmac.new(
            self.secret, json.dumps(params), hashlib.sha1).hexdigest()

    def build_payload(self, params):
        data = {}
        if 'auth' not in params:
            params['auth'] = {
                'key': self.key,
                'expires': (
                    datetime.utcnow() + timedelta(seconds=self.duration)
                ).strftime('%Y/%m/%d %H:%M:%S')
            }

        if self.max_size is not None:
            params['auth']['max_size'] = self.max_size

        data['params'] = json.dumps(params)
        data['signature'] = self._sign_request(params)
        return data

    def execute(self, path, method='GET', params=None, files=None):
        url = "{}{}".format(self.base_url, path)

        if params is None:
            params = {}

        data = self.build_payload(params)

        if method.upper() in ['POST', 'PUT', 'DELETE']:
            req_kwargs = {'data': data}
        else:
            req_kwargs = {'params': data}

        response = requests.request(
            method,
            url,
            files=files,
            headers=self.headers,
            **req_kwargs
        )

        return response.json()


class TransloadIt(object):
    def __init__(self, client=None, key=None, secret=None, **kwargs):

        if client is None:
            client = TransloadItClient(key, secret, **kwargs)

        self.client = client
        self.assemblies = assemblies.Assemblies(self.client)
        self.templates = templates.Templates(self.client)
<commit_msg>Update formatted expires to include utc offset<commit_after>from datetime import datetime
from datetime import timedelta
import hashlib
import hmac
import json

import requests

from pytransloadit.api import assemblies
from pytransloadit.api import templates

DEFAULT_BASE_URL = 'https://api2.transloadit.com'


class TransloadItClient(object):
    """HTTP REST client for transloadit APIs."""

    def __init__(self, key, secret,
                 duration=300,
                 max_size=None,
                 base_url=DEFAULT_BASE_URL, **kwargs):
        self.key = key
        self.secret = secret
        self.duration = duration
        self.max_size = max_size
        self.base_url = base_url
        self.headers = {
            'User-Agent': 'Python Transloadit 0.0.0'
        }
        self._client_kwargs = kwargs

    def _sign_request(self, params):
        return hmac.new(
            self.secret, json.dumps(params), hashlib.sha1).hexdigest()

    def build_payload(self, params):
        data = {}
        expires_dt = datetime.utcnow() + timedelta(seconds=self.duration)

        if 'auth' not in params:
            params['auth'] = {
                'key': self.key,
                'expires': expires_dt.strftime('%Y/%m/%d %H:%M:%S') + '+00:00'
            }

        if self.max_size is not None:
            params['auth']['max_size'] = self.max_size

        data['params'] = json.dumps(params)
        data['signature'] = self._sign_request(params)
        return data

    def execute(self, path, method='GET', params=None, files=None):
        url = "{}{}".format(self.base_url, path)

        if params is None:
            params = {}

        data = self.build_payload(params)

        if method.upper() in ['POST', 'PUT', 'DELETE']:
            req_kwargs = {'data': data}
        else:
            req_kwargs = {'params': data}

        response = requests.request(
            method,
            url,
            files=files,
            headers=self.headers,
            **req_kwargs
        )

        return response.json()


class TransloadIt(object):
    def __init__(self, client=None, key=None, secret=None, **kwargs):

        if client is None:
            client = TransloadItClient(key, secret, **kwargs)

        self.client = client
        self.assemblies = assemblies.Assemblies(self.client)
        self.templates = templates.Templates(self.client)

{'fraction_non_alphanumeric': 0.11342155009451796, 'fraction_numerical': 0.004200798151648814, 'mean_word_length': 2.0782159017453137, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3590380', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1338, 'n_words': 322}