1
# The contents of this file are subject to the Mozilla Public License Version
2
# 1.1 (the "License"); you may not use this file except in compliance with the
3
# License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
# Software distributed under the License is distributed on an "AS IS" basis,
6
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7
# the specific language governing rights and limitations under the License.
9
# The Original Code is the Python XPCOM language bindings.
11
# The Initial Developer of the Original Code is ActiveState Tool Corp.
12
# Portions created by ActiveState Tool Corp. are Copyright (C) 2000, 2001
13
# ActiveState Tool Corp. All Rights Reserved.
15
# Contributor(s): Mark Hammond <MarkH@ActiveState.com> (original author)
18
# The XPCOM (Cross Platform COM) package.
23
#sys.stdout = open("pystdout.log", "w")
24
if sys.version_info >= (2, 3):
25
# sick off the new hex() warnings, and no time to digest what the
28
warnings.filterwarnings("ignore", category=FutureWarning, append=1)
30
# A global "verbose" flag - currently used by the
31
# server package to print trace messages
35
# The standard XPCOM exception object.
36
# Instances of this class are raised by the XPCOM extension module.
37
class Exception(exceptions.Exception):
38
def __init__(self, errno, message = None):
39
assert int(errno) == errno, "The errno param must be an integer"
41
self.message = message
42
exceptions.Exception.__init__(self, errno)
46
for name, val in nsError.__dict__.items():
47
if type(val)==type(0):
49
message = self.message
51
message = hr_map.get(self.errno)
54
return "0x%x (%s)" % (self.errno, message)
56
# An alias for Exception - allows code to say "from xpcom import COMException"
57
# rather than "Exception" - thereby preventing clashes.
58
COMException = Exception
60
# Exceptions thrown by servers. It can be good for diagnostics to
61
# differentiate between a ServerException (which was presumably explicitly thrown)
62
# and a normal exception which may simply be propagating down.
63
# (When ServerException objects are thrown across the XPConnect
64
# gateway they will be converted back to normal client exceptions if
65
# subsequently re-caught by Python
66
class ServerException(Exception):
67
def __init__(self, errno=None, *args, **kw):
70
errno = nsError.NS_ERROR_FAILURE
71
Exception.__init__(self, errno, *args, **kw)
73
# Some global functions.