Commit 0510626ae6a614009c8a10d8d128fa826f0ca9c4

Authored by decalage2
1 parent 7a46e12d

tablestream: added TableStyleSlimSep, fixed a few issues causing extra separators

oletools/thirdparty/tablestream/tablestream.py
@@ -229,6 +229,17 @@ class TableStyleSlim(TableStyle): @@ -229,6 +229,17 @@ class TableStyleSlim(TableStyle):
229 bottom_middle = u'+' 229 bottom_middle = u'+'
230 bottom_right = u'' 230 bottom_right = u''
231 231
  232 +class TableStyleSlimSep(TableStyleSlim):
  233 + """
  234 + Style for a TableStream: slim with separator between all rows
  235 + Example:
  236 + ------+---
  237 + Header|
  238 + ------+---
  239 + |
  240 + ------+---
  241 + """
  242 + sep = True
232 243
233 244
234 class TableStream(object): 245 class TableStream(object):
@@ -351,7 +362,8 @@ class TableStream(object): @@ -351,7 +362,8 @@ class TableStream(object):
351 def write_header(self): 362 def write_header(self):
352 if self.style.header_top: 363 if self.style.header_top:
353 self.write_header_top() 364 self.write_header_top()
354 - self.write_row(self.header_row) 365 + self.write_row(self.header_row, last=True)
  366 + # here we use last=True just to avoid an extra separator if style.sep=True
355 if self.style.header_sep: 367 if self.style.header_sep:
356 self.write_header_sep() 368 self.write_header_sep()
357 369
@@ -369,9 +381,12 @@ class TableStream(object): @@ -369,9 +381,12 @@ class TableStream(object):
369 381
370 def write_bottom(self): 382 def write_bottom(self):
371 s = self.style 383 s = self.style
372 - line = self.make_line(left=s.bottom_left, horiz=s.bottom_horiz,  
373 - middle=s.bottom_middle, right=s.bottom_right)  
374 - self.write(line) 384 + # TODO: usually for the caller it's difficult to determine when to use last=True,
  385 + # so the last row will have already a separator if sep=True
  386 + if not s.sep:
  387 + line = self.make_line(left=s.bottom_left, horiz=s.bottom_horiz,
  388 + middle=s.bottom_middle, right=s.bottom_right)
  389 + self.write(line)
375 390
376 def close(self): 391 def close(self):
377 self.write_bottom() 392 self.write_bottom()