Sat, 02 Sep 2017 20:00:57 +0200
Started implementing a downloader and installer for web browser spell check dictionaries.
# -*- coding: utf-8 -*- # Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module to read the web browser spell check dictionaries list file. """ from __future__ import unicode_literals from .Config import dictionariesListFileFormatVersion from .XMLStreamReaderBase import XMLStreamReaderBase import Preferences class SpellCheckDictionariesReader(XMLStreamReaderBase): """ Class to read the web browser spell check dictionaries list file. """ supportedVersions = ["1.0",] def __init__(self, data, entryCallback): """ Constructor @param data reference to the data array to read XML from (QByteArray) @param entryCallback reference to a function to be called once the data for a dictionary has been read (function) """ XMLStreamReaderBase.__init__(self, data) self.__entryCallback = entryCallback self.version = "" def readXML(self): """ Public method to read and parse the XML document. """ while not self.atEnd(): self.readNext() if self.isStartElement(): if self.name() == "Dictionaries": self.version = self.attribute( "version", dictionariesListFileFormatVersion) if self.version not in self.supportedVersions: self.raiseUnsupportedFormatVersion(self.version) elif self.name() == "DictionariesUrl": url = self.readElementText() Preferences.setWebBrowser("SpellCheckDictionariesUrl", url) elif self.name() == "Dictionary": self.__readDictionary() else: self._skipUnknownElement() self.showErrorMessage() def __readDictionary(self): """ Private method to read the plug-in info. """ dictionaryInfo = {"short": "", "filename": "", } while not self.atEnd(): self.readNext() if self.isEndElement() and self.name() == "Dictionary": self.__entryCallback( dictionaryInfo["short"], dictionaryInfo["filename"]) break if self.isStartElement(): if self.name() == "Short": dictionaryInfo["short"] = self.readElementText() elif self.name() == "Filename": dictionaryInfo["filename"] = self.readElementText() else: self.raiseUnexpectedStartTag(self.name())