<commit_before>"""command-line interface (CLI)

For local development, use the `-s` switch to direct this client at
the localhost. E.g.,

    rcomp -s http://127.0.0.1:8000
"""
import argparse
import sys
import time
import json
import os.path
import os
import base64
import zlib

import requests

from . import __version__


def get(uri, verbose=False):
    if verbose:
        print('> GET {}'.format(uri))
    res = requests.get(uri)
    if verbose:
        print_httpresponse(res)
    return res

def post(uri, payload=None, verbose=False):
    """Wrapper for requests.post()

    If given, payload should be a `dict` object. Internally it is
    translated to JSON before calling requests.post().
    """
    if verbose:
        print('> POST {}'.format(uri))
        if payload is not None:
            print('> {}'.format(payload))
    if payload is None:
        res = requests.post(uri)
    else:
        res = requests.post(uri, data=json.dumps(payload))
    if verbose:
        print_httpresponse(res)
    return res

def print_httpresponse(res, prefix='< '):
    print('{PREFIX}{STATUS_CODE} {REASON}'.format(PREFIX=prefix, STATUS_CODE=res.status_code, REASON=res.reason))
    for hname, value in res.headers.items():
        print('{PREFIX}{HNAME}: {VALUE}'.format(PREFIX=prefix, HNAME=hname, VALUE=value))
    if len(res.text) > 0:
        print('{PREFIX}{TEXT}'.format(PREFIX=prefix, TEXT=res.text))


def find_files(command, argv):
    """Find files for given command.

    return copy of argv where file names are replaced with
    zlib-compressed file data.
    """
    if command == 'ltl2ba':
        start = 0
        while True:
            try:
                start = argv.index('-F', start) + 1
            except ValueError:
                break
            with open(argv[start], 'rb') as fp:<commit_msg>use correct Content-Type header from Python client<commit_after>"""command-line interface (CLI)

For local development, use the `-s` switch to direct this client at
the localhost. E.g.,

    rcomp -s http://127.0.0.1:8000
"""
import argparse
import sys
import time
import json
import os.path
import os
import base64
import zlib

import requests

from . import __version__


def get(uri, verbose=False):
    if verbose:
        print('> GET {}'.format(uri))
    res = requests.get(uri)
    if verbose:
        print_httpresponse(res)
    return res

def post(uri, payload=None, verbose=False):
    """Wrapper for requests.post()

    If given, payload should be a `dict` object. Internally it is
    translated to JSON before calling requests.post().
    """
    if verbose:
        print('> POST {}'.format(uri))
        if payload is not None:
            print('> {}'.format(payload))
    if payload is None:
        res = requests.post(uri)
    else:
        res = requests.post(uri, json=payload)
    if verbose:
        print_httpresponse(res)
    return res

def print_httpresponse(res, prefix='< '):
    print('{PREFIX}{STATUS_CODE} {REASON}'.format(PREFIX=prefix, STATUS_CODE=res.status_code, REASON=res.reason))
    for hname, value in res.headers.items():
        print('{PREFIX}{HNAME}: {VALUE}'.format(PREFIX=prefix, HNAME=hname, VALUE=value))
    if len(res.text) > 0:
        print('{PREFIX}{TEXT}'.format(PREFIX=prefix, TEXT=res.text))


def find_files(command, argv):
    """Find files for given command.

    return copy of argv where file names are replaced with
    zlib-compressed file data.
    """
    if command == 'ltl2ba':
        start = 0
        while True:
            try:
                start = argv.index('-F', start) + 1
            except ValueError:
                break
            with open(argv[start], 'rb') as fp:
{'fraction_non_alphanumeric': 0.12374491180461329, 'fraction_numerical': 0.008683853459972864, 'mean_word_length': 2.749745676500509, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '204878', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1111, 'n_words': 345}