[docutils:bugs] #494 rst2odt: TypeError with --stylesheet=styles.xml
Günter Milde via Docutils-develop <[email protected]> Wed, 30 Jul 2025 08:58:29 -0000
| Newsgroups | gmane.text.docutils.devel |
|---|---|
| Message-ID | </p/docutils/bugs/494/81bc38c8235882ac455f935f3e8a696f4185215f.bugs@docutils.p.sourceforge.net> |
- **status**: open-fixed --> closed-fixed
- **Comment**:
The bug is fixed in Docutils 0.22 released 2025-07-29.
Thank you for reporting.
---
**[bugs:#494] rst2odt: TypeError with --stylesheet=styles.xml**
**Status:** closed-fixed
**Labels:** ODT Writer
**Created:** Fri Oct 04, 2024 10:52 AM UTC by Paul Kishimoto
**Last Updated:** Fri Nov 29, 2024 08:29 AM UTC
**Owner:** nobody
The documentation (page “ODT Writer for Docutils”, section [“4 Styles and Classes”](https://docutils.sourceforge.io/docs/user/odt.html#styles-and-classes)) states:
> Note that with the `--stylesheet` command line option, you can use either `styles.odt` or `styles.xml`, as described below. Use of `styles.odt` is recommended over `styles.xml`.
With Python 3.12.3 and docutils 0.21.2, it appears that styles.xml is not usable, either from the command line or programmatically.
To reproduce from the command line:
1. A file `empty.rst`.
2. A file `styles.xml`, extracted from any valid ODT archive.
3. Run `$ docutils --writer=odt --stylesheet=styles.xml --traceback empty.rst >bug.odt`
The output is:
```
Traceback (most recent call last):
File "/home/khaeru/.venv/3.12/bin/docutils", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/khaeru/.venv/3.12/lib/python3.12/site-packages/docutils/__main__.py", line 78, in main
publish_cmdline(reader_name=args.reader,
File "/home/khaeru/.venv/3.12/lib/python3.12/site-packages/docutils/core.py", line 402, in publish_cmdline
output = publisher.publish(
^^^^^^^^^^^^^^^^^^
File "/home/khaeru/.venv/3.12/lib/python3.12/site-packages/docutils/core.py", line 237, in publish
output = self.writer.write(self.document, self.destination)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/khaeru/.venv/3.12/lib/python3.12/site-packages/docutils/writers/__init__.py", line 80, in write
self.translate()
File "/home/khaeru/.venv/3.12/lib/python3.12/site-packages/docutils/writers/odf_odt/__init__.py", line 510, in translate
self.visitor.retrieve_styles(self.EXTENSION)
File "/home/khaeru/.venv/3.12/lib/python3.12/site-packages/docutils/writers/odf_odt/__init__.py", line 941, in retrieve_styles
self.dom_stylesheetcontent = etree.fromstring(
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/xml/etree/ElementTree.py", line 1335, in XML
parser.feed(text)
TypeError: a bytes-like object is required, not 'NoneType'
```
The same error occurs when calling:
```python
from docutils.core import publish_string
publish_string(
source="",
writer_name="odt",
settings_overrides={"stylesheet": "styles.xml"},
)
```
This seems to be a consequence of `ODFTranslator.retrieve_styles()` ([here](https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/docutils/writers/odf_odt/__init__.py#l925)), wherein:
1. `s2 = None` is set.
2. If the provided path has extension `extension` (e.g. ".odt"), it is overwritten with content read from `content.xml` in the archive; **but** if the provided path has extension ".xml", it remains `None`.
3. This value is assigned to `self.str_stylesheetcontent` and then parsed with `etree.tostring()`.
Also, the parsed `self.dom_stylesheetcontent` does not appear to be used anywhere else in the module. It's not clear why it is needed.
---
Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/docutils/bugs/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.