<commit_before>"""
Standalone wrapper for the cheat.sh server.
"""

import sys
import textwrap

import cheat_wrapper

def show_usage():
    """
    Show how to use the program in the standalone mode
    """

    print textwrap.dedent("""
        Usage:

            lib/standalone.py [OPTIONS] QUERY

        For OPTIONS see :help
    """)[1:-1]

def parse_cmdline(args):
    """
    Parses command line arguments and returns
    query and request_options
    """

    if not args:
        show_usage()
        sys.exit(0)

    request_options = {}
    query = args[0]
    query = query.lstrip("/")
    if not query:
        query = ":firstpage"
    return query, request_options


def main(args):
    """
    standalone wrapper for cheat_wrapper()
    """

    query, request_options = parse_cmdline(args)
    answer, _ = cheat_wrapper.cheat_wrapper(query, request_options=request_options)
    sys.stdout.write(answer)

if __name__ == '__main__':
    main(sys.argv[1:])<commit_msg>lib/standalone.py: output is UTF-8<commit_after>"""
Standalone wrapper for the cheat.sh server.
"""

import sys
import textwrap

import cheat_wrapper

def show_usage():
    """
    Show how to use the program in the standalone mode
    """

    print textwrap.dedent("""
        Usage:

            lib/standalone.py [OPTIONS] QUERY

        For OPTIONS see :help
    """)[1:-1]

def parse_cmdline(args):
    """
    Parses command line arguments and returns
    query and request_options
    """

    if not args:
        show_usage()
        sys.exit(0)

    request_options = {}
    query = args[0]
    query = query.lstrip("/")
    if not query:
        query = ":firstpage"
    return query, request_options


def main(args):
    """
    standalone wrapper for cheat_wrapper()
    """

    query, request_options = parse_cmdline(args)
    answer, _ = cheat_wrapper.cheat_wrapper(query, request_options=request_options)
    sys.stdout.write(answer.encode("utf-8"))

if __name__ == '__main__':
    main(sys.argv[1:])
{'fraction_non_alphanumeric': 0.11494252873563218, 'fraction_numerical': 0.005997001499250375, 'mean_word_length': 2.742056074766355, 'pattern_counts': {'":': 2, '<': 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': '6566277', 'n_tokens_mistral': 651, 'n_tokens_neox': 619, 'n_words': 166}