<commit_before>import sys
import time
import hmac
import hashlib
import binascii
import urlparse
import urllib
import urllib2
import json

import click

from scalrtools import settings


def request(method, request_uri, query_data=None):
    method = method.upper()
    scheme = settings.API_SCHEME
    api_host = settings.API_HOST
    debug = 0 #settings.API_DEBUG
    query_string = urllib.urlencode(query_data) if query_data else ''
    time_iso8601 = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime())

    string_to_sign = "%s\n%s\n%s\n%s\n" % (method.upper(), time_iso8601, request_uri, query_string)
    digest = hmac.new(settings.API_SECRET_KEY, string_to_sign, hashlib.sha256).digest()
    signature = binascii.b2a_base64(digest).strip()

    try:
        assert settings.API_KEY_ID
        assert settings.API_SECRET_KEY

        headers = dict()
        headers['Content-Type'] = 'application/json; charset=utf-8'
        headers['X-Scalr-Key-Id'] = settings.API_KEY_ID
        headers['X-Scalr-Date'] = time_iso8601
        headers['X-Scalr-Signature'] = "%s %s" % (settings.SIGNATURE_VERSION, signature)
        if debug:
            headers['X-Scalr-Debug'] = 1

        url = urlparse.urlunsplit((scheme, api_host, request_uri, query_string, ''))

        if settings.debug_mode:
            click.echo("%s URL: %s" % (method, url))
            click.echo("Headers: %s " % json.dumps(headers, indent=2))


        req = urllib2.Request(url, headers=headers)
        req.get_method = lambda: method
        response = urllib2.urlopen(req)
        result = response.read()
    except BaseException, e:
        if settings.debug_mode:
            raise
        raise click.ClickException(str(e))
    return result<commit_msg>firstrun<commit_after>import sys
import time
import hmac
import hashlib
import binascii
import urlparse
import urllib
import urllib2
import json

import click

from scalrtools import settings


def request(method, request_uri, query_data=None):
    method = method.upper()
    scheme = settings.API_SCHEME
    api_host = settings.API_HOST
    debug = 0 #settings.API_DEBUG
    query_string = urllib.urlencode(query_data) if query_data else ''
    time_iso8601 = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime())

    try:
        assert settings.API_KEY_ID
        assert settings.API_SECRET_KEY
        
        string_to_sign = "%s\n%s\n%s\n%s\n" % (method.upper(), time_iso8601, request_uri, query_string)
        digest = hmac.new(settings.API_SECRET_KEY, string_to_sign, hashlib.sha256).digest()
        signature = binascii.b2a_base64(digest).strip()

        headers = dict()
        headers['Content-Type'] = 'application/json; charset=utf-8'
        headers['X-Scalr-Key-Id'] = settings.API_KEY_ID
        headers['X-Scalr-Date'] = time_iso8601
        headers['X-Scalr-Signature'] = "%s %s" % (settings.SIGNATURE_VERSION, signature)
        if debug:
            headers['X-Scalr-Debug'] = 1

        url = urlparse.urlunsplit((scheme, api_host, request_uri, query_string, ''))

        if settings.debug_mode:
            click.echo("%s URL: %s" % (method, url))
            click.echo("Headers: %s " % json.dumps(headers, indent=2))


        req = urllib2.Request(url, headers=headers)
        req.get_method = lambda: method
        response = urllib2.urlopen(req)
        result = response.read()
    except BaseException, e:
        if settings.debug_mode:
            raise
        raise click.ClickException(str(e))
    return result
{'fraction_non_alphanumeric': 0.11895910780669144, 'fraction_numerical': 0.016013726050900772, 'mean_word_length': 3.016073478760046, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3703782', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1135, 'n_words': 231}