eric6/E5XML/SpellCheckDictionariesReader.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2017 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module to read the web browser spell check dictionaries list file.
8 """
9
10 from __future__ import unicode_literals
11
12 from .Config import dictionariesListFileFormatVersion
13 from .XMLStreamReaderBase import XMLStreamReaderBase
14
15 import Preferences
16
17
18 class SpellCheckDictionariesReader(XMLStreamReaderBase):
19 """
20 Class to read the web browser spell check dictionaries list file.
21 """
22 supportedVersions = ["1.0", ]
23
24 def __init__(self, data, entryCallback):
25 """
26 Constructor
27
28 @param data reference to the data array to read XML from (QByteArray)
29 @param entryCallback reference to a function to be called once the
30 data for a dictionary has been read (function)
31 """
32 XMLStreamReaderBase.__init__(self, data)
33
34 self.__entryCallback = entryCallback
35
36 self.version = ""
37 self.baseUrl = ""
38
39 def readXML(self):
40 """
41 Public method to read and parse the XML document.
42 """
43 while not self.atEnd():
44 self.readNext()
45 if self.isStartElement():
46 if self.name() == "Dictionaries":
47 self.version = self.attribute(
48 "version",
49 dictionariesListFileFormatVersion)
50 self.baseUrl = self.attribute("baseurl", "")
51 if self.version not in self.supportedVersions:
52 self.raiseUnsupportedFormatVersion(self.version)
53 elif self.name() == "DictionariesUrl":
54 url = self.readElementText()
55 Preferences.setWebBrowser("SpellCheckDictionariesUrl", url)
56 elif self.name() == "Dictionary":
57 self.__readDictionary()
58 else:
59 self._skipUnknownElement()
60
61 self.showErrorMessage()
62
63 def __readDictionary(self):
64 """
65 Private method to read the plug-in info.
66 """
67 dictionaryInfo = {"short": "",
68 "filename": "",
69 "documentation": "",
70 "locales": [],
71 }
72
73 while not self.atEnd():
74 self.readNext()
75 if self.isEndElement() and self.name() == "Dictionary":
76 self.__entryCallback(
77 dictionaryInfo["short"], dictionaryInfo["filename"],
78 self.baseUrl + dictionaryInfo["filename"],
79 dictionaryInfo["documentation"], dictionaryInfo["locales"])
80 break
81
82 if self.isStartElement():
83 if self.name() == "Short":
84 dictionaryInfo["short"] = self.readElementText()
85 elif self.name() == "Filename":
86 dictionaryInfo["filename"] = self.readElementText()
87 elif self.name() == "Documentation":
88 dictionaryInfo["documentation"] = self.readElementText()
89 elif self.name() == "Locales":
90 dictionaryInfo["locales"] = self.readElementText().split()
91 else:
92 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial