~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/python/xpcom/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/
 
4
#
 
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.
 
8
#
 
9
# The Original Code is the Python XPCOM language bindings.
 
10
#
 
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.
 
14
#
 
15
# Contributor(s): Mark Hammond <MarkH@ActiveState.com> (original author)
 
16
#
 
17
 
 
18
# The XPCOM (Cross Platform COM) package.
 
19
import exceptions
 
20
 
 
21
 
 
22
import sys
 
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 
 
26
    # impact will be!
 
27
    import warnings
 
28
    warnings.filterwarnings("ignore", category=FutureWarning, append=1)
 
29
 
 
30
# A global "verbose" flag - currently used by the
 
31
# server package to print trace messages
 
32
verbose = 0
 
33
hr_map = {}
 
34
 
 
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"
 
40
        self.errno = errno
 
41
        self.message = message
 
42
        exceptions.Exception.__init__(self, errno)
 
43
    def __str__(self):
 
44
        if not hr_map:
 
45
            import nsError
 
46
            for name, val in nsError.__dict__.items():
 
47
                if type(val)==type(0):
 
48
                    hr_map[val] = name
 
49
        message = self.message
 
50
        if message is None:
 
51
            message = hr_map.get(self.errno)
 
52
            if message is None:
 
53
                message = ""
 
54
        return "0x%x (%s)" % (self.errno, message)
 
55
 
 
56
# An alias for Exception - allows code to say "from xpcom import COMException"
 
57
# rather than "Exception" - thereby preventing clashes.
 
58
COMException = Exception
 
59
 
 
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):
 
68
        if errno is None:
 
69
            import nsError
 
70
            errno = nsError.NS_ERROR_FAILURE
 
71
        Exception.__init__(self, errno, *args, **kw)
 
72
 
 
73
# Some global functions.