You're replying to a comment by yttrium.

yttrium Permalink
January 08, 2010, 14:54

bug:

class DetectionError(Exception):
    pass

NameError: global name 'DetectError' is not defined

    def detect(self, message):
        """
        Given a 'message' detects its language.
        Returns Language object.
        """

        message = quote_plus(message)
        real_url = LanguageDetector.detect_url % { 'message': message }

        try:
            detection = self.browser.get_page(real_url)
            data = json.loads(detection)

            if data['responseStatus'] != 200:
                raise DetectError, "Failed detecting language: %s" % data['responseDetails']

            rd = data['responseData']
            return Language(rd['language'], rd['confidence'], rd['isReliable'])

        except BrowserError, e:
            raise DetectError, "Failed detecting language (getting %s failed): %s" % (e.url, e.error)
        except ValueError, e:
            raise DetectErrro, "Failed detecting language (json failed): %s" % e.message
        except KeyError, e:
            raise DetectError, "Failed detecting language, response didn't contain the necessary data"

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "cdrom_158": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.