6b684ce7c9611847ad08022f5bff9def5c748b17
[platform/upstream/pygobject2.git] / gi / _error.py
1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
3 #
4 # Copyright (C) 2014 Simon Feltman <sfeltman@gnome.org>
5 #
6 #   _error.py: GError Python implementation
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
21 # USA
22
23
24 # NOTE: This file should not have any dependencies on introspection libs
25 # like gi.repository.GLib because it would cause a circular dependency.
26 # Developers wanting to use the GError class in their applications should
27 # use gi.repository.GLib.GError
28
29
30 class GError(RuntimeError):
31     def __init__(self, message='unknown error', domain='pygi-error', code=0):
32         super(GError, self).__init__(message)
33         self.message = message
34         self.domain = domain
35         self.code = code
36
37     def __str__(self):
38         return "%s: %s (%d)" % (self.domain, self.message, self.code)
39
40     def __repr__(self):
41         return "%s.%s('%s', '%s', %d)" % (GError.__module__, GError.__name__,
42                                           self.message, self.domain, self.code)
43
44     def copy(self):
45         return GError(self.message, self.domain, self.code)
46
47     def matches(self, domain, code):
48         """Placeholder that will be monkey patched in GLib overrides."""
49         raise NotImplementedError
50
51     @staticmethod
52     def new_literal(domain, message, code):
53         """Placeholder that will be monkey patched in GLib overrides."""
54         raise NotImplementedError