File: _exceptions.py

package info (click to toggle)
isbnlib 3.9.3-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 596 kB
  • sloc: python: 4,575; makefile: 4
file content (49 lines) | stat: -rw-r--r-- 1,367 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""Exceptions for isbnlib."""

import sys


def quiet_errors(exc_type, exc_value, traceback):
    """An error format suitable for end user scripts.

       Usage: enter the following lines in your script
              from isbnlib import quiet_errors
              sys.excepthook = quiet_errors
    """
    sys.stderr.write('Error: %s\n' % exc_value)  # pragma: no cover


class ISBNLibException(Exception):
    """Base class for isbnlib exceptions.

    This exception should not be raised directly,
    only subclasses of this exception should be used!
    """

    def __str__(self):
        return getattr(self, 'message', '')  # pragma: no cover


class NotRecognizedServiceError(ISBNLibException):
    """Exception raised when the service is not in config.py."""

    def __init__(self, service):
        self.message = "(%s) is not a recognized service" % service


class NotValidISBNError(ISBNLibException):
    """Exception raised when the ISBN is not valid."""

    def __init__(self, isbnlike):
        self.message = "(%s) is not a valid ISBN" % isbnlike


class PluginNotLoadedError(ISBNLibException):  # pragma: no cover
    """Exception raised when the plugin's loader doesn't load the plugin.

    TODO: Delete this in version 4?
    """

    def __init__(self, path):
        self.message = "plugin (%s) wasn't loaded" % path