f99ed4330490642f8a61ffeb37a6638dcad842c4
[odoo/odoo.git] / openerp / exceptions.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2011 OpenERP s.a. (<http://openerp.com>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 """ OpenERP core exceptions.
23
24 This module defines a few exception types. Those types are understood by the
25 RPC layer. Any other exception type bubbling until the RPC layer will be
26 treated as a 'Server error'.
27
28 """
29
30 import re
31
32 class Warning(Exception):
33     pass
34
35 class WarningConfig(Exception):
36     """ Warning bound to a misconfiguration. """
37     def __init__(self, msg):
38         # WIP WIP WIP WIP WIP WIP WIP
39         def sub_path(g):
40             menu_xml_id = g.group(1)
41
42             return '(group to convert: '+menu_xml_id+')'
43
44         def sub_path(g):
45             menu_xml_id = g.group(1)
46
47             return '(group to convert: '+menu_xml_id+')'
48
49         # Treat the msg: find the menu_xml_id and the field_name
50         teststr = 'coucou [path:blabla_bla_bla]'
51         print ">>>>> sub: ", re.sub(r'\[path:([a-z_]*)\]', sub_path, teststr)
52         super(WarningConfig, self).__init__(msg)
53
54 class AccessDenied(Exception):
55     """ Login/password error. No message, no traceback. """
56     def __init__(self):
57         super(AccessDenied, self).__init__('Access denied.')
58         self.traceback = ('', '', '')
59
60 class AccessError(Exception):
61     """ Access rights error. """
62
63 class DeferredException(Exception):
64     """ Exception object holding a traceback for asynchronous reporting.
65
66     Some RPC calls (database creation and report generation) happen with
67     an initial request followed by multiple, polling requests. This class
68     is used to store the possible exception occuring in the thread serving
69     the first request, and is then sent to a polling request.
70
71     ('Traceback' is misleading, this is really a exc_info() triple.)
72     """
73     def __init__(self, msg, tb):
74         self.message = msg
75         self.traceback = tb
76
77 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: