~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/error.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: iso-8859-1 -*-
2
2
""" MoinMoin errors
3
3
 
4
 
Supply Error class and sub classes used to raise various errors
 
4
    Supply Error class and sub classes used to raise various errors
5
5
 
6
 
@copyright: 2004, 2005 by Nir Soffer <nirs@freeshell.org>
7
 
@license: GNU GPL, see COPYING for details.
 
6
    @copyright: 2004-2005 Nir Soffer <nirs@freeshell.org>
 
7
    @license: GNU GPL, see COPYING for details.
8
8
"""
 
9
 
9
10
import sys
 
11
 
10
12
from MoinMoin import config
11
13
 
12
 
 
13
14
class Error(Exception):
14
15
    """ Base class for moin moin errors
15
16
 
16
17
    Use this class when you raise errors or create sub classes that
17
18
    may be used to display non ASCII error message.
18
 
    
 
19
 
19
20
    Standard errors work safely only with strings using ascii or
20
21
    unicode. This class can be used safely with both strings using
21
22
    config.charset and unicode.
23
24
    You can init this class with either unicode or string using
24
25
    config.charset encoding. On output, the class will convert the string
25
26
    to unicode or the unicode to string, using config.charset.
26
 
            
 
27
 
27
28
    When you want to render an error, use unicode() or str() as needed.
28
 
    
29
 
    TODO: translate strings?
30
29
    """
31
30
 
32
31
    def __init__(self, message):
43
42
            return unicode(self.message, config.charset)
44
43
        else:
45
44
            return unicode(self.message)
46
 
    
 
45
 
47
46
    def __str__(self):
48
47
        """ Return encoded message """
49
48
        if isinstance(self.message, unicode):
54
53
    def __getitem__(self, item):
55
54
        """ Make it possible to access attributes like a dict """
56
55
        return getattr(self, item)
57
 
    
 
56
 
58
57
 
59
58
class CompositeError(Error):
60
 
    ''' Base class for exceptions containing an exception
 
59
    """ Base class for exceptions containing an exception
61
60
 
62
61
    Do not use this class but its more specific sub classes.
63
62
 
67
66
    Example::
68
67
 
69
68
        class InternalError(CompositeError):
70
 
            """ Raise for internal errors """
71
 
        
 
69
            ''' Raise for internal errors '''
 
70
 
72
71
        try:
73
72
            # code that might fail...
74
73
        except HairyLowLevelError:
75
74
            raise InternalError("Sorry, internal error occurred")
76
 
            
 
75
 
77
76
    When showing a traceback, both InternalError traceback and
78
77
    HairyLowLevelError traceback are available.
79
 
    '''
 
78
    """
80
79
 
81
80
    def __init__(self, message):
82
81
        """ Save system exception info before this exception is raised """
83
82
        Error.__init__(self, message)
84
83
        self.innerException = sys.exc_info()
85
 
   
 
84
 
86
85
    def exceptions(self):
87
86
        """ Return a list of all inner exceptions """
88
87
        all = [self.innerException]
94
93
                break
95
94
        return all
96
95
 
97
 
   
98
96
class FatalError(CompositeError):
99
97
    """ Base class for fatal error we can't handle
100
98
 
111
109
    """ we didn't find a configuration for this URL """
112
110
    pass
113
111
 
 
112
class ConvertError(FatalError):
 
113
    """ Raise when html to storage format (e.g. 'wiki') conversion fails """
 
114
    name = "MoinMoin Convert Error"
 
115
 
 
116