Merge extensions/python/xpcom changes from DOM_AGNOSTIC2_BRANCH into the

trunk.


git-svn-id: svn://10.0.0.236/trunk@187878 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mhammond%skippinet.com.au
2006-01-20 05:50:28 +00:00
parent 28dfbf4814
commit d394dc834d
56 changed files with 1710 additions and 958 deletions

View File

@@ -39,8 +39,7 @@
#
# Hardly worth its own source file!
import xpcom
from xpcom import components, nsError, _xpcom
from xpcom import components, nsError, _xpcom, logger
class Factory:
_com_interfaces_ = components.interfaces.nsIFactory
@@ -53,18 +52,17 @@ class Factory:
if outer is not None:
raise xpcom.ServerException(nsError.NS_ERROR_NO_AGGREGATION)
if xpcom.verbose:
print "Python Factory creating", self.klass.__name__
logger.debug("Python Factory creating %s", self.klass.__name__)
try:
return self.klass()
except:
# An exception here may not be obvious to the user - none
# of their code has been called yet. It can be handy on
# failure to tell the user what class failed!
_xpcom.LogWarning("Creation of class '%r' failed!\nException details follow\n" % (self.klass,))
logger.error("Creation of class '%r' failed!\nException details follow\n",
self.klass)
# The framework itself will also report the error.
raise
def lockServer(self, lock):
if xpcom.verbose:
print "Python Factory LockServer called -", lock
logger.debug("Python Factory LockServer called '%s'", lock)

View File

@@ -36,7 +36,7 @@
# ***** END LICENSE BLOCK *****
import xpcom
from xpcom import components
from xpcom import components, nsError
import xpcom.shutdown
import module
@@ -93,6 +93,8 @@ class ModuleLoader:
def _getCOMModuleForLocation(self, componentFile):
fqn = componentFile.path
if not fqn.endswith(".py"):
raise xpcom.ServerException(nsError.NS_ERROR_INVALID_ARG)
mod = self.com_modules.get(fqn)
if mod is not None:
return mod

View File

@@ -35,12 +35,14 @@
#
# ***** END LICENSE BLOCK *****
from xpcom import xpcom_consts, _xpcom, client, nsError, ServerException, COMException
from xpcom import xpcom_consts, _xpcom, client, nsError, logger
from xpcom import ServerException, COMException
import xpcom
import traceback
import xpcom.server
import operator
import types
import logging
IID_nsISupports = _xpcom.IID_nsISupports
IID_nsIVariant = _xpcom.IID_nsIVariant
@@ -237,12 +239,11 @@ class DefaultPolicy:
if dt == xpcom_consts.VTYPE_ID:
return interface.getAsID()
# all else fails...
print "Warning: nsIVariant type %d not supported - returning a string" % (dt,)
logger.warning("Warning: nsIVariant type %d not supported - returning a string", dt)
try:
return interface.getAsString()
except COMException:
print "Error: failed to get Variant as a string - returning variant object"
traceback.print_exc()
logger.exception("Error: failed to get Variant as a string - returning variant object")
return interface
return client.Component(interface, iid)
@@ -278,17 +279,27 @@ class DefaultPolicy:
exc_val = exc_info[1]
is_server_exception = isinstance(exc_val, ServerException)
if is_server_exception:
if xpcom.verbose:
print "** Information: '%s' raised COM Exception %s" % (func_name, exc_val)
traceback.print_exception(exc_info[0], exc_val, exc_info[2])
print "** Returning nsresult from existing exception", exc_val
return exc_val.errno
# Unhandled exception - always print a warning.
print "** Unhandled exception calling '%s'" % (func_name,)
traceback.print_exception(exc_info[0], exc_val, exc_info[2])
print "** Returning nsresult of NS_ERROR_FAILURE"
return nsError.NS_ERROR_FAILURE
# When a component raised an explicit COM exception, it is
# considered 'normal' - however, we still write a debug log
# record to help track these otherwise silent exceptions.
# Note that Python 2.3 does not allow an explicit exc_info tuple
# and passing 'True' will not work as there is no exception pending.
# Trick things!
if logger.isEnabledFor(logging.DEBUG):
try:
raise exc_info[0], exc_info[1], exc_info[2]
except:
logger.debug("'%s' raised COM Exception %s",
func_name, exc_val, exc_info = 1)
return exc_val.errno
# Unhandled exception - always print a warning and the traceback.
# As above, trick the logging module to handle Python 2.3
try:
raise exc_info[0], exc_info[1], exc_info[2]
except:
logger.exception("Unhandled exception calling '%s'", func_name)
return nsError.NS_ERROR_FAILURE
# Called whenever an unhandled Python exception is detected as a result
# of _CallMethod_ - this exception may have been raised during the _CallMethod_
@@ -306,8 +317,12 @@ class DefaultPolicy:
import xpcom.xpt
m = xpcom.xpt.Method(info, index, None)
func_repr = m.Describe().lstrip()
except:
except COMException:
func_repr = "%s(%r)" % (name, param_descs)
except:
# any other errors are evil!? Log it
self._doHandleException("<building method repr>", sys.exc_info())
# And fall through to logging the original error.
return self._doHandleException(func_repr, exc_info)
# Called whenever a gateway fails due to anything other than _CallMethod_.
@@ -318,7 +333,7 @@ class DefaultPolicy:
_supports_primitives_data_ = [
("nsISupportsCString", "__str__", str),
("nsISupportsString", "__str__", str),
("nsISupportsString", "__unicode__", unicode),
("nsISupportsPRUint64", "__long__", long),
("nsISupportsPRInt64", "__long__", long),
("nsISupportsPRUint32", "__int__", int),