exceptions.py 3.78 KB
Newer Older
1 2 3 4 5 6 7
# -*- coding: utf-8 -*-

# Copyright(C) 2014 Romain Bignon
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Lesser General Public License as published by
9 10 11 12 13 14
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Lesser General Public License for more details.
16
#
17
# You should have received a copy of the GNU Lesser General Public License
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
# along with weboob. If not, see <http://www.gnu.org/licenses/>.

class BrowserIncorrectPassword(Exception):
    pass


class BrowserForbidden(Exception):
    pass


class BrowserBanned(BrowserIncorrectPassword):
    pass


class BrowserUnavailable(Exception):
    pass


36 37 38 39 40
class BrowserInteraction(Exception):
    pass


class BrowserQuestion(BrowserInteraction):
41 42 43 44 45
    """
    When raised by a browser,
    """
    def __init__(self, *fields):
        self.fields = fields
46 47


48 49 50 51
class BrowserRedirect(BrowserInteraction):
    def __init__(self, url):
        self.url = url

52 53 54
    def __str__(self):
        return 'Redirecting to %s' % self.url

55

56
class CaptchaQuestion(Exception):
57 58 59
    """Site requires solving a CAPTCHA (base class)"""
    # could be improved to pass the name of the backendconfig key

60
    def __init__(self, type=None, **kwargs):
61
        super(CaptchaQuestion, self).__init__("The site requires solving a captcha")
62
        self.type = type
63 64
        for key, value in kwargs.items():
            setattr(self, key, value)
65 66


67 68 69 70 71 72
class WrongCaptchaResponse(Exception):
    """when website tell us captcha response is not good"""
    def __init__(self, message=None):
        super(WrongCaptchaResponse, self).__init__(message or "Captcha response is wrong")


73 74 75 76 77 78 79 80 81 82
class ImageCaptchaQuestion(CaptchaQuestion):
    type = 'image_captcha'

    image_data = None

    def __init__(self, image_data):
        super(ImageCaptchaQuestion, self).__init__(self.type, image_data=image_data)


class NocaptchaQuestion(CaptchaQuestion):
83
    type = 'g_recaptcha'
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

    website_key = None
    website_url = None

    def __init__(self, website_key, website_url):
        super(NocaptchaQuestion, self).__init__(self.type, website_key=website_key, website_url=website_url)


class RecaptchaQuestion(CaptchaQuestion):
    type = 'g_recaptcha'

    website_key = None
    website_url = None

    def __init__(self, website_key, website_url):
        super(RecaptchaQuestion, self).__init__(self.type, website_key=website_key, website_url=website_url)


Florian Duguet's avatar
Florian Duguet committed
102 103 104 105 106 107 108 109 110 111 112 113
class FuncaptchaQuestion(CaptchaQuestion):
    type = 'funcaptcha'

    website_key = None
    website_url = None
    sub_domain = None

    def __init__(self, website_key, website_url, sub_domain=None):
        super(FuncaptchaQuestion, self).__init__(
            self.type, website_key=website_key, website_url=website_url, sub_domain=sub_domain)


114 115 116 117 118 119 120 121
class BrowserHTTPNotFound(BrowserUnavailable):
    pass


class BrowserHTTPError(BrowserUnavailable):
    pass


122 123 124 125
class BrowserHTTPSDowngrade(BrowserUnavailable):
    pass


126 127 128 129
class BrowserSSLError(BrowserUnavailable):
    pass


130 131
class ParseError(Exception):
    pass
132 133 134 135 136 137


class FormFieldConversionWarning(UserWarning):
    """
    A value has been set to a form's field and has been implicitly converted.
    """
Jean Walrave's avatar
Jean Walrave committed
138

139

Jean Walrave's avatar
Jean Walrave committed
140 141
class NoAccountsException(Exception):
    pass
142 143 144 145


class ModuleInstallError(Exception):
    pass
146 147 148 149


class ModuleLoadError(Exception):
    def __init__(self, module_name, msg):
150
        super(ModuleLoadError, self).__init__(msg)
151
        self.module = module_name
152 153 154 155


class ActionNeeded(Exception):
    pass
156 157


158 159 160 161
class AuthMethodNotImplemented(ActionNeeded):
    pass


162 163
class BrowserPasswordExpired(ActionNeeded):
    pass