create UserError exception

Modules can raise this exception when they want to print errors to user
This commit is contained in:
Romain Bignon 2012-04-25 13:43:52 +02:00
commit aea269e9f6
21 changed files with 68 additions and 47 deletions

View file

@ -27,6 +27,7 @@ import urllib
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserUnavailable
from weboob.tools.json import json
from weboob.capabilities.base import UserError
from weboob.capabilities.chat import ChatException, ChatMessage
from weboob.capabilities.messages import CantSendMessage
@ -34,7 +35,7 @@ from weboob.capabilities.messages import CantSendMessage
__all__ = ['AuMBrowser']
class AuMException(Exception):
class AuMException(UserError):
ERRORS = {"0.0.0": "Bad signature",
"0.0.1": "Malformed request",
"0.0.2": "Not logged",

View file

@ -20,6 +20,7 @@
import datetime
import re
from weboob.capabilities import UserError
from weboob.tools.capabilities.thumbnail import Thumbnail
from weboob.tools.browser import BasePage, BrokenPageError
@ -69,7 +70,7 @@ class VideoPage(BasePage):
def on_loaded(self):
p = self.parser.select(self.document.getroot(), 'p.alert')
if len(p) > 0:
raise Exception(p[0].text)
raise UserError(p[0].text)
def get_info_url(self):
try:

View file

@ -21,7 +21,7 @@
from dateutil.parser import parse as parse_dt
import urllib
from weboob.capabilities.base import NotAvailable
from weboob.capabilities.base import NotAvailable, UserError
from weboob.tools.capabilities.thumbnail import Thumbnail
from weboob.tools.browser import BasePage, BrokenPageError
from weboob.tools.misc import to_unicode
@ -32,7 +32,7 @@ from ..video import NolifeTVVideo
__all__ = ['VideoPage']
class ForbiddenVideo(Exception):
class ForbiddenVideo(UserError):
pass

View file

@ -19,6 +19,7 @@
import datetime
from weboob.capabilities import UserError
from weboob.tools.misc import to_unicode
from weboob.tools.browser import BasePage, BrokenPageError
@ -26,7 +27,7 @@ from weboob.tools.browser import BasePage, BrokenPageError
__all__ = ['StationNotFound', 'DeparturesPage']
class StationNotFound(Exception):
class StationNotFound(UserError):
pass
class DeparturesPage(BasePage):

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from .base import NotLoaded, NotAvailable, CapBaseObject, IBaseCap
from .base import UserError, NotLoaded, NotAvailable, CapBaseObject, IBaseCap
__all__ = ['NotLoaded', 'NotAvailable', 'CapBaseObject', 'IBaseCap']
__all__ = ['UserError', 'NotLoaded', 'NotAvailable', 'CapBaseObject', 'IBaseCap']

View file

@ -18,13 +18,13 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject, StringField, Field
from .base import IBaseCap, CapBaseObject, StringField, Field, UserError
__all__ = ['AccountRegisterError', 'Account', 'StatusField', 'ICapAccount']
class AccountRegisterError(Exception):
class AccountRegisterError(UserError):
"""
Raised when there is an error during registration.
"""

View file

@ -20,22 +20,22 @@
from datetime import date, datetime
from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField
from .base import CapBaseObject, Field, StringField, DateField, DecimalField, IntField, UserError
from .collection import ICapCollection
__all__ = ['AccountNotFound', 'TransferError', 'Recipient', 'Account', 'Transaction', 'Transfer', 'ICapBank']
class AccountNotFound(Exception):
class AccountNotFound(UserError):
"""
Raised when an account is not found.
"""
def __init__(self, msg='Account not found'):
Exception.__init__(self, msg)
UserError.__init__(self, msg)
class TransferError(Exception):
class TransferError(UserError):
"""
A transfer has failed.
"""

View file

@ -27,7 +27,7 @@ from weboob.tools.misc import to_unicode
from weboob.tools.ordereddict import OrderedDict
__all__ = ['FieldNotFound', 'NotAvailable', 'NotLoaded', 'IBaseCap',
__all__ = ['UserError', 'FieldNotFound', 'NotAvailable', 'NotLoaded', 'IBaseCap',
'Field', 'IntField', 'DecimalField', 'FloatField', 'StringField',
'BytesField', 'DateField', 'DeltaField', 'empty', 'CapBaseObject']
@ -44,6 +44,12 @@ def empty(value):
return False
class UserError(Exception):
"""
Exception containing an error message for user.
"""
class FieldNotFound(Exception):
"""
A field isn't found.

View file

@ -17,27 +17,28 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import CapBaseObject, StringField, DateField, DecimalField
from .base import CapBaseObject, StringField, DateField, DecimalField, UserError
from .collection import ICapCollection
__all__ = ['SubscriptionNotFound', 'BillNotFound', 'Detail', 'Bill', 'Subscription', 'ICapBill']
class SubscriptionNotFound(Exception):
class SubscriptionNotFound(UserError):
"""
Raised when a subscription is not found.
"""
def __init__(self, msg='Subscription not found'):
Exception.__init__(self, msg)
UserError.__init__(self, msg)
class BillNotFound(Exception):
class BillNotFound(UserError):
"""
Raised when a bill is not found.
"""
def __init__(self, msg='Bill not found'):
Exception.__init__(self, msg)
UserError.__init__(self, msg)
class Detail(CapBaseObject):

View file

@ -19,14 +19,14 @@
from .base import IBaseCap, CapBaseObject, Field, StringField, DateField, \
IntField, DeltaField
IntField, DeltaField, UserError
__all__ = ['IssueError', 'Project', 'User', 'Version', 'Status', 'Attachment',
'Change', 'Update', 'Issue', 'Query', 'ICapBugTracker']
class IssueError(Exception):
class IssueError(UserError):
"""
Raised when there is an error with an issue.
"""

View file

@ -20,13 +20,13 @@
import datetime
from .base import IBaseCap, CapBaseObject, StringField, DateField
from .base import IBaseCap, CapBaseObject, StringField, DateField, UserError
__all__ = ['ChatException', 'ChatMessage', 'ICapChat']
class ChatException(Exception):
class ChatException(UserError):
"""
Exception raised when there is a problem with the chat.
"""

View file

@ -17,18 +17,20 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject
from .base import IBaseCap, CapBaseObject, UserError
__all__ = ['ICapCollection', 'BaseCollection', 'Collection', 'CollectionNotFound']
class CollectionNotFound(Exception):
class CollectionNotFound(UserError):
def __init__(self, split_path=None):
if split_path is not None:
msg = 'Collection not found: %s' % '/'.join(split_path)
else:
msg = 'Collection not found'
Exception.__init__(self, msg)
UserError.__init__(self, msg)
class BaseCollection(CapBaseObject):

View file

@ -18,7 +18,8 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject, Field, StringField, BytesField, IntField
from .base import IBaseCap, CapBaseObject, Field, StringField, BytesField, IntField, \
UserError
from weboob.tools.ordereddict import OrderedDict
@ -108,7 +109,7 @@ class Contact(CapBaseObject):
setattr(photo, key, value)
class QueryError(Exception):
class QueryError(UserError):
"""
Raised when unable to send a query to a contact.
"""

View file

@ -18,14 +18,14 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject, Field, StringField, DateField
from .base import IBaseCap, CapBaseObject, Field, StringField, DateField, UserError
from .contact import Contact
__all__ = ['OptimizationNotFound', 'Optimization', 'Event', 'ICapDating']
class OptimizationNotFound(Exception):
class OptimizationNotFound(UserError):
"""
Raised when an optimization is not found.
"""

View file

@ -21,7 +21,8 @@
import datetime
import time
from .base import IBaseCap, CapBaseObject, NotLoaded, Field, StringField, DateField, IntField
from .base import IBaseCap, CapBaseObject, NotLoaded, Field, StringField, \
DateField, IntField, UserError
__all__ = ['Thread', 'Message', 'ICapMessages', 'CantSendMessage', 'ICapMessagesPost']
@ -198,7 +199,7 @@ class ICapMessages(IBaseCap):
"""
raise NotImplementedError()
class CantSendMessage(Exception):
class CantSendMessage(UserError):
"""
Raised when a message can't be send.
"""

View file

@ -18,13 +18,13 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject, NotLoaded, Field, StringField
from .base import IBaseCap, CapBaseObject, NotLoaded, Field, StringField, UserError
__all__ = ['PasteNotFound', 'BasePaste', 'ICapPaste']
class PasteNotFound(Exception):
class PasteNotFound(UserError):
"""
Raised when a paste is not found.
"""

View file

@ -18,19 +18,20 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject, Field, StringField, FloatField, DateField, IntField
from .base import IBaseCap, CapBaseObject, Field, StringField, FloatField, \
DateField, IntField, UserError
__all__ = ['MagnetOnly', 'Torrent', 'ICapTorrent']
class MagnetOnly(Exception):
class MagnetOnly(UserError):
"""
Raised when trying to get URL to torrent but only magnet is available.
"""
def __init__(self, magnet):
self.magnet = magnet
Exception.__init__(self, 'Only magnet URL is available')
UserError.__init__(self, 'Only magnet URL is available')
class Torrent(CapBaseObject):

View file

@ -18,28 +18,28 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject, StringField
from .base import IBaseCap, CapBaseObject, StringField, UserError
__all__ = ['TranslationFail', 'LanguageNotSupported', 'ICapTranslate']
class LanguageNotSupported(Exception):
class LanguageNotSupported(UserError):
"""
Raised when the language is not supported
"""
def __init__(self, msg='language is not supported'):
Exception.__init__(self,msg)
UserError.__init__(self,msg)
class TranslationFail(Exception):
class TranslationFail(UserError):
"""
Raised when no translation matches the given request
"""
def __init__(self, msg='No Translation Available'):
Exception.__init__(self, msg)
UserError.__init__(self, msg)
class Translation(CapBaseObject):

View file

@ -20,7 +20,8 @@
import datetime
from .base import IBaseCap, CapBaseObject, StringField, TimeField, DeltaField, DateField
from .base import IBaseCap, CapBaseObject, StringField, TimeField, DeltaField, \
DateField, UserError
__all__ = ['Station', 'Departure', 'RoadStep', 'RoadmapError', 'RoadmapFilters', 'ICapTravel']
@ -72,7 +73,7 @@ class RoadStep(CapBaseObject):
arrival = StringField('Arrival station')
duration = DeltaField('Duration of this step')
class RoadmapError(Exception):
class RoadmapError(UserError):
"""
Raised when the roadmap is unable to be calculated.
"""

View file

@ -20,7 +20,8 @@
from datetime import datetime
from .base import IBaseCap, CapBaseObject, Field, DateField, FloatField, StringField
from .base import IBaseCap, CapBaseObject, Field, DateField, FloatField, \
StringField, UserError
__all__ = ['Forecast', 'Current', 'City', 'CityNotFound', 'ICapWeather']
@ -70,7 +71,7 @@ class City(CapBaseObject):
CapBaseObject.__init__(self, id)
self.name = name
class CityNotFound(Exception):
class CityNotFound(UserError):
"""
Raised when a city is not found.
"""

View file

@ -34,6 +34,7 @@ from weboob.core.scheduler import IScheduler
from weboob.tools.browser import BrowserUnavailable, BrowserIncorrectPassword
from weboob.tools.value import ValueInt, ValueBool, ValueBackendPassword
from weboob.tools.misc import to_unicode
from weboob.capabilities import UserError
from ..base import BaseApplication
@ -173,10 +174,13 @@ class QtDo(QObject):
msg = 'Invalid login/password.'
elif isinstance(error, BrowserUnavailable):
if not msg:
msg = 'website is unavailable.'
msg = 'Website is unavailable.'
elif isinstance(error, NotImplementedError):
msg = 'This feature is not supported by this backend.\n\n' \
'To help the maintainer of this backend implement this feature, please contact: %s <%s>' % (backend.MAINTAINER, backend.EMAIL)
elif isinstance(error, UserError):
if not msg:
msg = type(error).__name__
elif logging.root.level == logging.DEBUG:
msg += u'<br />'
ul_opened = False