diff --git a/mozilla/extensions/python/xpcom/Makefile.in b/mozilla/extensions/python/xpcom/Makefile.in index bbf5ac5cc65..989216f37b8 100644 --- a/mozilla/extensions/python/xpcom/Makefile.in +++ b/mozilla/extensions/python/xpcom/Makefile.in @@ -42,6 +42,7 @@ include $(DEPTH)/config/autoconf.mk DIRS = \ src \ + components \ $(NULL) ifdef ENABLE_TESTS diff --git a/mozilla/extensions/python/xpcom/components/Makefile.in b/mozilla/extensions/python/xpcom/components/Makefile.in new file mode 100644 index 00000000000..ab756324804 --- /dev/null +++ b/mozilla/extensions/python/xpcom/components/Makefile.in @@ -0,0 +1,64 @@ +# ***** 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 +# http://www.mozilla.org/MPL/ +# +# 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 mozilla.org code. +# +# The Initial Developer of the Original Code is +# Mark Hammond . +# Portions created by the Initial Developer are Copyright (C) 2006 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# 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 ***** + +# The PyXPCOM test component. + +DEPTH =../../../.. + +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = pyxpcom +XPIDL_MODULE = pyxpcom_test +REQUIRES = xpcom string $(NULL) + +XPIDLSRCS = +PYCOMPONENTS=pyabout.py + +PYCOMPONENTS_INST := $(addprefix $(srcdir)/,$(PYCOMPONENTS)) + +include $(topsrcdir)/config/config.mk +include $(topsrcdir)/config/rules.mk + +libs:: + $(INSTALL) $(PYCOMPONENTS_INST) $(DIST)/bin/components + +clobber:: + $(RM) $(DIST)/bin/components/py_test_component.py + $(RM) $(DIST)/bin/components/pyxpcom_test.xpt diff --git a/mozilla/extensions/python/xpcom/components/README.txt b/mozilla/extensions/python/xpcom/components/README.txt new file mode 100644 index 00000000000..1b9282bb455 --- /dev/null +++ b/mozilla/extensions/python/xpcom/components/README.txt @@ -0,0 +1,12 @@ +This directory is for Python implemented components that ship with pyxpcom + +The .py files in this directory will end up on the XPCOM "components" +directory, while .idl files etc will be compiled and installed as normal. + +Of note: + +* pyabout.py allows you to type open the URL "about:python" and have + information about the local Python build displayed. + +Most other files not listed are probably used internally and not worth +paying attention to! diff --git a/mozilla/extensions/python/xpcom/components/pyabout.py b/mozilla/extensions/python/xpcom/components/pyabout.py new file mode 100644 index 00000000000..a7b7925f9ec --- /dev/null +++ b/mozilla/extensions/python/xpcom/components/pyabout.py @@ -0,0 +1,65 @@ +# about:python, originally by Alex Badea +from xpcom import components, verbose +import sys, os +import platform + +def getAbout(): + # Generate it each time so its always up-to-date. + # Sort to keep things purdy + mod_names = sys.modules.keys() + mod_names.sort() + env = os.environ.items() + env.sort() + return """ + + + + about:python + + +

about:python

+

+

Python %(version)s on %(platform)s

+

resources

+

Visit the pyxpcom wiki.

+

sys.path

%(path)s

+

environment

%(environment)s

+

modules

%(modules)s

+ + + +""" % { + 'version': sys.version, + 'platform': platform.platform(), + 'path': "
".join(sys.path), + 'environment': "
".join(["%s=%s" % (n,v) for n, v in env]), + 'modules': ", ".join(mod_names), +} + + +class AboutPython: + _com_interfaces_ = components.interfaces.nsIAboutModule + _reg_contractid_ = '@mozilla.org/network/protocol/about;1?what=python' + _reg_clsid_ = '{6d5d462e-6de7-4bca-bbc6-c488d481351b}' + _reg_desc_ = "about:python handler" + + def __init__(self): + pass + + def newChannel(self, aURI): + ioService = components.classes["@mozilla.org/network/io-service;1"] \ + .getService(); + + istream = components.classes["@mozilla.org/io/string-input-stream;1"] \ + .createInstance() + + about = getAbout() + istream.setData(about, len(about)) + + channel = components.classes["@mozilla.org/network/input-stream-channel;1"] \ + .createInstance(components.interfaces.nsIInputStreamChannel) + + channel.setURI(aURI) + #channel.contentType = "text/html" + channel.contentStream = istream + return channel