Exemple #1
0
    def matches_entry(self, model, itr, user_data=None):
        entry_text = self._entry.get_text()
        if not entry_text:
            # everything matches empty string
            return True

        value = model[itr][0]
        eng_value = self._xkl_wrapper.get_layout_variant_description(value, xlated=False)
        xlated_value = self._xkl_wrapper.get_layout_variant_description(value)
        translit_value = strip_accents(xlated_value).lower()
        translit_text = strip_accents(unicode(entry_text, "utf-8")).lower()

        return have_word_match(entry_text, eng_value) or have_word_match(entry_text, xlated_value) \
            or have_word_match(translit_text, translit_value)
Exemple #2
0
    def matches_entry(self, model, itr, user_data=None):
        entry_text = self._entry.get_text()
        if not entry_text:
            # everything matches empty string
            return True

        value = model[itr][0]
        eng_value = self._xkl_wrapper.get_layout_variant_description(
            value, xlated=False)
        xlated_value = self._xkl_wrapper.get_layout_variant_description(value)
        translit_value = strip_accents(xlated_value).lower()
        translit_text = strip_accents(unicode(entry_text, "utf-8")).lower()

        return have_word_match(entry_text, eng_value) or have_word_match(entry_text, xlated_value) \
            or have_word_match(translit_text, translit_value)
Exemple #3
0
def guess_username(fullname):
    fullname = fullname.split()

    # use last name word (at the end in most of the western countries..)
    if len(fullname) > 0:
        username = fullname[-1].decode("utf-8").lower()
    else:
        username = u""

    # and prefix it with the first name inital
    if len(fullname) > 1:
        username = fullname[0].decode("utf-8")[0].lower() + username

    username = strip_accents(username).encode("utf-8")
    return username
Exemple #4
0
def guess_username(fullname):
    fullname = fullname.split()

    # use last name word (at the end in most of the western countries..)
    if len(fullname) > 0:
        username = fullname[-1].decode("utf-8").lower()
    else:
        username = u""

    # and prefix it with the first name inital
    if len(fullname) > 1:
        username = fullname[0].decode("utf-8")[0].lower() + username

    username = strip_accents(username).encode("utf-8")
    return username
    def _matches_entry(self, model, itr, *args):
        # Nothing in the text entry?  Display everything.
        entry = self._languageEntry.get_text().strip()
        if not entry:
            return True

        # Need to strip out the pango markup before attempting to match.
        # Otherwise, starting to type "span" for "spanish" will match everything
        # due to the enclosing span tag.
        # (success, attrs, native, accel)
        native = Pango.parse_markup(model[itr][0], -1, "_")[2]
        english = model[itr][1]

        # Otherwise, filter the list showing only what is matched by the
        # text entry.  Either the English or native names can match.
        lowered = entry.lower()
        translit = strip_accents(unicode(native, "utf-8")).lower()
        if lowered in native.lower() or lowered in english.lower() or lowered in translit:
            return True
        else:
            return False
Exemple #6
0
    def _matches_entry(self, model, itr, *args):
        # Nothing in the text entry?  Display everything.
        entry = self._languageEntry.get_text().strip()
        if not entry:
            return True

        # Need to strip out the pango markup before attempting to match.
        # Otherwise, starting to type "span" for "spanish" will match everything
        # due to the enclosing span tag.
        # (success, attrs, native, accel)
        native = Pango.parse_markup(model[itr][0], -1, "_")[2]
        english = model[itr][1]

        # Otherwise, filter the list showing only what is matched by the
        # text entry.  Either the English or native names can match.
        lowered = entry.lower()
        translit = strip_accents(native).lower()
        if lowered in native.lower() or lowered in english.lower() or lowered in translit:
            return True
        else:
            return False
Exemple #7
0
    def strip_accents_test(self):
        """Test strip_accents."""

        # string needs to be Unicode,
        # otherwise TypeError is raised
        with self.assertRaises(TypeError):
            iutil.strip_accents("")
        with self.assertRaises(TypeError):
            iutil.strip_accents("abc")
        with self.assertRaises(TypeError):
            iutil.strip_accents("ěščřžýáíé")

        # empty Unicode string
        self.assertEquals(iutil.strip_accents(u""), u"")

        # some Czech accents
        self.assertEquals(iutil.strip_accents(u"ěščřžýáíéúů"), u"escrzyaieuu")
        self.assertEquals(iutil.strip_accents(u"v češtině"), u"v cestine")
        self.assertEquals(iutil.strip_accents(u"měšťánek rozšíří HÁČKY"),
                                              u"mestanek rozsiri HACKY")
        self.assertEquals(iutil.strip_accents(u"nejneobhospodařovávatelnějšímu"),
                                              u"nejneobhospodarovavatelnejsimu")

        # some German umlauts
        self.assertEquals(iutil.strip_accents(u"Lärmüberhörer"), u"Larmuberhorer")
        self.assertEquals(iutil.strip_accents(u"Heizölrückstoßabdämpfung"),
                                              u"Heizolrucksto\xdfabdampfung")

        # some Japanese
        self.assertEquals(iutil.strip_accents(u"日本語"), u"\u65e5\u672c\u8a9e")
        self.assertEquals(iutil.strip_accents(u"アナコンダ"),  # Anaconda
                          u"\u30a2\u30ca\u30b3\u30f3\u30bf")

        # combined
        input_string = u"ASCI měšťánek アナコンダ Heizölrückstoßabdämpfung"
        output_string =u"ASCI mestanek \u30a2\u30ca\u30b3\u30f3\u30bf Heizolrucksto\xdfabdampfung"
        self.assertEquals(iutil.strip_accents(input_string), output_string)
Exemple #8
0
    def strip_accents_test(self):
        """Test strip_accents."""

        # empty string
        self.assertEqual(iutil.strip_accents(u""), u"")
        self.assertEqual(iutil.strip_accents(""), "")

        # some Czech accents
        self.assertEqual(iutil.strip_accents(u"ěščřžýáíéúů"), u"escrzyaieuu")
        self.assertEqual(iutil.strip_accents(u"v češtině"), u"v cestine")
        self.assertEqual(iutil.strip_accents(u"měšťánek rozšíří HÁČKY"),
                         u"mestanek rozsiri HACKY")
        self.assertEqual(
            iutil.strip_accents(u"nejneobhospodařovávatelnějšímu"),
            u"nejneobhospodarovavatelnejsimu")

        # some German umlauts
        self.assertEqual(iutil.strip_accents(u"Lärmüberhörer"),
                         u"Larmuberhorer")
        self.assertEqual(iutil.strip_accents(u"Heizölrückstoßabdämpfung"),
                         u"Heizolrucksto\xdfabdampfung")

        # some Japanese
        self.assertEqual(iutil.strip_accents(u"日本語"), u"\u65e5\u672c\u8a9e")
        self.assertEqual(
            iutil.strip_accents(u"アナコンダ"),  # Anaconda
            u"\u30a2\u30ca\u30b3\u30f3\u30bf")

        # combined
        input_string = u"ASCI měšťánek アナコンダ Heizölrückstoßabdämpfung"
        output_string = u"ASCI mestanek \u30a2\u30ca\u30b3\u30f3\u30bf Heizolrucksto\xdfabdampfung"
        self.assertEqual(iutil.strip_accents(input_string), output_string)