[docutils:patches] #114 rst2odt_prepstyles.py: Port to ElementTree
"Günter Milde" via Docutils-develop <[email protected]>
| Newsgroups | gmane.text.docutils.devel |
|---|---|
| Message-ID | </p/docutils/patches/114/31e48ded272792f29f7ca9bf6408ff9173f7f1e5.patches@docutils.p.sourceforge.net> |
> lxml is not part of standard library, while xml.etree is.
I see. Thanks for the clarification.
When I try to use the patched script on a copy of `docutils/writers/odf_odt/styles.odt`, I get an error:
/usr/local/src/docutils-git-svn/docutils/tools/rst2odt_prepstyles.py styles.odt
Traceback (most recent call last):
File "/usr/local/src/docutils-git-svn/docutils/tools/rst2odt_prepstyles.py", line 78, in <module>
main()
File "/usr/local/src/docutils-git-svn/docutils/tools/rst2odt_prepstyles.py", line 74, in main
prepstyle(filename)
File "/usr/local/src/docutils-git-svn/docutils/tools/rst2odt_prepstyles.py", line 48, in prepstyle
for attr in el.attrib.keys():
RuntimeError: dictionary changed size during iteration
BTW, the non-patched version fails with:
~~~
/usr/local/src/docutils-git-svn/docutils/tools/rst2odt_prepstyles.py styles.odt
Traceback (most recent call last):
File "/usr/local/src/docutils-git-svn/docutils/tools/rst2odt_prepstyles.py", line 67, in <module>
main()
File "/usr/local/src/docutils-git-svn/docutils/tools/rst2odt_prepstyles.py", line 63, in main
prepstyle(filename)
File "/usr/local/src/docutils-git-svn/docutils/tools/rst2odt_prepstyles.py", line 49, in prepstyle
zout.writestr(item, zin.read(item.filename))
File "/usr/lib/python3.9/zipfile.py", line 1802, in writestr
with self.open(zinfo, mode='w') as dest:
File "/usr/lib/python3.9/zipfile.py", line 1505, in open
return self._open_to_write(zinfo, force_zip64=force_zip64)
File "/usr/lib/python3.9/zipfile.py", line 1600, in _open_to_write
self.fp.write(zinfo.FileHeader(zip64))
TypeError: write() argument must be str, not bytes
Exception ignored in: <function ZipFile.__del__ at 0x7f7e5b555700>
Traceback (most recent call last):
File "/usr/lib/python3.9/zipfile.py", line 1807, in __del__
self.close()
File "/usr/lib/python3.9/zipfile.py", line 1825, in close
self._write_end_record()
File "/usr/lib/python3.9/zipfile.py", line 1919, in _write_end_record
self.fp.write(endrec)
TypeError: write() argument must be str, not bytes
~~~
---
** [patches:#114] rst2odt_prepstyles.py: Port to ElementTree**
**Status:** pending-remind
**Group:** None
**Created:** Mon Aug 05, 2013 02:12 PM UTC by Michael Schutte
**Last Updated:** Fri Apr 21, 2023 08:52 PM UTC
**Owner:** nobody
**Attachments:**
- [rst2odt_prepstyles-elementtree.diff](https://sourceforge.net/p/docutils/patches/114/attachment/rst2odt_prepstyles-elementtree.diff) (1.8 kB; text/x-patch)
rst2odt_prepstyles.py currently uses lxml to parse, modify and write XML. The attached patch makes it use ElementTree instead, which has been part of Python's standard library since 2.5.
---
Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/docutils/patches/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/patches/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.