Python源码示例:tabulate.tabulate_formats()

示例1
def main():
	output_formats = copy.copy(tabulate.tabulate_formats)
	output_formats.append('json')
	parser = argparse.ArgumentParser(description='syscall_extractor: Extract syscalls from a Windows PE file', conflict_handler='resolve')
	parser.add_argument('-f', '--format', dest='output_format', default='simple', choices=output_formats, help='output format')
	parser.add_argument('pe_files', nargs='+', help='pe files to extract syscall numbers from')
	args = parser.parse_args()

	parsed_files = []
	for pe_file in args.pe_files:
		parsed_files.append(extract_syscalls(os.path.abspath(pe_file)))
	parsed_files = list(pe_file for pe_file in parsed_files if pe_file)
	print("[+] Found {0:,} syscalls".format(sum(len(pe_file['syscalls']) for pe_file in parsed_files)))

	if args.output_format == 'json':
		print(json.dumps(parsed_files, sort_keys=True, indent=2, separators=(',', ': ')))
	else:
		syscalls = []
		for pe_file in parsed_files:
			syscalls.extend(pe_file['syscalls'])
		syscalls = ((syscall[0], hex(syscall[1]), syscall[2], syscall[3]) for syscall in syscalls)
		print(tabulate.tabulate(syscalls, headers=('Number', 'RVA', 'Name', 'Ordinal'), tablefmt=args.output_format))
	return 0 
示例2
def _addCustomTabulateTables():
    """Create a custom ARMI tables within tabulate."""
    tabulate._table_formats["armi"] = tabulate.TableFormat(
        lineabove=tabulate.Line("", "-", "  ", ""),
        linebelowheader=tabulate.Line("", "-", "  ", ""),
        linebetweenrows=None,
        linebelow=tabulate.Line("", "-", "  ", ""),
        headerrow=tabulate.DataRow("", "  ", ""),
        datarow=tabulate.DataRow("", "  ", ""),
        padding=0,
        with_header_hide=None,
    )
    tabulate.tabulate_formats = list(sorted(tabulate._table_formats.keys()))
    tabulate.multiline_formats["armi"] = "armi"


# runLog makes tables, so make sure this is setup before we initialize the runLog 
示例3
def tables():
    """
    Render an ascii table using all possible styles provided by tabulate.
    """
    data = [
        ('text', 'int', 'float'),
        ('Cell 1', 100, 1/3),
        ('Cell 2', -25, 0.001),
        ('Cell 3', 0, 0)
    ]
    lines = []
    for table_fmt in tabulate_formats:
        lines.append(table_fmt)
        lines.append('')
        lines.append(gopher.formatter.tabulate(data, 'firstrow', table_fmt))
        lines.append('\n')
    return gopher.render_menu(*lines) 
示例4
def metric_parser():

    """
    Command line parser for the utility.
    """

    parser = argparse.ArgumentParser("Script to generate the available metrics")
    parser.add_argument("-f", "--format",
                        help="Format of the table to be printed out.",
                        choices=tabulate.tabulate_formats, default="rst")
    parser.add_argument("-o", "--out",
                        help="Optional output file",
                        type=argparse.FileType("w"), default=sys.stdout)
    parser.add_argument("-c", "--category",
                        help="Available categories to select from.",
                        default=[], nargs="+",
                        choices=sorted(set(
                            [_ for _ in [getattr(getattr(Transcript, metric), "category", "Descriptive") for metric in
                             Transcript.get_available_metrics()] if _ is not None] + ["Descriptive"])))
    parser.add_argument("metric", nargs="*")
    parser.set_defaults(func=launch)
    return parser 
示例5
def code_parser():

    """
    Command line parser for the utility.
    """

    parser = argparse.ArgumentParser("Script to generate the available class codes.")
    parser.add_argument("-f", "--format", choices=tabulate.tabulate_formats, default="rst")
    parser.add_argument("-c", "--category", nargs="+", default=[],
                        choices=list(set(_.category for _ in class_codes.codes.values())))
    parser.add_argument("-o", "--out", type=argparse.FileType("w"), default=sys.stdout)
    parser.add_argument("code", nargs="*", help="Codes to query.",
                        default=[],
                        choices=[[]] + list(class_codes.codes.keys()))
    parser.set_defaults(func=launch)
    return parser 
示例6
def test_tabulate_formats():
    "API: tabulate_formats is a list of strings" ""
    supported = tabulate_formats
    print("tabulate_formats = %r" % supported)
    assert type(supported) is list
    for fmt in supported:
        assert type(fmt) is type("")  # noqa 
示例7
def test_tabulate_formats():
    "API: tabulate_formats is a list of strings"""
    supported = tabulate_formats
    print("tabulate_formats = %r" % supported)
    assert type(supported) is list
    for fmt in supported:
        assert type(fmt) is type("") 
示例8
def output_options(fn):
    for decorator in reversed(
        (
            click.option(
                "--nl",
                help="Output newline-delimited JSON",
                is_flag=True,
                default=False,
            ),
            click.option(
                "--arrays",
                help="Output rows as arrays instead of objects",
                is_flag=True,
                default=False,
            ),
            click.option("-c", "--csv", is_flag=True, help="Output CSV"),
            click.option("--no-headers", is_flag=True, help="Omit CSV headers"),
            click.option("-t", "--table", is_flag=True, help="Output as a table"),
            click.option(
                "-f",
                "--fmt",
                help="Table format - one of {}".format(
                    ", ".join(tabulate.tabulate_formats)
                ),
                default="simple",
            ),
            click.option(
                "--json-cols",
                help="Detect JSON cols and output them as JSON, not escaped strings",
                is_flag=True,
                default=False,
            ),
        )
    ):
        fn = decorator(fn)
    return fn 
示例9
def add_arguments(self, parser):
        """Add custom arguments.

        See command.CommandBase.
        """
        command.add_sharding_arguments(parser)
        parser.add_argument(
            "-c", "--conf", help="Configuration file for namespaces", dest="conf"
        )

        formats = tabulate.tabulate_formats
        formats.append("graphite")
        parser.add_argument(
            "-f", "--format", help="Format: %s" % ", ".join(formats), dest="fmt"
        )
        parser.add_argument(
            "--carbon",
            help="Carbon host:port to send points to when using graphite output."
        )
        parser.add_argument(
            "--prefix",
            help="Prefix to add to every section name.",
            default='',
        )
        self._n_metrics = collections.defaultdict(int)
        self._n_points = collections.defaultdict(int)