Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    def __init__(self, sargs):
        """
        sargs -- stripped args (normally sys.args[1:])
        """
        self.wikiToOpen = None  # Path to wiki to open
                # (interpreted by PersonalWikiFrame)
        self.wikiWordsToOpen = None  # Name of wiki words to open
                # (interpreted by PersonalWikiFrame)
        self.anchorToOpen = None   # Name of anchor to open in wiki word
        self.exitFinally = False   # Exit WikidPad when done
                # (interpreted by PersonalWikiFrame)
        self.showHelp = False   # Show help text?
        self.cmdLineError = False   # Command line couldn't be interpreted
        self.exportWhat = None   # String identifying what to export
        self.exportType = None   # Export into which type of data?
        self.exportDest = None   # Destination path to dir/file
        self.exportCompFn = False   # Export with compatible filenames?
        self.exportSaved = None  # Name of saved export instead
        self.continuousExportSaved = None  # Name of saved export to run as continuous export
        self.rebuild = self.NOT_SET  # Rebuild the wiki
        self.frameToOpen = 1  # Open wiki in new frame? (yet unrecognized) 
                # 1:New frame, 2:Already open frame, 0:Use config default 
        self.activeTabNo = -1  # Number of tab to activate
                # (interpreted by PersonalWikiFrame)
        self.lastTabsSubCtrls = None  # Corresponding list of subcontrol names
                # for each wikiword to open
        self.noRecent = False  # Do not modify history of recently opened wikis

        if len(sargs) == 0:
            return
            
        if sargs[0][0] != "-":
            # Old style, mainly used by the system

            # mbcs decoding of parameters
            sargs = [mbcsDec(a, "replace")[0] for a in sargs]
            self.setWikiToOpen(sargs[0])

            if len(sargs) > 1:
                self.wikiWordsToOpen = (sargs[1],)

            return

        # New style
        try:
            opts, rargs = getopt.getopt(sargs, "hw:p:x",
                    ["help", "wiki=", "page=", "exit", "export-what=",
                    "export-type=", "export-dest=", "export-compfn",
                    "export-saved=", "continuous-export-saved=",
                    "anchor",
                    "rebuild", "update-ext", "no-recent", "preview", "editor"])
        except getopt.GetoptError:
            self.cmdLineError = True
            return

        wikiWordsToOpen = []

        for o, a in opts:
            if o in ("-h", "--help"):
                self.showHelp = True
            elif o in ("-w", "--wiki"):
                self.wikiToOpen = mbcsDec(a, "replace")[0]
            elif o in ("-p", "--page"):
                wikiWordsToOpen.append(mbcsDec(a, "replace")[0])
            elif o == "--anchor":
                self.anchorToOpen = mbcsDec(a, "replace")[0]
            elif o in ("-x", "--exit"):
                self.exitFinally = True
            elif o == "--export-what":
                self.exportWhat = mbcsDec(a, "replace")[0]
            elif o == "--export-type":
                self.exportType = mbcsDec(a, "replace")[0]
            elif o == "--export-dest":
                self.exportDest = mbcsDec(a, "replace")[0]
            elif o == "--export-compfn":
                self.exportCompFn = True
            elif o == "--export-saved":
                self.exportSaved = mbcsDec(a, "replace")[0]
            elif o == "--continuous-export-saved":
                self.continuousExportSaved = mbcsDec(a, "replace")[0]
            elif o == "--rebuild":
                self.rebuild = self.REBUILD_FULL
            elif o == "--update-ext":
                self.rebuild = self.REBUILD_EXT
            elif o == "--no-recent":                
                self.noRecent = True
            elif o == "--preview":
                self._fillLastTabsSubCtrls(len(wikiWordsToOpen), "preview")
            elif o == "--editor":
                self._fillLastTabsSubCtrls(len(wikiWordsToOpen), "textedit")


        if len(wikiWordsToOpen) > 0:
            self.wikiWordsToOpen = tuple(wikiWordsToOpen)
Ejemplo n.º 6
0
BulletRE = re.compile(
    ur"^(?P<indentBullet>[ \t]*)(?P<actualBullet>\*[ \t])", re.DOTALL | re.UNICODE | re.MULTILINE
)  # SPN
NumericBulletRE = re.compile(
    ur"^(?P<indentNumeric>[ \t]*)(?P<preLastNumeric>(?:\d+\.)*)(\d+)\.[ \t]", re.DOTALL | re.UNICODE | re.MULTILINE
)  # SPN


