~ubuntu-branches/ubuntu/intrepid/prewikka/intrepid

« back to all changes in this revision

Viewing changes to prewikka/Error.py

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2007-04-11 14:41:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070411144109-2hh7zx3amwd27b4l
Tags: upstream-0.9.10
ImportĀ upstreamĀ versionĀ 0.9.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004,2005 PreludeIDS Technologies. All Rights Reserved.
 
2
# Author: Nicolas Delon <nicolas.delon@prelude-ids.com>
 
3
#
 
4
# This file is part of the Prewikka program.
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2, or (at your option)
 
9
# any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; see the file COPYING.  If not, write to
 
18
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
 
 
21
import traceback
 
22
import StringIO
 
23
 
 
24
from prewikka import DataSet
 
25
from prewikka.templates import ErrorTemplate
 
26
 
 
27
 
 
28
 
 
29
class PrewikkaError(Exception):
 
30
    pass
 
31
 
 
32
class PrewikkaUserError(PrewikkaError):
 
33
    def __init__(self, name, message, display_traceback=False, log=None, log_user=None):
 
34
        self.dataset = DataSet.DataSet()
 
35
        self.template = "ErrorTemplate"
 
36
        self.dataset["message"] = message
 
37
        self.dataset["name"] = name
 
38
        self._log_priority = log
 
39
        self._log_user = log_user
 
40
        
 
41
        if display_traceback:
 
42
            output = StringIO.StringIO()
 
43
            traceback.print_exc(file=output)
 
44
            output.seek(0)
 
45
            tmp = output.read()
 
46
            self.dataset["traceback"] = tmp
 
47
        else:
 
48
            self.dataset["traceback"] = None
 
49
 
 
50
    def __str__(self):
 
51
        return self.dataset["message"]
 
52