Introduce the first of standard Python implemented components.

Not part of the build.
This commit is contained in:
mhammond%skippinet.com.au 2006-02-17 11:56:18 +00:00
parent 56f899faf6
commit 6f733b46d4
4 changed files with 142 additions and 0 deletions

View File

@ -42,6 +42,7 @@ include $(DEPTH)/config/autoconf.mk
DIRS = \
src \
components \
$(NULL)
ifdef ENABLE_TESTS

View File

@ -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 <mhammond@skippinet.com.au>.
# 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

View File

@ -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!

View File

@ -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 """
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>about:python</title>
</head>
<body>
<h1>about:python</h1>
<p> </p>
<p>Python %(version)s on %(platform)s</p>
<h2>resources</h2>
<p>Visit the <a href="http://developer.mozilla.org/en/docs/PyXPCOM">pyxpcom wiki.</a></p>
<h2>sys.path</h2><p>%(path)s</p><p> </p>
<h2>environment</h2><p>%(environment)s</p><p> </p>
<h2>modules</h2><p>%(modules)s</p><p> </p>
</body>
</html>
""" % {
'version': sys.version,
'platform': platform.platform(),
'path': "<br>".join(sys.path),
'environment': "<br>".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