<commit_before>"""Run PyNetgear from the command-line."""
import sys
import os

from argparse import ArgumentParser
from collections.abc import Iterable
from pynetgear import Netgear, BLOCK, ALLOW


def make_formatter(format_name):
    """Returns a callable that outputs the data. Defaults to print."""

    if "json" in format_name:
        from json import dumps
        if format_name == "prettyjson":
            jsondumps = lambda data: dumps(data, sort_keys=True, indent=2, separators=(',', ': '))
        else:
            jsondumps = dumps


        def jsonify(data):
            if isinstance(data, Iterable):
                if isinstance(data, dict):
                    print(jsondumps(data))
                else:
                    print(jsondumps([device._asdict() for device in data]))
            else:
                print(dumps({'result': data}))
        return jsonify
    else:
        def printer(data):
            if isinstance(data, Iterable):
                print(data)
            else:
                for row in data:
                    print(row)
        return printer


def argparser():
    """Constructs the ArgumentParser for the CLI"""

    parser = ArgumentParser(prog='pynetgear')

    parser.add_argument("--format", choices=['json', 'prettyjson', 'py'], default='prettyjson')

    router_args = parser.add_argument_group("router connection config")
    router_args.add_argument("--host", help="Hostname for the router")
    router_args.add_argument("--user", help="Account for login")
    router_args.add_argument("--port", help="Port exposed on the router")
    router_args.add_argument(<commit_msg>Fix Python 2 support<commit_after>"""Run PyNetgear from the command-line."""
import sys
import os

from argparse import ArgumentParser
from pynetgear import Netgear, BLOCK, ALLOW


def make_formatter(format_name):
    """Returns a callable that outputs the data. Defaults to print."""

    if "json" in format_name:
        from json import dumps
        if format_name == "prettyjson":
            jsondumps = lambda data: dumps(data, sort_keys=True, indent=2, separators=(',', ': '))
        else:
            jsondumps = dumps


        def jsonify(data):
            if isinstance(data, dict):
                print(jsondumps(data))
            elif isinstance(data, list):
                print(jsondumps([device._asdict() for device in data]))
            else:
                print(dumps({'result': data}))
        return jsonify
    else:
        def printer(data):
            if isinstance(data, dict):
                print(data)
            else:
                for row in data:
                    print(row)
        return printer


def argparser():
    """Constructs the ArgumentParser for the CLI"""

    parser = ArgumentParser(prog='pynetgear')

    parser.add_argument("--format", choices=['json', 'prettyjson', 'py'], default='prettyjson')

    router_args = parser.add_argument_group("router connection config")
    router_args.add_argument("--host", help="Hostname for the router")
    router_args.add_argument("--user", help="Account for login")
    router_args.add_argument("--port", help="Port exposed on the router")
    router_args.add_argument(
{'fraction_non_alphanumeric': 0.1124922311995028, 'fraction_numerical': 0.0009322560596643878, 'mean_word_length': 2.498913043478261, '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': '474014', 'n_tokens_mistral': 911, 'n_tokens_neox': 862, 'n_words': 249}