<commit_before>from collections import namedtuple
import urllib

from google.appengine.api import urlfetch
from google.appengine.ext import ndb

TRACKING_URI = 'https://ssl.google-analytics.com/collect'


def _request(ctx, data, extra_headers, deadline=None):
    if extra_headers is None:
      extra_headers = dict()
    if deadline is None:
      deadline = urlfetch.get_default_fetch_deadline()
    return ctx.urlfetch(TRACKING_URI, payload=urllib.urlencode(data), method="POST", headers=extra_headers, deadline=deadline)


def report_async(tracking_id, client_id, requestable, extra_info=None,
           extra_headers=None, deadline=None):
    """Actually report measurements to Google Analytics."""
    ctx = ndb.get_context()
    return [_request(ctx, data, extra_headers, deadline)
            for data, extra_headers in payloads(
            tracking_id, client_id, requestable, extra_info, extra_headers)]


def report(tracking_id, client_id, requestable, extra_info=None,
           extra_headers=None, deadline=None):
    futures = report_async(tracking_id, client_id, requestable, extra_info, extra_headers, deadline=deadline)
    for future in futures:
      future.check_success()
      yield future.get_result()


def payloads(tracking_id, client_id, requestable, extra_info=None,
             extra_headers=None):
    """Get data and headers of API requests for Google Analytics.

    Generates a sequence of (data, headers) pairs. Both `data` and `headers`
    are dicts.
    """
    extra_payload = {
        'v': '1',
        'tid': tracking_id,
        'cid': client_id,
        'aip': '1'}
    if extra_info:
        for payload in extra_info:
            extra_payload.update(payload)

    for request_payload in requestable:
        final_payload = dict(request_payload)
        final_payload.update(extra_payload)
        yield final_payload, extra_headers


class Requestable(object):

    def get_payload(self):
        raise NotImplementedError()<commit_msg>remove the `api` parameter from default values<commit_after>from collections import namedtuple
import urllib

from google.appengine.api import urlfetch
from google.appengine.ext import ndb

TRACKING_URI = 'https://ssl.google-analytics.com/collect'


def _request(ctx, data, extra_headers, deadline=None):
    if extra_headers is None:
      extra_headers = dict()
    if deadline is None:
      deadline = urlfetch.get_default_fetch_deadline()
    return ctx.urlfetch(TRACKING_URI, payload=urllib.urlencode(data), method="POST", headers=extra_headers, deadline=deadline)


def report_async(tracking_id, client_id, requestable, extra_info=None,
           extra_headers=None, deadline=None):
    """Actually report measurements to Google Analytics."""
    ctx = ndb.get_context()
    return [_request(ctx, data, extra_headers, deadline)
            for data, extra_headers in payloads(
            tracking_id, client_id, requestable, extra_info, extra_headers)]


def report(tracking_id, client_id, requestable, extra_info=None,
           extra_headers=None, deadline=None):
    futures = report_async(tracking_id, client_id, requestable, extra_info, extra_headers, deadline=deadline)
    for future in futures:
      future.check_success()
      yield future.get_result()


def payloads(tracking_id, client_id, requestable, extra_info=None,
             extra_headers=None):
    """Get data and headers of API requests for Google Analytics.

    Generates a sequence of (data, headers) pairs. Both `data` and `headers`
    are dicts.
    """
    extra_payload = {
        'v': '1',
        'tid': tracking_id,
        'cid': client_id,
    }
    if extra_info:
        for payload in extra_info:
            extra_payload.update(payload)

    for request_payload in requestable:
        final_payload = dict(request_payload)
        final_payload.update(extra_payload)
        yield final_payload, extra_headers


class Requestable(object):

    def get_payload(self):
        raise NotImplementedError()
{'fraction_non_alphanumeric': 0.08940646130728776, 'fraction_numerical': 0.0007513148009015778, 'mean_word_length': 3.6658878504672896, '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': '5614806', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1150, 'n_words': 305}