From 0d8d1a28b46abbb4e5c3a3dfc8b8bd62f071de99 Mon Sep 17 00:00:00 2001 From: decalage2 Date: Sun, 28 Aug 2016 21:26:27 +0200 Subject: [PATCH] mraptor3: import tablestream, removed tablestream3 --- oletools/mraptor3.py | 2 +- oletools/thirdparty/tablestream/tablestream3.py | 348 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2 files changed, 1 insertion(+), 349 deletions(-) delete mode 100644 oletools/thirdparty/tablestream/tablestream3.py diff --git a/oletools/mraptor3.py b/oletools/mraptor3.py index 2d77b79..d74cf58 100755 --- a/oletools/mraptor3.py +++ b/oletools/mraptor3.py @@ -66,7 +66,7 @@ import sys, logging, optparse, re from thirdparty.xglob import xglob # import the python 3 version of tablestream: -from thirdparty.tablestream import tablestream3 as tablestream +from thirdparty.tablestream import tablestream # import the python 3 version of olevba import olevba3 as olevba diff --git a/oletools/thirdparty/tablestream/tablestream3.py b/oletools/thirdparty/tablestream/tablestream3.py deleted file mode 100644 index 2daa2f8..0000000 --- a/oletools/thirdparty/tablestream/tablestream3.py +++ /dev/null @@ -1,348 +0,0 @@ -#!/usr/bin/env python -""" -tablestream - -tablestream can format table data for pretty printing as text, -to be displayed on the console or written to any file-like object. -The table data can be provided as rows, each row is an iterable of -cells. The text in each cell is wrapped to fit into a maximum width -set for each column. -Contrary to many table pretty printing libraries, TableStream writes -each row to the output as soon as it is provided, and the whole table -does not need to be built in memory before printing. -It is therefore suitable for large tables, or tables that take time to -be processed row by row. - -Author: Philippe Lagadec - http://www.decalage.info -License: BSD, see source code or documentation -""" - -#=== LICENSE ================================================================== - -# tablestream is copyright (c) 2015-2016 Philippe Lagadec (http://www.decalage.info) -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -from __future__ import print_function - -#------------------------------------------------------------------------------ -# CHANGELOG: -# 2015-11-01 v0.01 PL: - first version -# 2016-01-01 v0.02 PL: - added styles, color support -# 2016-04-19 v0.03 PL: - enable colorclass on Windows, fixed issue #39 -# 2016-05-25 v0.04 PL: - updated for colorclass 2.2.0 (now a package) -# 2016-07-29 v0.05 PL: - fixed oletools issue #57, bug when importing colorclass -# 2016-07-31 v0.06 PL: - handle newline characters properly in each cell - -__version__ = '0.06' - -#------------------------------------------------------------------------------ -# TODO: -# - several styles -# - colorized rows or cells -# - automatic width for the last column, based on max total width -# - automatic width for selected columns, based on N first lines -# - determine the console width - -# === IMPORTS ================================================================= - -import textwrap -import sys, os - -# add the thirdparty subfolder to sys.path (absolute+normalized path): -_thismodule_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) -# print('_thismodule_dir = %r' % _thismodule_dir) -# assumption: this module is in a subfolder of thirdparty: -_thirdparty_dir = os.path.normpath(os.path.join(_thismodule_dir, '..')) -# print('_thirdparty_dir = %r' % _thirdparty_dir) -if not _thirdparty_dir in sys.path: - sys.path.insert(0, _thirdparty_dir) - -import colorclass - -# On Windows, colorclass needs to be enabled: -if os.name == 'nt': - colorclass.Windows.enable(auto_colors=True) - - -# === CLASSES ================================================================= - - -class TableStyle(object): - """ - Style for a TableStream. - This base class can be derived to create new styles. - Default style: - +------+---+ - |Header| + - +------+---+ - | | | - +------+---+ - """ - # Header rows: - header_top = True - header_top_left = '+' - header_top_horiz = '-' - header_top_middle = '+' - header_top_right = '+' - - header_vertical_left = '|' - header_vertical_middle = '|' - header_vertical_right = '|' - - # Separator line between header and normal rows: - header_sep = True - header_sep_left = '+' - header_sep_horiz = '-' - header_sep_middle = '+' - header_sep_right = '+' - - # Top row if there is no header: - noheader_top = True - noheader_top_left = '+' - noheader_top_horiz = '-' - noheader_top_middle = '+' - noheader_top_right = '+' - - # Normal rows - vertical_left = '|' - vertical_middle = '|' - vertical_right = '|' - - # Separator line between rows: - sep = False - sep_left = '+' - sep_horiz = '-' - sep_middle = '+' - sep_right = '+' - - # Bottom line - bottom = True - bottom_left = '+' - bottom_horiz = '-' - bottom_middle = '+' - bottom_right = '+' - - -class TableStyleSlim(object): - """ - Style for a TableStream. - Example: - ------+--- - Header| - ------+--- - | - ------+--- - """ - # Header rows: - header_top = True - header_top_left = '' - header_top_horiz = '-' - header_top_middle = '+' - header_top_right = '' - - header_vertical_left = '' - header_vertical_middle = '|' - header_vertical_right = '' - - # Separator line between header and normal rows: - header_sep = True - header_sep_left = '' - header_sep_horiz = '-' - header_sep_middle = '+' - header_sep_right = '' - - # Top row if there is no header: - noheader_top = True - noheader_top_left = '' - noheader_top_horiz = '-' - noheader_top_middle = '+' - noheader_top_right = '' - - # Normal rows - vertical_left = '' - vertical_middle = '|' - vertical_right = '' - - # Separator line between rows: - sep = False - sep_left = '' - sep_horiz = '-' - sep_middle = '+' - sep_right = '' - - # Bottom line - bottom = True - bottom_left = '' - bottom_horiz = '-' - bottom_middle = '+' - bottom_right = '' - - - -class TableStream(object): - """ - a TableStream object can format table data for pretty printing as text, - to be displayed on the console or written to any file-like object. - The table data can be provided as rows, each row is an iterable of - cells. The text in each cell is wrapped to fit into a maximum width - set for each column. - Contrary to many table pretty printing libraries, TableStream writes - each row to the output as soon as it is provided, and the whole table - does not need to be built in memory before printing. - It is therefore suitable for large tables, or tables that take time to - be processed row by row. - """ - - def __init__(self, column_width, header_row=None, style=TableStyle, outfile=sys.stdout): - self.column_width = column_width - self.num_columns = len(column_width) - self.header_row = header_row - assert (header_row is None) or len(header_row) == self.num_columns - self.style = style - self.outfile = outfile - if header_row is not None: - self.write_header() - elif self.style.noheader_top: - self.write_noheader_top() - - - def write(self, s): - """ - shortcut for self.outfile.write() - """ - self.outfile.write(s) - - def write_row(self, row, last=False, colors=None): - assert len(row) == self.num_columns - columns = [] - max_lines = 0 - for i in range(self.num_columns): - cell = row[i] - # Convert to string: - # TODO: handle unicode properly - # TODO: use only unicode for textwrapper, to avoid str length issues - if isinstance(cell, bytes): - # encode to UTF8, avoiding errors - cell = cell.decode('utf-8', errors='replace') - else: - cell = cell - # Wrap cell text according to the column width - # TODO: use a TextWrapper object for each column instead - # split the string if it contains newline characters, otherwise - # textwrap replaces them with spaces: - column = [] - for line in cell.splitlines(): - column.extend(textwrap.wrap(line, width=self.column_width[i])) - # apply colors to each line of the cell if needed: - if colors is not None and self.outfile.isatty(): - color = colors[i] - if color: - for j in range(len(column)): - # print '%r: %s' % (column[j], type(column[j])) - column[j] = colorclass.Color('{auto%s}%s{/%s}' % (color, column[j], color)) - columns.append(column) - # determine which column has the highest number of lines - max_lines = max(len(columns[i]), max_lines) - # transpose: write output line by line - for j in range(max_lines): - self.write(self.style.vertical_left) - for i in range(self.num_columns): - column = columns[i] - if j