# WikiWords
# WikiWordRE      = re.compile(r"\b(?<!~)(?:[A-Z\xc0-\xde\x8a-\x8f]+[a-z\xdf-\xff\x9a-\x9f]+[A-Z\xc0-\xde\x8a-\x8f]+[a-zA-Z0-9\xc0-\xde\x8a-\x8f\xdf-\xff\x9a-\x9f]*|[A-Z\xc0-\xde\x8a-\x8f]{2,}[a-z\xdf-\xff\x9a-\x9f]+)\b")
# WikiWordRE2     = re.compile("\[[a-zA-Z0-9\-\_\s]+?\]")


# TODO To unicode

UPPERCASE = mbcsDec(string.uppercase)[0]
LOWERCASE = mbcsDec(string.lowercase)[0]
LETTERS = UPPERCASE + LOWERCASE


# # Pattern string for delimiter for search fragment after wiki word
# WikiWordSearchFragDelimPAT = ur"#"
#
# # Pattern string for search fragment itself
# WikiWordSearchFragPAT = ur"(?:#.|[^ \t\n#])+"


singleWikiWord = (
    ur"(?:["
    + UPPERCASE
    +
    def __init__(self, sargs):
        """
        sargs -- stripped args (normally sys.args[1:])
        """
        self.wikiToOpen = None  # Path to wiki to open
        # (interpreted by PersonalWikiFrame)
        self.wikiWordsToOpen = None  # Name of wiki words to open
        # (interpreted by PersonalWikiFrame)
        self.anchorToOpen = None  # Name of anchor to open in wiki word
        self.exitFinally = False  # Exit WikidPad when done
        # (interpreted by PersonalWikiFrame)
        self.showHelp = False  # Show help text?
        self.cmdLineError = False  # Command line couldn't be interpreted
        self.exportWhat = None  # String identifying what to export
        self.exportType = None  # Export into which type of data?
        self.exportDest = None  # Destination path to dir/file
        self.exportCompFn = False  # Export with compatible filenames?
        self.exportSaved = None  # Name of saved export instead
        self.continuousExportSaved = None  # Name of saved export to run as continuous export
        self.rebuild = self.NOT_SET  # Rebuild the wiki
        self.frameToOpen = 1  # Open wiki in new frame? (yet unrecognized)
        # 1:New frame, 2:Already open frame, 0:Use config default
        self.activeTabNo = -1  # Number of tab to activate
        # (interpreted by PersonalWikiFrame)
        self.lastTabsSubCtrls = None  # Corresponding list of subcontrol names
        # for each wikiword to open
        self.noRecent = False  # Do not modify history of recently opened wikis

        if len(sargs) == 0:
            return

        if sargs[0][0] != "-":
            # Old style, mainly used by the system

            # mbcs decoding of parameters
            sargs = [mbcsDec(a, "replace")[0] for a in sargs]
            self.setWikiToOpen(sargs[0])

            if len(sargs) > 1:
                self.wikiWordsToOpen = (sargs[1], )

            return

        # New style
        try:
            opts, rargs = getopt.getopt(sargs, "hw:p:x", [
                "help", "wiki=", "page=", "exit", "export-what=",
                "export-type=", "export-dest=", "export-compfn",
                "export-saved=", "continuous-export-saved=", "anchor",
                "rebuild", "update-ext", "no-recent", "preview", "editor"
            ])
        except getopt.GetoptError:
            self.cmdLineError = True
            return

        wikiWordsToOpen = []

        for o, a in opts:
            if o in ("-h", "--help"):
                self.showHelp = True
            elif o in ("-w", "--wiki"):
                self.wikiToOpen = mbcsDec(a, "replace")[0]
            elif o in ("-p", "--page"):
                wikiWordsToOpen.append(mbcsDec(a, "replace")[0])
            elif o == "--anchor":
                self.anchorToOpen = mbcsDec(a, "replace")[0]
            elif o in ("-x", "--exit"):
                self.exitFinally = True
            elif o == "--export-what":
                self.exportWhat = mbcsDec(a, "replace")[0]
            elif o == "--export-type":
                self.exportType = mbcsDec(a, "replace")[0]
            elif o == "--export-dest":
                self.exportDest = mbcsDec(a, "replace")[0]
            elif o == "--export-compfn":
                self.exportCompFn = True
            elif o == "--export-saved":
                self.exportSaved = mbcsDec(a, "replace")[0]
            elif o == "--continuous-export-saved":
                self.continuousExportSaved = mbcsDec(a, "replace")[0]
            elif o == "--rebuild":
                self.rebuild = self.REBUILD_FULL
            elif o == "--update-ext":
                self.rebuild = self.REBUILD_EXT
            elif o == "--no-recent":
                self.noRecent = True
            elif o == "--preview":
                self._fillLastTabsSubCtrls(len(wikiWordsToOpen), "preview")
            elif o == "--editor":
                self._fillLastTabsSubCtrls(len(wikiWordsToOpen), "textedit")

        if len(wikiWordsToOpen) > 0:
            self.wikiWordsToOpen = tuple(wikiWordsToOpen)