|
From: <mi...@us...> - 2024-06-06 14:03:37
|
Revision: 9744
http://sourceforge.net/p/docutils/code/9744
Author: milde
Date: 2024-06-06 14:03:33 +0000 (Thu, 06 Jun 2024)
Log Message:
-----------
xml-parser: Register IDs, report duplicate IDs.
Add element IDs to `document.ids`.
Report an ERROR system message for duplicate IDs.
Improves co-operation with "rST" parser when including XML
files in an rST file.
Modified Paths:
--------------
trunk/docutils/docutils/parsers/docutils_xml.py
trunk/docutils/test/test_parsers/test_docutils_xml/test_parse.py
trunk/docutils/test/test_parsers/test_docutils_xml/test_parse_element.py
Added Paths:
-----------
trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py
Modified: trunk/docutils/docutils/parsers/docutils_xml.py
===================================================================
--- trunk/docutils/docutils/parsers/docutils_xml.py 2024-06-06 14:03:21 UTC (rev 9743)
+++ trunk/docutils/docutils/parsers/docutils_xml.py 2024-06-06 14:03:33 UTC (rev 9744)
@@ -147,6 +147,14 @@
if key in node.list_attributes:
value = value.split()
node.attributes[key] = value # node becomes invalid!
+ # register ids, check for duplicates
+ for id in node['ids']:
+ document.ids.setdefault(id, node)
+ if document.ids[id] is not node:
+ document.reporter.error(f'Duplicate ID: "{id}" used by '
+ f'{document.ids[id].starttag()} '
+ f'and {node.starttag()}',
+ base_node=node)
# Append content:
# update "unindent" flag: change line indentation?
Added: trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py
===================================================================
--- trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py (rev 0)
+++ trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py 2024-06-06 14:03:33 UTC (rev 9744)
@@ -0,0 +1,91 @@
+#!/usr/bin/env python3
+# :Copyright: © 2024 Günter Milde.
+# :License: Released under the terms of the `2-Clause BSD license`_, in short:
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+# This file is offered as-is, without any warranty.
+#
+# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
+
+"""Various tests for the XML parser.
+
+Test parsing + transformations with `publish_string()`.
+"""
+
+from pathlib import Path
+import sys
+import unittest
+
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
+
+from docutils.core import publish_string
+from docutils.parsers import docutils_xml
+
+parser = docutils_xml.Parser()
+
+
+class XMLParserTests(unittest.TestCase):
+ maxDiff = None
+
+ mysettings = {'_disable_config': True,
+ 'output_encoding': 'unicode',
+ 'warning_stream': '',
+ }
+
+ def test_publish(self):
+ for name, (settings, cases) in totest.items():
+ settings = self.mysettings | settings
+ for casenum, (case_input, case_expected) in enumerate(cases):
+ with self.subTest(id=f'totest[{name!r}][{casenum}]'):
+ output = publish_string(case_input, parser=parser,
+ settings_overrides=settings)
+ self.assertEqual(case_expected, output)
+
+
+totest = {}
+
+totest['hyperlinks'] = ({},
+[
+# resolve anonymous hyperlinks
+["""\
+<document source="test data">
+ <paragraph>A <reference anonymous="1" name="link">link</reference> to Docutils.</paragraph>
+ <target anonymous="1" ids="target-1" refuri="http://docutils.sourceforge.io"/>
+</document>
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ A \n\
+ <reference anonymous="1" name="link" refuri="http://docutils.sourceforge.io">
+ link
+ to Docutils.
+ <target anonymous="1" ids="target-1" refuri="http://docutils.sourceforge.io">
+"""],
+# duplicate ids are an error
+["""\
+<tip ids="i1 i2">
+ <paragraph><strong ids="i2 i3"></strong></paragraph>
+</tip>
+""",
+"""\
+<document source="<string>">
+ <tip ids="i1 i2">
+ <paragraph>
+ <strong ids="i2 i3">
+ <section classes="system-messages">
+ <title>
+ Docutils System Messages
+ <system_message level="3" line="2" source="<string>" type="ERROR">
+ <paragraph>
+ Duplicate ID: "i2" used by <tip ids="i1 i2"> and <strong ids="i2 i3">
+"""],
+])
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Modified: trunk/docutils/test/test_parsers/test_docutils_xml/test_parse.py
===================================================================
--- trunk/docutils/test/test_parsers/test_docutils_xml/test_parse.py 2024-06-06 14:03:21 UTC (rev 9743)
+++ trunk/docutils/test/test_parsers/test_docutils_xml/test_parse.py 2024-06-06 14:03:33 UTC (rev 9744)
@@ -28,13 +28,13 @@
class XmlParserTestCase(unittest.TestCase):
- def test_parser(self):
- settings = get_default_settings(docutils_xml.Parser)
- # settings.warning_stream = ''
+ def test_parse(self):
+ settings = get_default_settings(parser)
+ settings.warning_stream = ''
for name, cases in totest.items():
for casenum, (case_input, case_expected) in enumerate(cases):
with self.subTest(id=f'totest[{name!r}][{casenum}]'):
- document = new_document('test data', settings.copy())
+ document = new_document('test data', settings)
parser.parse(case_input, document)
output = document.pformat()
self.assertEqual(case_expected, output)
Modified: trunk/docutils/test/test_parsers/test_docutils_xml/test_parse_element.py
===================================================================
--- trunk/docutils/test/test_parsers/test_docutils_xml/test_parse_element.py 2024-06-06 14:03:21 UTC (rev 9743)
+++ trunk/docutils/test/test_parsers/test_docutils_xml/test_parse_element.py 2024-06-06 14:03:33 UTC (rev 9744)
@@ -27,6 +27,7 @@
class ParseElementTestCase(unittest.TestCase):
"""Test the `docutils.xml.parse_element()` function."""
+ maxDiff = None
# supress warnings when passing `document` to `parse_element()`
settings = frontend.get_default_settings(docutils_xml.Parser)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-06 14:03:48
|
Revision: 9745
http://sourceforge.net/p/docutils/code/9745
Author: milde
Date: 2024-06-06 14:03:45 +0000 (Thu, 06 Jun 2024)
Log Message:
-----------
xml-parser: register decoration element
Update the internal attribute `document.decoration`
after creating a `decoration` element.
Prevents `transforms.universal.Decoration` from adding a second
`decoration` element.
Modified Paths:
--------------
trunk/docutils/docutils/parsers/docutils_xml.py
trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py
Modified: trunk/docutils/docutils/parsers/docutils_xml.py
===================================================================
--- trunk/docutils/docutils/parsers/docutils_xml.py 2024-06-06 14:03:33 UTC (rev 9744)
+++ trunk/docutils/docutils/parsers/docutils_xml.py 2024-06-06 14:03:45 UTC (rev 9745)
@@ -131,7 +131,9 @@
node = nodeclass()
node.line = int(element.get('source line'))
- if isinstance(node, Unknown):
+ if isinstance(node, nodes.decoration):
+ document.decoration = node
+ elif isinstance(node, Unknown):
node.tagname = element.tag
document.reporter.warning(
f'Unknown element type <{element.tag}>.',
Modified: trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py
===================================================================
--- trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py 2024-06-06 14:03:33 UTC (rev 9744)
+++ trunk/docutils/test/test_parsers/test_docutils_xml/test_misc.py 2024-06-06 14:03:45 UTC (rev 9745)
@@ -49,10 +49,29 @@
totest = {}
-totest['hyperlinks'] = ({},
+totest['decoration'] = ({'datestamp': 'pi-day'}, # generate footer
[
-# resolve anonymous hyperlinks
["""\
+<decoration>
+ <footer>
+ <paragraph>myfooter</paragraph>
+ </footer>
+</decoration>
+""",
+"""\
+<document source="<string>">
+ <decoration>
+ <footer>
+ <paragraph>
+ myfooter
+ <paragraph>
+ Generated on: pi-day.
+"""],
+])
+
+totest['hyperlinks'] = ({}, # resolve hyperlinks
+[
+["""\
<document source="test data">
<paragraph>A <reference anonymous="1" name="link">link</reference> to Docutils.</paragraph>
<target anonymous="1" ids="target-1" refuri="http://docutils.sourceforge.io"/>
@@ -87,5 +106,6 @@
"""],
])
+
if __name__ == '__main__':
unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-06 14:04:00
|
Revision: 9746
http://sourceforge.net/p/docutils/code/9746
Author: milde
Date: 2024-06-06 14:03:57 +0000 (Thu, 06 Jun 2024)
Log Message:
-----------
Better error reporting when parsing included (sub)documents.
Pass the included file's path to the parser when the "include"
directive is used with :parser: option.
Enables system messages with correct source/line indication.
Test with Docutils-XML file.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/parsers/rst/directives/misc.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
Added Paths:
-----------
trunk/docutils/test/data/duplicate-id.xml
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-06 14:03:45 UTC (rev 9745)
+++ trunk/docutils/HISTORY.txt 2024-06-06 14:03:57 UTC (rev 9746)
@@ -45,6 +45,12 @@
- New method `Parser.finish_parse()` to clean up (before validating).
+* docutils/parsers/rst/directives/misc.py
+
+ - Pass the included file's path to the parser when the
+ "include" directive is used with :parser: option.
+ Enables system messages with correct source/line indication.
+
* docutils/transforms/frontmatter.py
- Update `DocInfo` to work with corrected element categories.
Modified: trunk/docutils/docutils/parsers/rst/directives/misc.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/misc.py 2024-06-06 14:03:45 UTC (rev 9745)
+++ trunk/docutils/docutils/parsers/rst/directives/misc.py 2024-06-06 14:03:57 UTC (rev 9746)
@@ -200,13 +200,18 @@
if 'parser' in self.options:
# parse into a dummy document and return created nodes
- document = utils.new_document(path, settings)
+ _settings = settings.copy()
+ _settings._source = path
+ document = utils.new_document(path, _settings)
document.include_log = include_log + [(path, clip_options)]
parser = self.options['parser']()
parser.parse('\n'.join(include_lines), document)
+ self.state.document.parse_messages.extend(document.parse_messages)
# clean up doctree and complete parsing
document.transformer.populate_from_components((parser,))
document.transformer.apply_transforms()
+ self.state.document.transform_messages.extend(
+ document.transform_messages)
return document.children
# Include as rST source:
Added: trunk/docutils/test/data/duplicate-id.xml
===================================================================
--- trunk/docutils/test/data/duplicate-id.xml (rev 0)
+++ trunk/docutils/test/data/duplicate-id.xml 2024-06-06 14:03:57 UTC (rev 9746)
@@ -0,0 +1,5 @@
+<section>
+ <title ids="s4">nice heading</title>
+ <paragraph>Text with <strong ids="s4">strong
+ statement</strong> and more text.</paragraph>
+</section>
Property changes on: trunk/docutils/test/data/duplicate-id.xml
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2024-06-06 14:03:45 UTC (rev 9745)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2024-06-06 14:03:57 UTC (rev 9746)
@@ -90,9 +90,10 @@
include16 = mydir('includes/include16.txt')
include_literal = mydir('include_literal.txt')
include_md = mydir('include.md')
-include = os.path.join(TEST_ROOT, 'data/include.txt')
-latin2 = os.path.join(TEST_ROOT, 'data/latin2.txt')
-utf_16_file = os.path.join(TEST_ROOT, 'data/utf-16-le-sig.txt')
+include_xml = TEST_ROOT/'data/duplicate-id.xml'
+include = TEST_ROOT/'data/include.txt'
+latin2 = TEST_ROOT/'data/latin2.txt'
+utf_16_file = TEST_ROOT/'data/utf-16-le-sig.txt'
utf_16_error_str = ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xff "
"in position 0: ordinal not in range(128)")
rst_states_dir = os.path.dirname(parsers.rst.states.__file__)
@@ -1491,6 +1492,32 @@
File "include15.txt": example of rekursive inclusion.
"""],
[f"""\
+Include Docutils XML file:
+
+.. include:: {include_xml}
+ :parser: xml
+
+The duplicate id is reported and would be appended
+by the "universal.Messages" transform.
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Include Docutils XML file:
+ <section>
+ <title ids="s4">
+ nice heading
+ <paragraph>
+ Text with \n\
+ <strong ids="s4">
+ strong
+ statement
+ and more text.
+ <paragraph>
+ The duplicate id is reported and would be appended
+ by the "universal.Messages" transform.
+"""],
+[f"""\
No circular inclusion.
.. list-table::
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-07 12:48:25
|
Revision: 9747
http://sourceforge.net/p/docutils/code/9747
Author: milde
Date: 2024-06-07 12:48:23 +0000 (Fri, 07 Jun 2024)
Log Message:
-----------
Allow multiple `<term>` elements in a `<definition_list_item>`.
Fixes feature-request #60 where this is requested for a Sphinx extension.
There is currently no corresponding rST syntax, definition list items with
multiple terms can be generated programatically or by the XML parser.
Add an XML test sample, validated with
xmllint --dtdvalid ../../docs/ref/docutils.dtd multiple-term-definition.xml
and test cases.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docs/ref/doctree.txt
trunk/docutils/docs/ref/docutils.dtd
trunk/docutils/docutils/nodes.py
trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
trunk/docutils/test/test_writers/test_latex2e_misc.py
Added Paths:
-----------
trunk/docutils/test/data/multiple-term-definition.xml
Property Changed:
----------------
trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
trunk/docutils/test/test_writers/test_latex2e_misc.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-06 14:03:57 UTC (rev 9746)
+++ trunk/docutils/HISTORY.txt 2024-06-07 12:48:23 UTC (rev 9747)
@@ -22,6 +22,11 @@
- Add tox.ini to pyproject.toml to be in sdist (bug #486).
- Fix license issue (bug #487).
+* docs/ref/docutils.dtd
+
+ - Allow multiple <term> elements in a <definition_list_item>.
+ Fixes feature-request #60
+
* docutils/nodes.py
- Raise TypeError if the "rawsource" argument in `Element.__init__()`
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-06 14:03:57 UTC (rev 9746)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-07 12:48:23 UTC (rev 9747)
@@ -48,12 +48,6 @@
Document Tree / Docutils DTD
----------------------------
-* Allow multiple <term> elements in a <definition_list_item>
- in Docutils 0.22 (cf. `feature-requests:60`__).
- Third-party writers may need adaption.
-
- __ https://sourceforge.net/p/docutils/feature-requests/60/
-
* Do not lowercase reference names in the `refname attribute`_
(matching hyperlinks, footnotes, and citations remains case insensitive),
and drop the ``name`` attribute from <reference> nodes
@@ -212,8 +206,30 @@
Release 0.22b.dev (unpublished)
===============================
-.
+* Document Tree / Docutils DTD
+ - Allow multiple <term> elements in a <definition_list_item__>.
+ (Third-party writers may need adaption.)
+
+ - New method `Element.validate()`: Raise `nodes.ValidationError` if the
+ element does not comply with the `Docutils Document Model`_.
+ Provisional.
+
+ __ docs/ref/doctree.html#definition-list-item
+
+* New parser for `Docutils XML`_ (e.g., the output of the "xml" writer).
+ Provisional.
+
+ Try ``docutils --parser=xml test/data/multiple-term-definition.xml``
+ or use the :parser: option of the `"include" directive`_ to include
+ an XML file in a rST document.
+
+* Bugfixes and improvements (see HISTORY_).
+
+.. _Docutils Document Model:
+.. _Docutils XML: docs/ref/doctree.html
+
+
Release 0.21.2 (2024-04-23)
===========================
@@ -986,7 +1002,7 @@
Internationalization:
-* Added lithuanian mappings.
+* Added Lithuanian mappings.
Components:
Modified: trunk/docutils/docs/ref/doctree.txt
===================================================================
--- trunk/docutils/docs/ref/doctree.txt 2024-06-06 14:03:57 UTC (rev 9746)
+++ trunk/docutils/docs/ref/doctree.txt 2024-06-07 12:48:23 UTC (rev 9747)
@@ -1296,8 +1296,8 @@
<definition_list_item>
======================
-The <definition_list_item> element contains a single
-`\<term>`_/`\<definition>`_ pair (with optional `\<classifier>`_).
+A wrapper for a set of terms (with optional classifiers) and the
+associated definition in a `\<definition_list>`_.
:Category: `Body Subelements`_ (compound)
@@ -1304,7 +1304,7 @@
:Analogues: <definition_list_item> is analogous to the
DocBook_ <variablelistentry> element.
-:Processing: The optional `\<classifier>`_ can be rendered differently
+:Processing: The optional `\<classifier>`_\ s can be rendered differently
from the `\<term>`_. They should be separated visually,
typically by spaces plus a colon or dash.
@@ -1312,11 +1312,14 @@
<definition_list_item>.
:Children: <definition_list_item> elements each contain
- a single `\<term>`_, an optional `\<classifier>`_,
+ one or more `\<term>`_ elements,
+ zero or more `\<classifier>`_ elements,
and a `\<definition>`_::
- (term, classifier?, definition)
+ ((term, classifier*)+, definition)
+ Changed in Docutils 0.22: allow multiple terms.
+
:Attributes: The <definition_list_item> element contains only the
`common attributes`_.
Modified: trunk/docutils/docs/ref/docutils.dtd
===================================================================
--- trunk/docutils/docs/ref/docutils.dtd 2024-06-06 14:03:57 UTC (rev 9746)
+++ trunk/docutils/docs/ref/docutils.dtd 2024-06-07 12:48:23 UTC (rev 9747)
@@ -399,7 +399,7 @@
<!ELEMENT definition_list (definition_list_item+)>
<!ATTLIST definition_list %basic.atts;>
-<!ELEMENT definition_list_item (term, classifier*, definition)>
+<!ELEMENT definition_list_item ((term, classifier*)+, definition)>
<!ATTLIST definition_list_item %basic.atts;>
<!ELEMENT term %text.model;>
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2024-06-06 14:03:57 UTC (rev 9746)
+++ trunk/docutils/docutils/nodes.py 2024-06-07 12:48:23 UTC (rev 9747)
@@ -2023,9 +2023,9 @@
class definition_list_item(Part, Element):
- content_model = ( # (term, classifier*, definition)
+ content_model = ( # ((term, classifier*)+, definition)
(term, '.'),
- (classifier, '*'),
+ ((classifier, term), '*'),
(definition, '.'))
Added: trunk/docutils/test/data/multiple-term-definition.xml
===================================================================
--- trunk/docutils/test/data/multiple-term-definition.xml (rev 0)
+++ trunk/docutils/test/data/multiple-term-definition.xml 2024-06-07 12:48:23 UTC (rev 9747)
@@ -0,0 +1,31 @@
+<!DOCTYPE document PUBLIC "+//IDN docutils.sourceforge.net//DTD Docutils Generic//EN//XML" "http://docutils.sourceforge.net/docs/ref/docutils.dtd">
+<document source="test data">
+ <definition_list>
+ <definition_list_item>
+ <term>New in Docutils 0.22</term>
+ <definition>
+ <paragraph>A definition list item may contain several
+ terms with optional classifier(s).</paragraph>
+ <paragraph>However, there is currently no corresponding
+ reStructuredText syntax.</paragraph>
+ </definition>
+ </definition_list_item>
+ <definition_list_item>
+ <term>term 2a</term>
+ <term>term 2b</term>
+ <definition>
+ <paragraph>definition 2</paragraph>
+ </definition>
+ </definition_list_item>
+ <definition_list_item>
+ <term>term 3a</term>
+ <classifier>classifier 3a</classifier>
+ <classifier>classifier 3aa</classifier>
+ <term>term 3b</term>
+ <classifier>classifier 3b</classifier>
+ <definition>
+ <paragraph>definition 3</paragraph>
+ </definition>
+ </definition_list_item>
+ </definition_list>
+</document>
Property changes on: trunk/docutils/test/data/multiple-term-definition.xml
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Modified: trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_html5_polyglot_parts.py 2024-06-06 14:03:57 UTC (rev 9746)
+++ trunk/docutils/test/test_writers/test_html5_polyglot_parts.py 2024-06-07 12:48:23 UTC (rev 9747)
@@ -13,7 +13,6 @@
"""
from pathlib import Path
-import os
import re
import sys
import unittest
@@ -35,8 +34,10 @@
# pygments output changed in version 2.14
with_pygments = False
-ROOT_PREFIX = (Path(__file__).parent.parent/'functional'/'input').as_posix()
-DATA_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', 'data'))
+# TEST_ROOT is ./test/ from the docutils root
+TEST_ROOT = Path(__file__).parents[1]
+DATA_ROOT = TEST_ROOT / 'data'
+ROOT_PREFIX = (TEST_ROOT / 'functional/input').as_posix()
# Pillow/PIL is optional:
if PIL:
@@ -540,6 +541,28 @@
<p>No caption nor legend.</p>
""",
}],
+[f"""\
+.. include:: {DATA_ROOT}/multiple-term-definition.xml
+ :parser: xml
+""",
+{'fragment': """\
+<dl>
+<dt>New in Docutils 0.22</dt>
+<dd><p>A definition list item may contain several
+terms with optional classifier(s).</p>
+<p>However, there is currently no corresponding
+reStructuredText syntax.</p>
+</dd>
+<dt>term 2a</dt>
+<dt>term 2b</dt>
+<dd><p>definition 2</p>
+</dd>
+<dt>term 3a<span class="classifier">classifier 3a</span><span class="classifier">classifier 3aa</span><dt>term 3b<span class="classifier">classifier 3b</span></dt>
+<dd><p>definition 3</p>
+</dd>
+</dl>
+""",
+}],
])
Property changes on: trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Modified: trunk/docutils/test/test_writers/test_latex2e_misc.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e_misc.py 2024-06-06 14:03:57 UTC (rev 9746)
+++ trunk/docutils/test/test_writers/test_latex2e_misc.py 2024-06-07 12:48:23 UTC (rev 9747)
@@ -16,11 +16,23 @@
Miscellaneous LaTeX writer tests.
"""
+from pathlib import Path
+import sys
import unittest
+
+if __name__ == '__main__':
+ # prepend the "docutils root" to the Python library path
+ # so we import the local `docutils` package.
+ sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
+
from docutils import core
-contents_test_input = """\
+# TEST_ROOT is ./test/ from the docutils root
+TEST_ROOT = Path(__file__).parents[1]
+DATA_ROOT = TEST_ROOT / 'data'
+
+sample_toc = """\
.. contents:: TOC
foo
@@ -31,13 +43,38 @@
"""
+sample_multiterm = f"""\
+.. include:: {DATA_ROOT}/multiple-term-definition.xml
+ :parser: xml
+"""
+expected_multiterm = """
+\\begin{description}
+\\item[{New in Docutils 0.22}] \n\
+A definition list item may contain several
+terms with optional classifier(s).
+However, there is currently no corresponding
+reStructuredText syntax.
+
+\\item[{term 2a}] \n\
+\\item[{term 2b}] \n\
+definition 2
+
+\\item[{term 3a}] (\\textbf{classifier 3a})
+(\\textbf{classifier 3aa})
+\\item[{term 3b}] (\\textbf{classifier 3b})
+definition 3
+\\end{description}
+"""
+
+
class PublishTestCase(unittest.TestCase):
+ maxDiff = None
settings = {'_disable_config': True,
# avoid latex writer future warnings:
'use_latex_citations': False,
- 'legacy_column_widths': True,
+ 'legacy_column_widths': False,
}
def test_publish_from_doctree(self):
@@ -48,7 +85,7 @@
settings = self.settings.copy()
settings['output_encoding'] = 'unicode'
settings['warning_stream'] = '' # don't warn for missing ToC details
- doctree = core.publish_doctree(contents_test_input,
+ doctree = core.publish_doctree(sample_toc,
settings_overrides=settings)
result = core.publish_from_doctree(doctree,
writer_name='latex',
@@ -59,7 +96,7 @@
def test_publish_parts(self):
"""Check for the presence of documented parts.
"""
- parts = core.publish_parts(contents_test_input,
+ parts = core.publish_parts(sample_multiterm,
writer_name='latex',
settings_overrides=self.settings)
documented_parts = [
@@ -83,6 +120,7 @@
'whole'
]
self.assertEqual(documented_parts, sorted(parts.keys()))
+ self.assertEqual(expected_multiterm, parts['body'])
class WarningsTestCase(unittest.TestCase):
Property changes on: trunk/docutils/test/test_writers/test_latex2e_misc.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-10 14:24:02
|
Revision: 9749
http://sourceforge.net/p/docutils/code/9749
Author: milde
Date: 2024-06-10 14:24:00 +0000 (Mon, 10 Jun 2024)
Log Message:
-----------
encoding settings: remove shortcuts `-i` and `-o`, default to UTF-8.
Drop short options ``-i`` and ``-o``.
Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
(See `command line interface`_ for the rationale.)
Change the default input encoding from auto-detect to "utf-8".
Update documentation and tests.
Modified Paths:
--------------
trunk/docutils/FAQ.txt
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docs/api/publisher.txt
trunk/docutils/docs/howto/cmdline-tool.txt
trunk/docutils/docs/ref/rst/directives.txt
trunk/docutils/docs/ref/rst/restructuredtext.txt
trunk/docutils/docs/user/config.txt
trunk/docutils/docutils/frontend.py
trunk/docutils/test/data/help/docutils.txt
trunk/docutils/test/data/help/rst2html.txt
trunk/docutils/test/data/help/rst2latex.txt
trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
trunk/docutils/test/test_publisher.py
Modified: trunk/docutils/FAQ.txt
===================================================================
--- trunk/docutils/FAQ.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/FAQ.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -1139,11 +1139,8 @@
<http://www.reportlab.com/i18n/python_unicode_tutorial.html>`_
The common case is with the default output encoding (UTF-8), when
-either numbered sections are used (via the "sectnum_" directive) or
-symbol-footnotes. Three non-breaking spaces are inserted in each numbered
-section title, between the generated number and the title text. Most
-footnote symbols are not available in ASCII, nor are non-breaking
-spaces. When encoded with UTF-8 and viewed with ordinary ASCII tools,
+using symbol-footnotes. Most footnote symbols are not available in ASCII.
+When encoded with UTF-8 and viewed with ordinary ASCII tools,
these characters will appear to be multi-character garbage.
You may have an decoding problem in your browser (or editor, etc.).
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/HISTORY.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -27,6 +27,12 @@
- Allow multiple <term> elements in a <definition_list_item>.
Fixes feature-request #60
+* docutils/frontend.py
+
+ - Drop short options ``-i`` and ``-o`` for ``--input-encoding``
+ and ``--output-encoding``.
+ - Change the default input encoding from ``None`` (auto-detect) to "utf-8".
+
* docutils/nodes.py
- Raise TypeError if the "rawsource" argument in `Element.__init__()`
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -30,9 +30,6 @@
- COMMAND [OPTIONS] [SOURCE [DESTINATION]]
+ COMMAND [OPTIONS] [SOURCE [SOURCE2 [...]]] [>DESTINATION]
- * Remove short options ``-i`` and ``-o`` in Docutils 0.22.
- Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
-
* Stop accepting the DESTINATION positional argument in Docutils 1.0.
Use output redirection or the option ``--output=DESTINATION``
(available since Docutils 0.20).
@@ -58,14 +55,6 @@
.. _refname attribute: docs/ref/doctree.html#refname
-`Input encoding`_
------------------
-
-* Change the default input encoding from ``None`` (auto-detect) to
- "utf-8" in Docutils 0.22.
-
-* Remove the input encoding auto-detection code in Docutils 1.0 or later.
-
Writers
-------
@@ -152,6 +141,8 @@
.. _recommonmark parser: docs/user/config.html#recommonmark-parser
.. _MyST parser: docs/user/config.html#myst-parser
+* Remove the input encoding auto-detection code in Docutils 1.0.
+
* Remove the "rawsource" argument from `nodes.Text.__init__()`
in Docutils 2.0.
@@ -217,6 +208,12 @@
__ docs/ref/doctree.html#definition-list-item
+* Drop short options ``-i`` and ``-o``.
+ Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
+ (See `command line interface`_ for the rationale.)
+
+* Change the default input encoding from ``None`` (auto-detect) to "utf-8".
+
* New parser for `Docutils XML`_ (e.g., the output of the "xml" writer).
Provisional.
Modified: trunk/docutils/docs/api/publisher.txt
===================================================================
--- trunk/docutils/docs/api/publisher.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/api/publisher.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -41,8 +41,8 @@
publish_cmdline()
-----------------
-Function for custom `command-line front-end tools`_
-(like ``tools/rst2html.py``) or "console_scripts" `entry points`_
+Function for custom `command-line front-end tools`_
+(like ``tools/rst2html.py``) or "console_scripts" `entry points`_
(like `core.rst2html()`) with file I/O.
In addition to writing the output document to a file-like object, also
returns it as `str` instance (rsp. `bytes` for binary output document
@@ -71,11 +71,16 @@
`bytes` are decoded with input_encoding_.
Output
- * is a `bytes` instance, if output_encoding_ is set to an encoding
+ is handled similar to `xml.etree.ElementTree.tostring()`__:
+
+ * return a `bytes` instance, if output_encoding_ is set to an encoding
registered with Python's "codecs_" module (default: "utf-8"),
- * a `str` instance, if output_encoding_ is set to the special value
+ * return `str` instance, if output_encoding_ is set to the special value
``"unicode"``.
+__ https://docs.python.org/3/library/xml.etree.elementtree.html
+ #xml.etree.ElementTree.tostring
+
.. Caution::
The "output_encoding" and "output_encoding_error_handler" `runtime
settings`_ may affect the content of the output document:
@@ -439,33 +444,38 @@
Encodings
=========
-.. important:: Details will change over the next Docutils versions.
- See RELEASE-NOTES_
+Docutils supports all `standard encodings`_ and encodings registered__
+with the codecs_ module.
+The special value "unicode" can be used with `publish_string()`_ to skip
+encoding and return a `str` instance instead of `bytes`.
-The **input encoding** can be specified with the `input_encoding`_ setting.
+__ https://docs.python.org/3/library/codecs.html#codecs.register
-By default, the input encoding is detected from a
-`Unicode byte order mark` (BOM_) or a "magic comment" [#magic-comment]_
-similar to :PEP:`263`. The fallback is "utf-8".
-The default behaviour differs from Python's `open()`:
-- An `explicit encoding declaration` ((BOM_) or a "magic comment"
- [#magic-comment]_) in the source takes precedence over
- the `preferred encoding`_.
-- An optional BOM_ is removed from sources.
+The **input encoding** can be specified with the `input_encoding`_ setting.
+The default is "utf-8".
+The **output encoding** can be specified with the `output_encoding`_ setting.
+The default is "utf-8", too.
-The default will change to "utf-8" in Docutils 0.22,
-the input encoding detection will be removed in Docutils 1.0.
-
-
-The default **output encoding** is UTF-8.
-A different encoding can be specified with the `output_encoding`_ setting.
-
.. Caution:: Docutils may introduce non-ASCII text if you use
- `auto-symbol footnotes`_ or the `"contents" directive`_.
+ `auto-symbol footnotes`_.
In non-English documents, also auto-generated labels
may contain non-ASCII characters.
+auto-detection
+--------------
+
+Up to Docutils 0.21, the input encoding was detected from a `Unicode byte
+order mark` (BOM_) or an *encoding declaration* [#magic-comment]_ in the
+source unless an input_encoding_ was specified.
+
+The default input encoding changed to "utf-8" in Docutils 0.22.
+Currently, auto-detection can be selected with an input_encoding_ value
+``None`` (rsp. an empty string in a configuration file).
+However, input encoding "auto-detection_" is deprecated and **will be
+removed** in Docutils 1.0. See the `inspecting_codecs`_ package for a
+possible replacement.
+
.. [#magic-comment] A comment like ::
.. text encoding: <encoding name>
@@ -490,15 +500,12 @@
The first group of this expression is then interpreted as encoding name.
If the first line matches the second line is ignored.
- This feature is scheduled to be removed in Docutils 1.0.
- See the `inspecting_codecs`_ package for a possible replacement.
-.. _Inside A Docutils Command-Line Front-End Tool: ../howto/cmdline-tool.html
-.. _RELEASE-NOTES: ../../RELEASE-NOTES.html#future-changes
+.. _codecs: https://docs.python.org/3/library/codecs.html
+.. _standard encodings:
+ https://docs.python.org/3/library/codecs.html#standard-encodings
.. _input_encoding: ../user/config.html#input-encoding
-.. _preferred encoding:
- https://docs.python.org/3/library/locale.html#locale.getpreferredencoding
.. _BOM: https://docs.python.org/3/library/codecs.html#codecs.BOM
.. _output_encoding: ../user/config.html#output-encoding
.. _output_encoding_error_handler:
@@ -505,8 +512,6 @@
../user/config.html#output-encoding-error-handler
.. _auto-symbol footnotes:
../ref/rst/restructuredtext.html#auto-symbol-footnotes
-.. _"contents" directive:
- ../ref/rst/directives.html#table-of-contents
.. _document tree:
.. _Docutils document tree: ../ref/doctree.html
.. _Docutils Runtime Settings: ./runtime-settings.html
Modified: trunk/docutils/docs/howto/cmdline-tool.txt
===================================================================
--- trunk/docutils/docs/howto/cmdline-tool.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/howto/cmdline-tool.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -44,7 +44,7 @@
"""
This next block attempts to invoke locale support for
-internationalization services, specifically text encoding. It's not
+internationalization services. It's not
supported on all platforms though, so it's forgiving::
try:
Modified: trunk/docutils/docs/ref/rst/directives.txt
===================================================================
--- trunk/docutils/docs/ref/rst/directives.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/ref/rst/directives.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -1700,7 +1700,7 @@
``encoding`` : encoding_
The text encoding of the external raw data (with ``file`` or ``url``).
- Defaults to the main document's `input_encoding`_ (if specified).
+ Defaults to the main document's `input_encoding`_.
``file`` : path_
The local filesystem path of a raw data file to be included.
Modified: trunk/docutils/docs/ref/rst/restructuredtext.txt
===================================================================
--- trunk/docutils/docs/ref/rst/restructuredtext.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/ref/rst/restructuredtext.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -1812,7 +1812,7 @@
.. Note:: When using auto-symbol footnotes, the choice of output
encoding is important. Many of the symbols used are not encodable
- in certain common text encodings such as Latin-1 (ISO 8859-1). The
+ in 8-bit text encodings such as Latin-1 (ISO 8859-1). The
use of UTF-8 for the output encoding is recommended. An
alternative for HTML and XML output is to use the
"xmlcharrefreplace" `output encoding error handler`_.
Modified: trunk/docutils/docs/user/config.txt
===================================================================
--- trunk/docutils/docs/user/config.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docs/user/config.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -415,17 +415,17 @@
input_encoding
--------------
-The text encoding for input (use the empty string to restore the default).
+The text encoding for input.
-*Default*: None (auto-detect_). [#]_
-*Options*: ``--input-encoding``, ``-i``. [#i-o-options]_
+*Default*: utf-8. [#]_
+*Option*: ``--input-encoding`` [#i-o-options]_
-.. [#] The default will change to "utf-8" in Docutils 0.22.
-.. [#i-o-options] The short options ``-i`` and ``-o`` `will be removed`__
+.. [#] The default changed from None (auto-detect_) to "utf-8" in
+ Docutils 0.22.
+.. [#i-o-options] The short options ``-i`` and ``-o`` were removed
in Docutils 0.22.
.. _auto-detect: ../api/publisher.html#encodings
-__ ../../RELEASE-NOTES.html#command-line-interface
input_encoding_error_handler
@@ -504,7 +504,7 @@
This setting is ignored by the `ODF/ODT Writer`_ which always usues UTF-8.
-*Default*: "utf-8". *Options*: ``--output-encoding``, ``-o``. [#i-o-options]_
+*Default*: "utf-8". *Option*: ``--output-encoding``. [#i-o-options]_
output_encoding_error_handler
Modified: trunk/docutils/docutils/frontend.py
===================================================================
--- trunk/docutils/docutils/frontend.py 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/docutils/frontend.py 2024-06-10 14:24:00 UTC (rev 9749)
@@ -99,12 +99,14 @@
if value is None:
value = setting
if value == '':
- return None # allow overwriting a config file value
+ warnings.warn('Input encoding detection will be removed '
+ 'in Docutils 1.0.', DeprecationWarning, stacklevel=2)
+ return None
try:
codecs.lookup(value)
except LookupError:
- raise LookupError('setting "%s": unknown encoding: "%s"'
- % (setting, value))
+ prefix = f'setting "{setting}":' if setting else ''
+ raise LookupError(f'{prefix} unknown encoding: "{value}"')
return value
@@ -674,9 +676,9 @@
('Disable Python tracebacks. (default)',
['--no-traceback'], {'dest': 'traceback', 'action': 'store_false'}),
('Specify the encoding and optionally the '
- 'error handler of input text. Default: <auto-detect>:strict.',
- ['--input-encoding', '-i'],
- {'metavar': '<name[:handler]>',
+ 'error handler of input text. Default: utf-8.',
+ ['--input-encoding'],
+ {'metavar': '<name[:handler]>', 'default': 'utf-8',
'validator': validate_encoding_and_error_handler}),
('Specify the error handler for undecodable characters. '
'Choices: "strict" (default), "ignore", and "replace".',
@@ -683,8 +685,8 @@
['--input-encoding-error-handler'],
{'default': 'strict', 'validator': validate_encoding_error_handler}),
('Specify the text encoding and optionally the error handler for '
- 'output. Default: utf-8:strict.',
- ['--output-encoding', '-o'],
+ 'output. Default: utf-8.',
+ ['--output-encoding'],
{'metavar': '<name[:handler]>', 'default': 'utf-8',
'validator': validate_encoding_and_error_handler}),
('Specify error handler for unencodable output characters; '
Modified: trunk/docutils/test/data/help/docutils.txt
===================================================================
--- trunk/docutils/test/data/help/docutils.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/data/help/docutils.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -57,15 +57,15 @@
--warnings=<file> Send the output of system messages to <file>.
--traceback Enable Python tracebacks when Docutils is halted.
--no-traceback Disable Python tracebacks. (default)
---input-encoding=<name[:handler]>, -i <name[:handler]>
+--input-encoding=<name[:handler]>
Specify the encoding and optionally the error handler
- of input text. Default: <auto-detect>:strict.
+ of input text. Default: utf-8.
--input-encoding-error-handler=INPUT_ENCODING_ERROR_HANDLER
Specify the error handler for undecodable characters.
Choices: "strict" (default), "ignore", and "replace".
---output-encoding=<name[:handler]>, -o <name[:handler]>
+--output-encoding=<name[:handler]>
Specify the text encoding and optionally the error
- handler for output. Default: utf-8:strict.
+ handler for output. Default: utf-8.
--output-encoding-error-handler=OUTPUT_ENCODING_ERROR_HANDLER
Specify error handler for unencodable output
characters; "strict" (default), "ignore", "replace",
Modified: trunk/docutils/test/data/help/rst2html.txt
===================================================================
--- trunk/docutils/test/data/help/rst2html.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/data/help/rst2html.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -58,15 +58,15 @@
--warnings=<file> Send the output of system messages to <file>.
--traceback Enable Python tracebacks when Docutils is halted.
--no-traceback Disable Python tracebacks. (default)
---input-encoding=<name[:handler]>, -i <name[:handler]>
+--input-encoding=<name[:handler]>
Specify the encoding and optionally the error handler
- of input text. Default: <auto-detect>:strict.
+ of input text. Default: utf-8.
--input-encoding-error-handler=INPUT_ENCODING_ERROR_HANDLER
Specify the error handler for undecodable characters.
Choices: "strict" (default), "ignore", and "replace".
---output-encoding=<name[:handler]>, -o <name[:handler]>
+--output-encoding=<name[:handler]>
Specify the text encoding and optionally the error
- handler for output. Default: utf-8:strict.
+ handler for output. Default: utf-8.
--output-encoding-error-handler=OUTPUT_ENCODING_ERROR_HANDLER
Specify error handler for unencodable output
characters; "strict" (default), "ignore", "replace",
Modified: trunk/docutils/test/data/help/rst2latex.txt
===================================================================
--- trunk/docutils/test/data/help/rst2latex.txt 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/data/help/rst2latex.txt 2024-06-10 14:24:00 UTC (rev 9749)
@@ -58,15 +58,15 @@
--warnings=<file> Send the output of system messages to <file>.
--traceback Enable Python tracebacks when Docutils is halted.
--no-traceback Disable Python tracebacks. (default)
---input-encoding=<name[:handler]>, -i <name[:handler]>
+--input-encoding=<name[:handler]>
Specify the encoding and optionally the error handler
- of input text. Default: <auto-detect>:strict.
+ of input text. Default: utf-8.
--input-encoding-error-handler=INPUT_ENCODING_ERROR_HANDLER
Specify the error handler for undecodable characters.
Choices: "strict" (default), "ignore", and "replace".
---output-encoding=<name[:handler]>, -o <name[:handler]>
+--output-encoding=<name[:handler]>
Specify the text encoding and optionally the error
- handler for output. Default: utf-8:strict.
+ handler for output. Default: utf-8.
--output-encoding-error-handler=OUTPUT_ENCODING_ERROR_HANDLER
Specify error handler for unencodable output
characters; "strict" (default), "ignore", "replace",
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_include.py 2024-06-10 14:24:00 UTC (rev 9749)
@@ -549,32 +549,6 @@
Grüße
"""],
[f"""\
-Default encoding: auto-determine (here via BOM).
-
-.. include:: {utf_16_file}
-""",
-"""\
-<document source="test data">
- <paragraph>
- Default encoding: auto-determine (here via BOM).
- <paragraph>
- Grüße
-"""],
-[f"""\
-Default encoding: auto-determine (via encoding declaration).
-
-.. include:: {latin2}
-""",
-"""\
-<document source="test data">
- <paragraph>
- Default encoding: auto-determine (via encoding declaration).
- <comment xml:space="preserve">
- -*- encoding: latin2 -*-
- <paragraph>
- škoda
-"""],
-[f"""\
Include file is UTF-16-encoded, and is not valid ASCII.
.. include:: {utf_16_file}
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_raw.py 2024-06-10 14:24:00 UTC (rev 9749)
@@ -126,19 +126,6 @@
Grüße
"""],
[f"""\
-Default encoding: auto-determine (here via BOM).
-
-.. raw:: html
- :file: {utf_16_file}
-""",
-f"""\
-<document source="test data">
- <paragraph>
- Default encoding: auto-determine (here via BOM).
- <raw format="html" source="{utf_16_file}" xml:space="preserve">
- Grüße
-"""],
-[f"""\
Raw input file is UTF-16-encoded, and is not valid ASCII.
.. raw:: html
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2024-06-10 14:24:00 UTC (rev 9749)
@@ -1198,64 +1198,6 @@
\u00bfOn a \u03c3\u03c4\u03b9\u03ba?
"""],
["""\
-.. csv-table:: auto encoding
- :file: %s
- :header-rows: 1
-""" % utf_16_csv,
-"""\
-<document source="test data">
- <table>
- <title>
- auto encoding
- <tgroup cols="3">
- <colspec colwidth="33">
- <colspec colwidth="33">
- <colspec colwidth="33">
- <thead>
- <row>
- <entry>
- <paragraph>
- Treat
- <entry>
- <paragraph>
- Quantity
- <entry>
- <paragraph>
- Description
- <tbody>
- <row>
- <entry>
- <paragraph>
- Albatr\u00b0\u00df
- <entry>
- <paragraph>
- 2.99
- <entry>
- <paragraph>
- \u00a1On a \u03c3\u03c4\u03b9\u03ba!
- <row>
- <entry>
- <paragraph>
- Crunchy Frog
- <entry>
- <paragraph>
- 1.49
- <entry>
- <paragraph>
- If we took the b\u00f6nes out, it wouldn\u2019t be
- crunchy, now would it?
- <row>
- <entry>
- <paragraph>
- Gannet Ripple
- <entry>
- <paragraph>
- 1.99
- <entry>
- <paragraph>
- \u00bfOn a \u03c3\u03c4\u03b9\u03ba?
-"""],
-["""\
.. csv-table:: no CSV data
:file: %s
""" % empty_txt,
Modified: trunk/docutils/test/test_publisher.py
===================================================================
--- trunk/docutils/test/test_publisher.py 2024-06-08 08:08:37 UTC (rev 9748)
+++ trunk/docutils/test/test_publisher.py 2024-06-10 14:24:00 UTC (rev 9749)
@@ -105,22 +105,23 @@
def test_publish_string_input_encoding(self):
"""Test handling of encoded input."""
# Transparently decode `bytes` source (with "input_encoding" setting)
- # default: auto-detect, fallback utf-8
+ # default: utf-8
# Output is encoded according to "output_encoding" setting.
- settings = dict(self.settings)
+ settings = self.settings | {'input_encoding': 'utf-16',
+ 'output_encoding': 'unicode'}
source = 'test → me'
expected = ('<document source="<string>">\n'
' <paragraph>\n'
- ' test → me\n').encode('utf-8')
+ ' test → me\n')
output = core.publish_string(source.encode('utf-16'),
settings_overrides=settings)
self.assertEqual(expected, output)
- # encoding declaration in source
+ # encoding declaration in source (used if input_encoding is None)
+ # input encoding detection will be removed in Docutils 1.0
source = '.. encoding: latin1\n\nGrüße'
- # don't encode output (return `str`)
- settings['output_encoding'] = 'unicode'
- output = core.publish_string(source.encode('utf-16'),
+ settings['input_encoding'] = None
+ output = core.publish_string(source.encode('latin1'),
settings_overrides=settings)
self.assertTrue(output.endswith('Grüße\n'))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-11 08:55:34
|
Revision: 9750
http://sourceforge.net/p/docutils/code/9750
Author: milde
Date: 2024-06-11 08:55:31 +0000 (Tue, 11 Jun 2024)
Log Message:
-----------
Make MathML the default math_output_ for the "html5" writer.
Update tests, docs and TODO list and remove dead links.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docs/dev/todo.txt
trunk/docutils/docs/user/config.txt
trunk/docutils/docs/user/html.txt
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/docutils/writers/html4css1/__init__.py
trunk/docutils/test/data/help/docutils.txt
trunk/docutils/test/functional/expected/misc_rst_html5.html
trunk/docutils/test/functional/expected/standalone_rst_html5.html
trunk/docutils/test/test_writers/test_html5_polyglot_misc.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/HISTORY.txt 2024-06-11 08:55:31 UTC (rev 9750)
@@ -80,6 +80,14 @@
- `Messages` also handles "loose" system messages generated by the parser.
+* docutils/writers/_html_base.py
+
+ - Make MathML the default math_output_.
+
+* docutils/writers/html4css1/__init__.py
+
+ - Keep default math_output_ value "HTML math.css".
+
* docutils/writers/manpage.py
- Remove code for unused emdash bullets.
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-11 08:55:31 UTC (rev 9750)
@@ -81,9 +81,6 @@
__ https://www.w3.org/TR/2014/REC-html5-20141028/grouping-content.html
#the-blockquote-element
- - Change the default value for math_output_ to "MathML"
- in Docutils 0.22.
-
- Unitless image_ :width: and :hight: values and dimensions
read from the image due to a :scale: option will be written as
"width" and "hight" attributes instead of "style" rules to allow
@@ -199,21 +196,21 @@
* Document Tree / Docutils DTD
- - Allow multiple <term> elements in a <definition_list_item__>.
- (Third-party writers may need adaption.)
+ - Allow multiple <term> elements in a `\<definition_list_item>`__
+ (third-party writers may need adaption).
- - New method `Element.validate()`: Raise `nodes.ValidationError` if the
- element does not comply with the `Docutils Document Model`_.
- Provisional.
-
__ docs/ref/doctree.html#definition-list-item
-* Drop short options ``-i`` and ``-o``.
- Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
- (See `command line interface`_ for the rationale.)
+* Configuration changes:
-* Change the default input encoding from ``None`` (auto-detect) to "utf-8".
+ - Make MathML the default math_output_ for the "html5" writer.
+ - Change the default input encoding from ``None`` (auto-detect) to "utf-8".
+
+ - Drop short options ``-i`` and ``-o``.
+ Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
+ (See `command line interface`_ for the rationale.)
+
* New parser for `Docutils XML`_ (e.g., the output of the "xml" writer).
Provisional.
@@ -221,6 +218,10 @@
or use the :parser: option of the `"include" directive`_ to include
an XML file in a rST document.
+* New method `Element.validate()`: Raise `nodes.ValidationError` if the
+ element does not comply with the `Docutils Document Model`_.
+ Provisional.
+
* Bugfixes and improvements (see HISTORY_).
.. _Docutils Document Model:
@@ -243,17 +244,10 @@
Release 0.21.1 (2024-04-10)
===========================
-The sdist in 0.21 was incomplete
+Add missing metadata files to sdist.
+No changes to the code.
-- pypi allows no file replacing
-- adding a postrelease suffix "post1": docutils-0.21.post1.tar.gz
- works on pypi, but fails with pip because the metadata differs.
- But if the metadata is 0.21.post1 pypi makes it a new release.
-
- 0.21.1 is the same code except for the version number.
-
-
Release 0.21 (2024-04-09)
=========================
Modified: trunk/docutils/docs/dev/todo.txt
===================================================================
--- trunk/docutils/docs/dev/todo.txt 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/docs/dev/todo.txt 2024-06-11 08:55:31 UTC (rev 9750)
@@ -1498,80 +1498,39 @@
HTML output
```````````
-There is no native math support in HTML.
+There is no native math support in HTML4. HTML5 has built-in support for
+MathML. MathML is supported by all major browsers since 2023.
+
For supported math output variants see the `math-output setting`_.
-Add more/better alternatives?
MathML_
- Converters from LaTeX to MathML include
+ Additional converters from LaTeX to MathML
- * TtM_ (C), ``--math-output=MathML ttm``, undocumented, may be removed.
-
- No "matrix", "align" and "cases" environments.
-
- * MathToWeb_ (Java)
* TeX4ht_ (TeX based)
- * itex_ (also `used in Abiword`__)
- * `Steve’s LATEX-to-MathML translator`_
- ('mini-language', javascript, Python)
* `MathJax for Node`_
- * Write a new converter? E.g. based on:
-
- * a generic tokenizer (see e.g. a `latex-codec recipe`_,
- `updated latex-codec`_, )
- * the Unicode-Char <-> LaTeX mappings database unimathsymbols_
-
- __ http://msevior.livejournal.com/26377.html
.. _MathML: https://www.w3.org/TR/MathML2/
- .. _ttm: http://hutchinson.belmont.ma.us/tth/mml/
.. _TeX4ht: http://www.tug.org/applications/tex4ht/mn.html
- .. _MathToWeb: http://www.mathtoweb.com/
- .. _itex: http://golem.ph.utexas.edu/~distler/blog/itex2MMLcommands.html
- .. _Steve’s LATEX-to-MathML translator:
- http://www.gold-saucer.org/mathml/greasemonkey/dist/display-latex
- .. _latex-codec recipe:
- http://code.activestate.com/recipes/252124-latex-codec/
- .. _updated latex-codec:
- http://mirror.ctan.org/biblio/bibtex/utils/mab2bib/latex.py
- .. _unimathsymbols: http://milde.users.sourceforge.net/LUCR/Math/
.. _MathJax for Node: https://github.com/mathjax/MathJax-node
-.. URL seems down:
- .. _itex: http://pear.math.pitt.edu/mathzilla/itex2mmlItex.html
-
HTML/CSS
format math in standard HTML enhanced by CSS rules
- (Overview__, `Examples and experiments`__).
+ (`Examples and experiments`__).
The ``math-output=html`` option uses the converter from eLyXer_
(included with Docutils).
Alternatives: LaTeX-math to HTML/CSS converters include
- * TtH_ (C)
* Hevea_ (Objective Caml)
* `MathJax for Node`_
* KaTeX_
- __ http://www.cs.tut.fi/~jkorpela/math/
__ http://www.zipcon.net/~swhite/docs/math/math.html
.. _elyxer: http://elyxer.nongnu.org/
- .. _TtH: ttp://hutchinson.belmont.ma.us/tth/index.html
.. _Hevea: http://para.inria.fr/~maranget/hevea/
.. _KaTeX: https://katex.org
-images
- (PNG or SVG) like e.g. Wikipedia.
-
- * dvisvgm_
- * the pure-python MathML->SVG converter SVGMath_)
- * `MathJax for Node`_
-
- .. _dvisvgm: http://dvisvgm.sourceforge.net/
- .. _SVGMath: http://www.grigoriev.ru/svgmath/
-
-
client side JavaScript conversion
Use TeX notation in the web page and JavaScript in the displaying browser.
(implemented as `math-output setting`_ "mathjax").
Modified: trunk/docutils/docs/user/config.txt
===================================================================
--- trunk/docutils/docs/user/config.txt 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/docs/user/config.txt 2024-06-11 08:55:31 UTC (rev 9750)
@@ -1264,8 +1264,7 @@
The failsafe fallback.
-:Default: "HTML math.css". The default for the HTML5 writer will change
- to "MathML" in Docutils 0.22.
+:Default: writer dependent (see `[html4css1 writer]`_, `[html5 writer]`_).
:Option: ``--math-output``.
.. _MathJax: http://www.mathjax.org/
@@ -1406,6 +1405,7 @@
.. class:: run-in narrow
:`initial_header_level`_: 1 (for "<h1>").
+:`math_output`_: "HTML math.css".
:`stylesheet_path <stylesheet_path [html writers]_>`__: "html4css1.css".
:`xml_declaration <xml_declaration [html writers]_>`__: True.
@@ -1449,6 +1449,7 @@
.. class:: run-in narrow
:initial_header_level_: 2 (reserve <h1> for the `document title`_). [#]_
+:`math_output`_: "MathML" (changed in Docutils 0.22).
:`stylesheet_path <stylesheet_path [html writers]_>`__:
"minimal.css, plain.css".
:`xml_declaration <xml_declaration [html writers]_>`__: False.
Modified: trunk/docutils/docs/user/html.txt
===================================================================
--- trunk/docutils/docs/user/html.txt 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/docs/user/html.txt 2024-06-11 08:55:31 UTC (rev 9750)
@@ -98,7 +98,7 @@
:front-end: rst2html5_
:config: `[html5 writer]`_
-The ``html5_polyglot`` writer generates `polyglot HTML`_ [#]_ output, valid
+The ``html5`` writer generates `polyglot HTML`_ output, valid
XML [#safetext]_ that is compatible with `HTML5`_. New features and elements
are used if they are widely supported.
See the `HTML5 test page`_ (and the sources `html5-features.txt`_ and
@@ -114,7 +114,6 @@
New in Docutils 0.13
-.. [#] see also `Benefits of polyglot XHTML5`_
.. [#safetext] The validity of raw HTML and custom stylesheets must be
ensured by the author.
.. _HTML5 test page: https://docutils.sourceforge.io/test/functional/
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/docutils/writers/_html_base.py 2024-06-11 08:55:31 UTC (rev 9750)
@@ -115,10 +115,9 @@
['--table-style'],
{'default': ''}),
('Math output format (one of "MathML", "HTML", "MathJax", '
- 'or "LaTeX") and option(s). '
- '(default: "HTML math.css")',
+ 'or "LaTeX") and option(s). (default: "MathML")',
['--math-output'],
- {'default': 'HTML math.css',
+ {'default': 'MathML',
'validator': frontend.validate_math_output}),
('Prepend an XML declaration. ',
['--xml-declaration'],
@@ -238,7 +237,6 @@
"""
doctype = '<!DOCTYPE html>\n'
- doctype_mathml = doctype
head_prefix_template = ('<html xmlns="http://www.w3.org/1999/xhtml"'
' xml:lang="%(lang)s" lang="%(lang)s">\n<head>\n')
@@ -1363,7 +1361,6 @@
math_code = self.encode(math_code)
elif format == 'mathml':
if 'XHTML 1' in self.doctype:
- self.doctype = self.doctype_mathml
self.content_type = self.content_type_mathml
if self.math_options:
converter = getattr(tex2mathml_extern, self.math_options)
Modified: trunk/docutils/docutils/writers/html4css1/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html4css1/__init__.py 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/docutils/writers/html4css1/__init__.py 2024-06-11 08:55:31 UTC (rev 9750)
@@ -68,6 +68,12 @@
['--initial-header-level'],
{'choices': '1 2 3 4 5 6'.split(), 'default': '1',
'metavar': '<level>'}),
+ math_output=(
+ 'Math output format (one of "MathML", "HTML", "MathJax", or '
+ '"LaTeX") and option(s). (default: "HTML math.css")',
+ ['--math-output'],
+ {'default': 'HTML math.css',
+ 'validator': frontend.validate_math_output}),
xml_declaration=(
'Prepend an XML declaration (default). ',
['--xml-declaration'],
Modified: trunk/docutils/test/data/help/docutils.txt
===================================================================
--- trunk/docutils/test/data/help/docutils.txt 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/test/data/help/docutils.txt 2024-06-11 08:55:31 UTC (rev 9750)
@@ -194,8 +194,8 @@
right, colwidths-auto, colwidths-grid.
--math-output=MATH_OUTPUT
Math output format (one of "MathML", "HTML",
- "MathJax", or "LaTeX") and option(s). (default: "HTML
- math.css")
+ "MathJax", or "LaTeX") and option(s). (default:
+ "MathML")
--xml-declaration Prepend an XML declaration.
--no-xml-declaration Omit the XML declaration (default).
--cloak-email-addresses
Modified: trunk/docutils/test/functional/expected/misc_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/misc_rst_html5.html 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/test/functional/expected/misc_rst_html5.html 2024-06-11 08:55:31 UTC (rev 9750)
@@ -7,7 +7,6 @@
<title>Additional tests with HTML 5</title>
<link rel="stylesheet" href="../input/data/minimal.css" type="text/css" />
<link rel="stylesheet" href="../input/data/responsive.css" type="text/css" />
-<link rel="stylesheet" href="../input/data/math.css" type="text/css" />
</head>
<body class="with-toc">
<main id="additional-tests-with-html-5">
@@ -48,7 +47,12 @@
</li>
<li><p><a class="reference internal" href="#section-titles-with-inline-markup" id="toc-entry-10">Section titles with inline markup</a></p>
<ul>
-<li><p><a class="reference internal" href="#emphasized-h2o-x-2-and-references" id="toc-entry-11"><em>emphasized</em>, H<sub>2</sub>O, <span class="formula"><i>x</i><sup>2</sup></span>, and references</a></p></li>
+<li><p><a class="reference internal" href="#emphasized-h2o-x-2-and-references" id="toc-entry-11"><em>emphasized</em>, H<sub>2</sub>O, <math xmlns="http://www.w3.org/1998/Math/MathML">
+ <msup>
+ <mi>x</mi>
+ <mn>2</mn>
+ </msup>
+</math>, and references</a></p></li>
<li><p><a class="reference internal" href="#substitutions-fail" id="toc-entry-12">Substitutions work</a></p></li>
</ul>
</li>
@@ -95,7 +99,12 @@
<section id="section-titles-with-inline-markup">
<span id="references"></span><h2><a class="toc-backref" href="#contents" role="doc-backlink">Section titles with inline markup</a><a class="self-link" title="link to this section" href="#section-titles-with-inline-markup"></a></h2>
<section id="emphasized-h2o-x-2-and-references">
-<h3><em>emphasized</em>, H<sub>2</sub>O, <span class="formula"><i>x</i><sup>2</sup></span>, and <a class="reference internal" href="#references">references</a><a class="self-link" title="link to this section" href="#emphasized-h2o-x-2-and-references"></a></h3>
+<h3><em>emphasized</em>, H<sub>2</sub>O, <math xmlns="http://www.w3.org/1998/Math/MathML">
+ <msup>
+ <mi>x</mi>
+ <mn>2</mn>
+ </msup>
+</math>, and <a class="reference internal" href="#references">references</a><a class="self-link" title="link to this section" href="#emphasized-h2o-x-2-and-references"></a></h3>
</section>
<section id="substitutions-fail">
<h3><a class="toc-backref" href="#contents" role="doc-backlink">Substitutions work</a><a class="self-link" title="link to this section" href="#substitutions-fail"></a></h3>
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2024-06-11 08:55:31 UTC (rev 9750)
@@ -16,7 +16,6 @@
<link rel="schema.dcterms" href="http://purl.org/dc/terms/"/>
<link rel="stylesheet" href="../input/data/minimal.css" type="text/css" />
<link rel="stylesheet" href="../input/data/plain.css" type="text/css" />
-<link rel="stylesheet" href="../input/data/math.css" type="text/css" />
</head>
<body class="with-toc">
<header>
@@ -1012,7 +1011,16 @@
Inline markup is supported, e.g. <em>emphasis</em>, <strong>strong</strong>, <span class="docutils literal">literal
text</span>, <sub>sub-</sub> and <sup>super</sup>scripts,
-inline formulas: <span class="formula"><i>A</i> = 2<i>π</i><i>r</i><sup>2</sup></span>,
+inline formulas: <math xmlns="http://www.w3.org/1998/Math/MathML">
+ <mi>A</mi>
+ <mo>=</mo>
+ <mn>2</mn>
+ <mi>π</mi>
+ <msup>
+ <mi>r</mi>
+ <mn>2</mn>
+ </msup>
+</math>,
footnotes <a class="brackets" href="#footnote-1" id="footnote-reference-9" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a>, <span class="target" id="hyperlink-targets">hyperlink targets</span>, and <a class="reference external" href="http://www.python.org/">references</a>.</pre>
</section>
<section id="code">
@@ -1034,7 +1042,14 @@
or as base for special code roles, e.g. the LaTeX code in the next
paragraph.</p>
<p>Docutils uses LaTeX syntax for math directives and roles:
-<code class="tex">\alpha = f(x)</code> prints <span class="formula"><i>α</i> = <i>f</i>(<i>x</i>)</span>.</p>
+<code class="tex">\alpha = f(x)</code> prints <math xmlns="http://www.w3.org/1998/Math/MathML">
+ <mi>α</mi>
+ <mo>=</mo>
+ <mi>f</mi>
+ <mo stretchy="false">(</mo>
+ <mi>x</mi>
+ <mo stretchy="false">)</mo>
+</math>.</p>
<p>The <span class="docutils literal">:code:</span> option of the <cite>include</cite> directive sets the included content
as a code block, here the rst file <span class="docutils literal">header_footer.txt</span> with line numbers:</p>
<pre class="code rst literal-block"><small class="ln">1 </small><code data-lineno="1 ">.. header:: Document header
Modified: trunk/docutils/test/test_writers/test_html5_polyglot_misc.py
===================================================================
--- trunk/docutils/test/test_writers/test_html5_polyglot_misc.py 2024-06-10 14:24:00 UTC (rev 9749)
+++ trunk/docutils/test/test_writers/test_html5_polyglot_misc.py 2024-06-11 08:55:31 UTC (rev 9750)
@@ -184,11 +184,11 @@
data = ':math:`42`'
def test_math_output_default(self):
- # HTML with math.css stylesheet (since 0.11)
+ # default math output is MathML (since 0.22)
mys = {'_disable_config': True}
- styles = core.publish_parts(self.data, writer_name='html5_polyglot',
- settings_overrides=mys)['stylesheet']
- self.assertIn('convert LaTeX equations to HTML output.', styles)
+ fragment = core.publish_parts(self.data, writer_name='html5_polyglot',
+ settings_overrides=mys)['fragment']
+ self.assertIn('<mn>42</mn>', fragment)
def test_math_output_mathjax(self):
# Explicitly specifying math_output=MathJax, case insensitively
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 11:04:56
|
Revision: 9753
http://sourceforge.net/p/docutils/code/9753
Author: milde
Date: 2024-06-14 11:04:53 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
xml-parser: Handle case that the input has no XML element.
If there is no XML element in the input, the XMLPullParser does
not yield "events".
To handle this, ``element2node(None)`` now returns a
`paragraph` with a `problematic` node reporting the problem.
Modified Paths:
--------------
trunk/docutils/docutils/parsers/docutils_xml.py
trunk/docutils/test/test_parsers/test_docutils_xml/test_parse.py
trunk/docutils/test/test_parsers/test_docutils_xml/test_parse_element.py
Modified: trunk/docutils/docutils/parsers/docutils_xml.py
===================================================================
--- trunk/docutils/docutils/parsers/docutils_xml.py 2024-06-12 15:11:09 UTC (rev 9752)
+++ trunk/docutils/docutils/parsers/docutils_xml.py 2024-06-14 11:04:53 UTC (rev 9753)
@@ -116,7 +116,9 @@
document = utils.new_document('xml input',
frontend.get_default_settings(Parser))
document.source == 'xml input'
-
+ if element is None:
+ problem = nodes.problematic('', 'No XML element found.')
+ return nodes.paragraph('', '', problem)
# Get the corresponding `nodes.Element` instance:
try:
nodeclass = getattr(nodes, element.tag)
Modified: trunk/docutils/test/test_parsers/test_docutils_xml/test_parse.py
===================================================================
--- trunk/docutils/test/test_parsers/test_docutils_xml/test_parse.py 2024-06-12 15:11:09 UTC (rev 9752)
+++ trunk/docutils/test/test_parsers/test_docutils_xml/test_parse.py 2024-06-14 11:04:53 UTC (rev 9753)
@@ -204,6 +204,15 @@
A paragraph.
spurious tailing text
"""],
+["""\
+just spurious text
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ <problematic>
+ No XML element found.
+"""],
]
Modified: trunk/docutils/test/test_parsers/test_docutils_xml/test_parse_element.py
===================================================================
--- trunk/docutils/test/test_parsers/test_docutils_xml/test_parse_element.py 2024-06-12 15:11:09 UTC (rev 9752)
+++ trunk/docutils/test/test_parsers/test_docutils_xml/test_parse_element.py 2024-06-14 11:04:53 UTC (rev 9753)
@@ -50,6 +50,11 @@
node = docutils_xml.parse_element(xml, self.document)
self.assertEqual('<strong>text</strong>', str(node))
+ def test_nothing_but_junk_text(self):
+ xml = 'just text'
+ node = docutils_xml.parse_element(xml, self.document)
+ self.assertEqual(node.astext(), 'No XML element found.')
+
def test_nonexistent_element_type(self):
xml = '<tip><p>some text</p></tip>'
node = docutils_xml.parse_element(xml, self.document)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 11:05:08
|
Revision: 9754
http://sourceforge.net/p/docutils/code/9754
Author: milde
Date: 2024-06-14 11:05:04 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
More precise error message for ODT writer with wrong encoding.
The ODT writer returns a document in binary format.
Therefore, it cannot be used with `output_encoding` set to
the special value "unicode".
Modified Paths:
--------------
trunk/docutils/docutils/writers/odf_odt/__init__.py
trunk/docutils/test/test_publisher.py
Modified: trunk/docutils/docutils/writers/odf_odt/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/odf_odt/__init__.py 2024-06-14 11:04:53 UTC (rev 9753)
+++ trunk/docutils/docutils/writers/odf_odt/__init__.py 2024-06-14 11:05:04 UTC (rev 9754)
@@ -837,6 +837,10 @@
# nodes.SparseNodeVisitor.__init__(self, document)
nodes.GenericNodeVisitor.__init__(self, document)
self.settings = document.settings
+ if self.settings.output_encoding == 'unicode':
+ self.document.reporter.severe('The ODT writer returns `bytes` '
+ 'that cannot be decoded to `str`')
+ # TODO: return document as "flat" XML?
self.language_code = self.settings.language_code
self.language = languages.get_language(
self.language_code,
Modified: trunk/docutils/test/test_publisher.py
===================================================================
--- trunk/docutils/test/test_publisher.py 2024-06-14 11:04:53 UTC (rev 9753)
+++ trunk/docutils/test/test_publisher.py 2024-06-14 11:05:04 UTC (rev 9754)
@@ -143,12 +143,12 @@
TODO: return `str` with document as "flat XML" (.fodt).
"""
- settings = dict(self.settings)
- settings['output_encoding'] = 'unicode'
- with self.assertRaises(AssertionError) as cm:
+ settings = self.settings | {'output_encoding': 'unicode',
+ 'warning_stream': ''}
+ with self.assertRaisesRegex(docutils.utils.SystemMessage,
+ 'The ODT writer returns `bytes` '):
core.publish_string('test', writer_name='odt',
settings_overrides=settings)
- self.assertIn('`data` is no `str` instance', str(cm.exception))
class PublishDoctreeTestCase(unittest.TestCase, docutils.SettingsSpec):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 15:03:25
|
Revision: 9756
http://sourceforge.net/p/docutils/code/9756
Author: milde
Date: 2024-06-14 15:03:22 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove `nodes.Element.set_class()`.
Obsolete. Append to Element['classes'] directly.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/nodes.py
trunk/docutils/test/test_nodes.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 15:03:12 UTC (rev 9755)
+++ trunk/docutils/HISTORY.txt 2024-06-14 15:03:22 UTC (rev 9756)
@@ -47,6 +47,7 @@
convert string representations to correct data type,
normalize values,
raise ValueError for invalid attribute names or values.
+ - Removed `Element.set_class()`.
* docutils/parsers/docutils_xml.py
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:12 UTC (rev 9755)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:22 UTC (rev 9756)
@@ -222,6 +222,11 @@
element does not comply with the `Docutils Document Model`_.
Provisional.
+* Removed objects:
+
+ `docutils.nodes.Element.set_class()`
+ Obsolete. Append to Element['classes'] directly.
+
* Bugfixes and improvements (see HISTORY_).
.. _Docutils Document Model:
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2024-06-14 15:03:12 UTC (rev 9755)
+++ trunk/docutils/docutils/nodes.py 2024-06-14 15:03:22 UTC (rev 9756)
@@ -1076,15 +1076,6 @@
copy.extend([child.deepcopy() for child in self.children])
return copy
- def set_class(self, name):
- """Add a new class to the "classes" attribute."""
- warnings.warn('docutils.nodes.Element.set_class() is deprecated; '
- ' and will be removed in Docutils 0.21 or later.'
- "Append to Element['classes'] list attribute directly",
- DeprecationWarning, stacklevel=2)
- assert ' ' not in name
- self['classes'].append(name.lower())
-
def note_referenced_by(self, name=None, id=None):
"""Note that this Element has been referenced by its name
`name` or id `id`."""
@@ -1460,8 +1451,8 @@
class decoration(PreBibliographic, SubStructural, Element):
"""Container for `header` and `footer`."""
content_model = ( # (header?, footer?)
- (header, '?'),
- (footer, '?')) # TODO: empty element does not make sense.
+ (header, '?'), # Empty element does not make sense,
+ (footer, '?')) # but is simpler to define.
def get_header(self):
if not len(self.children) or not isinstance(self.children[0], header):
Modified: trunk/docutils/test/test_nodes.py
===================================================================
--- trunk/docutils/test/test_nodes.py 2024-06-14 15:03:12 UTC (rev 9755)
+++ trunk/docutils/test/test_nodes.py 2024-06-14 15:03:22 UTC (rev 9756)
@@ -464,12 +464,7 @@
self.assertEqual(child4['ids'], ['child4'])
self.assertEqual(len(parent), 5)
- def test_set_class_deprecation_warning(self):
- node = nodes.Element('test node')
- with self.assertWarns(DeprecationWarning):
- node.set_class('parrot')
-
class ElementValidationTests(unittest.TestCase):
def test_validate(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 15:03:35
|
Revision: 9757
http://sourceforge.net/p/docutils/code/9757
Author: milde
Date: 2024-06-14 15:03:32 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove tools/rst2odt_prepstyles.py
Obsoleted by `docutils.writers.odf_odt.prepstyles`.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
Removed Paths:
-------------
trunk/docutils/tools/rst2odt_prepstyles.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 15:03:22 UTC (rev 9756)
+++ trunk/docutils/HISTORY.txt 2024-06-14 15:03:32 UTC (rev 9757)
@@ -101,7 +101,11 @@
- Do not increase indentation of follow-up lines inside inline elements.
when formatting with `indents`_.
+* tools/rst2odt_prepstyles.py
+ - Removed. Use `docutils.writers.odf_odt.prepstyles`.
+
+
Release 0.21.2 (2024-04-23)
===========================
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:22 UTC (rev 9756)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:32 UTC (rev 9757)
@@ -227,6 +227,11 @@
`docutils.nodes.Element.set_class()`
Obsolete. Append to Element['classes'] directly.
+* Removed files:
+
+ ``tools/rst2odt_prepstyles.py``
+ Obsoleted by `docutils.writers.odf_odt.prepstyles`.
+
* Bugfixes and improvements (see HISTORY_).
.. _Docutils Document Model:
Deleted: trunk/docutils/tools/rst2odt_prepstyles.py
===================================================================
--- trunk/docutils/tools/rst2odt_prepstyles.py 2024-06-14 15:03:22 UTC (rev 9756)
+++ trunk/docutils/tools/rst2odt_prepstyles.py 2024-06-14 15:03:32 UTC (rev 9757)
@@ -1,20 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright: This module has been placed in the public domain.
-
-"""
-Adapt a word-processor-generated styles.odt for odtwriter use:
-
-Drop page size specifications from styles.xml in STYLE_FILE.odt.
-See https://docutils.sourceforge.io/docs/user/odt.html#page-size
-
-Provisional backwards compatibility stub (to be removed in Docutils >= 0.21).
-
-The actual code moved to the "docutils" library package and can be started
-with ``python -m docutils.writers.odf_odt.prepstyles``.
-"""
-
-from docutils.writers.odf_odt import prepstyles
-
-if __name__ == '__main__':
- prepstyles.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 15:03:45
|
Revision: 9758
http://sourceforge.net/p/docutils/code/9758
Author: milde
Date: 2024-06-14 15:03:42 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove `docutils.utils.error_reporting`.
Obsolete in Python 3
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
Removed Paths:
-------------
trunk/docutils/docutils/utils/error_reporting.py
trunk/docutils/test/test_error_reporting.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 15:03:32 UTC (rev 9757)
+++ trunk/docutils/HISTORY.txt 2024-06-14 15:03:42 UTC (rev 9758)
@@ -81,6 +81,10 @@
- `Messages` also handles "loose" system messages generated by the parser.
+* docutils/utils/error_reporting.py
+
+ - Removed. Obsolete in Python 3.
+
* docutils/writers/_html_base.py
- Make MathML the default math_output_.
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:32 UTC (rev 9757)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:42 UTC (rev 9758)
@@ -226,6 +226,8 @@
`docutils.nodes.Element.set_class()`
Obsolete. Append to Element['classes'] directly.
+ `docutils.utils.error_reporting`
+ Obsolete in Python 3
* Removed files:
Deleted: trunk/docutils/docutils/utils/error_reporting.py
===================================================================
--- trunk/docutils/docutils/utils/error_reporting.py 2024-06-14 15:03:32 UTC (rev 9757)
+++ trunk/docutils/docutils/utils/error_reporting.py 2024-06-14 15:03:42 UTC (rev 9758)
@@ -1,222 +0,0 @@
-#!/usr/bin/env python3
-# :Id: $Id$
-# :Copyright: © 2011 Günter Milde.
-# :License: Released under the terms of the `2-Clause BSD license`_, in short:
-#
-# Copying and distribution of this file, with or without modification,
-# are permitted in any medium without royalty provided the copyright
-# notice and this notice are preserved.
-# This file is offered as-is, without any warranty.
-#
-# .. _2-Clause BSD license: https://opensource.org/licenses/BSD-2-Clause
-
-"""
-Deprecated module to handle Exceptions across Python versions.
-
-.. warning::
- This module is deprecated with the end of support for Python 2.7
- and will be removed in Docutils 0.21 or later.
-
- Replacements:
- | SafeString -> str
- | ErrorString -> docutils.io.error_string()
- | ErrorOutput -> docutils.io.ErrorOutput
-
-Error reporting should be safe from encoding/decoding errors.
-However, implicit conversions of strings and exceptions like
-
->>> u'%s world: %s' % ('H\xe4llo', Exception(u'H\xe4llo'))
-
-fail in some Python versions:
-
-* In Python <= 2.6, ``unicode(<exception instance>)`` uses
- `__str__` and fails with non-ASCII chars in`unicode` arguments.
- (work around http://bugs.python.org/issue2517):
-
-* In Python 2, unicode(<exception instance>) fails, with non-ASCII
- chars in arguments. (Use case: in some locales, the errstr
- argument of IOError contains non-ASCII chars.)
-
-* In Python 2, str(<exception instance>) fails, with non-ASCII chars
- in `unicode` arguments.
-
-The `SafeString`, `ErrorString` and `ErrorOutput` classes handle
-common exceptions.
-"""
-
-import sys
-import warnings
-
-from docutils.io import _locale_encoding as locale_encoding # noqa
-
-warnings.warn('The `docutils.utils.error_reporting` module is deprecated '
- 'and will be removed in Docutils 0.21 or later.\n'
- 'Details with help("docutils.utils.error_reporting").',
- DeprecationWarning, stacklevel=2)
-
-
-if sys.version_info >= (3, 0):
- unicode = str # noqa
-
-
-class SafeString:
- """
- A wrapper providing robust conversion to `str` and `unicode`.
- """
-
- def __init__(self, data, encoding=None, encoding_errors='backslashreplace',
- decoding_errors='replace'):
- self.data = data
- self.encoding = (encoding or getattr(data, 'encoding', None)
- or locale_encoding or 'ascii')
- self.encoding_errors = encoding_errors
- self.decoding_errors = decoding_errors
-
- def __str__(self):
- try:
- return str(self.data)
- except UnicodeEncodeError:
- if isinstance(self.data, Exception):
- args = [str(SafeString(arg, self.encoding,
- self.encoding_errors))
- for arg in self.data.args]
- return ', '.join(args)
- if isinstance(self.data, unicode):
- if sys.version_info > (3, 0):
- return self.data
- else:
- return self.data.encode(self.encoding,
- self.encoding_errors)
- raise
-
- def __unicode__(self):
- """
- Return unicode representation of `self.data`.
-
- Try ``unicode(self.data)``, catch `UnicodeError` and
-
- * if `self.data` is an Exception instance, work around
- http://bugs.python.org/issue2517 with an emulation of
- Exception.__unicode__,
-
- * else decode with `self.encoding` and `self.decoding_errors`.
- """
- try:
- u = unicode(self.data)
- if isinstance(self.data, EnvironmentError):
- u = u.replace(": u'", ": '") # normalize filename quoting
- return u
- except UnicodeError as error: # catch ..Encode.. and ..Decode.. errors
- if isinstance(self.data, EnvironmentError):
- return "[Errno %s] %s: '%s'" % (
- self.data.errno,
- SafeString(self.data.strerror, self.encoding,
- self.decoding_errors),
- SafeString(self.data.filename, self.encoding,
- self.decoding_errors))
- if isinstance(self.data, Exception):
- args = [unicode(SafeString(
- arg, self.encoding,
- decoding_errors=self.decoding_errors))
- for arg in self.data.args]
- return u', '.join(args)
- if isinstance(error, UnicodeDecodeError):
- return unicode(self.data, self.encoding, self.decoding_errors)
- raise
-
-
-class ErrorString(SafeString):
- """
- Safely report exception type and message.
- """
- def __str__(self):
- return '%s: %s' % (self.data.__class__.__name__,
- super(ErrorString, self).__str__())
-
- def __unicode__(self):
- return u'%s: %s' % (self.data.__class__.__name__,
- super(ErrorString, self).__unicode__())
-
-
-class ErrorOutput:
- """
- Wrapper class for file-like error streams with
- failsafe de- and encoding of `str`, `bytes`, `unicode` and
- `Exception` instances.
- """
-
- def __init__(self, stream=None, encoding=None,
- encoding_errors='backslashreplace',
- decoding_errors='replace'):
- """
- :Parameters:
- - `stream`: a file-like object,
- a string (path to a file),
- `None` (write to `sys.stderr`, default), or
- evaluating to `False` (write() requests are ignored).
- - `encoding`: `stream` text encoding. Guessed if None.
- - `encoding_errors`: how to treat encoding errors.
- """
- if stream is None:
- stream = sys.stderr
- elif not stream:
- stream = False
- # if `stream` is a file name, open it
- elif isinstance(stream, str):
- stream = open(stream, 'w')
- elif isinstance(stream, unicode):
- stream = open(stream.encode(sys.getfilesystemencoding()), 'w')
-
- self.stream = stream
- """Where warning output is sent."""
-
- self.encoding = (encoding or getattr(stream, 'encoding', None)
- or locale_encoding or 'ascii')
- """The output character encoding."""
-
- self.encoding_errors = encoding_errors
- """Encoding error handler."""
-
- self.decoding_errors = decoding_errors
- """Decoding error handler."""
-
- def write(self, data):
- """
- Write `data` to self.stream. Ignore, if self.stream is False.
-
- `data` can be a `string`, `unicode`, or `Exception` instance.
- """
- if self.stream is False:
- return
- if isinstance(data, Exception):
- data = unicode(SafeString(data, self.encoding,
- self.encoding_errors,
- self.decoding_errors))
- try:
- self.stream.write(data)
- except UnicodeEncodeError:
- self.stream.write(data.encode(self.encoding, self.encoding_errors))
- except TypeError:
- if isinstance(data, unicode): # passed stream may expect bytes
- self.stream.write(data.encode(self.encoding,
- self.encoding_errors))
- return
- if self.stream in (sys.stderr, sys.stdout):
- self.stream.buffer.write(data) # write bytes to raw stream
- else:
- self.stream.write(unicode(data, self.encoding,
- self.decoding_errors))
-
- def close(self):
- """
- Close the error-output stream.
-
- Ignored if the stream is` sys.stderr` or `sys.stdout` or has no
- close() method.
- """
- if self.stream in (sys.stdout, sys.stderr):
- return
- try:
- self.stream.close()
- except AttributeError:
- pass
Deleted: trunk/docutils/test/test_error_reporting.py
===================================================================
--- trunk/docutils/test/test_error_reporting.py 2024-06-14 15:03:32 UTC (rev 9757)
+++ trunk/docutils/test/test_error_reporting.py 2024-06-14 15:03:42 UTC (rev 9758)
@@ -1,264 +0,0 @@
-#! /usr/bin/env python3
-# $Id$
-# Author: Günter Milde <mi...@us...>
-# Copyright: This module has been placed in the public domain.
-
-"""
-Test `EnvironmentError` reporting.
-
-In some locales, the `errstr` argument of IOError and OSError contains
-non-ASCII chars.
-
-In Python 2, converting an exception instance to `str` or `unicode`
-might fail, with non-ASCII chars in arguments and the default encoding
-and errors ('ascii', 'strict').
-
-Therefore, Docutils must not use string interpolation with exception
-instances like, e.g., ::
-
- try:
- something
- except IOError as error:
- print('Found %s' % error)
-
-unless the minimal required Python version has this problem fixed.
-"""
-
-from io import StringIO, BytesIO
-from pathlib import Path
-import sys
-import unittest
-import warnings
-
-if __name__ == '__main__':
- # prepend the "docutils root" to the Python library path
- # so we import the local `docutils` package.
- sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
-
-from docutils import frontend, utils
-import docutils.parsers.rst
-warnings.filterwarnings('ignore', category=DeprecationWarning,
- module='.*error_reporting')
-from docutils.utils.error_reporting import SafeString, ErrorString, ErrorOutput # noqa: E402, E501
-
-
-class SafeStringTests(unittest.TestCase):
-
- # test data:
- bs = b'\xc3\xbc' # str(bs) returns repr(bs)
- us = u'\xfc' # bytes(us) fails (requires encoding argument)
- be = Exception(bs)
- ue = Exception(us) # bytes(ue) fails
- # wrapped test data:
- wbs = SafeString(bs)
- wus = SafeString(us)
- wbe = SafeString(be)
- wue = SafeString(ue)
-
- def test_7bit(self):
- # wrapping (not required with 7-bit chars) must not change the
- # result of conversions:
- bs7 = b'foo'
- us7 = u'foo'
- be7 = Exception(bs7)
- ue7 = Exception(us7)
- self.assertEqual(str(bs7), str(SafeString(bs7)))
- self.assertEqual(str(us7), str(SafeString(us7)))
- self.assertEqual(str(be7), str(SafeString(be7)))
- self.assertEqual(str(ue7), str(SafeString(ue7)))
-
- def test_ustr(self):
- """Test conversion to a unicode-string."""
- # unicode(self.bs) fails
- self.assertEqual(str, type(str(self.wbs)))
- self.assertEqual(str(self.us), str(self.wus))
- # unicode(self.be) fails
- self.assertEqual(str, type(str(self.wbe)))
- self.assertEqual(str, type(str(self.ue)))
- self.assertEqual(str, type(str(self.wue)))
- self.assertEqual(self.us, str(self.wue))
-
- def test_str(self):
- """Test conversion to a string
-
- (bytes in Python 2, unicode in Python 3).
- """
- self.assertEqual(str(self.bs), str(self.wbs))
- self.assertEqual(str(self.be), str(self.wbe))
- self.assertEqual(str(self.us), str(self.wus))
- self.assertEqual(str(self.ue), str(self.wue))
-
-
-class ErrorStringTests(unittest.TestCase):
- bs = b'\xc3\xbc' # unicode(bs) fails, str(bs) in Python 3 return repr()
- us = u'\xfc' # bytes(us) fails; str(us) fails in Python 2
-
- def test_str(self):
- self.assertEqual('Exception: spam',
- str(ErrorString(Exception('spam'))))
- self.assertEqual('IndexError: '+str(self.bs),
- str(ErrorString(IndexError(self.bs))))
- self.assertEqual('ImportError: %s' % SafeString(self.us),
- str(ErrorString(ImportError(self.us))))
-
- def test_unicode(self):
- self.assertEqual(u'Exception: spam',
- str(ErrorString(Exception(u'spam'))))
- self.assertEqual(u'IndexError: '+self.us,
- str(ErrorString(IndexError(self.us))))
- self.assertEqual(u'ImportError: %s' % SafeString(self.bs),
- str(ErrorString(ImportError(self.bs))))
-
-
-# ErrorOutput tests
-# -----------------
-
-# Stub: Buffer with 'strict' auto-conversion of input to byte string:
-class BBuf(BytesIO):
- def write(self, data):
- if isinstance(data, str):
- data.encode('ascii', 'strict')
- super(BBuf, self).write(data)
-
-
-# Stub: Buffer expecting unicode string:
-class UBuf(StringIO):
- def write(self, data):
- # emulate Python 3 handling of stdout, stderr
- if isinstance(data, bytes):
- raise TypeError('must be unicode, not bytes')
- super(UBuf, self).write(data)
-
-
-class ErrorOutputTests(unittest.TestCase):
- def test_defaults(self):
- e = ErrorOutput()
- self.assertEqual(e.stream, sys.stderr)
-
- def test_bbuf(self):
- buf = BBuf() # buffer storing byte string
- e = ErrorOutput(buf, encoding='ascii')
- # write byte-string as-is
- e.write(b'b\xfc')
- self.assertEqual(buf.getvalue(), b'b\xfc')
- # encode unicode data with backslashescape fallback replacement:
- e.write(u' u\xfc')
- self.assertEqual(buf.getvalue(), b'b\xfc u\\xfc')
- # handle Exceptions with Unicode string args
- # unicode(Exception(u'e\xfc')) # fails in Python < 2.6
- e.write(AttributeError(u' e\xfc'))
- self.assertEqual(buf.getvalue(), b'b\xfc u\\xfc e\\xfc')
- # encode with `encoding` attribute
- e.encoding = 'utf-8'
- e.write(u' u\xfc')
- self.assertEqual(buf.getvalue(), b'b\xfc u\\xfc e\\xfc u\xc3\xbc')
-
- def test_ubuf(self):
- buf = UBuf() # buffer only accepting unicode string
- # decode of binary strings
- e = ErrorOutput(buf, encoding='ascii')
- e.write(b'b\xfc')
- self.assertEqual(buf.getvalue(), u'b\ufffd') # REPLACEMENT CHARACTER
- # write Unicode string and Exceptions with Unicode args
- e.write(u' u\xfc')
- self.assertEqual(buf.getvalue(), u'b\ufffd u\xfc')
- e.write(AttributeError(u' e\xfc'))
- self.assertEqual(buf.getvalue(), u'b\ufffd u\xfc e\xfc')
- # decode with `encoding` attribute
- e.encoding = 'latin1'
- e.write(b' b\xfc')
- self.assertEqual(buf.getvalue(), u'b\ufffd u\xfc e\xfc b\xfc')
-
-
-class SafeStringTests_locale(unittest.TestCase):
- """
- Test docutils.SafeString with 'problematic' locales.
-
- The error message in `EnvironmentError` instances comes from the OS
- and in some locales (e.g. ru_RU), contains high bit chars.
- """
- # test data:
- bs = b'\xc3\xbc'
- us = u'\xfc'
- try:
- open(b'\xc3\xbc')
- except IOError as e: # in Python 3 the name for the exception instance
- bioe = e # is local to the except clause
- try:
- open(u'\xfc')
- except IOError as e:
- uioe = e
- except UnicodeEncodeError:
- try:
- open(u'\xfc'.encode(sys.getfilesystemencoding(), 'replace'))
- except IOError as e:
- uioe = e
- bose = FileNotFoundError(2, 'The system cannot find the file specified')
- bose.filename = b'\xc3\xbc'
- uose = FileNotFoundError(2, 'The system cannot find the file specified')
- uose.filename = '\xfc'
- # wrapped test data:
- wbioe = SafeString(bioe)
- wuioe = SafeString(uioe)
- wbose = SafeString(bose)
- wuose = SafeString(uose)
-
- def test_ustr(self):
- """Test conversion to a unicode-string."""
- # unicode(bioe) fails with e.g. 'ru_RU.utf8' locale
- self.assertEqual(str, type(str(self.wbioe)))
- self.assertEqual(str, type(str(self.wuioe)))
- self.assertEqual(str, type(str(self.wbose)))
- self.assertEqual(str, type(str(self.wuose)))
-
- def test_str(self):
- """Test conversion to a string
-
- (bytes in Python 2, unicode in Python 3).
- """
- self.assertEqual(str(self.bioe), str(self.wbioe))
- self.assertEqual(str(self.uioe), str(self.wuioe))
- self.assertEqual(str(self.bose), str(self.wbose))
- self.assertEqual(str(self.uose), str(self.wuose))
-
-
-class ErrorReportingTests(unittest.TestCase):
- """
- Test cases where error reporting can go wrong.
-
- Do not test the exact output (as this varies with the locale), just
- ensure that the correct exception is thrown.
- """
-
- # These tests fail with a 'problematic locale',
- # Docutils revision < 7035, and Python 2:
-
- parser = docutils.parsers.rst.Parser()
- """Parser shared by all ParserTestCases."""
-
- settings = frontend.get_default_settings(parser)
- settings.report_level = 1
- settings.halt_level = 1
- settings.warning_stream = ''
- document = utils.new_document('test data', settings)
-
- def test_include(self):
- source = '.. include:: bogus.txt'
- self.assertRaises(utils.SystemMessage,
- self.parser.parse, source, self.document)
-
- def test_raw_file(self):
- source = ('.. raw:: html\n'
- ' :file: bogus.html\n')
- self.assertRaises(utils.SystemMessage,
- self.parser.parse, source, self.document)
-
- def test_csv_table(self):
- source = ('.. csv-table:: external file\n'
- ' :file: bogus.csv\n')
- self.assertRaises(utils.SystemMessage,
- self.parser.parse, source, self.document)
-
-
-if __name__ == '__main__':
- unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 15:03:58
|
Revision: 9759
http://sourceforge.net/p/docutils/code/9759
Author: milde
Date: 2024-06-14 15:03:55 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove `docutils.utils.Reporter.set_conditions()`.
Obsolete. Set attributes via configuration settings or directly.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/utils/__init__.py
trunk/docutils/test/test_settings.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 15:03:42 UTC (rev 9758)
+++ trunk/docutils/HISTORY.txt 2024-06-14 15:03:55 UTC (rev 9759)
@@ -81,6 +81,11 @@
- `Messages` also handles "loose" system messages generated by the parser.
+* docutils/utils/__init__.py
+
+ - Removed `Reporter.set_conditions()`.
+ Set attributes via configuration settings or directly.
+
* docutils/utils/error_reporting.py
- Removed. Obsolete in Python 3.
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:42 UTC (rev 9758)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:55 UTC (rev 9759)
@@ -228,6 +228,8 @@
Obsolete. Append to Element['classes'] directly.
`docutils.utils.error_reporting`
Obsolete in Python 3
+ `docutils.utils.Reporter.set_conditions()`
+ Obsolete. Set attributes via configuration settings or directly.
* Removed files:
Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py 2024-06-14 15:03:42 UTC (rev 9758)
+++ trunk/docutils/docutils/utils/__init__.py 2024-06-14 15:03:55 UTC (rev 9759)
@@ -126,19 +126,6 @@
self.max_level = -1
"""The highest level system message generated so far."""
- def set_conditions(self, category, report_level, halt_level,
- stream=None, debug=False):
- warnings.warn('docutils.utils.Reporter.set_conditions() deprecated; '
- 'Will be removed in Docutils 0.21 or later. '
- 'Set attributes via configuration settings or directly.',
- DeprecationWarning, stacklevel=2)
- self.report_level = report_level
- self.halt_level = halt_level
- if not isinstance(stream, io.ErrorOutput):
- stream = io.ErrorOutput(stream, self.encoding, self.error_handler)
- self.stream = stream
- self.debug_flag = debug
-
def attach_observer(self, observer):
"""
The `observer` parameter is a function or bound method which takes one
Modified: trunk/docutils/test/test_settings.py
===================================================================
--- trunk/docutils/test/test_settings.py 2024-06-14 15:03:42 UTC (rev 9758)
+++ trunk/docutils/test/test_settings.py 2024-06-14 15:03:55 UTC (rev 9759)
@@ -373,12 +373,6 @@
for v, result in tests:
self.assertEqual(frontend.validate_smartquotes_locales(v), result)
- def test_set_conditions_deprecation_warning(self):
- reporter = utils.Reporter('test', 1, 4)
- with self.assertWarnsRegex(DeprecationWarning,
- 'Set attributes via configuration '):
- reporter.set_conditions('foo', 1, 4) # trigger warning
-
if __name__ == '__main__':
unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 15:04:08
|
Revision: 9760
http://sourceforge.net/p/docutils/code/9760
Author: milde
Date: 2024-06-14 15:04:05 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove `docutils.core.Publisher.setup_option_parser()`.
internal, obsolete
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/core.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 15:03:55 UTC (rev 9759)
+++ trunk/docutils/HISTORY.txt 2024-06-14 15:04:05 UTC (rev 9760)
@@ -27,6 +27,10 @@
- Allow multiple <term> elements in a <definition_list_item>.
Fixes feature-request #60
+* docutils/core.py
+
+ - Removed `Publisher.setup_option_parser()` (internal, obsolete).
+
* docutils/frontend.py
- Drop short options ``-i`` and ``-o`` for ``--input-encoding``
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:03:55 UTC (rev 9759)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:04:05 UTC (rev 9760)
@@ -224,6 +224,8 @@
* Removed objects:
+ `docutils.core.Publisher.setup_option_parser()`
+ internal, obsolete
`docutils.nodes.Element.set_class()`
Obsolete. Append to Element['classes'] directly.
`docutils.utils.error_reporting`
@@ -335,8 +337,6 @@
Python 2 compatibility hacks
`docutils.utils.Reporter.set_conditions()`
obsolete
- `docutils.core.Publisher.setup_option_parser()`
- internal, obsolete
* New files:
Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py 2024-06-14 15:03:55 UTC (rev 9759)
+++ trunk/docutils/docutils/core.py 2024-06-14 15:04:05 UTC (rev 9760)
@@ -103,32 +103,27 @@
if self.writer is None:
self.set_writer(writer_name)
- def setup_option_parser(self, usage=None, description=None,
- settings_spec=None, config_section=None,
- **defaults):
- warnings.warn('Publisher.setup_option_parser is deprecated, '
- 'and will be removed in Docutils 0.21.',
- DeprecationWarning, stacklevel=2)
- if config_section:
- if not settings_spec:
- settings_spec = SettingsSpec()
- settings_spec.config_section = config_section
- parts = config_section.split()
- if len(parts) > 1 and parts[-1] == 'application':
- settings_spec.config_section_dependencies = ['applications']
- # @@@ Add self.source & self.destination to components in future?
- return OptionParser(
- components=(self.parser, self.reader, self.writer, settings_spec),
- defaults=defaults, read_config_files=True,
- usage=usage, description=description)
-
- def _setup_settings_parser(self, *args, **kwargs):
+ def _setup_settings_parser(self, usage=None, description=None,
+ settings_spec=None, config_section=None,
+ **defaults):
# Provisional: will change (docutils.frontend.OptionParser will
# be replaced by a parser based on arparse.ArgumentParser)
# and may be removed later.
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
- return self.setup_option_parser(*args, **kwargs)
+ if config_section:
+ if not settings_spec:
+ settings_spec = SettingsSpec()
+ settings_spec.config_section = config_section
+ parts = config_section.split()
+ if len(parts) > 1 and parts[-1] == 'application':
+ settings_spec.config_section_dependencies = ['applications'] # noqa: E501
+ # @@@ Add self.source & self.destination to components in future?
+ return OptionParser(
+ components=(self.parser, self.reader, self.writer,
+ settings_spec),
+ defaults=defaults, read_config_files=True,
+ usage=usage, description=description)
def get_settings(self, usage=None, description=None,
settings_spec=None, config_section=None, **defaults):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 15:04:22
|
Revision: 9761
http://sourceforge.net/p/docutils/code/9761
Author: milde
Date: 2024-06-14 15:04:19 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove `parsers.rst.directives.tables.CSVTable.(en|de)code_from_csv()`
Not required with Python 3.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/parsers/rst/directives/tables.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 15:04:05 UTC (rev 9760)
+++ trunk/docutils/HISTORY.txt 2024-06-14 15:04:19 UTC (rev 9761)
@@ -67,6 +67,11 @@
"include" directive is used with :parser: option.
Enables system messages with correct source/line indication.
+* docutils/parsers/rst/directives/tables.py
+
+ - Removed `CSVTable.decode_from_csv()` and `CSVTable.encode_from_csv()`.
+ Not required with Python 3.
+
* docutils/transforms/frontmatter.py
- Update `DocInfo` to work with corrected element categories.
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:04:05 UTC (rev 9760)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:04:19 UTC (rev 9761)
@@ -232,6 +232,10 @@
Obsolete in Python 3
`docutils.utils.Reporter.set_conditions()`
Obsolete. Set attributes via configuration settings or directly.
+ `docutils.parsers.rst.directives.tables.CSVTable.decode_from_csv()`
+ not required with Python 3
+ `docutils.parsers.rst.directives.tables.CSVTable.encode_from_csv()`
+ not required with Python 3
* Removed files:
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2024-06-14 15:04:05 UTC (rev 9760)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2024-06-14 15:04:19 UTC (rev 9761)
@@ -386,22 +386,6 @@
raise SystemMessagePropagation(error)
return csv_data, source
- @staticmethod
- def decode_from_csv(s):
- warnings.warn('CSVTable.decode_from_csv()'
- ' is not required with Python 3'
- ' and will be removed in Docutils 0.21 or later.',
- DeprecationWarning, stacklevel=2)
- return s
-
- @staticmethod
- def encode_for_csv(s):
- warnings.warn('CSVTable.encode_from_csv()'
- ' is not required with Python 3'
- ' and will be removed in Docutils 0.21 or later.',
- DeprecationWarning, stacklevel=2)
- return s
-
def parse_csv_data_into_rows(self, csv_data, dialect, source):
csv_reader = csv.reader((line + '\n' for line in csv_data),
dialect=dialect)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 16:19:23
|
Revision: 9762
http://sourceforge.net/p/docutils/code/9762
Author: milde
Date: 2024-06-14 16:19:20 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Define/use auxiliary function `parsers.rst.roles.normalize_options()`.
Renamed from `parsers.rst.roles.normalized_role_options()` (it is now also
used for directive options).
Replaces `parsers.rst.roles.set_classes()`
The obsoleted functions will be removed in Docutils 1.0.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/parsers/rst/directives/admonitions.py
trunk/docutils/docutils/parsers/rst/directives/body.py
trunk/docutils/docutils/parsers/rst/directives/images.py
trunk/docutils/docutils/parsers/rst/roles.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 15:04:19 UTC (rev 9761)
+++ trunk/docutils/HISTORY.txt 2024-06-14 16:19:20 UTC (rev 9762)
@@ -72,6 +72,11 @@
- Removed `CSVTable.decode_from_csv()` and `CSVTable.encode_from_csv()`.
Not required with Python 3.
+* docutils/parsers/rst/roles.py
+
+ - Renamed `normalized_role_options()` to `normalized_role_options()`
+ (it is now also used for directive options).
+
* docutils/transforms/frontmatter.py
- Update `DocInfo` to work with corrected element categories.
@@ -3639,11 +3644,11 @@
* docutils/languages/sk.py: Added to project; Slovak mappings by
Miroslav Vasko.
-* docutils/parser/__init__.py:
+* docutils/parsers/__init__.py:
- Added ``Parser.finish_parse()`` method.
-* docutils/parser/rst/__init__.py:
+* docutils/parsers/rst/__init__.py:
- Added options: ``--pep-references``, ``--rfc-references``,
``--tab-width``, ``--trim-footnote-reference-space``.
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 15:04:19 UTC (rev 9761)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 16:19:20 UTC (rev 9762)
@@ -140,6 +140,9 @@
* Remove the input encoding auto-detection code in Docutils 1.0.
+* Remove `parsers.rst.roles.set_classes()` and
+ `parsers.rst.roles.normalized_role_options()` in Docutils 1.0.
+
* Remove the "rawsource" argument from `nodes.Text.__init__()`
in Docutils 2.0.
Modified: trunk/docutils/docutils/parsers/rst/directives/admonitions.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/admonitions.py 2024-06-14 15:04:19 UTC (rev 9761)
+++ trunk/docutils/docutils/parsers/rst/directives/admonitions.py 2024-06-14 16:19:20 UTC (rev 9762)
@@ -11,7 +11,7 @@
from docutils.parsers.rst import Directive
from docutils.parsers.rst import directives
-from docutils.parsers.rst.roles import set_classes
+from docutils.parsers.rst.roles import normalize_options
from docutils import nodes
@@ -26,10 +26,10 @@
"""Subclasses must set this to the appropriate admonition node class."""
def run(self):
- set_classes(self.options)
+ options = normalize_options(self.options)
self.assert_has_content()
text = '\n'.join(self.content)
- admonition_node = self.node_class(text, **self.options)
+ admonition_node = self.node_class(text, **options)
self.add_name(admonition_node)
admonition_node.source, admonition_node.line = \
self.state_machine.get_source_and_line(self.lineno)
@@ -42,7 +42,7 @@
self.state_machine.get_source_and_line(self.lineno))
admonition_node += title
admonition_node += messages
- if 'classes' not in self.options:
+ if 'classes' not in options:
admonition_node['classes'] += ['admonition-'
+ nodes.make_id(title_text)]
self.state.nested_parse(self.content, self.content_offset,
Modified: trunk/docutils/docutils/parsers/rst/directives/body.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/body.py 2024-06-14 15:04:19 UTC (rev 9761)
+++ trunk/docutils/docutils/parsers/rst/directives/body.py 2024-06-14 16:19:20 UTC (rev 9762)
@@ -14,7 +14,7 @@
from docutils import nodes
from docutils.parsers.rst import Directive
from docutils.parsers.rst import directives
-from docutils.parsers.rst.roles import set_classes
+from docutils.parsers.rst.roles import normalize_options
from docutils.utils.code_analyzer import Lexer, LexerError, NumberLines
@@ -116,11 +116,11 @@
has_content = True
def run(self):
- set_classes(self.options)
+ options = normalize_options(self.options)
self.assert_has_content()
text = '\n'.join(self.content)
text_nodes, messages = self.state.inline_text(text, self.lineno)
- node = nodes.literal_block(text, '', *text_nodes, **self.options)
+ node = nodes.literal_block(text, '', *text_nodes, **options)
node.line = self.content_offset + 1
self.add_name(node)
return [node] + messages
@@ -147,12 +147,12 @@
language = self.arguments[0]
else:
language = ''
- set_classes(self.options)
+ options = normalize_options(self.options)
classes = ['code']
if language:
classes.append(language)
- if 'classes' in self.options:
- classes.extend(self.options['classes'])
+ if 'classes' in options:
+ classes.extend(options['classes'])
# set up lexical analyzer
try:
@@ -165,10 +165,10 @@
else:
raise self.warning(error)
- if 'number-lines' in self.options:
+ if 'number-lines' in options:
# optional argument `startline`, defaults to 1
try:
- startline = int(self.options['number-lines'] or 1)
+ startline = int(options['number-lines'] or 1)
except ValueError:
raise self.error(':number-lines: with non-integer start value')
endline = startline + len(self.content)
@@ -178,8 +178,8 @@
node = nodes.literal_block('\n'.join(self.content), classes=classes)
self.add_name(node)
# if called from "include", set the source
- if 'source' in self.options:
- node.attributes['source'] = self.options['source']
+ if 'source' in options:
+ node.attributes['source'] = options['source']
# analyze content and add nodes for every token
for classes, value in tokens:
if classes:
@@ -201,7 +201,7 @@
has_content = True
def run(self):
- set_classes(self.options)
+ options = normalize_options(self.options)
self.assert_has_content()
# join lines, separate blocks
content = '\n'.join(self.content).split('\n\n')
@@ -209,7 +209,7 @@
for block in content:
if not block:
continue
- node = nodes.math_block(self.block_text, block, **self.options)
+ node = nodes.math_block(self.block_text, block, **options)
(node.source,
node.line) = self.state_machine.get_source_and_line(self.lineno)
self.add_name(node)
@@ -226,10 +226,10 @@
'name': directives.unchanged}
def run(self):
- set_classes(self.options)
+ options = normalize_options(self.options)
rubric_text = self.arguments[0]
textnodes, messages = self.state.inline_text(rubric_text, self.lineno)
- rubric = nodes.rubric(rubric_text, '', *textnodes, **self.options)
+ rubric = nodes.rubric(rubric_text, '', *textnodes, **options)
self.add_name(rubric)
return [rubric] + messages
Modified: trunk/docutils/docutils/parsers/rst/directives/images.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/images.py 2024-06-14 15:04:19 UTC (rev 9761)
+++ trunk/docutils/docutils/parsers/rst/directives/images.py 2024-06-14 16:19:20 UTC (rev 9762)
@@ -24,7 +24,7 @@
from docutils.nodes import fully_normalize_name, whitespace_normalize_name
from docutils.parsers.rst import Directive
from docutils.parsers.rst import directives, states
-from docutils.parsers.rst.roles import set_classes
+from docutils.parsers.rst.roles import normalize_options
class Image(Directive):
@@ -95,8 +95,8 @@
else: # malformed target
messages.append(data) # data is a system message
del self.options['target']
- set_classes(self.options)
- image_node = nodes.image(self.block_text, **self.options)
+ options = normalize_options(self.options)
+ image_node = nodes.image(self.block_text, **options)
(image_node.source,
image_node.line) = self.state_machine.get_source_and_line(self.lineno)
self.add_name(image_node)
Modified: trunk/docutils/docutils/parsers/rst/roles.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/roles.py 2024-06-14 15:04:19 UTC (rev 9761)
+++ trunk/docutils/docutils/parsers/rst/roles.py 2024-06-14 16:19:20 UTC (rev 9762)
@@ -76,6 +76,7 @@
__docformat__ = 'reStructuredText'
+import warnings
from docutils import nodes
from docutils.parsers.rst import directives
@@ -207,7 +208,7 @@
def __call__(self, role, rawtext, text, lineno, inliner,
options=None, content=None):
- options = normalized_role_options(options)
+ options = normalize_options(options)
return [self.node_class(rawtext, text, **options)], []
@@ -224,7 +225,7 @@
def __call__(self, role, rawtext, text, lineno, inliner,
options=None, content=None):
- opts = normalized_role_options(self.supplied_options)
+ opts = normalize_options(self.supplied_options)
try:
opts.update(options)
except TypeError: # options may be ``None``
@@ -243,7 +244,7 @@
"""Base for custom roles if no other base role is specified."""
# Once nested inline markup is implemented, this and other methods should
# recursively call inliner.nested_parse().
- options = normalized_role_options(options)
+ options = normalize_options(options)
return [nodes.inline(rawtext, text, **options)], []
@@ -266,7 +267,7 @@
def pep_reference_role(role, rawtext, text, lineno, inliner,
options=None, content=None):
- options = normalized_role_options(options)
+ options = normalize_options(options)
try:
pepnum = int(nodes.unescape(text))
if pepnum < 0 or pepnum > 9999:
@@ -288,7 +289,7 @@
def rfc_reference_role(role, rawtext, text, lineno, inliner,
options=None, content=None):
- options = normalized_role_options(options)
+ options = normalize_options(options)
if "#" in text:
rfcnum, section = nodes.unescape(text).split("#", 1)
else:
@@ -315,7 +316,7 @@
def raw_role(role, rawtext, text, lineno, inliner, options=None, content=None):
- options = normalized_role_options(options)
+ options = normalize_options(options)
if not inliner.document.settings.raw_enabled:
msg = inliner.reporter.warning('raw (and derived) roles disabled')
prb = inliner.problematic(rawtext, rawtext, msg)
@@ -340,7 +341,7 @@
def code_role(role, rawtext, text, lineno, inliner,
options=None, content=None):
- options = normalized_role_options(options)
+ options = normalize_options(options)
language = options.get('language', '')
classes = ['code']
if 'classes' in options:
@@ -375,7 +376,7 @@
def math_role(role, rawtext, text, lineno, inliner,
options=None, content=None):
- options = normalized_role_options(options)
+ options = normalize_options(options)
text = nodes.unescape(text, True) # raw text without inline role markup
node = nodes.math(rawtext, text, **options)
return [node], []
@@ -411,11 +412,10 @@
def set_classes(options):
- """Deprecated. Obsoleted by ``normalized_role_options()``."""
- # TODO: Change use in directives.py and uncomment.
- # warnings.warn('The auxiliary function roles.set_classes() is obsoleted'
- # ' by roles.normalized_role_options() and will be removed'
- # ' in Docutils 0.21 or later', DeprecationWarning, stacklevel=2)
+ """Deprecated. Obsoleted by ``normalize_options()``."""
+ warnings.warn('The auxiliary function roles.set_classes() is obsoleted'
+ ' by roles.normalize_options() and will be removed'
+ ' in Docutils 1.0', DeprecationWarning, stacklevel=2)
if options and 'class' in options:
assert 'classes' not in options
options['classes'] = options['class']
@@ -423,8 +423,15 @@
def normalized_role_options(options):
+ warnings.warn('The auxiliary function roles.normalized_role_options() is '
+ 'obsoleted by roles.normalize_options() and will be removed'
+ ' in Docutils 1.0', DeprecationWarning, stacklevel=2)
+ return normalize_options(options)
+
+
+def normalize_options(options):
"""
- Return normalized dictionary of role options.
+ Return normalized dictionary of role/directive options.
* ``None`` is replaced by an empty dictionary.
* The key 'class' is renamed to 'classes'.
@@ -431,9 +438,9 @@
"""
if options is None:
return {}
- result = options.copy()
- if 'class' in result:
- assert 'classes' not in result
- result['classes'] = result['class']
- del result['class']
- return result
+ n_options = options.copy()
+ if 'class' in n_options:
+ assert 'classes' not in n_options
+ n_options['classes'] = n_options['class']
+ del n_options['class']
+ return n_options
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 16:19:37
|
Revision: 9763
http://sourceforge.net/p/docutils/code/9763
Author: milde
Date: 2024-06-14 16:19:29 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove `docutils.transforms.writer_aux.Compound`.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/transforms/writer_aux.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 16:19:20 UTC (rev 9762)
+++ trunk/docutils/HISTORY.txt 2024-06-14 16:19:29 UTC (rev 9763)
@@ -87,6 +87,10 @@
follows a <meta> or <decoration> element as this is invalid
according to ``docutils.dtd``.
+* docutils/transforms/writer_aux.py
+
+ - Removed `Compound` class.
+
* docutils/transforms/references.py
- Make `AnonymousHyperlinks` transform idempotent.
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 16:19:20 UTC (rev 9762)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 16:19:29 UTC (rev 9763)
@@ -228,17 +228,19 @@
* Removed objects:
`docutils.core.Publisher.setup_option_parser()`
- internal, obsolete
+ internal, obsolete
`docutils.nodes.Element.set_class()`
Obsolete. Append to Element['classes'] directly.
- `docutils.utils.error_reporting`
- Obsolete in Python 3
- `docutils.utils.Reporter.set_conditions()`
- Obsolete. Set attributes via configuration settings or directly.
`docutils.parsers.rst.directives.tables.CSVTable.decode_from_csv()`
not required with Python 3
`docutils.parsers.rst.directives.tables.CSVTable.encode_from_csv()`
not required with Python 3
+ `docutils.transforms.writer_aux.Compound`
+ not used since Dec 2010
+ `docutils.utils.error_reporting`
+ obsolete in Python 3
+ `docutils.utils.Reporter.set_conditions()`
+ Obsolete. Set attributes via configuration settings or directly.
* Removed files:
Modified: trunk/docutils/docutils/transforms/writer_aux.py
===================================================================
--- trunk/docutils/docutils/transforms/writer_aux.py 2024-06-14 16:19:20 UTC (rev 9762)
+++ trunk/docutils/docutils/transforms/writer_aux.py 2024-06-14 16:19:29 UTC (rev 9763)
@@ -14,53 +14,10 @@
__docformat__ = 'reStructuredText'
-import warnings
-
from docutils import nodes, languages
from docutils.transforms import Transform
-class Compound(Transform):
-
- """
- .. warning:: This transform is not used by Docutils since Dec 2010
- and will be removed in Docutils 0.21 or later.
-
- Flatten all compound paragraphs. For example, transform ::
-
- <compound>
- <paragraph>
- <literal_block>
- <paragraph>
-
- into ::
-
- <paragraph>
- <literal_block classes="continued">
- <paragraph classes="continued">
- """
-
- default_priority = 910
-
- def __init__(self, document, startnode=None):
- warnings.warn('docutils.transforms.writer_aux.Compound is deprecated'
- ' and will be removed in Docutils 0.21 or later.',
- DeprecationWarning, stacklevel=2)
- super().__init__(document, startnode)
-
- def apply(self):
- for compound in self.document.findall(nodes.compound):
- first_child = True
- for child in compound:
- if first_child:
- if not isinstance(child, nodes.Invisible):
- first_child = False
- else:
- child['classes'].append('continued')
- # Substitute children for compound.
- compound.replace_self(compound[:])
-
-
class Admonitions(Transform):
"""
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 16:19:44
|
Revision: 9764
http://sourceforge.net/p/docutils/code/9764
Author: milde
Date: 2024-06-14 16:19:42 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Remove optional argument `pxunit` of `LaTeXTranslator.to_latex_length()`
Ignored since at least 2012.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/writers/latex2e/__init__.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 16:19:29 UTC (rev 9763)
+++ trunk/docutils/HISTORY.txt 2024-06-14 16:19:42 UTC (rev 9764)
@@ -108,6 +108,11 @@
- Removed. Obsolete in Python 3.
+* docutils/writers/latex2e/__init__.py
+
+ - Remove optional argument `pxunit` of `LaTeXTranslator.to_latex_length()`
+ (ignored since at least 2012).
+
* docutils/writers/_html_base.py
- Make MathML the default math_output_.
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2024-06-14 16:19:29 UTC (rev 9763)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2024-06-14 16:19:42 UTC (rev 9764)
@@ -2377,15 +2377,9 @@
self.requirements['~header'] = ''.join(self.out)
self.pop_output_collector()
- def to_latex_length(self, length_str, pxunit=None):
+ def to_latex_length(self, length_str):
"""Convert `length_str` with rst length to LaTeX length
"""
- if pxunit is not None:
- warnings.warn(
- 'The optional argument `pxunit` '
- 'of LaTeXTranslator.to_latex_length() is ignored '
- 'and will be removed in Docutils 0.21 or later',
- DeprecationWarning, stacklevel=2)
match = re.match(r'(\d*\.?\d*)\s*(\S*)', length_str)
if not match:
return length_str
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 16:20:02
|
Revision: 9766
http://sourceforge.net/p/docutils/code/9766
Author: milde
Date: 2024-06-14 16:19:59 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Change "null" writer output from None to the empty string.
Fixes `core.publish_string()`: now returns a `bytes` or `str` instance
for all writers (as advertised).
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/writers/null.py
trunk/docutils/test/test_writers/test_null.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 16:19:49 UTC (rev 9765)
+++ trunk/docutils/HISTORY.txt 2024-06-14 16:19:59 UTC (rev 9766)
@@ -108,10 +108,10 @@
- Removed. Obsolete in Python 3.
-* docutils/writers/latex2e/__init__.py
+* docutils/writers/docutils-xml.py
- - Remove optional argument `pxunit` of `LaTeXTranslator.to_latex_length()`
- (ignored since at least 2012).
+ - Do not increase indentation of follow-up lines inside inline elements.
+ when formatting with `indents`_.
* docutils/writers/_html_base.py
@@ -121,6 +121,11 @@
- Keep default math_output_ value "HTML math.css".
+* docutils/writers/latex2e/__init__.py
+
+ - Remove optional argument `pxunit` of `LaTeXTranslator.to_latex_length()`
+ (ignored since at least 2012).
+
* docutils/writers/manpage.py
- Remove code for unused emdash bullets.
@@ -128,10 +133,9 @@
docutils version in header
- Stop converting text to full capitals (bug #481).
-* docutils/writers/docutils-xml.py
+* docutils/writers/null.py
- - Do not increase indentation of follow-up lines inside inline elements.
- when formatting with `indents`_.
+ - `null.Writer.translate()` sets `self.output` to the empty string.
* tools/rst2odt_prepstyles.py
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 16:19:49 UTC (rev 9765)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 16:19:59 UTC (rev 9766)
@@ -118,13 +118,6 @@
.. _reference-label: docs/user/config.html#reference-label
-* "null" writer: output will change to the empty string
- in Docutils 0.22.
-
-* "manpage" writer:
-
- - No more changing case in to uppercase, leave it to the source.
-
Misc
----
@@ -212,6 +205,16 @@
Use the long equivalents ``--input-encoding`` and ``--output-encoding``.
(See `command line interface`_ for the rationale.)
+Output changes
+ "manpage" writer:
+ Don't UPPERCASE section headings.
+
+ "null" writer:
+ output changed from None to the empty string.
+
+ `publish_string()` now returns a `bytes` or `str` instance
+ for all writers (as documented).
+
New objects
`parsers.docutils_xml`
parser for `Docutils XML`_ (e.g., the output of the "xml" writer).
Modified: trunk/docutils/docutils/writers/null.py
===================================================================
--- trunk/docutils/docutils/writers/null.py 2024-06-14 16:19:49 UTC (rev 9765)
+++ trunk/docutils/docutils/writers/null.py 2024-06-14 16:19:59 UTC (rev 9766)
@@ -5,7 +5,7 @@
"""
A do-nothing Writer.
-`self.output` will change from ``None`` to the empty string
+`self.output` changed from ``None`` to the empty string
in Docutils 0.22.
"""
@@ -21,5 +21,4 @@
config_section_dependencies = ('writers',)
def translate(self):
- # output = None # TODO in 0.22
- pass
+ self.output = ''
Modified: trunk/docutils/test/test_writers/test_null.py
===================================================================
--- trunk/docutils/test/test_writers/test_null.py 2024-06-14 16:19:49 UTC (rev 9765)
+++ trunk/docutils/test/test_writers/test_null.py 2024-06-14 16:19:59 UTC (rev 9766)
@@ -45,7 +45,7 @@
["""\
This is a paragraph.
""",
-None]
+'']
]
if __name__ == '__main__':
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-14 16:20:11
|
Revision: 9767
http://sourceforge.net/p/docutils/code/9767
Author: milde
Date: 2024-06-14 16:20:08 +0000 (Fri, 14 Jun 2024)
Log Message:
-----------
Update deprecation warnings.
Change warnings with `PendingDeprecationWarning` to `DeprectionWarning`.
Postpone removing `directives.CSVTable.HeaderDialect` to 1.0.
Modified Paths:
--------------
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/nodes.py
trunk/docutils/docutils/parsers/rst/directives/tables.py
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 16:19:59 UTC (rev 9766)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-14 16:20:08 UTC (rev 9767)
@@ -122,7 +122,7 @@
----
* Remove `parsers.rst.directives.CSVTable.HeaderDialect`
- in Docutils 0.22.
+ in Docutils 1.0.
* Remove support for the `recommonmark parser`_ in Docutils 1.0.
Recommonmark is unmaintained since 2021 and deprecated in favour
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2024-06-14 16:19:59 UTC (rev 9766)
+++ trunk/docutils/docutils/nodes.py 2024-06-14 16:20:08 UTC (rev 9767)
@@ -306,7 +306,7 @@
"""
# traverse() may be eventually removed:
warnings.warn('nodes.Node.traverse() is obsoleted by Node.findall().',
- PendingDeprecationWarning, stacklevel=2)
+ DeprecationWarning, stacklevel=2)
return list(self.findall(condition, include_self, descend,
siblings, ascend))
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2024-06-14 16:19:59 UTC (rev 9766)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2024-06-14 16:20:08 UTC (rev 9767)
@@ -249,8 +249,8 @@
def __init__(self):
warnings.warn('CSVTable.HeaderDialect will be removed '
- 'in Docutils 0.22.',
- PendingDeprecationWarning, stacklevel=2)
+ 'in Docutils 1.0',
+ DeprecationWarning, stacklevel=2)
super().__init__()
@staticmethod
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-15 12:08:30
|
Revision: 9768
http://sourceforge.net/p/docutils/code/9768
Author: milde
Date: 2024-06-15 12:08:27 +0000 (Sat, 15 Jun 2024)
Log Message:
-----------
Deprecate `io.BinaryFileOutput` and `core.publish_cmdline_to_binary()`.
Announce removal in Docutils 0.24 (2 releases after 0.22, which may also be
1.0 or 2.0).
Use `io.FileOutput` and `core.publish_cmdline()` instead
(works with `bytes` since Docutils 0.20).
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/core.py
trunk/docutils/docutils/io.py
trunk/docutils/tools/rst2odt.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-14 16:20:08 UTC (rev 9767)
+++ trunk/docutils/HISTORY.txt 2024-06-15 12:08:27 UTC (rev 9768)
@@ -139,6 +139,10 @@
* tools/rst2odt_prepstyles.py
+ - Use `core.publish_file()` instead of `core.publish_file_to_binary()`.
+
+* tools/rst2odt_prepstyles.py
+
- Removed. Use `docutils.writers.odf_odt.prepstyles`.
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-14 16:20:08 UTC (rev 9767)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-15 12:08:27 UTC (rev 9768)
@@ -121,6 +121,9 @@
Misc
----
+* Remove `io.BinaryFileOutput` and `core.publish_cmdline_to_binary()`
+ in Docutils 0.24.
+
* Remove `parsers.rst.directives.CSVTable.HeaderDialect`
in Docutils 1.0.
Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py 2024-06-14 16:20:08 UTC (rev 9767)
+++ trunk/docutils/docutils/core.py 2024-06-15 12:08:27 UTC (rev 9768)
@@ -595,7 +595,13 @@
line.
- `description`: Program description, output for the "--help" option
(along with command-line option descriptions).
+
+ Deprecated. Use `publish_cmdline()` (works with `bytes` since
+ Docutils 0.20). Will be removed in Docutils 0.24.
"""
+ warnings.warn('"publish_cmdline_to_binary()" is obsoleted'
+ ' by "publish_cmdline()" and will be removed'
+ ' in Docutils 0.24.', DeprecationWarning, stacklevel=2)
publisher = Publisher(reader, parser, writer, settings=settings,
destination_class=destination_class)
publisher.set_components(reader_name, parser_name, writer_name)
Modified: trunk/docutils/docutils/io.py
===================================================================
--- trunk/docutils/docutils/io.py 2024-06-14 16:20:08 UTC (rev 9767)
+++ trunk/docutils/docutils/io.py 2024-06-15 12:08:27 UTC (rev 9768)
@@ -554,12 +554,20 @@
class BinaryFileOutput(FileOutput):
"""
A version of docutils.io.FileOutput which writes to a binary file.
+
+ Deprecated. Use `FileOutput` (works with `bytes` since Docutils 0.20).
+ Will be removed in Docutils 0.24.
"""
- # Used by core.publish_cmdline_to_binary() which in turn is used by
- # tools/rst2odt.py but not by core.rst2odt().
+ # Used by core.publish_cmdline_to_binary() which is also deprecated.
mode = 'wb'
+ def __init__(self, *args, **kwargs):
+ warnings.warn('"BinaryFileOutput" is obsoleted by "FileOutput"'
+ ' and will be removed in Docutils 0.24.',
+ DeprecationWarning, stacklevel=2)
+ super().__init__(*args, **kwargs)
+
class StringInput(Input):
"""Input from a `str` or `bytes` instance."""
Modified: trunk/docutils/tools/rst2odt.py
===================================================================
--- trunk/docutils/tools/rst2odt.py 2024-06-14 16:20:08 UTC (rev 9767)
+++ trunk/docutils/tools/rst2odt.py 2024-06-15 12:08:27 UTC (rev 9768)
@@ -14,7 +14,7 @@
except Exception:
pass
-from docutils.core import publish_cmdline_to_binary, default_description
+from docutils.core import publish_cmdline, default_description
from docutils.writers.odf_odt import Writer, Reader
@@ -24,5 +24,4 @@
writer = Writer()
reader = Reader()
-output = publish_cmdline_to_binary(reader=reader, writer=writer,
- description=description)
+output = publish_cmdline(reader=reader, writer=writer, description=description)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-18 07:44:43
|
Revision: 9769
http://sourceforge.net/p/docutils/code/9769
Author: milde
Date: 2024-06-18 07:44:41 +0000 (Tue, 18 Jun 2024)
Log Message:
-----------
Deprecate "parser_name" argument of `readers.Reader.__init__()`.
Instead, the "parser" argument accepts now a parser name as well as
a `parsers.Parser` instance.
Also change some boolean values from `1` to `True`.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/readers/__init__.py
trunk/docutils/docutils/readers/pep.py
trunk/docutils/test/functional/tests/pep_html.py
Added Paths:
-----------
trunk/docutils/test/test_readers/test__init__.py
Removed Paths:
-------------
trunk/docutils/test/test_readers/test_get_reader_class.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-15 12:08:27 UTC (rev 9768)
+++ trunk/docutils/HISTORY.txt 2024-06-18 07:44:41 UTC (rev 9769)
@@ -77,6 +77,10 @@
- Renamed `normalized_role_options()` to `normalized_role_options()`
(it is now also used for directive options).
+* docutils/readers/__init__.py:
+
+ - Deprecate "parser_name" argument of `Reader.__init__()`.
+
* docutils/transforms/frontmatter.py
- Update `DocInfo` to work with corrected element categories.
Modified: trunk/docutils/docutils/readers/__init__.py
===================================================================
--- trunk/docutils/docutils/readers/__init__.py 2024-06-15 12:08:27 UTC (rev 9768)
+++ trunk/docutils/docutils/readers/__init__.py 2024-06-18 07:44:41 UTC (rev 9769)
@@ -9,6 +9,7 @@
__docformat__ = 'reStructuredText'
from importlib import import_module
+import warnings
from docutils import utils, parsers, Component
from docutils.transforms import universal
@@ -38,6 +39,9 @@
"""
Initialize the Reader instance.
+ :parser: A parser instance or name (an instance will be created).
+ :parser_name: deprecated, use "parser".
+
Several instance attributes are defined with dummy initial values.
Subclasses may use these attributes as they wish.
"""
@@ -46,8 +50,15 @@
"""A `parsers.Parser` instance shared by all doctrees. May be left
unspecified if the document source determines the parser."""
- if parser is None and parser_name:
- self.set_parser(parser_name)
+ if isinstance(parser, str):
+ self.set_parser(parser)
+ if parser_name is not None:
+ warnings.warn('Argument "parser_name" will be removed '
+ 'in Docutils 2.0.\n'
+ ' Specify parser name in the "parser" argument.',
+ DeprecationWarning, stacklevel=2)
+ if self.parser is None:
+ self.set_parser(parser_name)
self.source = None
"""`docutils.io` IO object, source of input data."""
Modified: trunk/docutils/docutils/readers/pep.py
===================================================================
--- trunk/docutils/docutils/readers/pep.py 2024-06-15 12:08:27 UTC (rev 9768)
+++ trunk/docutils/docutils/readers/pep.py 2024-06-18 07:44:41 UTC (rev 9769)
@@ -8,7 +8,6 @@
__docformat__ = 'reStructuredText'
-
from docutils.readers import standalone
from docutils.transforms import peps, frontmatter
from docutils.parsers import rst
@@ -37,12 +36,18 @@
transforms.extend([peps.Headers, peps.Contents, peps.TargetNotes])
return transforms
- settings_default_overrides = {'pep_references': 1, 'rfc_references': 1}
+ settings_default_overrides = {'pep_references': True,
+ 'rfc_references': True}
inliner_class = rst.states.Inliner
def __init__(self, parser=None, parser_name=None):
- """`parser` should be ``None``."""
- if parser is None:
+ """`parser` should be ``None``, `parser_name` is ignored.
+
+ The default parser is "rst" with PEP-specific settings
+ (since Docutils 0.3). Since Docutils 0.22, `parser` is ignored,
+ if it is a `str` instance.
+ """
+ if parser is None or isinstance(parser, str):
parser = rst.Parser(rfc2822=True, inliner=self.inliner_class())
- standalone.Reader.__init__(self, parser, '')
+ super().__init__(parser)
Modified: trunk/docutils/test/functional/tests/pep_html.py
===================================================================
--- trunk/docutils/test/functional/tests/pep_html.py 2024-06-15 12:08:27 UTC (rev 9768)
+++ trunk/docutils/test/functional/tests/pep_html.py 2024-06-18 07:44:41 UTC (rev 9769)
@@ -8,8 +8,8 @@
settings_overrides = {
'python_home': "http://www.python.org",
'pep_home': "http://www.python.org/peps",
- 'no_random': 1,
- 'cloak_email_addresses': 1,
+ 'no_random': True,
+ 'cloak_email_addresses': True,
# local copy of default stylesheet:
'stylesheet_path': 'functional/input/data/html4css1.css',
}
Added: trunk/docutils/test/test_readers/test__init__.py
===================================================================
--- trunk/docutils/test/test_readers/test__init__.py (rev 0)
+++ trunk/docutils/test/test_readers/test__init__.py 2024-06-18 07:44:41 UTC (rev 9769)
@@ -0,0 +1,78 @@
+#! /usr/bin/env python3
+
+# $Id$
+# Author: grubert abadger1999
+# Maintainer: doc...@li...
+# Copyright: This module has been placed in the public domain.
+
+"""Test the "docutils.readers" module."""
+
+from pathlib import Path
+import sys
+import unittest
+
+# Prepend the "docutils root" to the Python library path
+# so we import the local `docutils` and `test` packages.
+# ensure `test` package can be loaded also if not running as __main__
+# (required by ``python -m unittest``
+DOCUTILS_ROOT = Path(__file__).resolve().parents[2]
+if str(DOCUTILS_ROOT) not in sys.path:
+ sys.path.insert(0, str(DOCUTILS_ROOT))
+
+from docutils import parsers, readers # noqa: E402
+
+
+class ReaderTests(unittest.TestCase):
+
+ def test__init__(self):
+ # Initialization also instantiates a parser, if one is specified.
+ reader = readers.Reader()
+ self.assertEqual(reader.parser, None)
+ # The parser can be specified via its name
+ reader = readers.Reader('rst')
+ self.assertTrue(isinstance(reader.parser, parsers.rst.Parser),
+ f'should be Parser instance, not {reader.parser!r}')
+ # or passed as instance
+ parser = parsers.rst.Parser()
+ reader = readers.Reader(parser)
+ self.assertEqual(reader.parser, parser)
+ # # the second argument `parser_name` is deprecated
+ with self.assertWarnsRegex(
+ DeprecationWarning,
+ 'Specify parser name in the "parser" argument.'):
+ reader = readers.Reader(parser_name='rst')
+ self.assertTrue(isinstance(reader.parser, parsers.rst.Parser))
+ # if both arguments are specified, `parser` has precedence:
+ with self.assertWarns(DeprecationWarning):
+ reader = readers.Reader(parser, parser_name='null')
+ self.assertEqual(reader.parser, parser)
+
+ # __init__() is inherited or called by the standard readers:
+ reader = readers.get_reader_class('standalone')('null')
+ self.assertTrue(isinstance(reader, readers.standalone.Reader))
+ self.assertTrue(isinstance(reader.parser, parsers.null.Parser))
+
+ reader = readers.get_reader_class('pep')()
+ self.assertTrue(isinstance(reader, readers.pep.Reader))
+ # the "pep" reader uses the "rst" parser with special settings
+ self.assertTrue(isinstance(reader.parser, parsers.rst.Parser))
+
+
+class GetReaderClassTestCase(unittest.TestCase):
+
+ def test_registered_reader(self):
+ reader_class = readers.get_reader_class('pep')
+ self.assertEqual(reader_class, readers.pep.Reader)
+
+ def test_bogus_reader(self):
+ with self.assertRaises(ImportError):
+ readers.get_reader_class('nope')
+
+ def test_local_reader(self):
+ # requires local-reader.py in `test` package
+ reader_class = readers.get_reader_class('test.local-reader')
+ self.assertEqual(reader_class.supported, ('dummy', ))
+
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: trunk/docutils/test/test_readers/test__init__.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Deleted: trunk/docutils/test/test_readers/test_get_reader_class.py
===================================================================
--- trunk/docutils/test/test_readers/test_get_reader_class.py 2024-06-15 12:08:27 UTC (rev 9768)
+++ trunk/docutils/test/test_readers/test_get_reader_class.py 2024-06-18 07:44:41 UTC (rev 9769)
@@ -1,44 +0,0 @@
-#! /usr/bin/env python3
-
-# $Id$
-# Author: grubert abadger1999
-# Maintainer: doc...@li...
-# Copyright: This module has been placed in the public domain.
-
-"""
-test get_reader_class
-"""
-
-from pathlib import Path
-import sys
-import unittest
-
-# Prepend the "docutils root" to the Python library path
-# so we import the local `docutils` and `test` packages.
-# ensure `test` package can be loaded also if not running as __main__
-# (required by ``python -m unittest``
-DOCUTILS_ROOT = Path(__file__).resolve().parents[2]
-if str(DOCUTILS_ROOT) not in sys.path:
- sys.path.insert(0, str(DOCUTILS_ROOT))
-
-from docutils.readers import get_reader_class # noqa: E402
-
-
-class GetReaderClassTestCase(unittest.TestCase):
-
- def test_registered_reader(self):
- get_reader_class('pep')
- # raises ImportError on failure
-
- def test_bogus_reader(self):
- with self.assertRaises(ImportError):
- get_reader_class('nope')
-
- def test_local_reader(self):
- # requires local-reader.py in `test` package
- get_reader_class('test.local-reader')
- # raises ImportError on failure
-
-
-if __name__ == '__main__':
- unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-18 07:44:53
|
Revision: 9770
http://sourceforge.net/p/docutils/code/9770
Author: milde
Date: 2024-06-18 07:44:50 +0000 (Tue, 18 Jun 2024)
Log Message:
-----------
Unify arguments for component name and instance in core.py.
Allow a string value (component name or alias) in the
"reader", "parser", and "writer" arguments of `Publisher.__init__()`
and the `publish_*()` convenience functions.
Warn about the pending removal of the "reader_name",
"parser_name", and "writer_name" function arguments.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/core.py
trunk/docutils/test/test_publisher.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-18 07:44:41 UTC (rev 9769)
+++ trunk/docutils/HISTORY.txt 2024-06-18 07:44:50 UTC (rev 9770)
@@ -30,6 +30,9 @@
* docutils/core.py
- Removed `Publisher.setup_option_parser()` (internal, obsolete).
+ - Allow a string value (component name or alias) in the
+ "reader", "parser", and "writer" arguments of `Publisher.__init__()`
+ and the `publish_*()` convenience functions.
* docutils/frontend.py
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-06-18 07:44:41 UTC (rev 9769)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-06-18 07:44:50 UTC (rev 9770)
@@ -152,6 +152,11 @@
(obsoleted by the `"writer" setting`_ since Docutils 0.18)
in Docutils 2.0.
+* Remove the "reader_name", "parser_name", and "writer_name" arguments of
+ `core.Publisher.__init__()` and the `core.publish_*()` convenience
+ functions in Docutils 2.0. Since Docutils 0.22, you may use "reader",
+ "parser", and "writer" arguments for component names as well as instances.
+
* Revise the `String I/O`__ interface used by the `publish_string()`
and `publish_from_doctree()` publisher convenience functions.
(In Python 3, name and behaviour no longer match.)
Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py 2024-06-18 07:44:41 UTC (rev 9769)
+++ trunk/docutils/docutils/core.py 2024-06-18 07:44:50 UTC (rev 9770)
@@ -22,7 +22,7 @@
import warnings
from docutils import (__version__, __version_details__, SettingsSpec,
- io, utils, readers, writers)
+ io, utils, readers, parsers, writers)
from docutils.frontend import OptionParser
from docutils.readers import doctree
@@ -38,11 +38,23 @@
destination=None, destination_class=io.FileOutput,
settings=None):
"""
- Initial setup. If any of `reader`, `parser`, or `writer` are not
- specified, ``set_components()`` or the corresponding ``set_...()``
- method should be called with component names
- (`set_reader` sets the parser as well).
+ Initial setup.
+
+ The components `reader`, `parser`, or `writer` should all be
+ specified, either as instances or via their names.
"""
+ # get component instances from their names:
+ if isinstance(reader, str):
+ reader = readers.get_reader_class(reader)(parser)
+ if isinstance(parser, str):
+ if isinstance(reader, readers.Reader):
+ if reader.parser is None:
+ reader.set_parser(parser)
+ parser = reader.parser
+ else:
+ parser = parsers.get_parser_class(parser)()
+ if isinstance(writer, str):
+ writer = writers.get_writer_class(writer)()
self.document = None
"""The document tree (`docutils.nodes` objects)."""
@@ -56,13 +68,6 @@
self.writer = writer
"""A `docutils.writers.Writer` instance."""
- for component in 'reader', 'parser', 'writer':
- assert not isinstance(getattr(self, component), str), (
- 'passed string "%s" as "%s" parameter; pass an instance, '
- 'or use the "%s_name" parameter instead (in '
- 'docutils.core.publish_* convenience functions).'
- % (getattr(self, component), component, component))
-
self.source = source
"""The source of input data, a `docutils.io.Input` instance."""
@@ -82,11 +87,18 @@
self._stderr = io.ErrorOutput()
- def set_reader(self, reader_name, parser, parser_name):
- """Set `self.reader` by name."""
- reader_class = readers.get_reader_class(reader_name)
+ def set_reader(self, reader, parser=None, parser_name=None):
+ """Set `self.reader` by name.
+
+ The "paser_name" argument is deprecated,
+ use "parser" with parser name or instance.
+ """
+ reader_class = readers.get_reader_class(reader)
self.reader = reader_class(parser, parser_name)
- self.parser = self.reader.parser
+ if self.reader.parser is not None:
+ self.parser = self.reader.parser
+ elif self.parser is not None:
+ self.reader.parser = self.parser
def set_writer(self, writer_name):
"""Set `self.writer` by name."""
@@ -94,6 +106,10 @@
self.writer = writer_class()
def set_components(self, reader_name, parser_name, writer_name):
+ warnings.warn('`Publisher.set_components()` will be removed in '
+ 'Docutils 2.0. Specify component names '
+ 'at instantiation.',
+ PendingDeprecationWarning, stacklevel=2)
if self.reader is None:
self.set_reader(reader_name, self.parser, parser_name)
if self.parser is None:
@@ -371,9 +387,9 @@
# Chain several args as input and use --output or redirection for output:
# argparser.add_argument('source', nargs='+')
#
-def publish_cmdline(reader=None, reader_name='standalone',
- parser=None, parser_name='restructuredtext',
- writer=None, writer_name='pseudoxml',
+def publish_cmdline(reader=None, reader_name=None,
+ parser=None, parser_name=None,
+ writer=None, writer_name=None,
settings=None, settings_spec=None,
settings_overrides=None, config_section=None,
enable_exit_status=True, argv=None,
@@ -392,8 +408,13 @@
- `description`: Program description, output for the "--help" option
(along with command-line option descriptions).
"""
+ # The "*_name" arguments are deprecated.
+ _name_arg_warning(reader_name, parser_name, writer_name)
+ # The default is only used if both arguments are empty
+ reader = reader or reader_name or 'standalone'
+ parser = parser or parser_name or 'restructuredtext'
+ writer = writer or writer_name or 'pseudoxml'
publisher = Publisher(reader, parser, writer, settings=settings)
- publisher.set_components(reader_name, parser_name, writer_name)
output = publisher.publish(
argv, usage, description, settings_spec, settings_overrides,
config_section=config_section, enable_exit_status=enable_exit_status)
@@ -402,9 +423,9 @@
def publish_file(source=None, source_path=None,
destination=None, destination_path=None,
- reader=None, reader_name='standalone',
- parser=None, parser_name='restructuredtext',
- writer=None, writer_name='pseudoxml',
+ reader=None, reader_name=None,
+ parser=None, parser_name=None,
+ writer=None, writer_name=None,
settings=None, settings_spec=None, settings_overrides=None,
config_section=None, enable_exit_status=False):
"""
@@ -414,6 +435,9 @@
Parameters: see `publish_programmatically()`.
"""
+ # The "*_name" arguments are deprecated.
+ _name_arg_warning(reader_name, parser_name, writer_name)
+ # The default is set in publish_programmatically().
output, publisher = publish_programmatically(
source_class=io.FileInput, source=source, source_path=source_path,
destination_class=io.FileOutput,
@@ -429,9 +453,9 @@
def publish_string(source, source_path=None, destination_path=None,
- reader=None, reader_name='standalone',
- parser=None, parser_name='restructuredtext',
- writer=None, writer_name='pseudoxml',
+ reader=None, reader_name=None,
+ parser=None, parser_name=None,
+ writer=None, writer_name=None,
settings=None, settings_spec=None,
settings_overrides=None, config_section=None,
enable_exit_status=False):
@@ -444,7 +468,8 @@
the return value is a `bytes` instance (unless `output_encoding`_ is
"unicode", cf. `docutils.io.StringOutput.write()`).
- Parameters: see `publish_programmatically()`.
+ Parameters: see `publish_programmatically()` or
+ https://docutils.sourceforge.io/docs/api/publisher.html#publish-string
This function is provisional because in Python 3 name and behaviour
no longer match.
@@ -452,6 +477,9 @@
.. _output_encoding:
https://docutils.sourceforge.io/docs/user/config.html#output-encoding
"""
+ # The "*_name" arguments are deprecated.
+ _name_arg_warning(reader_name, parser_name, writer_name)
+ # The default is set in publish_programmatically().
output, publisher = publish_programmatically(
source_class=io.StringInput, source=source, source_path=source_path,
destination_class=io.StringOutput,
@@ -468,9 +496,9 @@
def publish_parts(source, source_path=None, source_class=io.StringInput,
destination_path=None,
- reader=None, reader_name='standalone',
- parser=None, parser_name='restructuredtext',
- writer=None, writer_name='pseudoxml',
+ reader=None, reader_name=None,
+ parser=None, parser_name=None,
+ writer=None, writer_name=None,
settings=None, settings_spec=None,
settings_overrides=None, config_section=None,
enable_exit_status=False):
@@ -490,6 +518,9 @@
__ https://docutils.sourceforge.io/docs/api/publisher.html#publish-parts
"""
+ # The "*_name" arguments are deprecated.
+ _name_arg_warning(reader_name, parser_name, writer_name)
+ # The default is set in publish_programmatically().
output, publisher = publish_programmatically(
source=source, source_path=source_path, source_class=source_class,
destination_class=io.StringOutput,
@@ -506,8 +537,8 @@
def publish_doctree(source, source_path=None,
source_class=io.StringInput,
- reader=None, reader_name='standalone',
- parser=None, parser_name='restructuredtext',
+ reader=None, reader_name=None,
+ parser=None, parser_name=None,
settings=None, settings_spec=None,
settings_overrides=None, config_section=None,
enable_exit_status=False):
@@ -516,6 +547,9 @@
Parameters: see `publish_programmatically()`.
"""
+ # The "*_name" arguments are deprecated.
+ _name_arg_warning(reader_name, parser_name, None)
+ # The default is set in publish_programmatically().
_output, publisher = publish_programmatically(
source=source, source_path=source_path,
source_class=source_class,
@@ -523,7 +557,7 @@
destination_class=io.NullOutput,
reader=reader, reader_name=reader_name,
parser=parser, parser_name=parser_name,
- writer=None, writer_name='null',
+ writer='null', writer_name=None,
settings=settings, settings_spec=settings_spec,
settings_overrides=settings_overrides, config_section=config_section,
enable_exit_status=enable_exit_status)
@@ -531,7 +565,7 @@
def publish_from_doctree(document, destination_path=None,
- writer=None, writer_name='pseudoxml',
+ writer=None, writer_name=None,
settings=None, settings_spec=None,
settings_overrides=None, config_section=None,
enable_exit_status=False):
@@ -554,13 +588,13 @@
This function is provisional because in Python 3 name and behaviour
of the `io.StringOutput` class no longer match.
"""
- reader = doctree.Reader(parser_name='null')
- publisher = Publisher(reader, None, writer,
+ # The "writer_name" argument is deprecated.
+ _name_arg_warning(None, None, writer_name)
+ publisher = Publisher(reader=doctree.Reader(),
+ writer=writer or writer_name or 'pseudoxml',
source=io.DocTreeInput(document),
destination_class=io.StringOutput,
settings=settings)
- if not writer and writer_name:
- publisher.set_writer(writer_name)
publisher.process_programmatic_settings(
settings_spec, settings_overrides, config_section)
publisher.set_destination(None, destination_path)
@@ -611,6 +645,15 @@
return output
+def _name_arg_warning(*name_args):
+ for component, name_arg in zip(('reader', 'parser', 'writer'), name_args):
+ if name_arg is not None:
+ warnings.warn(f'Argument "{component}_name" will be removed in '
+ f'Docutils 2.0. Specify {component} name '
+ f'in the "{component}" argument.',
+ PendingDeprecationWarning, stacklevel=3)
+
+
def publish_programmatically(source_class, source, source_path,
destination_class, destination, destination_path,
reader, reader_name,
@@ -625,7 +668,8 @@
Return the output (as `str` or `bytes`, depending on `destination_class`,
writer, and the "output_encoding" setting) and the Publisher object.
- Applications should not need to call this function directly. If it does
+ Internal:
+ Applications should not call this function directly. If it does
seem to be necessary to call this function directly, please write to the
Docutils-develop mailing list
<https://docutils.sourceforge.io/docs/user/mailing-lists.html#docutils-develop>.
@@ -675,20 +719,20 @@
output; optional. Used for determining relative paths (stylesheets,
source links, etc.).
- * `reader`: A `docutils.readers.Reader` object.
+ * `reader`: A `docutils.readers.Reader` instance, name, or alias.
+ Default: "standalone".
- * `reader_name`: Name or alias of the Reader class to be instantiated if
- no `reader` supplied.
+ * `reader_name`: Deprecated. Use `reader`.
- * `parser`: A `docutils.parsers.Parser` object.
+ * `parser`: A `docutils.parsers.Parser` instance, name, or alias.
+ Default: "restructuredtext".
- * `parser_name`: Name or alias of the Parser class to be instantiated if
- no `parser` supplied.
+ * `parser_name`: Deprecated. Use `parser`.
- * `writer`: A `docutils.writers.Writer` object.
+ * `writer`: A `docutils.writers.Writer` instance, name, or alias.
+ Default: "pseudoxml".
- * `writer_name`: Name or alias of the Writer class to be instantiated if
- no `writer` supplied.
+ * `writer_name`: Deprecated. Use `writer`.
* `settings`: A runtime settings (`docutils.frontend.Values`) object, for
dotted-attribute access to runtime settings. It's the end result of the
@@ -712,10 +756,13 @@
* `enable_exit_status`: Boolean; enable exit status at end of processing?
"""
+ reader = reader or reader_name or 'standalone'
+ parser = parser or parser_name or 'restructuredtext'
+ writer = writer or writer_name or 'pseudoxml'
+
publisher = Publisher(reader, parser, writer, settings=settings,
source_class=source_class,
destination_class=destination_class)
- publisher.set_components(reader_name, parser_name, writer_name)
publisher.process_programmatic_settings(
settings_spec, settings_overrides, config_section)
publisher.set_source(source, source_path)
@@ -728,7 +775,7 @@
# cf. https://packaging.python.org/en/latest/specifications/entry-points/
def rst2something(writer, documenttype, doc_path=''):
- # Helper function for the common parts of rst2...
+ # Helper function for the common parts of `rst2*()`
# writer: writer name
# documenttype: output document type
# doc_path: documentation path (relative to the documentation root)
@@ -738,7 +785,7 @@
f'<https://docutils.sourceforge.io/docs/{doc_path}>. '
+ default_description)
locale.setlocale(locale.LC_ALL, '')
- publish_cmdline(writer_name=writer, description=description)
+ publish_cmdline(writer=writer, description=description)
def rst2html():
Modified: trunk/docutils/test/test_publisher.py
===================================================================
--- trunk/docutils/test/test_publisher.py 2024-06-18 07:44:41 UTC (rev 9769)
+++ trunk/docutils/test/test_publisher.py 2024-06-18 07:44:50 UTC (rev 9770)
@@ -7,7 +7,6 @@
"""
Test the `Publisher` facade and the ``publish_*`` convenience functions.
"""
-import os.path
import pickle
from pathlib import Path
import sys
@@ -19,11 +18,13 @@
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import docutils
-from docutils import core, nodes
+from docutils import core, nodes, parsers, readers, writers
+import docutils.parsers.null
# DATA_ROOT is ./test/data/ from the docutils root
-DATA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
+DATA_ROOT = Path(__file__).parent / 'data'
+
test_document = """\
Test Document
=============
@@ -64,14 +65,106 @@
class PublisherTests(unittest.TestCase):
+ def test__init__(self):
+ reader = readers.standalone.Reader()
+ parser = parsers.null.Parser()
+ writer = writers.null.Writer()
+ # arguments may be component instances ...
+ publisher = core.Publisher(reader, parser, writer)
+ self.assertEqual(publisher.reader, reader)
+ self.assertEqual(publisher.parser, parser)
+ self.assertEqual(publisher.writer, writer)
+ # ... or names
+ publisher = core.Publisher('standalone', parser, writer)
+ self.assertTrue(isinstance(publisher.reader,
+ readers.standalone.Reader))
+ self.assertEqual(publisher.parser, parser)
+ self.assertEqual(publisher.writer, writer)
+
+ publisher = core.Publisher(reader, 'rst', writer)
+ self.assertEqual(publisher.reader, reader)
+ self.assertTrue(isinstance(publisher.parser, parsers.rst.Parser))
+ self.assertEqual(publisher.writer, writer)
+
+ publisher = core.Publisher(reader, parser, 'latex')
+ self.assertEqual(publisher.reader, reader)
+ self.assertEqual(publisher.parser, parser)
+ self.assertTrue(isinstance(publisher.writer, writers.latex2e.Writer))
+
+ def test_set_reader(self):
+ publisher = core.Publisher(parser='null')
+ parser = parsers.null.Parser()
+ # "parser" argument can be an instance or name
+ publisher.set_reader('standalone', parser='rst')
+ self.assertTrue(isinstance(publisher.parser, parsers.rst.Parser))
+ # synchronize parser attributes of publisher and reader:
+ self.assertEqual(publisher.reader.parser, publisher.parser)
+ # the "parser_name" argument is deprecated;
+ with self.assertWarnsRegex(DeprecationWarning,
+ 'Argument "parser_name" will be removed'):
+ publisher.set_reader('standalone', parser=None, parser_name='rst')
+ self.assertTrue(isinstance(publisher.parser, parsers.rst.Parser))
+ self.assertEqual(publisher.reader.parser, publisher.parser)
+ # "parser" takes precedence
+ with self.assertWarns(DeprecationWarning):
+ publisher.set_reader('standalone', parser, parser_name='rst')
+ self.assertEqual(publisher.parser, parser)
+ self.assertEqual(publisher.reader.parser, publisher.parser)
+ # if there is no other parser specified, use self.parser
+ publisher.set_reader('standalone')
+ self.assertTrue(isinstance(publisher.parser, parsers.null.Parser))
+ self.assertEqual(publisher.reader.parser, publisher.parser)
+
+ def test_set_components(self):
+ publisher = core.Publisher()
+ reader = readers.standalone.Reader()
+ parser = parsers.null.Parser()
+ writer = writers.null.Writer()
+ # set components from names
+ with self.assertWarnsRegex(PendingDeprecationWarning,
+ 'set_components.* will be removed'):
+ publisher.set_components('pep', 'rst', 'odt')
+ self.assertTrue(isinstance(publisher.reader, readers.pep.Reader))
+ self.assertTrue(isinstance(publisher.parser, parsers.rst.Parser))
+ self.assertTrue(isinstance(publisher.writer, writers.odf_odt.Writer))
+ # but don't overwrite registered component instances
+ publisher = core.Publisher(reader, parser, writer)
+ with self.assertWarns(PendingDeprecationWarning):
+ publisher.set_components('standalone', 'xml', 'odt')
+ self.assertEqual(publisher.reader, reader)
+ self.assertEqual(publisher.parser, parser)
+ self.assertEqual(publisher.writer, writer)
+
+ def test_set_destination(self):
+ # Exit if `_destination` and `output` settings conflict.
+ publisher = core.Publisher()
+ publisher.get_settings(output='out_name', _destination='out_name')
+ # no conflict if both have same value:
+ publisher.set_destination()
+ # no conflict if both are overridden:
+ publisher.set_destination(destination_path='winning_dest')
+ # ... also sets _destination to 'winning_dest' -> conflict
+ with self.assertRaises(SystemExit):
+ publisher.set_destination()
+
+
+class ConvenienceFunctionTests(unittest.TestCase):
+ maxDiff = None
+
settings = {'_disable_config': True,
'datestamp': False}
+ def test_publish_cmdline(self):
+ # the "*_name" arguments will be removed
+ with self.assertWarns(PendingDeprecationWarning):
+ core.publish_cmdline(writer_name='null',
+ argv=[(DATA_ROOT/'include.txt').as_posix()],
+ settings_overrides={'traceback': True})
+
def test_input_error_handling(self):
# core.publish_cmdline(argv=['nonexisting/path'])
# exits with a short message, if `traceback` is False,
-
- # pass IOErrors to calling application if `traceback` is True
+ # pass IOErrors to calling application if `traceback` is True:
with self.assertRaises(IOError):
core.publish_cmdline(argv=['nonexisting/path'],
settings_overrides={'traceback': True})
@@ -79,22 +172,10 @@
def test_output_error_handling(self):
# pass IOErrors to calling application if `traceback` is True
with self.assertRaises(docutils.io.OutputError):
- core.publish_cmdline(argv=[os.path.join(DATA_ROOT, 'include.txt'),
+ core.publish_cmdline(argv=[(DATA_ROOT/'include.txt').as_posix(),
'nonexisting/path'],
settings_overrides={'traceback': True})
- def test_set_destination(self):
- # Exit if `_destination` and `output` settings conflict.
- publisher = core.Publisher()
- publisher.get_settings(output='out_name', _destination='out_name')
- # no conflict if both have same value:
- publisher.set_destination()
- # no conflict if both are overridden:
- publisher.set_destination(destination_path='winning_dest')
- # ... also sets _destination to 'winning_dest' -> conflict
- with self.assertRaises(SystemExit):
- publisher.set_destination()
-
def test_destination_output_conflict(self):
# Exit if positional argument and --output option conflict.
settings = {'output': 'out_name'}
@@ -126,8 +207,7 @@
self.assertTrue(output.endswith('Grüße\n'))
def test_publish_string_output_encoding(self):
- settings = dict(self.settings)
- settings['output_encoding'] = 'latin1'
+ settings = self.settings | {'output_encoding': 'latin1'}
settings['output_encoding_error_handler'] = 'replace'
source = 'Grüß → dich'
expected = ('<document source="<string>">\n'
@@ -147,26 +227,37 @@
'warning_stream': ''}
with self.assertRaisesRegex(docutils.utils.SystemMessage,
'The ODT writer returns `bytes` '):
- core.publish_string('test', writer_name='odt',
+ core.publish_string('test', writer='odt',
settings_overrides=settings)
+ def test_publish_string_deprecation_warning(self):
+ """The "*_name" arguments are deprecated."""
+ source = 'test → me'
+ with self.assertWarns(PendingDeprecationWarning):
+ output = core.publish_string(source, writer_name='xml')
+ # ... but should still set the corresponding component:
+ self.assertTrue(output.decode('utf-8').startswith(
+ '<?xml version="1.0" encoding="utf-8"?>'))
+
class PublishDoctreeTestCase(unittest.TestCase, docutils.SettingsSpec):
settings_default_overrides = {
'_disable_config': True,
- 'warning_stream': docutils.io.NullOutput()}
+ 'warning_stream': docutils.io.NullOutput(),
+ 'output_encoding': 'unicode'}
def test_publish_doctree(self):
# Test `publish_doctree` and `publish_from_doctree`.
# Produce the document tree.
- doctree = core.publish_doctree(
- source=test_document, reader_name='standalone',
- parser_name='restructuredtext', settings_spec=self,
- settings_overrides={'expose_internals':
- ['refnames', 'do_not_expose'],
- 'report_level': 5})
+ with self.assertWarns(PendingDeprecationWarning):
+ doctree = core.publish_doctree(
+ source=test_document, reader='standalone',
+ parser_name='restructuredtext', settings_spec=self,
+ settings_overrides={'expose_internals':
+ ['refnames', 'do_not_expose'],
+ 'report_level': 5})
self.assertTrue(isinstance(doctree, nodes.document))
# Confirm that transforms have been applied (in this case, the
@@ -182,7 +273,8 @@
doctree.do_not_expose = 'test'
# Write out the document:
output = core.publish_from_doctree(
- doctree, writer_name='pseudoxml',
+ doctree,
+ writer='pseudoxml',
settings_spec=self,
settings_overrides={'expose_internals':
['refnames', 'do_not_expose'],
@@ -192,8 +284,8 @@
# Test publishing parts using document as the source.
parts = core.publish_parts(
- reader_name='doctree', source_class=docutils.io.DocTreeInput,
- source=doctree, source_path='test', writer_name='html',
+ reader='doctree', source_class=docutils.io.DocTreeInput,
+ source=doctree, source_path='test', writer='html',
settings_spec=self)
self.assertTrue(isinstance(parts, dict))
@@ -203,8 +295,8 @@
# Produce the document tree.
doctree = core.publish_doctree(
source=test_document,
- reader_name='standalone',
- parser_name='restructuredtext',
+ reader='standalone',
+ parser='restructuredtext',
settings_spec=self)
self.assertTrue(isinstance(doctree, nodes.document))
@@ -229,10 +321,12 @@
self.assertTrue(isinstance(doctree_zombie, nodes.document))
# Write out the document:
- output = core.publish_from_doctree(doctree_zombie,
- writer_name='pseudoxml',
- settings_spec=self)
- self.assertEqual(pseudoxml_output, output.decode())
+ with self.assertWarnsRegex(PendingDeprecationWarning,
+ 'Argument "writer_name" will be removed '):
+ output = core.publish_from_doctree(doctree_zombie,
+ writer_name='pseudoxml',
+ settings_spec=self)
+ self.assertEqual(pseudoxml_output, output)
if __name__ == '__main__':
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-06-18 08:00:15
|
Revision: 9771
http://sourceforge.net/p/docutils/code/9771
Author: milde
Date: 2024-06-18 08:00:10 +0000 (Tue, 18 Jun 2024)
Log Message:
-----------
Update calls to the `core.publish_*()` convenience functions.
Don't call the internal auxilliary function `publish_programmatically()`
from the "example.py" usage example.
Use "reader", "parser", "writer" instad of
"reader_name", "parser_name", "writer_name".
Simplifies code and avoids `PendingDeprecationsWarning`s.
Modified Paths:
--------------
trunk/docutils/docutils/__main__.py
trunk/docutils/docutils/examples.py
trunk/docutils/test/functional/tests/compact_lists.py
trunk/docutils/test/functional/tests/dangerous.py
trunk/docutils/test/functional/tests/field_name_limit.py
trunk/docutils/test/functional/tests/footnotes_html5.py
trunk/docutils/test/functional/tests/latex_babel.py
trunk/docutils/test/functional/tests/latex_cornercases.py
trunk/docutils/test/functional/tests/latex_cyrillic.py
trunk/docutils/test/functional/tests/latex_docinfo.py
trunk/docutils/test/functional/tests/latex_leavevmode.py
trunk/docutils/test/functional/tests/latex_literal_block.py
trunk/docutils/test/functional/tests/latex_literal_block_fancyvrb.py
trunk/docutils/test/functional/tests/latex_literal_block_listings.py
trunk/docutils/test/functional/tests/latex_literal_block_verbatim.py
trunk/docutils/test/functional/tests/latex_literal_block_verbatimtab.py
trunk/docutils/test/functional/tests/latex_memoir.py
trunk/docutils/test/functional/tests/math_output_html.py
trunk/docutils/test/functional/tests/math_output_latex.py
trunk/docutils/test/functional/tests/math_output_mathjax.py
trunk/docutils/test/functional/tests/math_output_mathml.py
trunk/docutils/test/functional/tests/misc_rst_html4css1.py
trunk/docutils/test/functional/tests/misc_rst_html5.py
trunk/docutils/test/functional/tests/pep_html.py
trunk/docutils/test/functional/tests/standalone_rst_docutils_xml.py
trunk/docutils/test/functional/tests/standalone_rst_html4css1.py
trunk/docutils/test/functional/tests/standalone_rst_html5.py
trunk/docutils/test/functional/tests/standalone_rst_html5_tuftig.py
trunk/docutils/test/functional/tests/standalone_rst_latex.py
trunk/docutils/test/functional/tests/standalone_rst_manpage.py
trunk/docutils/test/functional/tests/standalone_rst_pseudoxml.py
trunk/docutils/test/functional/tests/standalone_rst_s5_html_1.py
trunk/docutils/test/functional/tests/standalone_rst_s5_html_2.py
trunk/docutils/test/functional/tests/standalone_rst_xetex.py
trunk/docutils/test/functional/tests/standalone_xml_xml.py
trunk/docutils/test/functional/tests/xetex_cyrillic.py
trunk/docutils/test/test_dependencies.py
trunk/docutils/test/test_parsers/test_get_parser_class.py
trunk/docutils/test/test_traversals.py
trunk/docutils/test/test_utils/test_math/test_tex2mathml_extern.py
trunk/docutils/test/test_writers/test_docutils_xml.py
trunk/docutils/test/test_writers/test_html4css1_misc.py
trunk/docutils/test/test_writers/test_html4css1_parts.py
trunk/docutils/test/test_writers/test_html4css1_template.py
trunk/docutils/test/test_writers/test_html5_polyglot_misc.py
trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
trunk/docutils/test/test_writers/test_html5_template.py
trunk/docutils/test/test_writers/test_latex2e.py
trunk/docutils/test/test_writers/test_latex2e_misc.py
trunk/docutils/test/test_writers/test_manpage.py
trunk/docutils/test/test_writers/test_null.py
trunk/docutils/test/test_writers/test_odt.py
trunk/docutils/test/test_writers/test_pseudoxml.py
trunk/docutils/test/test_writers/test_s5.py
trunk/docutils/tools/buildhtml.py
trunk/docutils/tools/dev/profile_docutils.py
trunk/docutils/tools/rst2html.py
trunk/docutils/tools/rst2html4.py
trunk/docutils/tools/rst2html5.py
trunk/docutils/tools/rst2latex.py
trunk/docutils/tools/rst2s5.py
trunk/docutils/tools/rst2xetex.py
trunk/docutils/tools/rst2xml.py
trunk/docutils/tools/rstpep2html.py
Modified: trunk/docutils/docutils/__main__.py
===================================================================
--- trunk/docutils/docutils/__main__.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/docutils/__main__.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -75,9 +75,9 @@
CliSettingsSpec.settings_default_overrides = args.__dict__
try:
- publish_cmdline(reader_name=args.reader,
- parser_name=args.parser,
- writer_name=args.writer,
+ publish_cmdline(reader=args.reader,
+ parser=args.parser,
+ writer=args.writer,
settings_spec=CliSettingsSpec,
description=description,
argv=remainder)
Modified: trunk/docutils/docutils/examples.py
===================================================================
--- trunk/docutils/docutils/examples.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/docutils/examples.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -46,7 +46,7 @@
parts = core.publish_parts(
source=input_string, source_path=source_path,
destination_path=destination_path,
- writer_name='html', settings_overrides=overrides)
+ writer='html', settings_overrides=overrides)
return parts
@@ -74,7 +74,7 @@
return fragment
-def internals(input_string, source_path=None, destination_path=None,
+def internals(source, source_path=None, destination_path=None,
input_encoding='unicode', settings_overrides=None):
"""
Return the document tree and publisher, for exploring Docutils internals.
@@ -81,19 +81,20 @@
Parameters: see `html_parts()`.
"""
- if settings_overrides:
- overrides = settings_overrides.copy()
- else:
- overrides = {}
- overrides['input_encoding'] = input_encoding
- output, pub = core.publish_programmatically(
- source_class=io.StringInput, source=input_string,
- source_path=source_path,
- destination_class=io.NullOutput, destination=None,
- destination_path=destination_path,
- reader=None, reader_name='standalone',
- parser=None, parser_name='restructuredtext',
- writer=None, writer_name='null',
- settings=None, settings_spec=None, settings_overrides=overrides,
- config_section=None, enable_exit_status=None)
- return pub.writer.document, pub
+ if settings_overrides is None:
+ settings_overrides = {}
+ overrides = settings_overrides | {'input_encoding': input_encoding}
+
+ publisher = core.Publisher('standalone', 'rst', 'null',
+ source_class=io.StringInput,
+ destination_class=io.NullOutput)
+ publisher.process_programmatic_settings(settings_spec=None,
+ settings_overrides=overrides,
+ config_section=None)
+ publisher.set_source(source, source_path)
+ publisher.publish()
+ return publisher.document, publisher
+
+
+if __name__ == '__main__':
+ print(internals('test')[0])
Modified: trunk/docutils/test/functional/tests/compact_lists.py
===================================================================
--- trunk/docutils/test/functional/tests/compact_lists.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/compact_lists.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "compact_lists.html"
# Keyword parameters passed to publish_file()
-writer_name = "html4"
+writer = "html4"
settings_overrides = {
# location of stylesheets (relative to ``docutils/test/``)
'stylesheet_dirs': ('functional/input/data', ),
Modified: trunk/docutils/test/functional/tests/dangerous.py
===================================================================
--- trunk/docutils/test/functional/tests/dangerous.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/dangerous.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "dangerous.html"
# Keyword parameters passed to publish_file()
-writer_name = "html4"
+writer = "html4"
settings_overrides = {
'file_insertion_enabled': False,
'raw_enabled': False,
Modified: trunk/docutils/test/functional/tests/field_name_limit.py
===================================================================
--- trunk/docutils/test/functional/tests/field_name_limit.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/field_name_limit.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "field_name_limit.html"
# Keyword parameters passed to publish_file()
-writer_name = "html4"
+writer = "html4"
settings_overrides = {
'field_name_limit': 0, # no limit
'docinfo_xform': False,
Modified: trunk/docutils/test/functional/tests/footnotes_html5.py
===================================================================
--- trunk/docutils/test/functional/tests/footnotes_html5.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/footnotes_html5.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "footnotes_html5.html"
# Keyword parameters passed to publish_file()
-writer_name = "html5"
+writer = "html5"
settings_overrides = {
'sectsubtitle_xform': True,
'footnote_references': 'superscript',
Modified: trunk/docutils/test/functional/tests/latex_babel.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_babel.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_babel.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_babel.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'legacy_column_widths': False,
'use_latex_citations': True,
Modified: trunk/docutils/test/functional/tests/latex_cornercases.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_cornercases.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_cornercases.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_cornercases.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'legacy_column_widths': False,
'use_latex_citations': True,
Modified: trunk/docutils/test/functional/tests/latex_cyrillic.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_cyrillic.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_cyrillic.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "cyrillic.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'font_encoding': 'T1,T2A',
'stylesheet': 'cmlgc',
Modified: trunk/docutils/test/functional/tests/latex_docinfo.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_docinfo.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_docinfo.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_docinfo.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'use_latex_docinfo': 1,
'legacy_column_widths': False,
Modified: trunk/docutils/test/functional/tests/latex_leavevmode.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_leavevmode.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_leavevmode.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_leavevmode.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'smart_quotes': True,
'legacy_column_widths': True,
Modified: trunk/docutils/test/functional/tests/latex_literal_block.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_literal_block.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_literal_block.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_literal_block.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'stylesheet': 'docutils',
'legacy_column_widths': True,
Modified: trunk/docutils/test/functional/tests/latex_literal_block_fancyvrb.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_literal_block_fancyvrb.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_literal_block_fancyvrb.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_literal_block_fancyvrb.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'stylesheet': 'docutils',
'legacy_column_widths': True,
Modified: trunk/docutils/test/functional/tests/latex_literal_block_listings.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_literal_block_listings.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_literal_block_listings.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_literal_block_listings.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'stylesheet': 'docutils',
'legacy_column_widths': True,
Modified: trunk/docutils/test/functional/tests/latex_literal_block_verbatim.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_literal_block_verbatim.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_literal_block_verbatim.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_literal_block_verbatim.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'stylesheet': 'docutils',
'legacy_column_widths': True,
Modified: trunk/docutils/test/functional/tests/latex_literal_block_verbatimtab.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_literal_block_verbatimtab.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_literal_block_verbatimtab.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_literal_block_verbatimtab.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'stylesheet': 'docutils',
'legacy_column_widths': True,
Modified: trunk/docutils/test/functional/tests/latex_memoir.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_memoir.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/latex_memoir.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "latex_memoir.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'use_latex_docinfo': 1,
'documentclass': "memoir",
Modified: trunk/docutils/test/functional/tests/math_output_html.py
===================================================================
--- trunk/docutils/test/functional/tests/math_output_html.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/math_output_html.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "math_output_html.html"
# Keyword parameters passed to publish_file()
-writer_name = "html4"
+writer = "html4"
settings_overrides = {
'math_output': 'HTML math.css',
# location of stylesheets (relative to ``docutils/test/``)
Modified: trunk/docutils/test/functional/tests/math_output_latex.py
===================================================================
--- trunk/docutils/test/functional/tests/math_output_latex.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/math_output_latex.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "math_output_latex.html"
# Keyword parameters passed to publish_file()
-writer_name = "html4"
+writer = "html4"
settings_overrides = {
'math_output': 'latex',
# location of stylesheets (relative to ``docutils/test/``)
Modified: trunk/docutils/test/functional/tests/math_output_mathjax.py
===================================================================
--- trunk/docutils/test/functional/tests/math_output_mathjax.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/math_output_mathjax.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "math_output_mathjax.html"
# Keyword parameters passed to publish_file()
-writer_name = "html4"
+writer = "html4"
settings_overrides = {
'math_output': 'MathJax /usr/share/javascript/mathjax/MathJax.js',
# location of stylesheets (relative to ``docutils/test/``)
Modified: trunk/docutils/test/functional/tests/math_output_mathml.py
===================================================================
--- trunk/docutils/test/functional/tests/math_output_mathml.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/math_output_mathml.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "math_output_mathml.html"
# Keyword parameters passed to publish_file()
-writer_name = "html5"
+writer = "html5"
settings_overrides = {
'math_output': 'MathML',
# location of stylesheets (relative to ``docutils/test/``)
Modified: trunk/docutils/test/functional/tests/misc_rst_html4css1.py
===================================================================
--- trunk/docutils/test/functional/tests/misc_rst_html4css1.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/misc_rst_html4css1.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "misc_rst_html4css1.html"
# Keyword parameters passed to publish_file()
-writer_name = "html4css1"
+writer = "html4css1"
settings_overrides = {
# test for encoded attribute value in optional stylesheet name,
# 'stylesheet' setting, values are used verbatim
Modified: trunk/docutils/test/functional/tests/misc_rst_html5.py
===================================================================
--- trunk/docutils/test/functional/tests/misc_rst_html5.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/misc_rst_html5.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "misc_rst_html5.html"
# Keyword parameters passed to publish_file()
-writer_name = "html5"
+writer = "html5"
settings_overrides = {
# location of stylesheets (relative to ``docutils/test/``)
'stylesheet_dirs': ('functional/input/data', ),
Modified: trunk/docutils/test/functional/tests/pep_html.py
===================================================================
--- trunk/docutils/test/functional/tests/pep_html.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/pep_html.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,8 +3,8 @@
test_destination = "pep_html.html"
# Keyword parameters passed to publish_file()
-reader_name = "pep"
-writer_name = "pep_html"
+reader = "pep"
+writer = "pep_html"
settings_overrides = {
'python_home': "http://www.python.org",
'pep_home': "http://www.python.org/peps",
Modified: trunk/docutils/test/functional/tests/standalone_rst_docutils_xml.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_docutils_xml.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_docutils_xml.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "standalone_rst_docutils_xml.xml"
# Keyword parameters passed to publish_file()
-writer_name = "docutils_xml"
+writer = "docutils_xml"
settings_overrides = {
'sectsubtitle_xform': True,
# format output with indents and newlines
Modified: trunk/docutils/test/functional/tests/standalone_rst_html4css1.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_html4css1.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_html4css1.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "standalone_rst_html4css1.html"
# Keyword parameters passed to publish_file()
-writer_name = "html4css1"
+writer = "html4css1"
settings_overrides = {
'sectsubtitle_xform': True,
# location of stylesheets (relative to ``docutils/test/``)
Modified: trunk/docutils/test/functional/tests/standalone_rst_html5.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_html5.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_html5.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "standalone_rst_html5.html"
# Keyword parameters passed to publish_file()
-writer_name = "html5"
+writer = "html5"
settings_overrides = {
'sectsubtitle_xform': True,
# "smart" quotes:
Modified: trunk/docutils/test/functional/tests/standalone_rst_html5_tuftig.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_html5_tuftig.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_html5_tuftig.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "rst_html5_tuftig.html"
# Keyword parameters passed to publish_file()
-writer_name = "html5"
+writer = "html5"
settings_overrides = {
'sectsubtitle_xform': True,
'smart_quotes': 'yes',
Modified: trunk/docutils/test/functional/tests/standalone_rst_latex.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_latex.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_latex.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "standalone_rst_latex.tex"
# Keyword parameters passed to publish_file()
-writer_name = "latex"
+writer = "latex"
settings_overrides = {
'sectsubtitle_xform': True,
# use "smartquotes" transition:
Modified: trunk/docutils/test/functional/tests/standalone_rst_manpage.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_manpage.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_manpage.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "standalone_rst_manpage.man"
# Keyword parameters passed to publish_file()
-writer_name = "manpage"
+writer = "manpage"
settings_overrides = {
'sectsubtitle_xform': True,
}
Modified: trunk/docutils/test/functional/tests/standalone_rst_pseudoxml.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_pseudoxml.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_pseudoxml.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "standalone_rst_pseudoxml.txt"
# Keyword parameters passed to publish_file()
-writer_name = "pseudoxml"
+writer = "pseudoxml"
settings_overrides = {
'sectsubtitle_xform': True,
# enable INFO-level system messages in this test:
Modified: trunk/docutils/test/functional/tests/standalone_rst_s5_html_1.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_s5_html_1.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_s5_html_1.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = 'standalone_rst_s5_html_1.html'
# Keyword parameters passed to publish_file:
-writer_name = 's5_html'
+writer = 's5_html'
settings_overrides = {
'sectsubtitle_xform': True,
'theme_url': 'ui/small-black', # don't attempt to copy theme files
Modified: trunk/docutils/test/functional/tests/standalone_rst_s5_html_2.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_s5_html_2.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_s5_html_2.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = 'standalone_rst_s5_html_2.html'
# Keyword parameters passed to publish_file:
-writer_name = 's5_html'
+writer = 's5_html'
settings_overrides = {
'sectsubtitle_xform': True,
# local copy of default stylesheet:
Modified: trunk/docutils/test/functional/tests/standalone_rst_xetex.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_rst_xetex.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_rst_xetex.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "standalone_rst_xetex.tex"
# Keyword parameters passed to publish_file()
-writer_name = "xetex"
+writer = "xetex"
settings_overrides = {
'sectsubtitle_xform': True,
# use "smartquotes" transition:
Modified: trunk/docutils/test/functional/tests/standalone_xml_xml.py
===================================================================
--- trunk/docutils/test/functional/tests/standalone_xml_xml.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/standalone_xml_xml.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -8,6 +8,6 @@
test_destination = 'standalone_rst_docutils_xml.xml'
# Keyword parameters passed to publish_file()
-parser_name = 'xml'
-writer_name = 'xml'
+parser = 'xml'
+writer = 'xml'
settings_overrides = {'indents': True}
Modified: trunk/docutils/test/functional/tests/xetex_cyrillic.py
===================================================================
--- trunk/docutils/test/functional/tests/xetex_cyrillic.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/functional/tests/xetex_cyrillic.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -3,7 +3,7 @@
test_destination = "xetex-cyrillic.tex"
# Keyword parameters passed to publish_file()
-writer_name = "xetex"
+writer = "xetex"
settings_overrides = {
'language_code': 'ru',
# use "smartquotes" transition:
Modified: trunk/docutils/test/test_dependencies.py
===================================================================
--- trunk/docutils/test/test_dependencies.py 2024-06-18 07:44:50 UTC (rev 9770)
+++ trunk/docutils/test/test_dependencies.py 2024-06-18 08:00:10 UTC (rev 9771)
@@ -76,7 +76,7 @@
if PIL and os.path.exists('../docs/user/rst/images/'):
keys += ['figure-image']
expected = [paths[key] for key in keys]
- record, output = self.get_record(writer_name='xml')
+ record, output = self.get_record(writer='xml')
# the order of the files is arbitrary
self.assertEqual(sorted(expected), sorted(record))
@@ -89,7 +89,7 @@
settings = {'stylesheet_path': None,
'stylesheet': None,
'report_level': 4} # drop warning if PIL is missing
- record, output = self.get_record(writer_name='html5',
+ record, output = self.get_record(writer='html5',
settings_overrides=settings)
# the order of the files is arbitrary
self.assertEqual(sorted(expected), sorted(record),
@@ -105,7 +105,7 @@
keys += ['figure-image']
expected = [paths[key] for key in keys]
record, output = self.get_record(
- writer_name='latex',
+ writer='latex',
settings_overrides=latex_settings_overwrites)
# the order of the files is arbitrary
self.assertEqual(sorted(expected), sorted(record),
@@ -123,22 +123,22 @@
'stylesheet': None}
settings.update(latex_settings_overwrites)
settings['embed_stylesheet'] = False
- record, output = self.get_record(writer_name='html',
+ record, output = self.get_record(writer='html',
settings_overrides=settings)
self.assertTrue(stylesheet not in record,
f'{stylesheet!r} should not be in {record!r}')
- record, output = self.get_record(writer_name='latex',
+ record, output = self.get_record(writer='latex',
settings_overrides=settings)
self.assertTrue(stylesheet not in record,
f'{stylesheet!r} should not be in {record!r}')
settings['embed_stylesheet'] = True
- record, output = self.get_record(writer_name='html',
+ record, output = self.get_record(writer='html',
settings_overrides=settings)
self.assertTrue(stylesheet in record,
f'{stylesheet!r} should be in {record!r}')
settings['embed_stylesheet'] = True
- record, output = self.get_record(writer_n...
[truncated message content] |
|
From: <mi...@us...> - 2024-06-29 21:23:12
|
Revision: 9772
http://sourceforge.net/p/docutils/code/9772
Author: milde
Date: 2024-06-29 21:23:01 +0000 (Sat, 29 Jun 2024)
Log Message:
-----------
Change the default input encoding from ``None`` to "utf-8" in io.py.
Fixup for [r9749]. See also [bugs:#490].
Change the default encoding from ``None`` (auto-detect) to "utf-8"
in `docutils.io.Input` and `docutils.io.FileInput`.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/io.py
trunk/docutils/test/test_io.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2024-06-18 08:00:10 UTC (rev 9771)
+++ trunk/docutils/HISTORY.txt 2024-06-29 21:23:01 UTC (rev 9772)
@@ -40,6 +40,10 @@
and ``--output-encoding``.
- Change the default input encoding from ``None`` (auto-detect) to "utf-8".
+* docutils/io.py
+
+ - Change the default input encoding from ``None`` (auto-detect) to "utf-8".
+
* docutils/nodes.py
- Raise TypeError if the "rawsource" argument in `Element.__init__()`
Modified: trunk/docutils/docutils/io.py
===================================================================
--- trunk/docutils/docutils/io.py 2024-06-18 08:00:10 UTC (rev 9771)
+++ trunk/docutils/docutils/io.py 2024-06-29 21:23:01 UTC (rev 9772)
@@ -82,7 +82,7 @@
default_source_path = None
- def __init__(self, source=None, source_path=None, encoding=None,
+ def __init__(self, source=None, source_path=None, encoding='utf-8',
error_handler='strict'):
self.encoding = encoding
"""Text encoding for the input source."""
@@ -357,7 +357,7 @@
Input for single, simple file-like objects.
"""
def __init__(self, source=None, source_path=None,
- encoding=None, error_handler='strict',
+ encoding='utf-8', error_handler='strict',
autoclose=True, mode='r'):
"""
:Parameters:
Modified: trunk/docutils/test/test_io.py
===================================================================
--- trunk/docutils/test/test_io.py 2024-06-18 08:00:10 UTC (rev 9771)
+++ trunk/docutils/test/test_io.py 2024-06-29 21:23:01 UTC (rev 9772)
@@ -74,7 +74,8 @@
"""Cases where the comparison fails."""
# stream.encoding is None:
self.assertEqual(None,
- du_io.check_encoding(du_io.FileInput(), 'ascii'))
+ du_io.check_encoding(du_io.FileInput(encoding=None),
+ 'ascii'))
# stream.encoding does not exist:
self.assertEqual(None, du_io.check_encoding(BBuf, 'ascii'))
# encoding is None or empty string:
@@ -102,11 +103,14 @@
# default input encoding will change to UTF-8 in Docutils 0.22
source = '\ufeffdata\n\ufeff blah\n'
expected = 'data\n\ufeff blah\n' # only leading ZWNBSP removed
- input = du_io.StringInput(source=source.encode('utf-16-be'))
+ input = du_io.StringInput(source=source.encode('utf-16-be'),
+ encoding=None)
self.assertEqual(expected, input.read())
- input = du_io.StringInput(source=source.encode('utf-16-le'))
+ input = du_io.StringInput(source=source.encode('utf-16-le'),
+ encoding=None)
self.assertEqual(expected, input.read())
- input = du_io.StringInput(source=source.encode('utf-8'))
+ input = du_io.StringInput(source=source.encode('utf-8'),
+ encoding=None)
self.assertEqual(expected, input.read())
# With `str` input all ZWNBSPs are still there.
input = du_io.StringInput(source=source)
@@ -117,7 +121,7 @@
.. -*- coding: ascii -*-
data
blah
-""")
+""", encoding=None)
data = input.read() # noqa: F841
self.assertEqual('ascii', input.successful_encoding)
input = du_io.StringInput(source=b"""\
@@ -124,7 +128,7 @@
#! python
# -*- coding: ascii -*-
print("hello world")
-""")
+""", encoding=None)
data = input.read() # noqa: F841
self.assertEqual('ascii', input.successful_encoding)
input = du_io.StringInput(source=b"""\
@@ -257,7 +261,8 @@
"""Drop optional BOM from utf-8 encoded files.
"""
source = du_io.FileInput(
- source_path=os.path.join(DATA_ROOT, 'utf-8-sig.txt'))
+ source_path=os.path.join(DATA_ROOT, 'utf-8-sig.txt'),
+ encoding=None)
self.assertTrue(source.read().startswith('Grüße'))
def test_bom_utf_16(self):
@@ -265,7 +270,8 @@
"""
# Assert correct decoding, BOM is gone.
source = du_io.FileInput(
- source_path=os.path.join(DATA_ROOT, 'utf-16-le-sig.txt'))
+ source_path=os.path.join(DATA_ROOT, 'utf-16-le-sig.txt'),
+ encoding=None)
self.assertTrue(source.read().startswith('Grüße'))
def test_coding_slug(self):
@@ -272,7 +278,8 @@
"""Use self-declared encoding.
"""
source = du_io.FileInput(
- source_path=os.path.join(DATA_ROOT, 'latin2.txt'))
+ source_path=os.path.join(DATA_ROOT, 'latin2.txt'),
+ encoding=None)
self.assertTrue(source.read().endswith('škoda\n'))
def test_fallback_utf8(self):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mi...@us...> - 2024-07-28 10:50:15
|
Revision: 9780
http://sourceforge.net/p/docutils/code/9780
Author: milde
Date: 2024-07-28 10:50:12 +0000 (Sun, 28 Jul 2024)
Log Message:
-----------
Announce change to `<footnote>` Doctree element content definition.
The first child, `<label>` will become mandatory to match the
definition/documentation/implementation of footnotes in the
reStructuredText parser and the definition of the `<citation>`
element.
Cf. [bugs:#489]
Modified Paths:
--------------
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docs/ref/doctree.txt
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2024-07-28 10:50:05 UTC (rev 9779)
+++ trunk/docutils/RELEASE-NOTES.txt 2024-07-28 10:50:12 UTC (rev 9780)
@@ -51,8 +51,11 @@
in Docutils 1.0.
* Use the ``%tbl.table.att`` parameter entity instead of ``%bodyatt``
- to customize the <table> element's attribute list in Docutils 1.0.
+ to customize the <table> element's attribute list in Docutils 1.0.
+* The <footnote> element's first child (<label>) will become mandatory
+ in Docutils 1.0.
+
.. _refname attribute: docs/ref/doctree.html#refname
Writers
Modified: trunk/docutils/docs/ref/doctree.txt
===================================================================
--- trunk/docutils/docs/ref/doctree.txt 2024-07-28 10:50:05 UTC (rev 9779)
+++ trunk/docutils/docs/ref/doctree.txt 2024-07-28 10:50:12 UTC (rev 9780)
@@ -1992,7 +1992,7 @@
`%structure.model`_ parameter entities in their content models
may contain <footnote>.
-:Children: <footnote> elements begin with an optional `\<label>`_
+:Children: <footnote> elements begin with an optional [#]_ `\<label>`_
and contain `body elements`_. ::
(label?, (%body.elements;)+)
@@ -2004,6 +2004,8 @@
directly includes <footnote>. The `%structure.model`_
parameter entity indirectly includes <footnote>.
+.. [#] The footnote label will become mandatory in Docutils 1.0.
+
Examples
--------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|