exceptions.py 3.21 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 73 74 75 76
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):
77
    type = 'g_recaptcha'
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

    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)


96 97 98 99 100 101 102 103
class BrowserHTTPNotFound(BrowserUnavailable):
    pass


class BrowserHTTPError(BrowserUnavailable):
    pass


104 105 106 107
class BrowserHTTPSDowngrade(BrowserUnavailable):
    pass


108 109 110 111
class BrowserSSLError(BrowserUnavailable):
    pass


112 113
class ParseError(Exception):
    pass
114 115 116 117 118 119


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
120

121

Jean Walrave's avatar
Jean Walrave committed
122 123
class NoAccountsException(Exception):
    pass
124 125 126 127


class ModuleInstallError(Exception):
    pass
128 129 130 131


class ModuleLoadError(Exception):
    def __init__(self, module_name, msg):
132
        super(ModuleLoadError, self).__init__(msg)
133
        self.module = module_name
134 135 136 137


class ActionNeeded(Exception):
    pass
138 139


140 141 142 143
class AuthMethodNotImplemented(ActionNeeded):
    pass


144 145
class BrowserPasswordExpired(ActionNeeded):
    pass