Back to index

lightning-sunbird  0.9+nobinonly
__init__.py
Go to the documentation of this file.
00001 # ***** BEGIN LICENSE BLOCK *****
00002 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003 #
00004 # The contents of this file are subject to the Mozilla Public License Version
00005 # 1.1 (the "License"); you may not use this file except in compliance with
00006 # the License. You may obtain a copy of the License at
00007 # http://www.mozilla.org/MPL/
00008 #
00009 # Software distributed under the License is distributed on an "AS IS" basis,
00010 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011 # for the specific language governing rights and limitations under the
00012 # License.
00013 #
00014 # The Original Code is the Python XPCOM language bindings.
00015 #
00016 # The Initial Developer of the Original Code is
00017 # Activestate Tool Corp.
00018 # Portions created by the Initial Developer are Copyright (C) 2000
00019 # the Initial Developer. All Rights Reserved.
00020 #
00021 # Contributor(s):
00022 #   Mark Hammond <MarkH@activestate.com>
00023 #
00024 # Alternatively, the contents of this file may be used under the terms of
00025 # either the GNU General Public License Version 2 or later (the "GPL"), or
00026 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027 # in which case the provisions of the GPL or the LGPL are applicable instead
00028 # of those above. If you wish to allow use of your version of this file only
00029 # under the terms of either the GPL or the LGPL, and not to allow others to
00030 # use your version of this file under the terms of the MPL, indicate your
00031 # decision by deleting the provisions above and replace them with the notice
00032 # and other provisions required by the GPL or the LGPL. If you do not delete
00033 # the provisions above, a recipient may use your version of this file under
00034 # the terms of any one of the MPL, the GPL or the LGPL.
00035 #
00036 # ***** END LICENSE BLOCK *****
00037 #
00038 
00039 # The XPCOM (Cross Platform COM) package.
00040 import exceptions
00041 
00042 
00043 import sys
00044 #sys.stdout = open("pystdout.log", "w")
00045 if sys.version_info >= (2, 3):
00046     # sick off the new hex() warnings, and no time to digest what the 
00047     # impact will be!
00048     import warnings
00049     warnings.filterwarnings("ignore", category=FutureWarning, append=1)
00050 
00051 # A global "verbose" flag - currently used by the
00052 # server package to print trace messages
00053 verbose = 0
00054 hr_map = {}
00055 
00056 # The standard XPCOM exception object.
00057 # Instances of this class are raised by the XPCOM extension module.
00058 class Exception(exceptions.Exception):
00059     def __init__(self, errno, message = None):
00060         assert int(errno) == errno, "The errno param must be an integer"
00061         self.errno = errno
00062         self.message = message
00063         exceptions.Exception.__init__(self, errno)
00064     def __str__(self):
00065         if not hr_map:
00066             import nsError
00067             for name, val in nsError.__dict__.items():
00068                 if type(val)==type(0):
00069                     hr_map[val] = name
00070         message = self.message
00071         if message is None:
00072             message = hr_map.get(self.errno)
00073             if message is None:
00074                 message = ""
00075         return "0x%x (%s)" % (self.errno, message)
00076 
00077 # An alias for Exception - allows code to say "from xpcom import COMException"
00078 # rather than "Exception" - thereby preventing clashes.
00079 COMException = Exception
00080 
00081 # Exceptions thrown by servers.  It can be good for diagnostics to
00082 # differentiate between a ServerException (which was presumably explicitly thrown)
00083 # and a normal exception which may simply be propagating down.
00084 # (When ServerException objects are thrown across the XPConnect
00085 # gateway they will be converted back to normal client exceptions if
00086 # subsequently re-caught by Python
00087 class ServerException(Exception):
00088     def __init__(self, errno=None, *args, **kw):
00089         if errno is None:
00090             import nsError
00091             errno = nsError.NS_ERROR_FAILURE
00092         Exception.__init__(self, errno, *args, **kw)
00093 
00094 # Some global functions.