prettytable 0.7.1__tar.bz2 → 0.7.2__tar.bz2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {prettytable-0.7.1/prettytable.egg-info → prettytable-0.7.2}/PKG-INFO +1 -1
- {prettytable-0.7.1 → prettytable-0.7.2/prettytable.egg-info}/PKG-INFO +1 -1
- {prettytable-0.7.1 → prettytable-0.7.2}/prettytable.py +32 -5
- {prettytable-0.7.1 → prettytable-0.7.2}/prettytable_test.py +19 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/CHANGELOG +0 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/COPYING +0 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/MANIFEST.in +0 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/README +0 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/prettytable.egg-info/SOURCES.txt +0 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/prettytable.egg-info/dependency_links.txt +0 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/prettytable.egg-info/top_level.txt +0 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/setup.cfg +0 -0
- {prettytable-0.7.1 → prettytable-0.7.2}/setup.py +0 -0
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
30
30
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
31
31
|
|
|
32
|
-
__version__ = "0.7.
|
|
32
|
+
__version__ = "0.7.2"
|
|
33
33
|
|
|
34
34
|
import copy
|
|
35
35
|
import csv
|
|
@@ -126,7 +126,7 @@ class PrettyTable(object):
|
|
|
126
126
|
# Options
|
|
127
127
|
self._options = "start end fields header border sortby reversesort sort_key attributes format hrules vrules".split()
|
|
128
128
|
self._options.extend("int_format float_format padding_width left_padding_width right_padding_width".split())
|
|
129
|
-
self._options.extend("vertical_char horizontal_char junction_char header_style valign xhtml".split())
|
|
129
|
+
self._options.extend("vertical_char horizontal_char junction_char header_style valign xhtml print_empty".split())
|
|
130
130
|
for option in self._options:
|
|
131
131
|
if option in kwargs:
|
|
132
132
|
self._validate_option(option, kwargs[option])
|
|
@@ -166,6 +166,10 @@ class PrettyTable(object):
|
|
|
166
166
|
self._horizontal_char = kwargs["horizontal_char"] or self._unicode("-")
|
|
167
167
|
self._junction_char = kwargs["junction_char"] or self._unicode("+")
|
|
168
168
|
|
|
169
|
+
if kwargs["print_empty"] in (True, False):
|
|
170
|
+
self._print_empty = kwargs["print_empty"]
|
|
171
|
+
else:
|
|
172
|
+
self._print_empty = True
|
|
169
173
|
self._format = kwargs["format"] or False
|
|
170
174
|
self._xhtml = kwargs["xhtml"] or False
|
|
171
175
|
self._attributes = kwargs["attributes"] or {}
|
|
@@ -264,7 +268,7 @@ class PrettyTable(object):
|
|
|
264
268
|
self._validate_vrules(option, val)
|
|
265
269
|
elif option in ("fields"):
|
|
266
270
|
self._validate_all_field_names(option, val)
|
|
267
|
-
elif option in ("header", "border", "reversesort", "xhtml"):
|
|
271
|
+
elif option in ("header", "border", "reversesort", "xhtml", "print_empty"):
|
|
268
272
|
self._validate_true_or_false(option, val)
|
|
269
273
|
elif option in ("header_style"):
|
|
270
274
|
self._validate_header_style(val)
|
|
@@ -697,6 +701,18 @@ class PrettyTable(object):
|
|
|
697
701
|
self._format = val
|
|
698
702
|
format = property(_get_format, _set_format)
|
|
699
703
|
|
|
704
|
+
def _get_print_empty(self):
|
|
705
|
+
"""Controls whether or not empty tables produce a header and frame or just an empty string
|
|
706
|
+
|
|
707
|
+
Arguments:
|
|
708
|
+
|
|
709
|
+
print_empty - True or False"""
|
|
710
|
+
return self._print_empty
|
|
711
|
+
def _set_print_empty(self, val):
|
|
712
|
+
self._validate_option("print_empty", val)
|
|
713
|
+
self._print_empty = val
|
|
714
|
+
print_empty = property(_get_print_empty, _set_print_empty)
|
|
715
|
+
|
|
700
716
|
def _get_attributes(self):
|
|
701
717
|
"""A dictionary of HTML attribute name/value pairs to be included in the <table> tag when printing HTML
|
|
702
718
|
|
|
@@ -952,7 +968,8 @@ class PrettyTable(object):
|
|
|
952
968
|
junction_char - single character string used to draw line junctions
|
|
953
969
|
sortby - name of field to sort rows by
|
|
954
970
|
sort_key - sorting key function, applied to data points before sorting
|
|
955
|
-
reversesort - True or False to sort in descending or ascending order
|
|
971
|
+
reversesort - True or False to sort in descending or ascending order
|
|
972
|
+
print empty - if True, stringify just the header for an empty table, if False return an empty string """
|
|
956
973
|
|
|
957
974
|
options = self._get_options(kwargs)
|
|
958
975
|
|
|
@@ -960,7 +977,7 @@ class PrettyTable(object):
|
|
|
960
977
|
|
|
961
978
|
# Don't think too hard about an empty table
|
|
962
979
|
# Is this the desired behaviour? Maybe we should still print the header?
|
|
963
|
-
if self.rowcount == 0:
|
|
980
|
+
if self.rowcount == 0 and (not options["print_empty"] or not options["border"]):
|
|
964
981
|
return ""
|
|
965
982
|
|
|
966
983
|
# Get the rows we need to print, taking into account slicing, sorting, etc.
|
|
@@ -998,6 +1015,10 @@ class PrettyTable(object):
|
|
|
998
1015
|
bits = [options["junction_char"]]
|
|
999
1016
|
else:
|
|
1000
1017
|
bits = [options["horizontal_char"]]
|
|
1018
|
+
# For tables with no data or fieldnames
|
|
1019
|
+
if not self._field_names:
|
|
1020
|
+
bits.append(options["junction_char"])
|
|
1021
|
+
return "".join(bits)
|
|
1001
1022
|
for field, width in zip(self._field_names, self._widths):
|
|
1002
1023
|
if options["fields"] and field not in options["fields"]:
|
|
1003
1024
|
continue
|
|
@@ -1023,6 +1044,12 @@ class PrettyTable(object):
|
|
|
1023
1044
|
bits.append(options["vertical_char"])
|
|
1024
1045
|
else:
|
|
1025
1046
|
bits.append(" ")
|
|
1047
|
+
# For tables with no data or field names
|
|
1048
|
+
if not self._field_names:
|
|
1049
|
+
if options["vrules"] in (ALL, FRAME):
|
|
1050
|
+
bits.append(options["vertical_char"])
|
|
1051
|
+
else:
|
|
1052
|
+
bits.append(" ")
|
|
1026
1053
|
for field, width, in zip(self._field_names, self._widths):
|
|
1027
1054
|
if options["fields"] and field not in options["fields"]:
|
|
1028
1055
|
continue
|
|
@@ -223,6 +223,25 @@ class HrulesAllBasicTests(BasicTests):
|
|
|
223
223
|
BasicTests.setUp(self)
|
|
224
224
|
self.x.hrules = ALL
|
|
225
225
|
|
|
226
|
+
class EmptyTableTests(CityDataTest):
|
|
227
|
+
|
|
228
|
+
"""Make sure the print_empty option works"""
|
|
229
|
+
|
|
230
|
+
def setUp(self):
|
|
231
|
+
CityDataTest.setUp(self)
|
|
232
|
+
self.y = PrettyTable()
|
|
233
|
+
self.y.field_names = ["City name", "Area", "Population", "Annual Rainfall"]
|
|
234
|
+
|
|
235
|
+
def testPrintEmptyTrue(self):
|
|
236
|
+
assert self.y.get_string(print_empty=True) != ""
|
|
237
|
+
assert self.x.get_string(print_empty=True) != self.y.get_string(print_empty=True)
|
|
238
|
+
|
|
239
|
+
def testPrintEmptyFalse(self):
|
|
240
|
+
assert self.y.get_string(print_empty=False) == ""
|
|
241
|
+
assert self.y.get_string(print_empty=False) != self.x.get_string(print_empty=False)
|
|
242
|
+
|
|
243
|
+
def testInteractionWithBorder(self):
|
|
244
|
+
assert self.y.get_string(border=False, print_empty=True) == ""
|
|
226
245
|
class PresetBasicTests(BasicTests):
|
|
227
246
|
|
|
228
247
|
"""Run the basic tests after using set_style"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|