File: get_column_widths-compatibility.diff

package info (click to toggle)
python-docutils 0.13.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,728 kB
  • ctags: 7,259
  • sloc: python: 43,776; lisp: 13,142; xml: 1,644; sh: 164; makefile: 151
file content (112 lines) | stat: -rw-r--r-- 5,460 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
From a2af4ee3e032e26da1e478a4e807213ff15a48ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnter=20Milde?= <milde@users.sf.net>
Date: Tue, 3 Jan 2017 16:14:00 +0000
Subject: improve backwards compatibility of patch 120

Patch 120 (tables accept option widths: list of relative widths, auto or
grid) changed the API in parsers.rst.directives.tables

This patch lets get_column_widths() return one result again.

Origin: upstream, https://sourceforge.net/p/docutils/code/8010/
Bug: https://bugs.debian.org/851739
Patch-Name: get_column_widths-compatibility.diff
---
 docutils/parsers/rst/directives/tables.py | 29 ++++++++++++-----------------
 docutils/parsers/rst/states.py            |  6 ++++--
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/docutils/parsers/rst/directives/tables.py b/docutils/parsers/rst/directives/tables.py
index 0e890b6..5904c3e 100644
--- a/docutils/parsers/rst/directives/tables.py
+++ b/docutils/parsers/rst/directives/tables.py
@@ -112,13 +112,7 @@ class Table(Directive):
                 'No table data detected in CSV file.', nodes.literal_block(
                 self.block_text, self.block_text), line=self.lineno)
             raise SystemMessagePropagation(error)
-        if self.widths == 'auto':
-            widths = 'auto'
-        elif self.widths: # "grid" or list of integers
-            widths = 'given'
-        else:
-            widths = self.widths
-        return widths, col_widths
+        return col_widths
 
     def extend_short_rows_with_empty_cells(self, columns, parts):
         for part in parts:
@@ -253,7 +247,7 @@ class CSVTable(Table):
             self.check_table_dimensions(rows, header_rows, stub_columns)
             table_head.extend(rows[:header_rows])
             table_body = rows[header_rows:]
-            widths, col_widths = self.get_column_widths(max_cols)
+            col_widths = self.get_column_widths(max_cols)
             self.extend_short_rows_with_empty_cells(max_cols,
                                                     (table_head, table_body))
         except SystemMessagePropagation, detail:
@@ -269,7 +263,7 @@ class CSVTable(Table):
             return [error]
         table = (col_widths, table_head, table_body)
         table_node = self.state.build_table(table, self.content_offset,
-                                            stub_columns, widths=widths)
+                                            stub_columns, widths=self.widths)
         table_node['classes'] += self.options.get('class', [])
         if 'align' in self.options:
             table_node['align'] = self.options.get('align')
@@ -413,7 +407,7 @@ class ListTable(Table):
         node = nodes.Element()          # anonymous container for parsing
         self.state.nested_parse(self.content, self.content_offset, node)
         try:
-            num_cols, widths, col_widths = self.check_list_content(node)
+            num_cols, col_widths = self.check_list_content(node)
             table_data = [[item.children for item in row_list[0]]
                           for row_list in node[0]]
             header_rows = self.options.get('header-rows', 0)
@@ -421,7 +415,7 @@ class ListTable(Table):
             self.check_table_dimensions(table_data, header_rows, stub_columns)
         except SystemMessagePropagation, detail:
             return [detail.args[0]]
-        table_node = self.build_table_from_list(table_data, widths, col_widths,
+        table_node = self.build_table_from_list(table_data, col_widths,
                                                 header_rows, stub_columns)
         if 'align' in self.options:
             table_node['align'] = self.options.get('align')
@@ -467,14 +461,15 @@ class ListTable(Table):
                     raise SystemMessagePropagation(error)
             else:
                 num_cols = len(item[0])
-        widths, col_widths = self.get_column_widths(num_cols)
-        return num_cols, widths, col_widths
+        col_widths = self.get_column_widths(num_cols)
+        return num_cols, col_widths
 
-    def build_table_from_list(self, table_data, widths, col_widths, header_rows,
-                              stub_columns):
+    def build_table_from_list(self, table_data, col_widths, header_rows, stub_columns):
         table = nodes.table()
-        if widths:
-            table['classes'] += ['colwidths-%s' % widths]
+        if self.widths == 'auto':
+            table['classes'] += ['colwidths-auto']
+        elif self.widths: # "grid" or list of integers
+            table['classes'] += ['colwidths-given']
         tgroup = nodes.tgroup(cols=len(col_widths))
         table += tgroup
         for col_width in col_widths:
diff --git a/docutils/parsers/rst/states.py b/docutils/parsers/rst/states.py
index bc6ac95..c5cc424 100644
--- a/docutils/parsers/rst/states.py
+++ b/docutils/parsers/rst/states.py
@@ -1768,8 +1768,10 @@ class Body(RSTState):
     def build_table(self, tabledata, tableline, stub_columns=0, widths=None):
         colwidths, headrows, bodyrows = tabledata
         table = nodes.table()
-        if widths:
-            table['classes'] += ['colwidths-%s' % widths]
+        if widths == 'auto':
+            table['classes'] += ['colwidths-auto']
+        elif widths: # "grid" or list of integers
+            table['classes'] += ['colwidths-given']
         tgroup = nodes.tgroup(cols=len(colwidths))
         table += tgroup
         for colwidth in colwidths: