TSVZ 3.15__py3-none-any.whl → 3.17__py3-none-any.whl

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.
TSVZ.py CHANGED
@@ -22,7 +22,7 @@ if os.name == 'nt':
22
22
  elif os.name == 'posix':
23
23
  import fcntl
24
24
 
25
- version = '3.15'
25
+ version = '3.17'
26
26
  __version__ = version
27
27
  author = 'pan@zopyr.us'
28
28
 
@@ -56,8 +56,8 @@ def get_delimiter(delimiter,file_name = ''):
56
56
  DEFAULT_DELIMITER = rtn
57
57
  return rtn
58
58
 
59
- def pretty_format_table(data, delimiter = DEFAULT_DELIMITER):
60
- version = 1.0
59
+ def pretty_format_table(data, delimiter = DEFAULT_DELIMITER,header = None):
60
+ version = 1.11
61
61
  if not data:
62
62
  return ''
63
63
  if type(data) == str:
@@ -87,19 +87,40 @@ def pretty_format_table(data, delimiter = DEFAULT_DELIMITER):
87
87
  #col_widths[c] = max(len(row[c]) for row in data)
88
88
  # handle ansii escape sequences
89
89
  col_widths[c] = max(len(re.sub(r'\x1b\[[0-?]*[ -/]*[@-~]','',row[c])) for row in data)
90
+ if header:
91
+ header_widths = [len(re.sub(r'\x1b\[[0-?]*[ -/]*[@-~]', '', col)) for col in header]
92
+ col_widths = [max(col_widths[i], header_widths[i]) for i in range(num_cols)]
90
93
  # Build the row format string
91
94
  row_format = ' | '.join('{{:<{}}}'.format(width) for width in col_widths)
92
95
  # Print the header
93
- header = data[0]
94
- outTable = []
95
- outTable.append(row_format.format(*header))
96
- outTable.append('-+-'.join('-' * width for width in col_widths))
97
- for row in data[1:]:
98
- # if the row is empty, print an divider
99
- if not any(row):
100
- outTable.append('-+-'.join('-' * width for width in col_widths))
101
- else:
102
- outTable.append(row_format.format(*row))
96
+ if not header:
97
+ header = data[0]
98
+ outTable = []
99
+ outTable.append(row_format.format(*header))
100
+ outTable.append('-+-'.join('-' * width for width in col_widths))
101
+ for row in data[1:]:
102
+ # if the row is empty, print an divider
103
+ if not any(row):
104
+ outTable.append('-+-'.join('-' * width for width in col_widths))
105
+ else:
106
+ outTable.append(row_format.format(*row))
107
+ else:
108
+ # pad / truncate header to appropriate length
109
+ if isinstance(header,str):
110
+ header = header.split(delimiter)
111
+ if len(header) < num_cols:
112
+ header += ['']*(num_cols-len(header))
113
+ elif len(header) > num_cols:
114
+ header = header[:num_cols]
115
+ outTable = []
116
+ outTable.append(row_format.format(*header))
117
+ outTable.append('-+-'.join('-' * width for width in col_widths))
118
+ for row in data:
119
+ # if the row is empty, print an divider
120
+ if not any(row):
121
+ outTable.append('-+-'.join('-' * width for width in col_widths))
122
+ else:
123
+ outTable.append(row_format.format(*row))
103
124
  return '\n'.join(outTable) + '\n'
104
125
 
105
126
  def format_bytes(size, use_1024_bytes=None, to_int=False, to_str=False,str_format='.2f'):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: TSVZ
3
- Version: 3.15
3
+ Version: 3.17
4
4
  Summary: An simple in memory wrapper around a TSV file to function as a database
5
5
  Home-page: https://github.com/yufei-pan/TSVZ
6
6
  Author: Yufei Pan
@@ -0,0 +1,6 @@
1
+ TSVZ.py,sha256=9ccdCwpUlduKSChPpZ1xaLpnVKSoBfkKHs2mtTm2PtI,68057
2
+ tsvz-3.17.dist-info/METADATA,sha256=4W_qIeWuVgvkQELUdgtAGEaycfFi-h-BCkv8eUwUvXs,1826
3
+ tsvz-3.17.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
4
+ tsvz-3.17.dist-info/entry_points.txt,sha256=WeXidyV5yKCRLaVsnAY35xGa08QgytOfvr1CK9aescI,60
5
+ tsvz-3.17.dist-info/top_level.txt,sha256=OPx4LvOpaYykaos7oL_jGaObSWXxLzhHiWLuz-K147g,5
6
+ tsvz-3.17.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- TSVZ.py,sha256=ubb2xT12PS2kIMMQDDkSUcjexKI3UnYkjqJwOF6uOp8,67076
2
- TSVZ-3.15.dist-info/METADATA,sha256=IDGBJjOXdGAg3o5U96P_GHaCspv1F_Y5HRFSrazvdH4,1826
3
- TSVZ-3.15.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
4
- TSVZ-3.15.dist-info/entry_points.txt,sha256=WeXidyV5yKCRLaVsnAY35xGa08QgytOfvr1CK9aescI,60
5
- TSVZ-3.15.dist-info/top_level.txt,sha256=OPx4LvOpaYykaos7oL_jGaObSWXxLzhHiWLuz-K147g,5
6
- TSVZ-3.15.dist-info/RECORD,,