Exemple #1
0
    def reverse(self, name):  # pylint:disable=arguments-differ
        with_country = (GuessitConverter._with_country_regexp.match(name)
                        or GuessitConverter._with_country_regexp2.match(name))

        name = name.lower()
        if with_country:
            lang = babelfish.Language.fromguessit(
                with_country.group(1).strip())
            lang.country = babelfish.Country.fromguessit(
                with_country.group(2).strip())
            return lang.alpha3, lang.country.alpha2 if lang.country else None, lang.script or None

        # exceptions come first, as they need to override a potential match
        # with any of the other guessers
        try:
            return self.guessit_exceptions[name]
        except KeyError:
            pass

        for conv in [
                babelfish.Language, babelfish.Language.fromalpha3b,
                babelfish.Language.fromalpha2, babelfish.Language.fromname,
                babelfish.Language.fromopensubtitles
        ]:
            try:
                reverse = conv(name)
                return reverse.alpha3, reverse.country, reverse.script
            except (ValueError, babelfish.LanguageReverseError):
                pass

        raise babelfish.LanguageReverseError(name)
Exemple #2
0
    def reverse(self, name):  # pylint:disable=arguments-renamed
        name = name.lower()
        # exceptions come first, as they need to override a potential match
        # with any of the other guessers
        try:
            return self.guessit_exceptions[name]
        except KeyError:
            pass

        for conv in [
                babelfish.Language, babelfish.Language.fromalpha3b,
                babelfish.Language.fromalpha2, babelfish.Language.fromname,
                babelfish.Language.fromopensubtitles,
                babelfish.Language.fromietf
        ]:
            try:
                reverse = conv(name)
                return reverse.alpha3, reverse.country, reverse.script
            except (ValueError, babelfish.LanguageReverseError):
                pass

        raise babelfish.LanguageReverseError(name)