Esempio n. 1
0
def sqlite_testMatch(context, values):
    """
    Sqlite user-defined function "testMatch" for WikiData.search()
    method
    """
    nakedword = utf8Dec(values[0].value_blob(), "replace")[0]
    fileContents = utf8Dec(values[1].value_blob(), "replace")[0]
    sarOp = sqlite.getTransObject(values[2].value_int())
    if sarOp.testWikiPage(nakedword, fileContents) == True:
        context.result_int(1)
    else:
        context.result_null()
Esempio n. 2
0
def sqlite_utf8Normcase(context, values):
    """
    Sqlite user-defined function "utf8Normcase" to get the lowercase of a word
    encoded in UTF-8. The result is also encoded in UTF-8.
    """
    normalWord = utf8Dec(values[0].value_text(), "replace")[0].lower()
    context.result_text(utf8Enc(normalWord)[0])
Esempio n. 3
0
def sqlite_utf8Normcase(context, values):
    """
    Sqlite user-defined function "utf8Normcase" to get the lowercase of a word
    encoded in UTF-8. The result is also encoded in UTF-8.
    """
    normalWord = utf8Dec(values[0].value_text(), "replace")[0].lower()
    context.result_text(utf8Enc(normalWord)[0])
Esempio n. 4
0
def sqlite_utf8ToMbcs(context, values):
    """
    Used as user-defined sqlite function
    """
    enc = codecs.getencoder("mbcs")
    
    s = values[0].value_text()
    context.result_text(enc(utf8Dec(s, "replace")[0], "replace")[0])
Esempio n. 5
0
def sqlite_nakedWord(context, values):
    """
    Sqlite user-defined function "nakedWord" to remove brackets around
    wiki words. Needed for version update from 4 to 5.
    """
    word = utf8Dec(values[0].value_text(), "replace")[0]
    if word.startswith("[") and word.endswith("]"):
        nakedword = word[1:-1]
    else:
        nakedword = word

    context.result_text(utf8Enc(nakedword)[0])
Esempio n. 6
0
def column_utftext(stmt, col):
    return utf8Dec(column_text(stmt, col), "replace")[0]
Esempio n. 7
0
                raise DbWriteAccessError(e)

        lastException = None
        try:
            # Further possible updates
            DbStructure.updateDatabase2(self.connWrap)
        except sqlite.Error, e:
            # Remember but continue
            lastException = DbWriteAccessError(e)

        # Activate UTF8 support for text in database (content is blob!)
        DbStructure.registerUtf8Support(self.connWrap)

        # Function to convert from content in database to
        # return value, used by getContent()
        self.contentDbToOutput = lambda c: utf8Dec(c, "replace")[0]

        try:
            # Set marker for database type
            self.wikiDocument.getWikiConfig().set("main", "wiki_database_type",
                    "original_sqlite")
        except (IOError, OSError, sqlite.Error), e:
            # Remember but continue
            lastException = DbWriteAccessError(e)

        # Function to convert unicode strings from input to content in database
        # used by setContent

        def contentUniInputToDb(unidata):
            return utf8Enc(unidata, "replace")[0]
Esempio n. 8
0
def column_utftext(stmt, col):
    return utf8Dec(column_text(stmt, col), "replace")[0]
Esempio n. 9
0
def _utf8ToUni(ob):
    if type(ob) is str:
        return utf8Dec(ob, "replace")[0]
    else:
        return ob
Esempio n. 10
0
def _utf8ToUni(ob):
    if type(ob) is str:
        return utf8Dec(ob, "replace")[0]
    else:
        return ob