TSVZ 3.16__tar.gz → 3.18__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: TSVZ
3
- Version: 3.16
3
+ Version: 3.18
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: TSVZ
3
- Version: 3.16
3
+ Version: 3.18
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
@@ -22,7 +22,7 @@ if os.name == 'nt':
22
22
  elif os.name == 'posix':
23
23
  import fcntl
24
24
 
25
- version = '3.16'
25
+ version = '3.18'
26
26
  __version__ = version
27
27
  author = 'pan@zopyr.us'
28
28
 
@@ -57,10 +57,10 @@ def get_delimiter(delimiter,file_name = ''):
57
57
  return rtn
58
58
 
59
59
  def pretty_format_table(data, delimiter = DEFAULT_DELIMITER,header = None):
60
- version = 1.1
60
+ version = 1.11
61
61
  if not data:
62
62
  return ''
63
- if type(data) == str:
63
+ if isinstance(data, str):
64
64
  data = data.strip('\n').split('\n')
65
65
  data = [line.split(delimiter) for line in data]
66
66
  elif isinstance(data, dict):
@@ -72,7 +72,7 @@ def pretty_format_table(data, delimiter = DEFAULT_DELIMITER,header = None):
72
72
  else:
73
73
  # it is a dict of lists
74
74
  data = [[key] + list(value) for key, value in data.items()]
75
- elif type(data) != list:
75
+ elif not isinstance(data,list):
76
76
  data = list(data)
77
77
  # format the list into 2d list of list of strings
78
78
  if isinstance(data[0], dict):
@@ -87,6 +87,9 @@ def pretty_format_table(data, delimiter = DEFAULT_DELIMITER,header = None):
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
@@ -425,7 +428,7 @@ def _formatHeader(header,verbose = False,teeLogger = None,delimiter = DEFAULT_DE
425
428
  Returns:
426
429
  str: The formatted header string.
427
430
  """
428
- if type(header) != str:
431
+ if not isinstance(header,str):
429
432
  try:
430
433
  header = delimiter.join(header)
431
434
  except:
@@ -644,17 +647,22 @@ def appendLinesTabularFile(fileName,linesToAppend,teeLogger = None,header = '',c
644
647
  return
645
648
  formatedLines = []
646
649
  for line in linesToAppend:
647
- if type(line) == str:
650
+ if isinstance(linesToAppend,dict):
651
+ key = line
652
+ line = linesToAppend[key]
653
+ if isinstance(line,str):
648
654
  line = line.split(delimiter)
649
- else:
655
+ elif line:
650
656
  for i in range(len(line)):
651
- if type(line[i]) != str:
657
+ if not isinstance(line[i],str):
652
658
  try:
653
659
  line[i] = str(line[i])
654
660
  except Exception as e:
655
661
  line[i] = str(e)
662
+ if isinstance(linesToAppend,dict):
663
+ if not line or line[0] != key:
664
+ line = [key]+line
656
665
  formatedLines.append(line)
657
-
658
666
  with open(fileName, mode ='r+b')as file:
659
667
  correctColumnNum = max([len(line) for line in formatedLines])
660
668
  if header.rstrip():
@@ -843,10 +851,10 @@ class TSVZed(OrderedDict):
843
851
  if not key:
844
852
  self.__teePrintOrNot('Key cannot be empty','error')
845
853
  return
846
- if type(value) == str:
854
+ if isinstance(value,str):
847
855
  value = value.split(self.delimiter)
848
856
  # sanitize the value
849
- value = [(str(segment).rstrip() if type(segment) != str else segment.rstrip()) if segment else '' for segment in value]
857
+ value = [(str(segment).rstrip() if not isinstance(segment,str) else segment.rstrip()) if segment else '' for segment in value]
850
858
  # escape the delimiter and newline characters
851
859
  value = [segment.replace(self.delimiter,'<sep>').replace('\n','\\n') for segment in value]
852
860
  # the first field in value should be the key
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes