Commit 49514219 authored by Scott Kitterman's avatar Scott Kitterman

Imported Upstream version 0.9.2

parent 32c66e1f
########## PrettyTable 0.7 - Feb 17, 2013 ###########
########## PrettyTable 0.9 - May 1, 2015 ###########
* Improved Python 2 and 3 compatibility (2.4-3.2).
* Add command line tool ``ptable``. Usage: ``ptable --csv=filename``.
########## PrettyTable 0.8 - Oct XX, 2013 ###########
* New "paginate" method can be used to produce strings suitable
for piping to lp/lpr.
* from_html now handles HTML tables with colspan, rather than
choking on them.
* Added "min_width", "min_table_width" and "max_table_width"
attribute/options for better control of table sizing.
* Added "title" attribute/option for table titles.
* When slice syntax is used to create a new sub-table out of an
existing table, the rows are sorted before, not after, the slicing.
The old behaviour (slice then sort) can be achieved by setting
oldsortslice=True.
* The from_csv table factory now accepts CSV format parameters as
keyword arguments (e.g. delimiter, doublequote, escapechar, etc.)
########## PrettyTable 0.7 - Jan XX, 2013 ###########
* Improved Python 3 compatibility.
* Improved support for non-Latin characters. Table widths should
now be calculated correctly for tables with e.g. Japanese text.
* Table contents can now be read in from a .csv file
* Table contents can now be read in from a DB-API compatible cursor
* Table contents can now be read in from a string containing a
HTML table (thanks to Christoph Robbert for submitting this patch!)
* new valign attribute controls vertical alignment of text when
some cells in a row have multiple lines of text and others don't.
(thanks to Google Code user maartendb for submitting this patch!)
* hrules attribute can now be set to HEADER, which draws a rule only
under the header row
* new vrules attribute controls drawing of vertical rules and can
......
# Copyright (c) 2009-2013 Luke Maurits <luke@maurits.id.au>
# Copyright (c) 2009-2014 Luke Maurits <luke@maurits.id.au>
# All rights reserved.
# With contributions from:
# * Chris Clark
# * Christoph Robbert
# * Klein Stephane
# * "maartendb"
# * John Filleau
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
......
include COPYING
include CHANGELOG
include README
include prettytable_test.py
include README.rst
include test_prettytable.py
This diff is collapsed.
This diff is collapsed.
CHANGELOG
COPYING
MANIFEST.in
README.rst
setup.py
PTable.egg-info/PKG-INFO
PTable.egg-info/SOURCES.txt
PTable.egg-info/dependency_links.txt
PTable.egg-info/entry_points.txt
PTable.egg-info/not-zip-safe
PTable.egg-info/pbr.json
PTable.egg-info/top_level.txt
prettytable/__init__.py
prettytable/_compact.py
prettytable/cli.py
prettytable/factory.py
prettytable/prettytable.py
\ No newline at end of file
[console_scripts]
ptable = prettytable.cli:main
{"is_release": false, "git_version": "1753bc4"}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Metadata-Version: 1.0
Name: prettytable
Version: 0.7.2
Summary: A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
Home-page: http://code.google.com/p/prettytable
Author: Luke Maurits
Author-email: luke@maurits.id.au
License: BSD (3 clause)
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.4
Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: BSD License
Classifier: Topic :: Text Processing
CHANGELOG
COPYING
MANIFEST.in
README
prettytable.py
prettytable_test.py
setup.py
prettytable.egg-info/PKG-INFO
prettytable.egg-info/SOURCES.txt
prettytable.egg-info/dependency_links.txt
prettytable.egg-info/top_level.txt
\ No newline at end of file
# Copyright (c) 2009-2014, Luke Maurits <luke@maurits.id.au>
# All rights reserved.
# With contributions from:
# * Chris Clark
# * Klein Stephane
# * John Filleau
# PTable is forked from original Google Code page in April, 2015, and now
# maintained by Kane Blueriver <kxxoling@gmail.com>.
#
# 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.
# * The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# 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 OWNER 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.
__version__ = "0.9.2"
from .prettytable import PrettyTable
from .prettytable import ALL, HEADER, MSWORD_FRIENDLY, NONE
from .factory import from_csv, from_db_cursor, from_html, from_html_one
import sys
py3k = sys.version_info[0] >= 3
if py3k:
str_types = (str, )
unicode_ = str
basestring_ = str
itermap = map
iterzip = zip
uni_chr = chr
from html.parser import HTMLParser
import io as StringIO
else:
unicode_ = unicode
basestring_ = basestring
str_types = (unicode, str)
import itertools
itermap = itertools.imap
iterzip = itertools.izip
uni_chr = unichr
from HTMLParser import HTMLParser
import StringIO
HTMLParser, StringIO
if py3k and sys.version_info[1] >= 2:
from html import escape
else:
from cgi import escape
escape
from __future__ import print_function
import argparse
import sys
from .factory import from_csv
from ._compact import StringIO
def main():
text_in = sys.stdin.read()
if text_in:
print(from_csv(StringIO.StringIO(text_in)))
return
parser = argparse.ArgumentParser(description='A simple Python library designed to make it quick and easy to '
'represent tabular data in visually appealing ASCII tables.')
parser.add_argument('--csv', help='CSV file name')
args = parser.parse_args()
with open(args.csv) as fp:
print(from_csv(fp))
if __name__ == '__main__':
main()
"""
Table factories
"""
import csv
from .prettytable import PrettyTable
from ._compact import py3k, HTMLParser
def from_csv(fp, field_names=None, **kwargs):
fmtparams = {}
for param in ["delimiter", "doublequote", "escapechar", "lineterminator",
"quotechar", "quoting", "skipinitialspace", "strict"]:
if param in kwargs:
fmtparams[param] = kwargs.pop(param)
if fmtparams:
reader = csv.reader(fp, **fmtparams)
else:
dialect = csv.Sniffer().sniff(fp.read(1024))
fp.seek(0)
reader = csv.reader(fp, dialect)
table = PrettyTable(**kwargs)
if field_names:
table.field_names = field_names
else:
if py3k:
table.field_names = [x.strip() for x in next(reader)]
else:
table.field_names = [x.strip() for x in reader.next()]
for row in reader:
table.add_row([x.strip() for x in row])
return table
def from_db_cursor(cursor, **kwargs):
if cursor.description:
table = PrettyTable(**kwargs)
table.field_names = [col[0] for col in cursor.description]
for row in cursor.fetchall():
table.add_row(row)
return table
class TableHandler(HTMLParser):
def __init__(self, **kwargs):
HTMLParser.__init__(self)
self.kwargs = kwargs
self.tables = []
self.last_row = []
self.rows = []
self.max_row_width = 0
self.active = None
self.last_content = ""
self.is_last_row_header = False
self.colspan = 0
def handle_starttag(self, tag, attrs):
self.active = tag
if tag == "th":
self.is_last_row_header = True
for (key, value) in attrs:
if key == "colspan":
self.colspan = int(value)
def handle_endtag(self, tag):
if tag in ["th", "td"]:
stripped_content = self.last_content.strip()
self.last_row.append(stripped_content)
if self.colspan:
for i in range(1, self.colspan):
self.last_row.append("")
self.colspan = 0
if tag == "tr":
self.rows.append(
(self.last_row, self.is_last_row_header))
self.max_row_width = max(self.max_row_width, len(self.last_row))
self.last_row = []
self.is_last_row_header = False
if tag == "table":
table = self.generate_table(self.rows)
self.tables.append(table)
self.rows = []
self.last_content = " "
self.active = None
def handle_data(self, data):
self.last_content += data
def generate_table(self, rows):
"""
Generates from a list of rows a PrettyTable object.
"""
table = PrettyTable(**self.kwargs)
for row in self.rows:
if len(row[0]) < self.max_row_width:
appends = self.max_row_width - len(row[0])
for i in range(1, appends):
row[0].append("-")
if row[1] is True:
self.make_fields_unique(row[0])
table.field_names = row[0]
else:
table.add_row(row[0])
return table
def make_fields_unique(self, fields):
"""
iterates over the row and make each field unique
"""
for i in range(0, len(fields)):
for j in range(i + 1, len(fields)):
if fields[i] == fields[j]:
fields[j] += "'"
def from_html(html_code, **kwargs):
"""
Generates a list of PrettyTables from a string of HTML code. Each <table> in
the HTML becomes one PrettyTable object.
"""
parser = TableHandler(**kwargs)
parser.feed(html_code)
return parser.tables
def from_html_one(html_code, **kwargs):
"""
Generates a PrettyTables from a string of HTML code which contains only a
single <table>
"""
tables = from_html(html_code, **kwargs)
try:
assert len(tables) == 1
except AssertionError:
raise Exception("More than one <table> in provided HTML code! Use from_html instead.")
return tables[0]
This diff is collapsed.
......@@ -2,9 +2,22 @@
from setuptools import setup
from prettytable import __version__ as version
def fread(filepath):
with open(filepath, 'r') as f:
return f.read()
setup(
name='prettytable',
name='PTable',
version=version,
include_package_data=True,
zip_safe=False,
entry_points={
'console_scripts': [
'ptable = prettytable.cli:main',
]
},
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2.4',
......@@ -17,9 +30,13 @@ setup(
],
license="BSD (3 clause)",
description='A simple Python library for easily displaying tabular data in a visually appealing ASCII table format',
long_description=fread('README.rst'),
author='Luke Maurits',
author_email='luke@maurits.id.au',
url='http://code.google.com/p/prettytable',
py_modules=['prettytable'],
test_suite = "prettytable_test"
maintainer='Kane Blueriver',
maintainer_email='kxxoling@gmail.com',
url='https://github.com/kxxoling/PTable',
py_modules=['prettytable', 'prettytable.cli', 'prettytable.prettytable',
'prettytable.factory', 'prettytable._compact'],
test_suite="test_prettytable",
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment