diff --git a/.github/workflows/test_linux.yml b/.github/workflows/test_linux.yml index 346b8db5..30b50db2 100644 --- a/.github/workflows/test_linux.yml +++ b/.github/workflows/test_linux.yml @@ -14,7 +14,7 @@ jobs: testLinux: strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11"] runs-on: ubuntu-latest steps: - name: Python Setup diff --git a/CREDITS.md b/CREDITS.md index 489495dd..d792ce6f 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -40,7 +40,6 @@ The following libraries are dependencies of novelWriter: * [Qt5](https://www.qt.io) by Qt Company * [PyQt5](https://www.riverbankcomputing.com/software/pyqt) by Riverbank Computing -* [lxml](https://lxml.de) by Martijn Faassen * [Enchant](https://abiword.github.io/enchant) by Dom Lachowicz * [PyEnchant](https://pyenchant.github.io/pyenchant) by Dimitri Merejkowsky diff --git a/docs/source/int_source.rst b/docs/source/int_source.rst index 3ae3bfaf..3630b537 100644 --- a/docs/source/int_source.rst +++ b/docs/source/int_source.rst @@ -46,13 +46,10 @@ format of the main project file. Everything else is handled with standard Python The following Python packages are needed to run novelWriter: * ``PyQt5`` – needed for connecting with the Qt5 libraries. -* ``lxml`` – needed for full XML support. * ``PyEnchant`` – needed for spell checking (optional). PyQt/Qt should be at least 5.10, but ideally 5.13 or higher for all features to work. For instance, -searching using regular expressions with full Unicode support requires 5.13. There is no known -minimum version requirement for package ``lxml``, but the code was originally written with 4.2, -which is therefore set as the minimum. It may work on lower versions. You have to test it. +searching using regular expressions with full Unicode support requires 5.13. If you want spell checking, you must install the ``PyEnchant`` package. The spell check library must be at least 3.0 to work with Windows. On Linux, 2.0 also works fine. diff --git a/novelwriter/__init__.py b/novelwriter/__init__.py index ccc9a333..c85d949b 100644 --- a/novelwriter/__init__.py +++ b/novelwriter/__init__.py @@ -185,12 +185,6 @@ def main(sysArgs=None): ) errorCode |= 0x10 - try: - import lxml # noqa: F401 - except ImportError: - errorData.append("Python module 'lxml' is missing") - errorCode |= 0x20 - if errorData: errApp = QApplication([]) errDlg = QErrorMessage() diff --git a/novelwriter/assets/text/credits_en.htm b/novelwriter/assets/text/credits_en.htm index 80790378..525ffca9 100644 --- a/novelwriter/assets/text/credits_en.htm +++ b/novelwriter/assets/text/credits_en.htm @@ -47,7 +47,6 @@ more contributions are listed on the project's Qt5 by Qt Company
PyQt5 by Riverbank Computing
- lxml by Martijn Faassen
Enchant by Dom Lachowicz
PyEnchant by Dimitri Merejkowsky

