Skip to content

Commit

Permalink
release 0.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
foutaise committed Sep 16, 2016
1 parent 86ca0d3 commit f5cd62c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
4 changes: 2 additions & 2 deletions PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Metadata-Version: 1.0
Name: texttable
Version: 0.8.4
Version: 0.8.5
Summary: module for creating simple ASCII tables
Home-page: https://github.com/foutaise/texttable/
Author: Gerome Fournier
Author-email: jef(at)foutaise.org
License: LGPL
Download-URL: https://github.com/foutaise/texttable/archive/v0.8.4.tar.gz
Download-URL: https://github.com/foutaise/texttable/archive/v0.8.5.tar.gz
Description: texttable is a module to generate a formatted text table, using ASCII
characters.
Platform: any
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Python module for creating simple ASCII tables

## Availability

This module is available on [PypI](https://pypi.python.org/pypi/texttable/0.8.4), and has been packaged for several Linux/Unix platforms
This module is available on [PypI](https://pypi.python.org/pypi/texttable/0.8.5), and has been packaged for several Linux/Unix platforms
([Debian](https://packages.debian.org/search?&searchon=names&keywords=python-texttable+),
[FreeBSD](https://www.freebsd.org/cgi/ports.cgi?query=texttable&stype=all), Fedora, Suse...).

Expand Down Expand Up @@ -190,10 +190,10 @@ DATA
__author__ = 'Gerome Fournier <jef(at)foutaise.org>'
__credits__ = 'Jeff Kowalczyk:\n - textwrap improved import\n ...:\...
__license__ = 'LGPL'
__version__ = '0.8.4'
__version__ = '0.8.5'
VERSION
0.8.4
0.8.5
AUTHOR
Gerome Fournier <jef(at)foutaise.org>
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

setup(
name = "texttable",
version = "0.8.4",
version = "0.8.5",
author = "Gerome Fournier",
author_email = "jef(at)foutaise.org",
url = "https://github.com/foutaise/texttable/",
download_url = "https://github.com/foutaise/texttable/archive/v0.8.4.tar.gz",
download_url = "https://github.com/foutaise/texttable/archive/v0.8.5.tar.gz",
license = "LGPL",
py_modules = ["texttable"],
description = DESCRIPTION,
Expand Down
47 changes: 27 additions & 20 deletions texttable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
table = Texttable()
table.set_cols_align(["l", "r", "c"])
table.set_cols_valign(["t", "m", "b"])
table.add_rows([["Name", "Age", "Nickname"],
table.add_rows([["Name", "Age", "Nickname"],
["Mr\\nXavier\\nHuon", 32, "Xav'"],
["Mr\\nBaptiste\\nClement", 1, "Baby"]])
print table.draw() + "\\n"
table = Texttable()
table.set_deco(Texttable.HEADER)
table.set_cols_dtype(['t', # text
table.set_cols_dtype(['t', # text
'f', # float (decimal)
'e', # float (exponent)
'i', # integer
Expand Down Expand Up @@ -113,12 +113,30 @@
if sys.version >= '2.7':
from functools import reduce

def obj2unicode(obj):
"""Return a unicode representation of a python object
"""
try:
if sys.version >= '3.0':
return str(obj)
else:
if isinstance(obj, unicode):
return obj
else:
return str(obj).decode('utf')
except UnicodeDecodeError as strerror:
sys.stderr.write("UnicodeDecodeError exception for string '%s': %s\n" % (obj, strerror))
if sys.version >= '3.0':
return str(obj, 'utf', 'replace')
else:
return str(obj).decode('utf', 'replace')

def len(iterable):
"""Redefining len here so it will be able to work with non-ASCII characters
"""
if not isinstance(iterable, str):
return iterable.__len__()

try:
if sys.version >= '3.0':
return len(str)
Expand Down Expand Up @@ -303,7 +321,7 @@ def add_row(self, array):

if not hasattr(self, "_dtype"):
self._dtype = ["a"] * self._row_size

cells = []
for i, x in enumerate(array):
cells.append(self._str(i, x))
Expand All @@ -318,7 +336,7 @@ def add_rows(self, rows, header=True):
of the table
"""

# nb: don't use 'iter' on by-dimensional arrays, to get a
# nb: don't use 'iter' on by-dimensional arrays, to get a
# usable code for python 2.1
if header:
if hasattr(rows, '__iter__') and hasattr(rows, 'next'):
Expand Down Expand Up @@ -359,13 +377,13 @@ def draw(self):
def _str(self, i, x):
"""Handles string formatting of cell data
i - index of the cell datatype in self._dtype
i - index of the cell datatype in self._dtype
x - cell data to format
"""
try:
f = float(x)
except:
return str(x)
return obj2unicode(x)

n = self._precision
dtype = self._dtype[i]
Expand All @@ -377,7 +395,7 @@ def _str(self, i, x):
elif dtype == 'e':
return '%.*e' % (n, f)
elif dtype == 't':
return str(x)
return obj2unicode(x)
else:
if f - round(f) == 0:
if abs(f) > 1e8:
Expand Down Expand Up @@ -554,17 +572,6 @@ def _splitit(self, line, isheader):
for cell, width in zip(line, self._width):
array = []
for c in cell.split('\n'):
try:
if sys.version >= '3.0':
c = str(c)
else:
c = unicode(c, 'utf')
except UnicodeDecodeError as strerror:
sys.stderr.write("UnicodeDecodeError exception for string '%s': %s\n" % (c, strerror))
if sys.version >= '3.0':
c = str(c, 'utf', 'replace')
else:
c = unicode(c, 'utf', 'replace')
array.extend(textwrap.wrap(c, width))
line_wrapped.append(array)
max_cell_lines = reduce(max, list(map(len, line_wrapped)))
Expand Down Expand Up @@ -593,7 +600,7 @@ def _splitit(self, line, isheader):

table = Texttable()
table.set_deco(Texttable.HEADER)
table.set_cols_dtype(['t', # text
table.set_cols_dtype(['t', # text
'f', # float (decimal)
'e', # float (exponent)
'i', # integer
Expand Down

0 comments on commit f5cd62c

Please sign in to comment.