[go: up one dir, main page]

File: exceptions.py

package info (click to toggle)
sclapp 0.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 316 kB
  • ctags: 466
  • sloc: python: 2,961; makefile: 35
file content (67 lines) | stat: -rw-r--r-- 1,847 bytes parent folder | download | duplicates (4)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (c) 2005-2007 Forest Bond.
# This file is part of the sclapp software package.
# 
# sclapp is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License version 2 as published by the Free
# Software Foundation.
# 
# A copy of the license has been included in the COPYING file.

'''This module implements sclapp exceptions.'''

from sclapp.util import safe_encode, safe_decode

class Error(Exception):
    '''Base exception for other exceptions defined in this module.'''

class CriticalError(Error):
    '''Indicates a fatal error.'''

    code = None
    message = None

    def __init__(self, code = 0, message = u''):
        if type(code) != int:
            raise ValueError, (
              u'first argument to CriticalError initializer '
              'should be an integer'
            )
        self.code = code
        self.message = message
        Error.__init__(self)

    def __str__(self):
        return safe_encode(self.message)

    def __unicode__(self):
        return safe_decode(self.message)

class UsageError(CriticalError):
    '''Indicates a usage error.'''

    def __init__(self, message = None):
        if message is not None:
            code = -1
        else:
            code = 0
        CriticalError.__init__(self, code, message)

class SignalError(Error):
    '''Indicates that a notify signal has been caught.'''

    def __init__(self, signum):
        self.signum = signum
        Error.__init__(self)

    def __str__(self):
        return 'caught signal %i' % self.signum

class ExitSignalError(CriticalError):
    '''Indicates that an exit signal has been caught.'''

    def __init__(self, signum):
        self.signum = signum
        CriticalError.__init__(self)

    def __str__(self):
        return 'caught exit signal %i' % self.signum