annotate enso_pyxpcom.py @ 0:b1c0ab5d5f14

Origination, originally taken from the about:python source code from pyxpcom.
author Atul Varma <varmaa@toolness.com>
date Thu, 08 May 2008 11:06:36 -0700
parents
children 6e4335fa3321
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
1 from xpcom import components, verbose
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
2 import sys, os
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
3 import logging
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
4 import platform
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
5
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
6 _ensoStarted = False
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
7
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
8 def getAbout():
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
9 global _ensoStarted
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
10
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
11 import enso
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
12 if not _ensoStarted:
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
13 logging.info("Launching Enso.")
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
14 _ensoStarted = True
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
15 enso.run()
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
16 return "Enso is running."
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
17
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
18 class ShutdownObserver:
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
19 _com_interfaces_ = components.interfaces.nsIObserver
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
20
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
21 def observe(self, subject, topic, data):
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
22 print "quit-application received; calling sys.exitfunc()."
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
23 sys.exitfunc()
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
24
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
25 class AboutPython:
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
26 _com_interfaces_ = components.interfaces.nsIAboutModule
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
27 _reg_contractid_ = '@mozilla.org/network/protocol/about;1?what=enso'
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
28 _reg_clsid_ = '{6d5d462e-6de7-4bca-bbc6-c488d481351c}'
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
29 _reg_desc_ = "about:enso handler"
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
30
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
31 def __init__(self):
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
32 logging.basicConfig( level=logging.INFO )
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
33 logging.info("Setting shutdown observer.")
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
34 observerService = components.classes["@mozilla.org/observer-service;1"].getService(components.interfaces.nsIObserverService)
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
35 observerService.addObserver(ShutdownObserver(), "quit-application", False)
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
36
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
37 def newChannel(self, aURI):
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
38 ioService = components.classes["@mozilla.org/network/io-service;1"] \
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
39 .getService();
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
40
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
41 istream = components.classes["@mozilla.org/io/string-input-stream;1"] \
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
42 .createInstance()
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
43
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
44 about = getAbout()
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
45 istream.setData(about, len(about))
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
46
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
47 channel = components.classes["@mozilla.org/network/input-stream-channel;1"] \
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
48 .createInstance(components.interfaces.nsIInputStreamChannel)
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
49
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
50 channel.setURI(aURI)
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
51 #channel.contentType = "text/html"
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
52 channel.contentStream = istream
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
53 return channel
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
54
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
55 def getURIFlags(self, aURI):
b1c0ab5d5f14 Origination, originally taken from the about:python source code from pyxpcom.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
56 return 0;