def _getDict(self, lang, path): key = (lang, path) if key not in self._dictCache: broker = Broker() broker.set_param('enchant.myspell.dictionary.path', path) broker.set_ordering('*', 'myspell') currentDict = Dict(lang, broker) self._dictCache[key] = currentDict else: currentDict = self._dictCache[key] return currentDict
def test_prov_ordering(broker): """Test that provider ordering works correctly.""" langs = {} provs = [] # Find the providers for each language, and a list of all providers for (tag, prov) in broker.list_dicts(): # Skip hyphenation dictionaries installed by OOo if tag.startswith("hyph_") and prov.name == "myspell": continue # Canonicalize separators tag = tag.replace("-", "_") langs[tag] = [] # NOTE: we are excluding Zemberek here as it appears to return # a broker for any language, even nonexistent ones if prov not in provs and prov.name != "zemberek": provs.append(prov) for prov in provs: for tag in langs: b2 = Broker() b2.set_ordering(tag, prov.name) try: d = b2.request_dict(tag) if d.provider != prov: raise ValueError() langs[tag].append(prov) # TODO: bare except except: # noqa pass # Check availability using a single entry in ordering for tag in langs: for prov in langs[tag]: b2 = Broker() b2.set_ordering(tag, prov.name) d = b2.request_dict(tag) assert (d.provider, tag) == (prov, tag) del d del b2 # Place providers that don't have the language in the ordering for tag in langs: for prov in langs[tag]: order = prov.name for prov2 in provs: if prov2 not in langs[tag]: order = prov2.name + "," + order b2 = Broker() b2.set_ordering(tag, order) d = b2.request_dict(tag) assert (d.provider, tag, order) == (prov, tag, order) del d del b2