Example #1
0
    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
Example #2
0
    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
Example #3
0
    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)
Example #4
0
    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
Example #5
0
    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
Example #6
0
    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)
Example #7
0
    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))
Example #9
0
    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
Example #10
0
    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)
Example #11
0
    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))
Example #12
0
    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)
Example #13
0
    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
Example #14
0
 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
Example #15
0
 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
Example #16
0
    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
Example #17
0
    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)
Example #19
0
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)
Example #20
0
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)
Example #21
0
            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
Example #22
0
            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]
Example #23
0
 def strxfrm(self, s):
     """
     Returns a byte string usable as byte sort key for string s
     """
     return utf8Enc(s)[0]
 def strxfrm(self, s):
     """
     Returns a byte string usable as byte sort key for string s
     """
     return utf8Enc(s)[0]