From 1d4c3d48fd9a5606925562c1c97e67332578cc65 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 27 Aug 2019 12:11:30 +0000 Subject: [PATCH 25/26] Simplify code. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8373 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 Signed-off-by: Doan Tran Cong Danh --- docutils/parsers/rst/tableparser.py | 3 +-- docutils/statemachine.py | 3 +-- docutils/writers/odf_odt/__init__.py | 6 ++---- test/DocutilsTestSupport.py | 10 +++------- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/docutils/parsers/rst/tableparser.py b/docutils/parsers/rst/tableparser.py index 408d6d8..64a192f 100644 --- a/docutils/parsers/rst/tableparser.py +++ b/docutils/parsers/rst/tableparser.py @@ -290,8 +290,7 @@ class GridTableParser(TableParser): rowindex = {} for i in range(len(rowseps)): rowindex[rowseps[i]] = i # row boundary -> row number mapping - colseps = list(self.colseps.keys()) # list of column boundaries - colseps.sort() + colseps = sorted(self.colseps.keys()) # list of column boundaries colindex = {} for i in range(len(colseps)): colindex[colseps[i]] = i # column boundary -> col number map diff --git a/docutils/statemachine.py b/docutils/statemachine.py index 0cbf9d3..ebb52ad 100644 --- a/docutils/statemachine.py +++ b/docutils/statemachine.py @@ -1297,8 +1297,7 @@ class ViewList(object): self.parent = None def sort(self, *args): - tmp = list(zip(self.data, self.items)) - tmp.sort(*args) + tmp = sorted(zip(self.data, self.items), *args) self.data = [entry[0] for entry in tmp] self.items = [entry[1] for entry in tmp] self.parent = None diff --git a/docutils/writers/odf_odt/__init__.py b/docutils/writers/odf_odt/__init__.py index ad32613..d03f8e0 100644 --- a/docutils/writers/odf_odt/__init__.py +++ b/docutils/writers/odf_odt/__init__.py @@ -1167,10 +1167,8 @@ class ODFTranslator(nodes.GenericNodeVisitor): def setup_paper(self, root_el): try: fin = os.popen("paperconf -s 2> /dev/null") - content = fin.read() - content = content.split() - content = list(map(float, content)) - w, h = content + dimensions = fin.read().split() + w, h = (float(s) for s in dimensions) except (IOError, ValueError): w, h = 612, 792 # default to Letter finally: diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 222c202..5e9fed9 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -810,14 +810,10 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): self.standard_html_meta_value, '...') parts['html_prolog'] = parts['html_prolog'].replace( self.standard_html_prolog, '') - # remove empty values: - for key in list(parts.keys()): - if not parts[key]: - del parts[key] - # standard output format: - keys = sorted(parts.keys()) output = [] - for key in keys: + for key in sorted(parts.keys()): + if not parts[key]: + continue output.append("%r: '''%s'''" % (key, parts[key])) if output[-1].endswith("\n'''"): -- 2.24.0.375.geb5ae68d41