loader.py revision aa39f6d95b7cee99986fe66102fef493497da0d8
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Python XPCOM language bindings.
#
# The Initial Developer of the Original Code is
# Activestate Tool Corp.
# Portions created by the Initial Developer are Copyright (C) 2000
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Hammond <MarkH@ActiveState.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
import xpcom
import module
# Until we get interface constants.
When_Startup = 0
When_Component = 1
When_Timer = 2
# Actually allows "None" to be specified to disable inherited attributes.
def FindCOMComponents(py_module):
# For now, just run over all classes looking for likely candidates.
comps = []
try:
except TypeError:
# The issubclass call raises TypeError when the obj is not a class.
pass;
return comps
svc = _xpcom.GetServiceManager().getServiceByContractID("@mozilla.org/categorymanager;1", components.interfaces.nsICategoryManager)
class PythonComponentLoader:
_reg_contractid_ = "moz.pyloader.1"
_reg_desc_ = "Python component loader"
# Optional function which performs additional special registration
# Appears that no special unregistration is needed for ComponentLoaders, hence no unregister function.
_reg_registrar_ = (register_self,None)
# Custom attributes for ComponentLoader registration.
if mod is not None:
return mod
# Make and remember the COM module.
return mod
# return the factory
assert type == self._reg_component_type_, "Being asked to create an object not of my type:%s" % (type,)
# FIXME: how to do this without obsolete component manager?
# delegate to the module.
# void
# Called when a component of the appropriate type is registered,
# to give the component loader an opportunity to do things like
# annotate the registry and such.
# ToDo - work out the right thing here
# eg - do we recurse?
# - do we support packages?
while entries.HasMoreElements():
try:
# Handle some common user errors
# If the interface name does not exist, suppress the traceback
else:
except SyntaxError, details:
# Syntax error in source file - no useful traceback here either.
except:
# All other exceptions get the full traceback.
# bool return
# Check if we actually need to do anything
return 1
# New components may have just installed new Python
# modules into the main python directory (including new .pth files)
# So we ask Python to re-process our site directory.
# Note that the pyloader does the equivalent when loading.
try:
import site
NS_XPCOM_CURRENT_PROCESS_DIR="XCurProcD"
except:
# auto-register via the module.
return 1
# bool return
# auto-unregister via the module.
try:
finally:
return 1
# bool return
return 0 # no more to register
# This is called at shutdown time - don't get too upset if an error
# results from logging due to the logfile being closed
try:
except:
# Evil blank except, but restricting to just catching IOError
# failure means custom logs could still screw us
pass
self.com_modules = {}
import module