def isOptionAllowed(self, section, option): """ The function tests if an option is valid. Only options can be set/retrieved which have an entry in the defaults and if the configParserObject is valid. """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] checkWiki = True checkGlobal = True if option.startswith("option/wiki/"): option = option[12:] checkGlobal = False elif option.startswith("option/user/"): option = option[12:] checkWiki = False if checkWiki and WIKIDEFAULTS.has_key((section, option)): return True if checkGlobal and GLOBALDEFAULTS.has_key((section, option)): return True return False
def set(self, section, option, value): if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] if option.startswith("option/wiki/"): option = option[12:] self.wikiConfig.set(section, option, value) elif option.startswith("option/user/"): option = option[12:] self.globalConfig.set(section, option, value) elif self.wikiConfig is not None and \ self.wikiConfig.getFallthroughDict().has_key((section, option)): raise UnknownOptionException, _(u"Ambiguos option set %s:%s") % ( section, option) else: if self.wikiConfig is not None and \ self.wikiConfig.isOptionAllowed(section, option): self.wikiConfig.set(section, option, value) elif self.globalConfig is not None: self.globalConfig.set(section, option, value) else: raise UnknownOptionException, _(u"Unknown option %s:%s") % ( section, option)
def get(self, section, option, default=None): """ Return a configuration value returned as string/unicode which is entered in given section and has specified option key. """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] result = None if self.isOptionAllowed(section, option): if self.configParserObject.has_option(section, option): result = self.configParserObject.get(section, option) else: result = self.configDefaults[(section, option)] else: raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option) if result is None: return default try: result = utf8Dec(result)[0] except UnicodeError: # Result is not Utf-8 -> try mbcs try: result = mbcsDec(result)[0] except UnicodeError: # Result can't be converted result = default return result
def set(self, section, option, value): if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] if self.isOptionAllowed(section, option): _setValue(section, option, value, self.configParserObject) else: raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
def isOptionAllowed(self, section, option): """ The function tests if an option is valid. Only options can be set/retrieved which have an entry in the defaults and if the configParserObject is valid. """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] return self.configParserObject is not None and self.configDefaults.has_key((section, option))
def get(self, section, option, default=None): """ Return a configuration value returned as string/unicode which is entered in given section and has specified option key. """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] result = None checkWiki = True checkGlobal = True if option.startswith("option/wiki/"): option = option[12:] checkGlobal = False elif option.startswith("option/user/"): option = option[12:] checkWiki = False if checkWiki: if self.wikiConfig is not None and \ self.wikiConfig.isOptionAllowed(section, option): result = self.wikiConfig.get(section, option, default) ftDict = self.wikiConfig.getFallthroughDict() if not ftDict.has_key((section, option)) or \ ftDict[(section, option)] != result: checkGlobal = False # TODO more elegantly elif WIKIDEFAULTS.has_key((section, option)): result = default checkGlobal = False elif not checkGlobal: raise UnknownOptionException, _(u"Unknown option %s:%s") % ( section, option) if checkGlobal: if self.globalConfig is not None: result = self.globalConfig.get(section, option, default) else: raise UnknownOptionException, _(u"Unknown option %s:%s") % ( section, option) if result is None: return default return result
def getDefault(self, section, option): """ Return the default configuration value as string/unicode """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] if self.isOptionAllowed(section, option): return self.configDefaults[(section, option)] else: raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
def isOptionAllowed(self, section, option): """ The function tests if an option is valid. Only options can be set/retrieved which have an entry in the defaults and if the configParserObject is valid. """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] return self.configParserObject is not None and \ self.configDefaults.has_key((section, option))
def get(self, section, option, default=None): """ Return a configuration value returned as string/unicode which is entered in given section and has specified option key. """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] result = None checkWiki = True checkGlobal = True if option.startswith("option/wiki/"): option = option[12:] checkGlobal = False elif option.startswith("option/user/"): option = option[12:] checkWiki = False if checkWiki: if self.wikiConfig is not None and \ self.wikiConfig.isOptionAllowed(section, option): result = self.wikiConfig.get(section, option, default) ftDict = self.wikiConfig.getFallthroughDict() if not ftDict.has_key((section, option)) or \ ftDict[(section, option)] != result: checkGlobal = False # TODO more elegantly elif WIKIDEFAULTS.has_key((section, option)): result = default checkGlobal = False elif not checkGlobal: raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option) if checkGlobal: if self.globalConfig is not None: result = self.globalConfig.get(section, option, default) else: raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option) if result is None: return default return result
def serUniUtf8(self, us): """ Serialize unicode string, encoded as UTF-8 """ if self.isReadMode(): return utf8Dec(self.serString(""), "replace")[0] else: self.serString(utf8Enc(us)[0]) return us
def getDefault(self, section, option): """ Return the default configuration value as string/unicode """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] result = None checkWiki = True checkGlobal = True if option.startswith("option/wiki/"): option = option[12:] checkGlobal = False elif option.startswith("option/user/"): option = option[12:] checkWiki = False if checkWiki: # TODO more elegantly if WIKIDEFAULTS.has_key((section, option)): result = WIKIDEFAULTS.get((section, option)) if not WIKIFALLTHROUGH.has_key((section, option)) or \ WIKIFALLTHROUGH[(section, option)] != result: checkGlobal = False elif not checkGlobal: raise UnknownOptionException, _(u"Unknown option %s:%s") % ( section, option) if checkGlobal: if self.globalConfig is not None: result = self.globalConfig.getDefault(section, option) else: raise UnknownOptionException, _(u"Unknown option %s:%s") % ( section, option) return result
def getDefault(self, section, option): """ Return the default configuration value as string/unicode """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] result = None checkWiki = True checkGlobal = True if option.startswith("option/wiki/"): option = option[12:] checkGlobal = False elif option.startswith("option/user/"): option = option[12:] checkWiki = False if checkWiki: # TODO more elegantly if WIKIDEFAULTS.has_key((section, option)): result = WIKIDEFAULTS.get((section, option)) if not WIKIFALLTHROUGH.has_key((section, option)) or \ WIKIFALLTHROUGH[(section, option)] != result: checkGlobal = False elif not checkGlobal: raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option) if checkGlobal: if self.globalConfig is not None: result = self.globalConfig.getDefault(section, option) else: raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option) return result
def set(self, section, option, value): if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] if option.startswith("option/wiki/"): option = option[12:] self.wikiConfig.set(section, option, value) elif option.startswith("option/user/"): option = option[12:] self.globalConfig.set(section, option, value) elif self.wikiConfig is not None and self.wikiConfig.getFallthroughDict().has_key((section, option)): raise UnknownOptionException, _(u"Ambiguos option set %s:%s") % (section, option) else: if self.wikiConfig is not None and self.wikiConfig.isOptionAllowed(section, option): self.wikiConfig.set(section, option, value) elif self.globalConfig is not None: self.globalConfig.set(section, option, value) else: raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
def _setValue(section, option, value, config): """ if value is of type str, it is assumed to be mbcs-coded if section or option are of type str, they are assumed to be utf8 coded (it is recommended to use only ascii characters for section/option names) """ if type(section) is unicode: section = utf8Enc(section)[0] if type(option) is unicode: option = utf8Enc(option)[0] if type(value) is str: value = utf8Enc(mbcsDec(value)[0])[0] elif type(value) is unicode: value = utf8Enc(value)[0] else: value = utf8Enc(unicode(value))[0] if not config.has_section(section): config.add_section(section) config.set(section, option, value)
self.exporterInstance.tempFileSet.clear() self.exporterInstance.buildStyleSheetList() content = self.presenter.getLiveText() html = self.exporterInstance.exportWikiPageToHtmlString(wikiPage) wx.GetApp().getInsertionPluginManager().taskEnd() if self.currentLoadedWikiWord == word and \ self.anchor is None: htpath = self.htpaths[self.currentHtpath] with open(htpath, "w") as f: f.write(utf8Enc(html)[0]) url = "file:" + urlFromPathname(htpath) self.currentLoadedUrl = url self.passNavigate += 1 # self.RefreshPage(iewin.REFRESH_COMPLETELY) lx, ly = self.GetViewStart() self.LoadUrl( url, iewin.NAV_NoReadFromCache | iewin.NAV_NoWriteToCache) self.scrollDeferred(lx, ly) else: self.currentLoadedWikiWord = word self.currentHtpath = 1 - self.currentHtpath
self.exporterInstance.tempFileSet.clear() self.exporterInstance.buildStyleSheetList() content = self.presenter.getLiveText() html = self.exporterInstance.exportWikiPageToHtmlString(wikiPage) wx.GetApp().getInsertionPluginManager().taskEnd() if self.currentLoadedWikiWord == word and \ self.anchor is None: htpath = self.htpaths[self.currentHtpath] with open(htpath, "w") as f: f.write(utf8Enc(html)[0]) url = "file:" + urlFromPathname(htpath) self.currentLoadedUrl = url self.passNavigate += 1 # self.RefreshPage(iewin.REFRESH_COMPLETELY) lx, ly = self.GetViewStart() self.LoadUrl(url, iewin.NAV_NoReadFromCache | iewin.NAV_NoWriteToCache) self.scrollDeferred(lx, ly) else: self.currentLoadedWikiWord = word self.currentHtpath = 1 - self.currentHtpath htpath = self.htpaths[self.currentHtpath]
def strxfrm(self, s): """ Returns a byte string usable as byte sort key for string s """ return utf8Enc(s)[0]