diff --git a/novelwriter/common.py b/novelwriter/common.py index 91058fd0..5813ec1e 100644 --- a/novelwriter/common.py +++ b/novelwriter/common.py @@ -23,10 +23,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ +from __future__ import annotations + import json import uuid import hashlib import logging +import xml.etree.ElementTree as ET from pathlib import Path from datetime import datetime @@ -435,6 +438,45 @@ def jsonEncode(data, n=0, nmax=0): return "".join(buffer) +def xmlIndent(tree: ET.Element | ET.ElementTree): + """A modified version of the XML indent function in the standard + library. It behaves more closely to how the one from lxml does. + """ + if isinstance(tree, ET.ElementTree): + tree = tree.getroot() + + indentations = ["\n"] + + def indentChildren(elem, level): + chLevel = level + 1 + try: + chIndent = indentations[chLevel] + except IndexError: + chIndent = indentations[level] + " " + indentations.append(chIndent) + + if elem.text is None: + elem.text = chIndent + + last = None + for child in elem: + if len(child): + indentChildren(child, chLevel) + if child.tail is None: + child.tail = chIndent + last = child + + # Dedent the last child + if last is not None: + last.tail = indentations[level] + + if len(tree): + indentChildren(tree, 0) + tree.tail = "\n" + + return + + # =============================================================================================== # # File and File System Functions # =============================================================================================== # diff --git a/novelwriter/config.py b/novelwriter/config.py index 89019ce4..68f44ec4 100644 --- a/novelwriter/config.py +++ b/novelwriter/config.py @@ -196,7 +196,6 @@ class Config: # Check Python Version self.verPyString = sys.version.split()[0] - self.verPyHexVal = sys.hexversion # Check OS Type self.osType = sys.platform diff --git a/novelwriter/core/projectxml.py b/novelwriter/core/projectxml.py index 581a0ef7..b39356a2 100644 --- a/novelwriter/core/projectxml.py +++ b/novelwriter/core/projectxml.py @@ -26,16 +26,16 @@ along with this program. If not, see . """ import logging +import xml.etree.ElementTree as ET from enum import Enum -from lxml import etree from time import time from pathlib import Path from novelwriter import __version__, __hexversion__ from novelwriter.common import ( checkBool, checkInt, checkString, checkStringNone, formatTimeStamp, - hexToInt, simplified, yesNo + hexToInt, simplified, xmlIndent, yesNo ) from novelwriter.constants import nwFiles @@ -163,7 +163,7 @@ class ProjectXMLReader: logger.debug("Reading project XML") try: - xml = etree.parse(str(self._path)) + xml = ET.parse(str(self._path)) self._state = XMLReadState.NO_ERROR except Exception as exc: @@ -174,7 +174,7 @@ class ProjectXMLReader: backFile = self._path.with_suffix(".bak") if backFile.is_file(): try: - xml = etree.parse(str(backFile)) + xml = ET.parse(str(backFile)) self._state = XMLReadState.PARSED_BACKUP logger.info("Backup project file parsed") except Exception as exc: @@ -500,7 +500,7 @@ class ProjectXMLWriter: tStart = time() logger.debug("Writing project XML") - xRoot = etree.Element("novelWriterXML", attrib={ + xRoot = ET.Element("novelWriterXML", attrib={ "appVersion": str(__version__), "hexVersion": str(__hexversion__), "fileVersion": FILE_VERSION, @@ -515,13 +515,13 @@ class ProjectXMLWriter: "editTime": str(editTime), } - xProject = etree.SubElement(xRoot, "project", attrib=projAttr) + xProject = ET.SubElement(xRoot, "project", attrib=projAttr) self._packSingleValue(xProject, "name", projData.name) self._packSingleValue(xProject, "title", projData.title) self._packSingleValue(xProject, "author", projData.author) # Save Project Settings - xSettings = etree.SubElement(xRoot, "settings") + xSettings = ET.SubElement(xRoot, "settings") self._packSingleValue(xSettings, "doBackup", yesNo(projData.doBackup)) self._packSingleValue(xSettings, "language", projData.language) self._packSingleValue(xSettings, "spellChecking", projData.spellLang, attrib={ @@ -532,11 +532,11 @@ class ProjectXMLWriter: self._packDictKeyValue(xSettings, "titleFormat", projData.titleFormat) # Save Status/Importance - xStatus = etree.SubElement(xSettings, "status") + xStatus = ET.SubElement(xSettings, "status") for label, attrib in projData.itemStatus.pack(): self._packSingleValue(xStatus, "entry", label, attrib=attrib) - xImport = etree.SubElement(xSettings, "importance") + xImport = ET.SubElement(xSettings, "importance") for label, attrib in projData.itemImport.pack(): self._packSingleValue(xImport, "entry", label, attrib=attrib) @@ -547,11 +547,11 @@ class ProjectXMLWriter: "notesWords": str(projData.currCounts[1]), } - xContent = etree.SubElement(xRoot, "content", attrib=contAttr) + xContent = ET.SubElement(xRoot, "content", attrib=contAttr) for item in projContent: - xItem = etree.SubElement(xContent, "item", attrib=item.get("itemAttr", {})) - etree.SubElement(xItem, "meta", attrib=item.get("metaAttr", {})) - xName = etree.SubElement(xItem, "name", attrib=item.get("nameAttr", {})) + xItem = ET.SubElement(xContent, "item", attrib=item.get("itemAttr", {})) + ET.SubElement(xItem, "meta", attrib=item.get("metaAttr", {})) + xName = ET.SubElement(xItem, "name", attrib=item.get("nameAttr", {})) xName.text = item["name"] # Write the XML tree to file @@ -559,9 +559,9 @@ class ProjectXMLWriter: tempFile = saveFile.with_suffix(".tmp") backFile = saveFile.with_suffix(".bak") try: - tempFile.write_bytes(etree.tostring( - xRoot, pretty_print=True, encoding="utf-8", xml_declaration=True - )) + xml = ET.ElementTree(xRoot) + xmlIndent(xml) + xml.write(tempFile, encoding="utf-8", xml_declaration=True) except Exception as exc: self._error = exc return False @@ -587,17 +587,17 @@ class ProjectXMLWriter: def _packSingleValue(self, xParent, name, value, attrib=None): """Pack a single value into an XML element. """ - xItem = etree.SubElement(xParent, name, attrib=attrib) + xItem = ET.SubElement(xParent, name, attrib=attrib or {}) xItem.text = str(value) or "" return def _packDictKeyValue(self, xParent, name, data): """Pack the entries of a dictionary into an XML element. """ - xItem = etree.SubElement(xParent, name) + xItem = ET.SubElement(xParent, name) for key, value in data.items(): if len(key) > 0: - xEntry = etree.SubElement(xItem, "entry", attrib={"key": key}) + xEntry = ET.SubElement(xItem, "entry", attrib={"key": key}) xEntry.text = str(value) or "" return diff --git a/novelwriter/core/toodt.py b/novelwriter/core/toodt.py index 4892d435..40932ec2 100644 --- a/novelwriter/core/toodt.py +++ b/novelwriter/core/toodt.py @@ -27,13 +27,14 @@ along with this program. If not, see . """ import logging +import xml.etree.ElementTree as ET -from lxml import etree from hashlib import sha256 from zipfile import ZipFile from datetime import datetime from novelwriter import __version__ +from novelwriter.common import xmlIndent from novelwriter.constants import nwKeyWords, nwLabels from novelwriter.core.tokenizer import Tokenizer, stripEscape @@ -41,30 +42,27 @@ logger = logging.getLogger(__name__) # Main XML NameSpaces XML_NS = { - "office": "urn:oasis:names:tc:opendocument:xmlns:office:1.0", - "style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0", - "loext": "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0", - "text": "urn:oasis:names:tc:opendocument:xmlns:text:1.0", - "meta": "urn:oasis:names:tc:opendocument:xmlns:meta:1.0", - "fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", - "dc": "http://purl.org/dc/elements/1.1/", -} -MANI_NS = { - "manifest": "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" -} -OFFICE_NS = { - "office": "urn:oasis:names:tc:opendocument:xmlns:office:1.0", + "manifest": "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0", + "office": "urn:oasis:names:tc:opendocument:xmlns:office:1.0", + "style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0", + "loext": "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0", + "text": "urn:oasis:names:tc:opendocument:xmlns:text:1.0", + "meta": "urn:oasis:names:tc:opendocument:xmlns:meta:1.0", + "fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", + "dc": "http://purl.org/dc/elements/1.1/", } +for ns, uri in XML_NS.items(): + ET.register_namespace(ns, uri) -def _mkTag(nsName, tagName, nsMap=XML_NS): +def _mkTag(ns, tag): """Assemble namespace and tag name. """ - theNS = nsMap.get(nsName, "") - if theNS: - return f"{{{theNS}}}{tagName}" - logger.warning("Missing xml namespace '%s'", nsName) - return tagName + uri = XML_NS.get(ns, "") + if uri: + return f"{{{uri}}}{tag}" + logger.warning("Missing xml namespace '%s'", ns) + return tag # Mimetype and Version @@ -97,20 +95,20 @@ class ToOdt(Tokenizer): self._isFlat = isFlat # Flat: .fodt, otherwise .odt - self._dFlat = None # FODT file XML root - self._dCont = None # ODT content.xml root - self._dMeta = None # ODT meta.xml root - self._dStyl = None # ODT styles.xml root + self._dFlat = ET.Element("") # FODT file XML root + self._dCont = ET.Element("") # ODT content.xml root + self._dMeta = ET.Element("") # ODT meta.xml root + self._dStyl = ET.Element("") # ODT styles.xml root - self._xMeta = None # Office meta root - self._xFont = None # Office font face declaration - self._xFnt2 = None # Office font face declaration, secondary - self._xStyl = None # Office styles root - self._xAuto = None # Office auto-styles root - self._xAut2 = None # Office auto-styles root, secondary - self._xMast = None # Office master-styles root - self._xBody = None # Office body root - self._xText = None # Office text root + self._xMeta = ET.Element("") # Office meta root + self._xFont = ET.Element("") # Office font face declaration + self._xFnt2 = ET.Element("") # Office font face declaration, secondary + self._xStyl = ET.Element("") # Office styles root + self._xAuto = ET.Element("") # Office auto-styles root + self._xAut2 = ET.Element("") # Office auto-styles root, secondary + self._xMast = ET.Element("") # Office master-styles root + self._xBody = ET.Element("") # Office body root + self._xText = ET.Element("") # Office text root self._mainPara = {} # User-accessible paragraph styles self._autoPara = {} # Auto-generated paragraph styles @@ -287,16 +285,16 @@ class ToOdt(Tokenizer): tAttr[_mkTag("office", "mimetype")] = X_MIME tFlat = _mkTag("office", "document") - self._dFlat = etree.Element(tFlat, attrib=tAttr, nsmap=XML_NS) + self._dFlat = ET.Element(tFlat, attrib=tAttr) - self._xMeta = etree.SubElement(self._dFlat, _mkTag("office", "meta")) - self._xFont = etree.SubElement(self._dFlat, _mkTag("office", "font-face-decls")) - self._xStyl = etree.SubElement(self._dFlat, _mkTag("office", "styles")) - self._xAuto = etree.SubElement(self._dFlat, _mkTag("office", "automatic-styles")) - self._xMast = etree.SubElement(self._dFlat, _mkTag("office", "master-styles")) - self._xBody = etree.SubElement(self._dFlat, _mkTag("office", "body")) + self._xMeta = ET.SubElement(self._dFlat, _mkTag("office", "meta")) + self._xFont = ET.SubElement(self._dFlat, _mkTag("office", "font-face-decls")) + self._xStyl = ET.SubElement(self._dFlat, _mkTag("office", "styles")) + self._xAuto = ET.SubElement(self._dFlat, _mkTag("office", "automatic-styles")) + self._xMast = ET.SubElement(self._dFlat, _mkTag("office", "master-styles")) + self._xBody = ET.SubElement(self._dFlat, _mkTag("office", "body")) - etree.SubElement(self._xFont, _mkTag("style", "font-face"), attrib=fAttr) + ET.SubElement(self._xFont, _mkTag("style", "font-face"), attrib=fAttr) else: @@ -308,59 +306,59 @@ class ToOdt(Tokenizer): tStyl = _mkTag("office", "document-styles") # content.xml - self._dCont = etree.Element(tCont, attrib=tAttr, nsmap=XML_NS) - self._xFont = etree.SubElement(self._dCont, _mkTag("office", "font-face-decls")) - self._xAuto = etree.SubElement(self._dCont, _mkTag("office", "automatic-styles")) - self._xBody = etree.SubElement(self._dCont, _mkTag("office", "body")) + self._dCont = ET.Element(tCont, attrib=tAttr) + self._xFont = ET.SubElement(self._dCont, _mkTag("office", "font-face-decls")) + self._xAuto = ET.SubElement(self._dCont, _mkTag("office", "automatic-styles")) + self._xBody = ET.SubElement(self._dCont, _mkTag("office", "body")) # meta.xml - self._dMeta = etree.Element(tMeta, attrib=tAttr, nsmap=XML_NS) - self._xMeta = etree.SubElement(self._dMeta, _mkTag("office", "meta")) + self._dMeta = ET.Element(tMeta, attrib=tAttr) + self._xMeta = ET.SubElement(self._dMeta, _mkTag("office", "meta")) # styles.xml - self._dStyl = etree.Element(tStyl, attrib=tAttr, nsmap=XML_NS) - self._xFnt2 = etree.SubElement(self._dStyl, _mkTag("office", "font-face-decls")) - self._xStyl = etree.SubElement(self._dStyl, _mkTag("office", "styles")) - self._xAut2 = etree.SubElement(self._dStyl, _mkTag("office", "automatic-styles")) - self._xMast = etree.SubElement(self._dStyl, _mkTag("office", "master-styles")) + self._dStyl = ET.Element(tStyl, attrib=tAttr) + self._xFnt2 = ET.SubElement(self._dStyl, _mkTag("office", "font-face-decls")) + self._xStyl = ET.SubElement(self._dStyl, _mkTag("office", "styles")) + self._xAut2 = ET.SubElement(self._dStyl, _mkTag("office", "automatic-styles")) + self._xMast = ET.SubElement(self._dStyl, _mkTag("office", "master-styles")) - etree.SubElement(self._xFont, _mkTag("style", "font-face"), attrib=fAttr) - etree.SubElement(self._xFnt2, _mkTag("style", "font-face"), attrib=fAttr) + ET.SubElement(self._xFont, _mkTag("style", "font-face"), attrib=fAttr) + ET.SubElement(self._xFnt2, _mkTag("style", "font-face"), attrib=fAttr) # Finalise # ======== - self._xText = etree.SubElement(self._xBody, _mkTag("office", "text")) + self._xText = ET.SubElement(self._xBody, _mkTag("office", "text")) timeStamp = datetime.now().isoformat(sep="T", timespec="seconds") # Office Meta Data - xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "creation-date")) + xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "creation-date")) xMeta.text = timeStamp - xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "generator")) + xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "generator")) xMeta.text = f"novelWriter/{__version__}" - xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "initial-creator")) + xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "initial-creator")) xMeta.text = self.theProject.data.author - xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "editing-cycles")) + xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "editing-cycles")) xMeta.text = str(self.theProject.data.saveCount) # Format is: PnYnMnDTnHnMnS # https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#duration eT = self.theProject.data.editTime - xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "editing-duration")) + xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "editing-duration")) xMeta.text = f"P{eT//86400:d}DT{eT%86400//3600:d}H{eT%3600//60:d}M{eT%60:d}S" # Dublin Core Meta Data - xMeta = etree.SubElement(self._xMeta, _mkTag("dc", "title")) + xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "title")) xMeta.text = self.theProject.data.title or self.theProject.data.name - xMeta = etree.SubElement(self._xMeta, _mkTag("dc", "date")) + xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "date")) xMeta.text = timeStamp - xMeta = etree.SubElement(self._xMeta, _mkTag("dc", "creator")) + xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "creator")) xMeta.text = self.theProject.data.author self._pageStyles() @@ -506,51 +504,43 @@ class ToOdt(Tokenizer): """Save the data to an .fodt file. """ with open(savePath, mode="wb") as outFile: - outFile.write(etree.tostring( - self._dFlat, - pretty_print=True, - encoding="utf-8", - xml_declaration=True - )) + xml = ET.ElementTree(self._dFlat) + xmlIndent(xml) + xml.write(outFile, encoding="utf-8", xml_declaration=True) return def saveOpenDocText(self, savePath): """Save the data to an .odt file. """ - mMani = _mkTag("manifest", "manifest", nsMap=MANI_NS) - mVers = _mkTag("manifest", "version", nsMap=MANI_NS) - mPath = _mkTag("manifest", "full-path", nsMap=MANI_NS) - mType = _mkTag("manifest", "media-type", nsMap=MANI_NS) - mFile = _mkTag("manifest", "file-entry", nsMap=MANI_NS) + mMani = _mkTag("manifest", "manifest") + mVers = _mkTag("manifest", "version") + mPath = _mkTag("manifest", "full-path") + mType = _mkTag("manifest", "media-type") + mFile = _mkTag("manifest", "file-entry") - xMani = etree.Element(mMani, attrib={mVers: X_VERS}, nsmap=MANI_NS) - etree.SubElement(xMani, mFile, attrib={mPath: "/", mVers: X_VERS, mType: X_MIME}) - etree.SubElement(xMani, mFile, attrib={mPath: "settings.xml", mType: "text/xml"}) - etree.SubElement(xMani, mFile, attrib={mPath: "content.xml", mType: "text/xml"}) - etree.SubElement(xMani, mFile, attrib={mPath: "meta.xml", mType: "text/xml"}) - etree.SubElement(xMani, mFile, attrib={mPath: "styles.xml", mType: "text/xml"}) + xMani = ET.Element(mMani, attrib={mVers: X_VERS}) + ET.SubElement(xMani, mFile, attrib={mPath: "/", mVers: X_VERS, mType: X_MIME}) + ET.SubElement(xMani, mFile, attrib={mPath: "settings.xml", mType: "text/xml"}) + ET.SubElement(xMani, mFile, attrib={mPath: "content.xml", mType: "text/xml"}) + ET.SubElement(xMani, mFile, attrib={mPath: "meta.xml", mType: "text/xml"}) + ET.SubElement(xMani, mFile, attrib={mPath: "styles.xml", mType: "text/xml"}) - oRoot = _mkTag("office", "document-settings", nsMap=OFFICE_NS) - oVers = _mkTag("office", "version", nsMap=OFFICE_NS) - xSett = etree.Element(oRoot, nsmap=OFFICE_NS, attrib={oVers: X_VERS}) + oRoot = _mkTag("office", "document-settings") + oVers = _mkTag("office", "version") + xSett = ET.Element(oRoot, attrib={oVers: X_VERS}) - with ZipFile(savePath, mode="w") as outFile: - outFile.writestr("mimetype", X_MIME) - outFile.writestr("META-INF/manifest.xml", etree.tostring( - xMani, pretty_print=False, encoding="utf-8", xml_declaration=True - )) - outFile.writestr("settings.xml", etree.tostring( - xSett, pretty_print=False, encoding="utf-8", xml_declaration=True - )) - outFile.writestr("content.xml", etree.tostring( - self._dCont, pretty_print=False, encoding="utf-8", xml_declaration=True - )) - outFile.writestr("meta.xml", etree.tostring( - self._dMeta, pretty_print=False, encoding="utf-8", xml_declaration=True - )) - outFile.writestr("styles.xml", etree.tostring( - self._dStyl, pretty_print=False, encoding="utf-8", xml_declaration=True - )) + def putInZip(name, xObj, zipObj): + with zipObj.open(name, mode="w") as fObj: + xml = ET.ElementTree(xObj) + xml.write(fObj, encoding="utf-8", xml_declaration=True) + + with ZipFile(savePath, mode="w") as outZip: + outZip.writestr("mimetype", X_MIME) + putInZip("META-INF/manifest.xml", xMani, outZip) + putInZip("settings.xml", xSett, outZip) + putInZip("content.xml", self._dCont, outZip) + putInZip("meta.xml", self._dMeta, outZip) + putInZip("styles.xml", self._dStyl, outZip) return @@ -607,10 +597,10 @@ class ToOdt(Tokenizer): tAttr[_mkTag("text", "outline-level")] = oLevel pTag = "h" if isHead else "p" - xElem = etree.SubElement(self._xText, _mkTag("text", pTag), attrib=tAttr) + xElem = ET.SubElement(self._xText, _mkTag("text", pTag), attrib=tAttr) # It's important to set the initial text field to empty, otherwise - # lxml will add a line break if the first subelement is a span. + # xmlIndent will add a line break if the first subelement is a span. xElem.text = "" if not theText: @@ -735,25 +725,25 @@ class ToOdt(Tokenizer): theAttr = {} theAttr[_mkTag("style", "name")] = "PM1" if self._isFlat: - xPage = etree.SubElement(self._xAuto, _mkTag("style", "page-layout"), attrib=theAttr) + xPage = ET.SubElement(self._xAuto, _mkTag("style", "page-layout"), attrib=theAttr) else: - xPage = etree.SubElement(self._xAut2, _mkTag("style", "page-layout"), attrib=theAttr) + xPage = ET.SubElement(self._xAut2, _mkTag("style", "page-layout"), attrib=theAttr) theAttr = {} theAttr[_mkTag("fo", "margin-top")] = self._mDocTop theAttr[_mkTag("fo", "margin-bottom")] = self._mDocBtm theAttr[_mkTag("fo", "margin-left")] = self._mDocLeft theAttr[_mkTag("fo", "margin-right")] = self._mDocRight - etree.SubElement(xPage, _mkTag("style", "page-layout-properties"), attrib=theAttr) + ET.SubElement(xPage, _mkTag("style", "page-layout-properties"), attrib=theAttr) - xHead = etree.SubElement(xPage, _mkTag("style", "header-style")) + xHead = ET.SubElement(xPage, _mkTag("style", "header-style")) theAttr = {} theAttr[_mkTag("fo", "min-height")] = "0.600cm" theAttr[_mkTag("fo", "margin-left")] = "0.000cm" theAttr[_mkTag("fo", "margin-right")] = "0.000cm" theAttr[_mkTag("fo", "margin-bottom")] = "0.500cm" - etree.SubElement(xHead, _mkTag("style", "header-footer-properties"), attrib=theAttr) + ET.SubElement(xHead, _mkTag("style", "header-footer-properties"), attrib=theAttr) return @@ -765,13 +755,13 @@ class ToOdt(Tokenizer): theAttr = {} theAttr[_mkTag("style", "family")] = "paragraph" - xStyl = etree.SubElement(self._xStyl, _mkTag("style", "default-style"), attrib=theAttr) + xStyl = ET.SubElement(self._xStyl, _mkTag("style", "default-style"), attrib=theAttr) theAttr = {} theAttr[_mkTag("style", "line-break")] = "strict" theAttr[_mkTag("style", "tab-stop-distance")] = "1.251cm" theAttr[_mkTag("style", "writing-mode")] = "page" - etree.SubElement(xStyl, _mkTag("style", "paragraph-properties"), attrib=theAttr) + ET.SubElement(xStyl, _mkTag("style", "paragraph-properties"), attrib=theAttr) theAttr = {} theAttr[_mkTag("style", "font-name")] = self._textFont @@ -779,7 +769,7 @@ class ToOdt(Tokenizer): theAttr[_mkTag("fo", "font-size")] = self._fSizeText theAttr[_mkTag("fo", "language")] = self._dLanguage theAttr[_mkTag("fo", "country")] = self._dCountry - etree.SubElement(xStyl, _mkTag("style", "text-properties"), attrib=theAttr) + ET.SubElement(xStyl, _mkTag("style", "text-properties"), attrib=theAttr) # Add Standard Paragraph Style # ============================ @@ -788,13 +778,13 @@ class ToOdt(Tokenizer): theAttr[_mkTag("style", "name")] = "Standard" theAttr[_mkTag("style", "family")] = "paragraph" theAttr[_mkTag("style", "class")] = "text" - xStyl = etree.SubElement(self._xStyl, _mkTag("style", "style"), attrib=theAttr) + xStyl = ET.SubElement(self._xStyl, _mkTag("style", "style"), attrib=theAttr) theAttr = {} theAttr[_mkTag("style", "font-name")] = self._textFont theAttr[_mkTag("fo", "font-family")] = self._fontFamily theAttr[_mkTag("fo", "font-size")] = self._fSizeText - etree.SubElement(xStyl, _mkTag("style", "text-properties"), attrib=theAttr) + ET.SubElement(xStyl, _mkTag("style", "text-properties"), attrib=theAttr) # Add Default Heading Style # ========================= @@ -805,19 +795,19 @@ class ToOdt(Tokenizer): theAttr[_mkTag("style", "parent-style-name")] = "Standard" theAttr[_mkTag("style", "next-style-name")] = "Text_20_body" theAttr[_mkTag("style", "class")] = "text" - xStyl = etree.SubElement(self._xStyl, _mkTag("style", "style"), attrib=theAttr) + xStyl = ET.SubElement(self._xStyl, _mkTag("style", "style"), attrib=theAttr) theAttr = {} theAttr[_mkTag("fo", "margin-top")] = self._mTopHead theAttr[_mkTag("fo", "margin-bottom")] = self._mBotHead theAttr[_mkTag("fo", "keep-with-next")] = "always" - etree.SubElement(xStyl, _mkTag("style", "paragraph-properties"), attrib=theAttr) + ET.SubElement(xStyl, _mkTag("style", "paragraph-properties"), attrib=theAttr) theAttr = {} theAttr[_mkTag("style", "font-name")] = self._textFont theAttr[_mkTag("fo", "font-family")] = self._fontFamily theAttr[_mkTag("fo", "font-size")] = self._fSizeHead - etree.SubElement(xStyl, _mkTag("style", "text-properties"), attrib=theAttr) + ET.SubElement(xStyl, _mkTag("style", "text-properties"), attrib=theAttr) # Add Header and Footer Styles # ============================ @@ -827,7 +817,7 @@ class ToOdt(Tokenizer): theAttr[_mkTag("style", "family")] = "paragraph" theAttr[_mkTag("style", "parent-style-name")] = "Standard" theAttr[_mkTag("style", "class")] = "extra" - etree.SubElement(self._xStyl, _mkTag("style", "style"), attrib=theAttr) + ET.SubElement(self._xStyl, _mkTag("style", "style"), attrib=theAttr) return @@ -992,23 +982,24 @@ class ToOdt(Tokenizer): theAttr = {} theAttr[_mkTag("style", "name")] = "Standard" theAttr[_mkTag("style", "page-layout-name")] = "PM1" - xPage = etree.SubElement(self._xMast, _mkTag("style", "master-page"), attrib=theAttr) + xPage = ET.SubElement(self._xMast, _mkTag("style", "master-page"), attrib=theAttr) # Standard Page Header - xHead = etree.SubElement(xPage, _mkTag("style", "header")) - xPar = etree.SubElement(xHead, _mkTag("text", "p"), attrib={ + xHead = ET.SubElement(xPage, _mkTag("style", "header")) + xPar = ET.SubElement(xHead, _mkTag("text", "p"), attrib={ _mkTag("text", "style-name"): "Header" }) xPar.text = self._headerText.strip() + " " - xTail = etree.SubElement(xPar, _mkTag("text", "page-number"), attrib={ + xTail = ET.SubElement(xPar, _mkTag("text", "page-number"), attrib={ _mkTag("text", "select-page"): "current" }) xTail.text = "2" + xTail.tail = "" # Prevent line break in indented XML # First Page Header - xHead = etree.SubElement(xPage, _mkTag("style", "header-first")) - xPar = etree.SubElement(xHead, _mkTag("text", "p"), attrib={ + xHead = ET.SubElement(xPage, _mkTag("style", "header-first")) + xPar = ET.SubElement(xHead, _mkTag("text", "p"), attrib={ _mkTag("text", "style-name"): "Header" }) @@ -1212,7 +1203,7 @@ class ODTParagraphStyle: if aVal is not None: theAttr[_mkTag(aNm, aName)] = aVal - xEntry = etree.SubElement(xParent, _mkTag("style", "style"), attrib=theAttr) + xEntry = ET.SubElement(xParent, _mkTag("style", "style"), attrib=theAttr) theAttr = {} for aName, (aNm, aVal) in self._pAttr.items(): @@ -1220,7 +1211,7 @@ class ODTParagraphStyle: theAttr[_mkTag(aNm, aName)] = aVal if theAttr: - etree.SubElement(xEntry, _mkTag("style", "paragraph-properties"), attrib=theAttr) + ET.SubElement(xEntry, _mkTag("style", "paragraph-properties"), attrib=theAttr) theAttr = {} for aName, (aNm, aVal) in self._tAttr.items(): @@ -1228,7 +1219,7 @@ class ODTParagraphStyle: theAttr[_mkTag(aNm, aName)] = aVal if theAttr: - etree.SubElement(xEntry, _mkTag("style", "text-properties"), attrib=theAttr) + ET.SubElement(xEntry, _mkTag("style", "text-properties"), attrib=theAttr) return @@ -1299,7 +1290,7 @@ class ODTTextStyle: theAttr = {} theAttr[_mkTag("style", "name")] = xName theAttr[_mkTag("style", "family")] = "text" - xEntry = etree.SubElement(xParent, _mkTag("style", "style"), attrib=theAttr) + xEntry = ET.SubElement(xParent, _mkTag("style", "style"), attrib=theAttr) theAttr = {} for aName, (aNm, aVal) in self._tAttr.items(): @@ -1307,7 +1298,7 @@ class ODTTextStyle: theAttr[_mkTag(aNm, aName)] = aVal if theAttr: - etree.SubElement(xEntry, _mkTag("style", "text-properties"), attrib=theAttr) + ET.SubElement(xEntry, _mkTag("style", "text-properties"), attrib=theAttr) return @@ -1328,8 +1319,6 @@ class XMLParagraph: """This is a helper class to manage the text content of a single XML element using mixed content tags. - See: https://lxml.de/tutorial.html#the-element-class - Rules: * The root tag can only have text set, never tail. * Any span must be under root, and the text in the span is set in @@ -1349,8 +1338,8 @@ class XMLParagraph: def __init__(self, xRoot): self._xRoot = xRoot - self._xTail = None - self._xSing = None + self._xTail = ET.Element("") + self._xSing = ET.Element("") self._nState = X_ROOT_TEXT self._chrPos = 0 @@ -1380,26 +1369,26 @@ class XMLParagraph: if c == "\n": if self._nState in (X_ROOT_TEXT, X_ROOT_TAIL): - self._xTail = etree.SubElement(self._xRoot, TAG_BR) + self._xTail = ET.SubElement(self._xRoot, TAG_BR) self._xTail.tail = "" self._nState = X_ROOT_TAIL self._chrPos += 1 elif self._nState in (X_SPAN_TEXT, X_SPAN_SING): - self._xSing = etree.SubElement(self._xTail, TAG_BR) + self._xSing = ET.SubElement(self._xTail, TAG_BR) self._xSing.tail = "" self._nState = X_SPAN_SING self._chrPos += 1 elif c == "\t": if self._nState in (X_ROOT_TEXT, X_ROOT_TAIL): - self._xTail = etree.SubElement(self._xRoot, TAG_TAB) + self._xTail = ET.SubElement(self._xRoot, TAG_TAB) self._xTail.tail = "" self._nState = X_ROOT_TAIL self._chrPos += 1 elif self._nState in (X_SPAN_TEXT, X_SPAN_SING): - self._xSing = etree.SubElement(self._xTail, TAG_TAB) + self._xSing = ET.SubElement(self._xTail, TAG_TAB) self._xSing.tail = "" self._chrPos += 1 self._nState = X_SPAN_SING @@ -1429,7 +1418,7 @@ class XMLParagraph: Therefore we return to the root element level when we're done processing the text of the span. """ - self._xTail = etree.SubElement(self._xRoot, TAG_SPAN, attrib={ + self._xTail = ET.SubElement(self._xRoot, TAG_SPAN, attrib={ TAG_STNM: tFmt }) self._xTail.text = "" # Defaults to None @@ -1482,20 +1471,20 @@ class XMLParagraph: if nSpaces == 2: if self._nState in (X_ROOT_TEXT, X_ROOT_TAIL): - self._xTail = etree.SubElement(self._xRoot, TAG_SPC) + self._xTail = ET.SubElement(self._xRoot, TAG_SPC) self._xTail.tail = "" self._nState = X_ROOT_TAIL self._chrPos += nSpaces - 1 elif self._nState in (X_SPAN_TEXT, X_SPAN_SING): - self._xSing = etree.SubElement(self._xTail, TAG_SPC) + self._xSing = ET.SubElement(self._xTail, TAG_SPC) self._xSing.tail = "" self._nState = X_SPAN_SING self._chrPos += nSpaces - 1 elif nSpaces > 2: if self._nState in (X_ROOT_TEXT, X_ROOT_TAIL): - self._xTail = etree.SubElement(self._xRoot, TAG_SPC, attrib={ + self._xTail = ET.SubElement(self._xRoot, TAG_SPC, attrib={ TAG_NSPC: str(nSpaces - 1) }) self._xTail.tail = "" @@ -1503,7 +1492,7 @@ class XMLParagraph: self._chrPos += nSpaces - 1 elif self._nState in (X_SPAN_TEXT, X_SPAN_SING): - self._xSing = etree.SubElement(self._xTail, TAG_SPC, attrib={ + self._xSing = ET.SubElement(self._xTail, TAG_SPC, attrib={ TAG_NSPC: str(nSpaces - 1) }) self._xSing.tail = "" diff --git a/novelwriter/error.py b/novelwriter/error.py index 74f45318..441c138f 100644 --- a/novelwriter/error.py +++ b/novelwriter/error.py @@ -128,12 +128,6 @@ class NWErrorMessage(QDialog): except Exception: kernelVersion = "Unknown" - try: - import lxml - lxmlVersion = lxml.__version__ # type: ignore - except Exception: - lxmlVersion = "Unknown" - try: import enchant enchantVersion = enchant.__version__ @@ -148,7 +142,6 @@ class NWErrorMessage(QDialog): f"Host OS: {sys.platform} ({kernelVersion})\n" f"Python: {sys.version.split()[0]} ({sys.hexversion:#x})\n" f"Qt: {QT_VERSION_STR}, PyQt: {PYQT_VERSION_STR}\n" - f"lxml: {lxmlVersion}\n" f"enchant: {enchantVersion}\n\n" f"{exType.__name__}:\n{str(exValue)}\n\n" f"Traceback:\n{exTrace}\n" diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 44bfaebb..41dd5904 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ +import sys import logging from enum import Enum @@ -31,10 +32,10 @@ from pathlib import Path from datetime import datetime from PyQt5.QtCore import Qt, QTimer, QThreadPool, pyqtSlot -from PyQt5.QtGui import QIcon, QKeySequence, QCursor +from PyQt5.QtGui import QCursor, QIcon, QKeySequence from PyQt5.QtWidgets import ( - qApp, QMainWindow, QVBoxLayout, QWidget, QSplitter, QFileDialog, QShortcut, - QMessageBox, QDialog, QStackedWidget + qApp, QDialog, QFileDialog, QMainWindow, QMessageBox, QShortcut, QSplitter, + QStackedWidget, QVBoxLayout, QWidget ) from novelwriter import CONFIG, __hexversion__ @@ -89,7 +90,7 @@ class GuiMain(QMainWindow): logger.info("Host: %s", CONFIG.hostName) logger.info("Qt5: %s (0x%06x)", CONFIG.verQtString, CONFIG.verQtValue) logger.info("PyQt5: %s (0x%06x)", CONFIG.verPyQtString, CONFIG.verPyQtValue) - logger.info("Python: %s (0x%08x)", CONFIG.verPyString, CONFIG.verPyHexVal) + logger.info("Python: %s (0x%08x)", CONFIG.verPyString, sys.hexversion) logger.info("GUI Language: %s", CONFIG.guiLocale) # Core Classes diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 1e51d52f..afb0157a 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,6 +1,6 @@ - - + + Sample Project Sample Project Jane Smith @@ -25,7 +25,7 @@ Chapter %chw%: %title% %title% Scene %ch%.%sc%: %title% - + New @@ -45,111 +45,111 @@ - + Novel - + Title Page - + Page - + Part One - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! - + Sequel - + Title Page - + Chapter One - + Characters - + Main Characters - + John Smith - + Jane Smith - + Locations - + Earth - + Space - + Mars - + Archive - + Scenes - + Old File - + Trash - + Delete Me! diff --git a/setup.cfg b/setup.cfg index 6111f0d1..b9572076 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,6 @@ include_package_data = True packages = find_namespace: install_requires = pyqt5>=5.10 - lxml>=4.2.0 pyenchant>=3.0.0 [options.packages.find] diff --git a/setup/debian/control b/setup/debian/control index bbcb49d7..0fb2616b 100644 --- a/setup/debian/control +++ b/setup/debian/control @@ -2,14 +2,14 @@ Source: novelwriter Maintainer: Veronica Berglyd Olsen Section: text Priority: optional -Build-Depends: dh-python, python3-setuptools, python3-all, debhelper (>= 9), python3 (>=3.7), python3-pyqt5 (>= 5.10), python3-lxml (>= 4.0), python3-enchant (>= 2.0) +Build-Depends: dh-python, python3-setuptools, python3-all, debhelper (>= 9), python3 (>=3.7), python3-pyqt5 (>= 5.10), python3-enchant (>= 2.0) Standards-Version: 4.5.1 Homepage: https://novelwriter.io X-Python3-Version: >= 3.7 Package: novelwriter Architecture: all -Depends: ${misc:Depends}, ${python3:Depends}, python3 (>=3.7), python3-pyqt5 (>= 5.10), python3-lxml (>= 4.0), python3-enchant (>= 2.0) +Depends: ${misc:Depends}, ${python3:Depends}, python3 (>=3.7), python3-pyqt5 (>= 5.10), python3-enchant (>= 2.0) Description: A markdown-like text editor for planning and writing novels novelWriter is a plain text editor designed for writing novels assembled from many smaller text documents. It uses a minimal formatting syntax inspired by diff --git a/setup/windows_install.bat b/setup/windows_install.bat index 474c8861..4b2c80d6 100644 --- a/setup/windows_install.bat +++ b/setup/windows_install.bat @@ -19,7 +19,7 @@ if exist setup.py ( ) echo. -:: Install the PyQt5, lxml and pyenchant dependencies +:: Install the PyQt5 and pyenchant dependencies pip install --user pywin32 -r requirements.txt :: Create the desktop and start menu icons diff --git a/setup/windows_uninstall.bat b/setup/windows_uninstall.bat index 7522f4bd..18523176 100644 --- a/setup/windows_uninstall.bat +++ b/setup/windows_uninstall.bat @@ -29,7 +29,7 @@ goto afterUninst :: Remove the desktop and start menu icons python setup.py win-uninstall -:: Remove the PyQt5, lxml and pyenchant dependencies +:: Remove the PyQt5 and pyenchant dependencies pip uninstall --yes -r requirements.txt :afterUninst diff --git a/tests/files/nwProject-1.5.nwx b/tests/files/nwProject-1.5.nwx index 8bee81e4..8952b63b 100644 --- a/tests/files/nwProject-1.5.nwx +++ b/tests/files/nwProject-1.5.nwx @@ -25,7 +25,7 @@ Chapter %chw%: %title% %title% Scene %ch%.%sc%: %title% - + New @@ -45,111 +45,111 @@ - + Novel - + Title Page - + Page - + Part One - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! - + Sequel - + Title Page - + Chapter One - + Characters - + Main Characters - + John Smith - + Jane Smith - + Locations - + Earth - + Space - + Mars - + Archive - + Scenes - + Old File - + Trash - + Delete Me! diff --git a/tests/lipsum/nwProject.nwx b/tests/lipsum/nwProject.nwx index 086183c6..0a4a69e5 100644 --- a/tests/lipsum/nwProject.nwx +++ b/tests/lipsum/nwProject.nwx @@ -1,6 +1,6 @@ - - + + Lorem Ipsum Lorem Ipsum lipsum.com @@ -24,7 +24,7 @@ Chapter %ch%: %title% %title% * * * - + New @@ -41,88 +41,88 @@ - + Novel - + Lorem Ipsum - + Front Matter - + Prologue - + Act One - + Chapter One - + Chapter One - + Scene One - + Scene Two - + Interlude - + Chapter Two - + Chapter Two - + Scene Three - + Scene Four - + Scene Five - + Characters - + Mr. Nobody - + Plot - + Main - + World - + Ancient Europe - + \ No newline at end of file diff --git a/tests/reference/coreProject_NewFileFolder_nwProject.nwx b/tests/reference/coreProject_NewFileFolder_nwProject.nwx index 5000c7d9..c80520fa 100644 --- a/tests/reference/coreProject_NewFileFolder_nwProject.nwx +++ b/tests/reference/coreProject_NewFileFolder_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -15,13 +15,13 @@ None None - + %title% %title% %title% * * * - + New @@ -38,47 +38,47 @@ - + Novel - + Plot - + Characters - + World - + Title Page - + New Chapter - + New Chapter - + New Scene - + Stuff - + Hello - + Jane diff --git a/tests/reference/coreProject_NewRoot_nwProject.nwx b/tests/reference/coreProject_NewRoot_nwProject.nwx index 06a0ca07..c94ce28e 100644 --- a/tests/reference/coreProject_NewRoot_nwProject.nwx +++ b/tests/reference/coreProject_NewRoot_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -15,13 +15,13 @@ None None - + %title% %title% %title% * * * - + New @@ -38,67 +38,67 @@ - + Novel - + Plot - + Characters - + World - + Title Page - + New Chapter - + New Chapter - + New Scene - + Novel - + Plot - + Characters - + Locations - + Timeline - + Objects - + Custom - + Custom diff --git a/tests/reference/coreToOdt_SaveFlat_document.fodt b/tests/reference/coreToOdt_SaveFlat_document.fodt index 6e879a5c..0c2b658e 100644 --- a/tests/reference/coreToOdt_SaveFlat_document.fodt +++ b/tests/reference/coreToOdt_SaveFlat_document.fodt @@ -1,72 +1,72 @@ - + - 2023-02-12T15:10:11 - novelWriter/2.0.4 + 2023-05-29T22:10:15 + novelWriter/2.0.7 Jane Smith 1234 P42DT12H34M56S Test Project - 2023-02-12T15:10:11 + 2023-05-29T22:10:15 Jane Smith - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + @@ -75,7 +75,7 @@ Test Project / Jane Smith / 2 - + diff --git a/tests/reference/coreToOdt_SaveFull_content.xml b/tests/reference/coreToOdt_SaveFull_content.xml index 4e191f7c..0654b0f3 100644 --- a/tests/reference/coreToOdt_SaveFull_content.xml +++ b/tests/reference/coreToOdt_SaveFull_content.xml @@ -1,11 +1,11 @@ - + - + - + diff --git a/tests/reference/coreToOdt_SaveFull_manifest.xml b/tests/reference/coreToOdt_SaveFull_manifest.xml index f939a7b3..858f5ff8 100644 --- a/tests/reference/coreToOdt_SaveFull_manifest.xml +++ b/tests/reference/coreToOdt_SaveFull_manifest.xml @@ -1,8 +1,8 @@ - - - - - + + + + + diff --git a/tests/reference/coreToOdt_SaveFull_meta.xml b/tests/reference/coreToOdt_SaveFull_meta.xml index 79930faa..8791d9d7 100644 --- a/tests/reference/coreToOdt_SaveFull_meta.xml +++ b/tests/reference/coreToOdt_SaveFull_meta.xml @@ -1,13 +1,13 @@ - + - 2023-02-12T15:09:03 - novelWriter/2.0.4 + 2023-05-29T19:48:33 + novelWriter/2.0.7 Jane Smith 1234 P42DT12H34M56S Test Project - 2023-02-12T15:09:03 + 2023-05-29T19:48:33 Jane Smith diff --git a/tests/reference/coreToOdt_SaveFull_settings.xml b/tests/reference/coreToOdt_SaveFull_settings.xml index 7b5218f2..53e43d1f 100644 --- a/tests/reference/coreToOdt_SaveFull_settings.xml +++ b/tests/reference/coreToOdt_SaveFull_settings.xml @@ -1,2 +1,2 @@ - + diff --git a/tests/reference/coreToOdt_SaveFull_styles.xml b/tests/reference/coreToOdt_SaveFull_styles.xml index 5319adf2..6c5f9bd2 100644 --- a/tests/reference/coreToOdt_SaveFull_styles.xml +++ b/tests/reference/coreToOdt_SaveFull_styles.xml @@ -1,68 +1,69 @@ - + - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - Test Project / Jane Smith / 2 + Test Project / Jane Smith / 2 + - + diff --git a/tests/reference/coreTools_NewCustomA_nwProject.nwx b/tests/reference/coreTools_NewCustomA_nwProject.nwx index ffa4f38a..84419675 100644 --- a/tests/reference/coreTools_NewCustomA_nwProject.nwx +++ b/tests/reference/coreTools_NewCustomA_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -15,13 +15,13 @@ None None - + %title% %title% %title% * * * - + New @@ -38,91 +38,91 @@ - + Novel - + Title Page - + Chapter 1 - + Scene 1.1 - + Scene 1.2 - + Scene 1.3 - + Chapter 2 - + Scene 2.1 - + Scene 2.2 - + Scene 2.3 - + Chapter 3 - + Scene 3.1 - + Scene 3.2 - + Scene 3.3 - + Plot - + Main Plot - + Characters - + Protagonist - + Locations - + Main Location - + Archive - + Trash diff --git a/tests/reference/coreTools_NewCustomB_nwProject.nwx b/tests/reference/coreTools_NewCustomB_nwProject.nwx index 38084419..53e23cd8 100644 --- a/tests/reference/coreTools_NewCustomB_nwProject.nwx +++ b/tests/reference/coreTools_NewCustomB_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -15,13 +15,13 @@ None None - + %title% %title% %title% * * * - + New @@ -38,67 +38,67 @@ - + Novel - + Title Page - + Scene 1 - + Scene 2 - + Scene 3 - + Scene 4 - + Scene 5 - + Scene 6 - + Plot - + Main Plot - + Characters - + Protagonist - + Locations - + Main Location - + Archive - + Trash diff --git a/tests/reference/coreTools_NewMinimal_nwProject.nwx b/tests/reference/coreTools_NewMinimal_nwProject.nwx index dc3f2d43..04ad571c 100644 --- a/tests/reference/coreTools_NewMinimal_nwProject.nwx +++ b/tests/reference/coreTools_NewMinimal_nwProject.nwx @@ -1,9 +1,9 @@ - + New Project New Project - + yes @@ -15,13 +15,13 @@ None None - + %title% %title% %title% * * * - + New @@ -38,35 +38,35 @@ - + Novel - + Title Page - + New Chapter - + New Scene - + Plot - + Characters - + Locations - + Archive diff --git a/tests/reference/guiBuild_Tool_Step1_Lorem_Ipsum.fodt b/tests/reference/guiBuild_Tool_Step1_Lorem_Ipsum.fodt index d327ee5b..4bd71182 100644 --- a/tests/reference/guiBuild_Tool_Step1_Lorem_Ipsum.fodt +++ b/tests/reference/guiBuild_Tool_Step1_Lorem_Ipsum.fodt @@ -1,84 +1,84 @@ - + - 2023-02-12T14:52:03 - novelWriter/2.0.4 + 2023-05-29T22:10:29 + novelWriter/2.0.7 lipsum.com - 38 - P0DT0H31M40S + 40 + P0DT0H31M45S Lorem Ipsum - 2023-02-12T14:52:03 + 2023-05-29T22:10:29 lipsum.com - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - + - + @@ -87,7 +87,7 @@ Lorem Ipsum / lipsum.com / 2 - + diff --git a/tests/reference/guiBuild_Tool_Step2_Lorem_Ipsum.fodt b/tests/reference/guiBuild_Tool_Step2_Lorem_Ipsum.fodt index d179c99d..cf329eb6 100644 --- a/tests/reference/guiBuild_Tool_Step2_Lorem_Ipsum.fodt +++ b/tests/reference/guiBuild_Tool_Step2_Lorem_Ipsum.fodt @@ -1,96 +1,96 @@ - + - 2023-02-12T15:00:22 - novelWriter/2.0.4 + 2023-05-29T22:11:22 + novelWriter/2.0.7 lipsum.com - 38 - P0DT0H31M40S + 40 + P0DT0H31M45S Lorem Ipsum - 2023-02-12T15:00:22 + 2023-05-29T22:11:22 lipsum.com - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - + - + - + - + @@ -99,7 +99,7 @@ Lorem Ipsum / lipsum.com / 2 - + @@ -147,9 +147,9 @@ Ut et consequat enim, quis ornare nibh. In lectus neque, mollis et suscipit et, vestibulum vitae augue. Praesent id ante sit amet odio venenatis placerat a at erat. Sed sed metus sed nisi dictum varius. Integer tincidunt fermentum purus ac porta. Fusce porttitor non risus eget tristique. Donec augue nunc, maximus at fermentum vel, varius et neque. Ut sed consectetur mauris. Quisque ipsum enim, porttitor vitae imperdiet sit amet, tempor et mauris. Aliquam malesuada tincidunt lectus quis blandit. Sed commodo orci felis, quis ultrices tellus facilisis sed. Nunc vel varius est. Duis ullamcorper eu metus in pulvinar. Morbi at sapien dictum, rutrum mauris eget, interdum tellus. Why do we use it? Comment: Exctracted from the lipsum.com website. - It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. - The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. - Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). + It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. + The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. + Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Chapter Two: Chapter Two Point of View: Bod Plot: Main diff --git a/tests/reference/guiBuild_Tool_Step3_Lorem_Ipsum.fodt b/tests/reference/guiBuild_Tool_Step3_Lorem_Ipsum.fodt index ca391d27..d5891721 100644 --- a/tests/reference/guiBuild_Tool_Step3_Lorem_Ipsum.fodt +++ b/tests/reference/guiBuild_Tool_Step3_Lorem_Ipsum.fodt @@ -1,96 +1,96 @@ - + - 2023-02-12T15:01:25 - novelWriter/2.0.4 + 2023-05-29T22:11:58 + novelWriter/2.0.7 lipsum.com - 38 - P0DT0H31M40S + 40 + P0DT0H31M45S Lorem Ipsum - 2023-02-12T15:01:25 + 2023-05-29T22:11:58 lipsum.com - + - - + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - + - + - + - + @@ -99,7 +99,7 @@ Lorem Ipsum / lipsum.com / 2 - + @@ -147,9 +147,9 @@ Ut et consequat enim, quis ornare nibh. In lectus neque, mollis et suscipit et, vestibulum vitae augue. Praesent id ante sit amet odio venenatis placerat a at erat. Sed sed metus sed nisi dictum varius. Integer tincidunt fermentum purus ac porta. Fusce porttitor non risus eget tristique. Donec augue nunc, maximus at fermentum vel, varius et neque. Ut sed consectetur mauris. Quisque ipsum enim, porttitor vitae imperdiet sit amet, tempor et mauris. Aliquam malesuada tincidunt lectus quis blandit. Sed commodo orci felis, quis ultrices tellus facilisis sed. Nunc vel varius est. Duis ullamcorper eu metus in pulvinar. Morbi at sapien dictum, rutrum mauris eget, interdum tellus. Why do we use it? Comment: Exctracted from the lipsum.com website. - It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. - The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. - Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). + It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. + The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. + Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Chapter Two: Chapter Two Point of View: Bod Plot: Main diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index dc0456a7..c5c3b367 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -15,13 +15,13 @@ 0000000000008 None - + %title% %title% %title% * * * - + New @@ -38,47 +38,47 @@ - + Novel - + Title Page - + New Chapter - + New Chapter - + New Scene - + Plot - + New Note - + Characters - + New Note - + World - + New Note diff --git a/tests/reference/guiEditor_Main_Initial_nwProject.nwx b/tests/reference/guiEditor_Main_Initial_nwProject.nwx index 977f03c1..4d758791 100644 --- a/tests/reference/guiEditor_Main_Initial_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Initial_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -15,13 +15,13 @@ None None - + %title% %title% %title% * * * - + New @@ -38,35 +38,35 @@ - + Novel - + Title Page - + New Chapter - + New Chapter - + New Scene - + Plot - + Characters - + World diff --git a/tests/reference/projectXML_ReadLegacy10.nwx b/tests/reference/projectXML_ReadLegacy10.nwx index 5b189c1e..edcab5b4 100644 --- a/tests/reference/projectXML_ReadLegacy10.nwx +++ b/tests/reference/projectXML_ReadLegacy10.nwx @@ -25,7 +25,7 @@ Chapter %ch%: %title% %title% Scene %ch%.%sc%: %title% - + New @@ -45,91 +45,91 @@ - + Novel - + Title Page - + Page - + Part One - + A Folder - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! - + Characters - + Main Characters - + John Smith - + Jane Smith - + Locations - + Earth - + Space - + Mars - + Trash - + Delete Me! diff --git a/tests/reference/projectXML_ReadLegacy11.nwx b/tests/reference/projectXML_ReadLegacy11.nwx index afc87cef..fcc987ef 100644 --- a/tests/reference/projectXML_ReadLegacy11.nwx +++ b/tests/reference/projectXML_ReadLegacy11.nwx @@ -25,7 +25,7 @@ Chapter %ch%: %title% %title% Scene %ch%.%sc%: %title% - + New @@ -45,91 +45,91 @@ - + Novel - + Title Page - + Page - + Part One - + A Folder - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! - + Characters - + Main Characters - + John Smith - + Jane Smith - + Locations - + Earth - + Space - + Mars - + Trash - + Delete Me! diff --git a/tests/reference/projectXML_ReadLegacy12.nwx b/tests/reference/projectXML_ReadLegacy12.nwx index e31f035a..b44e9acf 100644 --- a/tests/reference/projectXML_ReadLegacy12.nwx +++ b/tests/reference/projectXML_ReadLegacy12.nwx @@ -25,7 +25,7 @@ Chapter %chw%: %title% %title% Scene %ch%.%sc%: %title% - + New @@ -45,103 +45,103 @@ - + Novel - + Title Page - + Page - + Part One - + A Folder - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! - + Characters - + Main Characters - + John Smith - + Jane Smith - + Locations - + Earth - + Space - + Mars - + Outtakes - + Scenes - + Old File - + Trash - + Delete Me! diff --git a/tests/reference/projectXML_ReadLegacy13.nwx b/tests/reference/projectXML_ReadLegacy13.nwx index d629079d..06fc3145 100644 --- a/tests/reference/projectXML_ReadLegacy13.nwx +++ b/tests/reference/projectXML_ReadLegacy13.nwx @@ -25,7 +25,7 @@ Chapter %chw%: %title% %title% Scene %ch%.%sc%: %title% - + New @@ -45,103 +45,103 @@ - + Novel - + Title Page - + Page - + Part One - + A Folder - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! - + Characters - + Main Characters - + John Smith - + Jane Smith - + Locations - + Earth - + Space - + Mars - + Archive - + Scenes - + Old File - + Trash - + Delete Me! diff --git a/tests/reference/projectXML_ReadLegacy14.nwx b/tests/reference/projectXML_ReadLegacy14.nwx index 6bc7154c..e40e3a07 100644 --- a/tests/reference/projectXML_ReadLegacy14.nwx +++ b/tests/reference/projectXML_ReadLegacy14.nwx @@ -25,7 +25,7 @@ Chapter %chw%: %title% %title% Scene %ch%.%sc%: %title% - + New @@ -45,111 +45,111 @@ - + Novel - + Title Page - + Page - + Part One - + Chapter One - + Making a Scene - + Another Scene - + Interlude - + A Note on Structure - + Chapter Two - + We Found John! - + Sequel - + Title Page - + Chapter One - + Characters - + Main Characters - + John Smith - + Jane Smith - + Locations - + Earth - + Space - + Mars - + Archive - + Scenes - + Old File - + Trash - + Delete Me! diff --git a/tests/test_base/test_base_init.py b/tests/test_base/test_base_init.py index 71056fb7..a932dcfa 100644 --- a/tests/test_base/test_base_init.py +++ b/tests/test_base/test_base_init.py @@ -154,7 +154,6 @@ def testBaseInit_Imports(caplog, monkeypatch, fncPath): monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.__init__", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.resize", lambda *a: None) monkeypatch.setattr("PyQt5.QtWidgets.QErrorMessage.showMessage", lambda *a: None) - monkeypatch.setitem(sys.modules, "lxml", None) monkeypatch.setattr("sys.hexversion", 0x0) monkeypatch.setattr("novelwriter.CONFIG.verQtValue", 0x050000) monkeypatch.setattr("novelwriter.CONFIG.verPyQtValue", 0x050000) @@ -167,11 +166,9 @@ def testBaseInit_Imports(caplog, monkeypatch, fncPath): assert ex.value.code & 4 == 4 # Python version not satisfied assert ex.value.code & 8 == 8 # Qt version not satisfied assert ex.value.code & 16 == 16 # PyQt version not satisfied - assert ex.value.code & 32 == 32 # lxml package missing assert "At least Python" in caplog.messages[0] assert "At least Qt5" in caplog.messages[1] assert "At least PyQt5" in caplog.messages[2] - assert "lxml" in caplog.messages[3] # END Test testBaseInit_Imports diff --git a/tests/test_core/test_core_projectxml.py b/tests/test_core/test_core_projectxml.py index 4d099632..35132107 100644 --- a/tests/test_core/test_core_projectxml.py +++ b/tests/test_core/test_core_projectxml.py @@ -226,7 +226,7 @@ def testCoreProjectXML_ReadCurrent(monkeypatch, tstPaths, fncPath): # Fail saving with monkeypatch.context() as mp: - mp.setattr("pathlib.Path.write_bytes", causeOSError) + mp.setattr("xml.etree.ElementTree.ElementTree.write", causeOSError) assert xmlWriter.write(data, packedContent, timeStamp, 1000) is False assert str(xmlWriter.error) == "Mock OSError" diff --git a/tests/test_core/test_core_toodt.py b/tests/test_core/test_core_toodt.py index 6e3ea446..55c6d785 100644 --- a/tests/test_core/test_core_toodt.py +++ b/tests/test_core/test_core_toodt.py @@ -21,12 +21,13 @@ along with this program. If not, see . import pytest import zipfile +import xml.etree.ElementTree as ET -from lxml import etree from shutil import copyfile from tools import ODT_IGNORE, cmpFiles +from novelwriter.common import xmlIndent from novelwriter.core.toodt import ToOdt, ODTParagraphStyle, ODTTextStyle, XMLParagraph, _mkTag from novelwriter.core.project import NWProject @@ -44,7 +45,7 @@ XML_NS = [ def xmlToText(xElem): """Get the text content of an XML element. """ - rTxt = etree.tostring(xElem, encoding="utf-8", xml_declaration=False).decode() + rTxt = ET.tostring(xElem, encoding="utf-8", xml_declaration=False).decode() for nSpace in XML_NS: rTxt = rTxt.replace(nSpace, "") return rTxt @@ -63,21 +64,21 @@ def testCoreToOdt_Init(mockGUI): theDoc.initDocument() # Document XML - assert theDoc._dFlat is not None - assert theDoc._dCont is None - assert theDoc._dMeta is None - assert theDoc._dStyl is None + assert theDoc._dFlat.tag == _mkTag("office", "document") + assert theDoc._dCont.tag == "" + assert theDoc._dMeta.tag == "" + assert theDoc._dStyl.tag == "" # Content XML - assert theDoc._xMeta is not None - assert theDoc._xFont is not None - assert theDoc._xFnt2 is None - assert theDoc._xStyl is not None - assert theDoc._xAuto is not None - assert theDoc._xAut2 is None - assert theDoc._xMast is not None - assert theDoc._xBody is not None - assert theDoc._xText is not None + assert theDoc._xMeta.tag == _mkTag("office", "meta") + assert theDoc._xFont.tag == _mkTag("office", "font-face-decls") + assert theDoc._xFnt2.tag == "" + assert theDoc._xStyl.tag == _mkTag("office", "styles") + assert theDoc._xAuto.tag == _mkTag("office", "automatic-styles") + assert theDoc._xAut2.tag == "" + assert theDoc._xMast.tag == _mkTag("office", "master-styles") + assert theDoc._xBody.tag == _mkTag("office", "body") + assert theDoc._xText.tag == _mkTag("office", "text") # ODT Doc # ======= @@ -86,21 +87,22 @@ def testCoreToOdt_Init(mockGUI): theDoc.initDocument() # Document XML - assert theDoc._dFlat is None - assert theDoc._dCont is not None - assert theDoc._dMeta is not None - assert theDoc._dStyl is not None + assert theDoc._dFlat.tag == "" + assert theDoc._dCont.tag == _mkTag("office", "document-content") + assert theDoc._dMeta.tag == _mkTag("office", "document-meta") + assert theDoc._dStyl.tag == _mkTag("office", "document-styles") # Content XML - assert theDoc._xMeta is not None - assert theDoc._xFont is not None - assert theDoc._xFnt2 is not None - assert theDoc._xStyl is not None - assert theDoc._xAuto is not None - assert theDoc._xAut2 is not None - assert theDoc._xMast is not None - assert theDoc._xBody is not None - assert theDoc._xText is not None + assert theDoc._xMeta.tag == _mkTag("office", "meta") + assert theDoc._xFont.tag == _mkTag("office", "font-face-decls") + assert theDoc._xFnt2.tag == _mkTag("office", "font-face-decls") + assert theDoc._xStyl.tag == _mkTag("office", "styles") + assert theDoc._xAuto.tag == _mkTag("office", "automatic-styles") + assert theDoc._xAut2.tag == _mkTag("office", "automatic-styles") + assert theDoc._xMast.tag == _mkTag("office", "master-styles") + assert theDoc._xBody.tag == _mkTag("office", "body") + assert theDoc._xText.tag == _mkTag("office", "text") + # END Test testCoreToOdt_Init @@ -113,7 +115,7 @@ def testCoreToOdt_TextFormatting(mockGUI): theDoc = ToOdt(theProject, isFlat=True) theDoc.initDocument() - assert xmlToText(theDoc._xText) == "" + assert xmlToText(theDoc._xText) == "" # Paragraph Style # =============== @@ -147,7 +149,7 @@ def testCoreToOdt_TextFormatting(mockGUI): theDoc._addTextPar("Standard", oStyle, "") assert xmlToText(theDoc._xText) == ( "" - "" + "" "" ) @@ -217,7 +219,7 @@ def testCoreToOdt_TextFormatting(mockGUI): assert theDoc.getErrors() == [] assert xmlToText(theDoc._xText) == ( "" - "HelloWorld" + "HelloWorld" "" ) @@ -366,7 +368,7 @@ def testCoreToOdt_Convert(mockGUI): assert theDoc.getErrors() == [] assert xmlToText(theDoc._xText) == ( '' - 'Some text.Next line' + 'Some text.Next line' '' ) @@ -379,7 +381,7 @@ def testCoreToOdt_Convert(mockGUI): assert theDoc.getErrors() == [] assert xmlToText(theDoc._xText) == ( '' - 'Item 1Item 2' + 'Item 1Item 2' '' ) @@ -393,7 +395,7 @@ def testCoreToOdt_Convert(mockGUI): assert xmlToText(theDoc._xText) == ( '' 'Some ' - 'boldtext' + 'boldtext' '' ) @@ -413,8 +415,8 @@ def testCoreToOdt_Convert(mockGUI): '' 'Scene' 'Hello World' - 'Hello World' - 'Hello World' + 'Hello World' + 'Hello World' '' ) @@ -474,9 +476,9 @@ def testCoreToOdt_Convert(mockGUI): assert theDoc.getErrors() == [] assert xmlToText(theDoc._xText) == ( '' - '' + '' 'Text' - '' + '' 'Text' '' ) @@ -540,7 +542,7 @@ def testCoreToOdt_Convert(mockGUI): '' 'Scene' 'Regular paragraph' - 'withbreak' + 'withbreak' 'Left Align' '' ) @@ -592,7 +594,7 @@ def testCoreToOdt_ConvertDirect(mockGUI): assert ( '' - '' + '' '' ) in xmlToText(theDoc._xAuto) assert xmlToText(theDoc._xText) == ( @@ -613,7 +615,7 @@ def testCoreToOdt_ConvertDirect(mockGUI): assert ( '' - '' + '' '' ) in xmlToText(theDoc._xAuto) assert xmlToText(theDoc._xText) == ( @@ -723,15 +725,10 @@ def testCoreToOdt_SaveFull(mockGUI, fncPath, tstPaths): stylOut = tstPaths.outDir / "coreToOdt_SaveFull" / "styles.xml" def prettifyXml(inFile, outFile): - with open(outFile, mode="wb") as fileStream: - fileStream.write( - etree.tostring( - etree.parse(str(inFile)), - pretty_print=True, - encoding="utf-8", - xml_declaration=True - ) - ) + with open(outFile, mode="wb") as fStream: + xml = ET.parse(inFile) + xmlIndent(xml) + xml.write(fStream, encoding="utf-8", xml_declaration=True) prettifyXml(maniOut, maniFile) prettifyXml(settOut, settFile) @@ -949,20 +946,16 @@ def testCoreToOdt_ODTParagraphStyle(): # Pack XML # ======== - xStyle = etree.Element("test", nsmap={ - "style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0", - "loext": "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0", - "fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", - }) + xStyle = ET.Element("test") parStyle.packXML(xStyle, "test") assert xmlToText(xStyle) == ( '' '' '' + 'fo:margin-left="0.000cm" fo:margin-right="0.000cm" fo:line-height="1.15" />' '' + 'fo:font-size="12pt" fo:color="#000000" loext:opacity="1.00" />' '' '' ) @@ -1059,15 +1052,12 @@ def testCoreToOdt_ODTTextStyle(): txtStyle.setFontStyle("italic") txtStyle.setStrikeStyle("solid") txtStyle.setStrikeType("single") - xStyle = etree.Element("test", nsmap={ - "style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0", - "fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", - }) + xStyle = ET.Element("test") txtStyle.packXML(xStyle, "test") assert xmlToText(xStyle) == ( '' + 'style:text-line-through-type="single" />' ) # END Test testCoreToOdt_ODTTextStyle @@ -1077,20 +1067,11 @@ def testCoreToOdt_ODTTextStyle(): def testCoreToOdt_XMLParagraph(): """Test XML encoding of paragraph. """ - nsMap = { - "office": "urn:oasis:names:tc:opendocument:xmlns:office:1.0", - "style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0", - "loext": "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0", - "text": "urn:oasis:names:tc:opendocument:xmlns:text:1.0", - "meta": "urn:oasis:names:tc:opendocument:xmlns:meta:1.0", - "fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0", - } - # Stage 1 : Text # ============== - xRoot = etree.Element("root", nsmap=nsMap) - xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"]) + xRoot = ET.Element("root") + xElem = ET.SubElement(xRoot, _mkTag("text", "p")) xmlPar = XMLParagraph(xElem) # Plain Text @@ -1126,15 +1107,15 @@ def testCoreToOdt_XMLParagraph(): # Stage 2 : Line Breaks # ===================== - xRoot = etree.Element("root", nsmap=nsMap) - xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"]) + xRoot = ET.Element("root") + xElem = ET.SubElement(xRoot, _mkTag("text", "p")) xmlPar = XMLParagraph(xElem) # Plain Text w/Line Break xmlPar.appendText("Hello\nWorld\n!!") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' + 'HelloWorld!!' '' ) @@ -1142,8 +1123,8 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendSpan("spanned\ntext", "T1") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' - 'spannedtext' + 'HelloWorld!!' + 'spannedtext' '' ) @@ -1151,9 +1132,9 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendText("more\ntext") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' - 'spannedtext' - 'moretext' + 'HelloWorld!!' + 'spannedtext' + 'moretext' '' ) @@ -1162,15 +1143,15 @@ def testCoreToOdt_XMLParagraph(): # Stage 3 : Tabs # ============== - xRoot = etree.Element("root", nsmap=nsMap) - xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"]) + xRoot = ET.Element("root") + xElem = ET.SubElement(xRoot, _mkTag("text", "p")) xmlPar = XMLParagraph(xElem) # Plain Text w/Line Break xmlPar.appendText("Hello\tWorld\t!!") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' + 'HelloWorld!!' '' ) @@ -1178,8 +1159,8 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendSpan("spanned\ttext", "T1") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' - 'spannedtext' + 'HelloWorld!!' + 'spannedtext' '' ) @@ -1187,9 +1168,9 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendText("more\ttext") assert xmlToText(xRoot) == ( '' - 'HelloWorld!!' - 'spannedtext' - 'moretext' + 'HelloWorld!!' + 'spannedtext' + 'moretext' '' ) @@ -1198,15 +1179,15 @@ def testCoreToOdt_XMLParagraph(): # Stage 4 : Spaces # ================ - xRoot = etree.Element("root", nsmap=nsMap) - xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"]) + xRoot = ET.Element("root") + xElem = ET.SubElement(xRoot, _mkTag("text", "p")) xmlPar = XMLParagraph(xElem) # Plain Text w/Spaces xmlPar.appendText("Hello World !!") assert xmlToText(xRoot) == ( '' - 'Hello World !!' + 'Hello World !!' '' ) @@ -1214,8 +1195,8 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendSpan("spanned text", "T1") assert xmlToText(xRoot) == ( '' - 'Hello World !!' - 'spanned text' + 'Hello World !!' + 'spanned text' '' ) @@ -1223,9 +1204,9 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendText("more text") assert xmlToText(xRoot) == ( '' - 'Hello World !!' - 'spanned text' - 'more text' + 'Hello World !!' + 'spanned text' + 'more text' '' ) @@ -1234,15 +1215,15 @@ def testCoreToOdt_XMLParagraph(): # Stage 5 : Lots of Spaces # ======================== - xRoot = etree.Element("root", nsmap=nsMap) - xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"]) + xRoot = ET.Element("root") + xElem = ET.SubElement(xRoot, _mkTag("text", "p")) xmlPar = XMLParagraph(xElem) # Plain Text w/Many Spaces xmlPar.appendText(" \t A \n B ") assert xmlToText(xRoot) == ( '' - ' A B ' + ' A B ' '' ) @@ -1250,9 +1231,9 @@ def testCoreToOdt_XMLParagraph(): xmlPar.appendSpan(" C \t D \n E ", "T1") assert xmlToText(xRoot) == ( '' - ' A B ' - ' C D ' - ' E ' + ' A B ' + ' C D ' + ' E ' '' ) @@ -1261,8 +1242,8 @@ def testCoreToOdt_XMLParagraph(): # Check Error # =========== - xRoot = etree.Element("root", nsmap=nsMap) - xElem = etree.SubElement(xRoot, "{%s}p" % nsMap["text"]) + xRoot = ET.Element("root") + xElem = ET.SubElement(xRoot, _mkTag("text", "p")) xmlPar = XMLParagraph(xElem) xmlPar.appendText("A") diff --git a/tests/tools.py b/tests/tools.py index a9933bc4..7463e3a1 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -27,7 +27,7 @@ from pathlib import Path from PyQt5.QtWidgets import qApp XML_IGNORE = ("