From 74b78d8e3f546a93694e970091dd5704d86959b6 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Tue, 2 Jun 2009 15:43:32 -0700 Subject: [PATCH] Added python-modules dir for build system from jetpack's repository. Soon we'll replace manage.py to use paver and jsbridge from this directory. --- python-modules/jsbridge/__init__.py | 159 +++ .../jsbridge/extension/chrome.manifest | 10 + .../extension/chrome/content/overlay.js | 40 + .../extension/chrome/content/overlay.xul | 5 + .../jsbridge/extension/components/cmdarg.js | 172 +++ python-modules/jsbridge/extension/install.rdf | 52 + .../extension/resource/modules/events.js | 13 + .../extension/resource/modules/init.js | 40 + .../extension/resource/modules/json2.js | 471 +++++++++ .../extension/resource/modules/server.js | 304 ++++++ python-modules/jsbridge/jsobjects.py | 167 +++ python-modules/jsbridge/network.py | 268 +++++ python-modules/mozrunner/__init__.py | 558 ++++++++++ python-modules/mozrunner/killableprocess.py | 251 +++++ python-modules/mozrunner/winprocess.py | 275 +++++ python-modules/paver/__init__.py | 0 python-modules/paver/defaults.py | 20 + python-modules/paver/easy.py | 106 ++ python-modules/paver/misctasks.py | 67 ++ python-modules/paver/options.py | 171 +++ python-modules/paver/path.py | 999 ++++++++++++++++++ python-modules/paver/path25.py | 35 + python-modules/paver/release.py | 19 + python-modules/paver/setuputils.py | 245 +++++ python-modules/paver/tasks.py | 618 +++++++++++ python-modules/simplejson/__init__.py | 376 +++++++ python-modules/simplejson/decoder.py | 343 ++++++ python-modules/simplejson/encoder.py | 385 +++++++ python-modules/simplejson/scanner.py | 67 ++ python-modules/simplejson/tests/__init__.py | 22 + .../simplejson/tests/test_decode.py | 15 + .../simplejson/tests/test_default.py | 9 + python-modules/simplejson/tests/test_dump.py | 13 + .../tests/test_encode_basestring_ascii.py | 36 + python-modules/simplejson/tests/test_fail.py | 76 ++ python-modules/simplejson/tests/test_float.py | 9 + .../simplejson/tests/test_indent.py | 41 + python-modules/simplejson/tests/test_pass1.py | 76 ++ python-modules/simplejson/tests/test_pass2.py | 14 + python-modules/simplejson/tests/test_pass3.py | 20 + .../simplejson/tests/test_recursion.py | 65 ++ .../simplejson/tests/test_scanstring.py | 102 ++ .../simplejson/tests/test_separators.py | 42 + .../simplejson/tests/test_unicode.py | 55 + python-modules/simplejson/tool.py | 44 + 45 files changed, 6875 insertions(+) create mode 100755 python-modules/jsbridge/__init__.py create mode 100644 python-modules/jsbridge/extension/chrome.manifest create mode 100644 python-modules/jsbridge/extension/chrome/content/overlay.js create mode 100644 python-modules/jsbridge/extension/chrome/content/overlay.xul create mode 100644 python-modules/jsbridge/extension/components/cmdarg.js create mode 100644 python-modules/jsbridge/extension/install.rdf create mode 100644 python-modules/jsbridge/extension/resource/modules/events.js create mode 100644 python-modules/jsbridge/extension/resource/modules/init.js create mode 100644 python-modules/jsbridge/extension/resource/modules/json2.js create mode 100644 python-modules/jsbridge/extension/resource/modules/server.js create mode 100755 python-modules/jsbridge/jsobjects.py create mode 100755 python-modules/jsbridge/network.py create mode 100644 python-modules/mozrunner/__init__.py create mode 100644 python-modules/mozrunner/killableprocess.py create mode 100644 python-modules/mozrunner/winprocess.py create mode 100755 python-modules/paver/__init__.py create mode 100755 python-modules/paver/defaults.py create mode 100755 python-modules/paver/easy.py create mode 100755 python-modules/paver/misctasks.py create mode 100755 python-modules/paver/options.py create mode 100755 python-modules/paver/path.py create mode 100755 python-modules/paver/path25.py create mode 100755 python-modules/paver/release.py create mode 100755 python-modules/paver/setuputils.py create mode 100755 python-modules/paver/tasks.py create mode 100644 python-modules/simplejson/__init__.py create mode 100644 python-modules/simplejson/decoder.py create mode 100644 python-modules/simplejson/encoder.py create mode 100644 python-modules/simplejson/scanner.py create mode 100644 python-modules/simplejson/tests/__init__.py create mode 100644 python-modules/simplejson/tests/test_decode.py create mode 100644 python-modules/simplejson/tests/test_default.py create mode 100644 python-modules/simplejson/tests/test_dump.py create mode 100644 python-modules/simplejson/tests/test_encode_basestring_ascii.py create mode 100644 python-modules/simplejson/tests/test_fail.py create mode 100644 python-modules/simplejson/tests/test_float.py create mode 100644 python-modules/simplejson/tests/test_indent.py create mode 100644 python-modules/simplejson/tests/test_pass1.py create mode 100644 python-modules/simplejson/tests/test_pass2.py create mode 100644 python-modules/simplejson/tests/test_pass3.py create mode 100644 python-modules/simplejson/tests/test_recursion.py create mode 100644 python-modules/simplejson/tests/test_scanstring.py create mode 100644 python-modules/simplejson/tests/test_separators.py create mode 100644 python-modules/simplejson/tests/test_unicode.py create mode 100644 python-modules/simplejson/tool.py diff --git a/python-modules/jsbridge/__init__.py b/python-modules/jsbridge/__init__.py new file mode 100755 index 00000000..7bdd2b19 --- /dev/null +++ b/python-modules/jsbridge/__init__.py @@ -0,0 +1,159 @@ +# ***** 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 Corporation Code. +# +# The Initial Developer of the Original Code is +# Mikeal Rogers. +# Portions created by the Initial Developer are Copyright (C) 2008 -2009 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Mikeal Rogers +# +# 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 socket +import os +import copy +from time import sleep + +import mozrunner + +from network import Bridge, BackChannel, create_network +from jsobjects import JSObject + +settings_env = 'JSBRIDGE_SETTINGS_FILE' + +parent = os.path.abspath(os.path.dirname(__file__)) +extension_path = os.path.join(parent, 'extension') + +window_string = "Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('')" + +def wait_and_create_network(host, port, timeout=10): + ttl = 0 + while ttl < timeout: + sleep(.25) + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((host, port)) + s.close() + break + except socket.error: + pass + return create_network(host, port) + +class CLI(mozrunner.CLI): + + parser_options = copy.copy(mozrunner.CLI.parser_options) + parser_options[('-D', '--debug',)] = dict(dest="debug", + action="store_true", + help="Install debugging plugins.", + metavar="JSBRIDGE_DEBUG", + default=False ) + parser_options[('-s', '--shell',)] = dict(dest="shell", + action="store_true", + help="Start a Python shell", + metavar="JSBRIDGE_SHELL", + default=False ) + parser_options[('-u', '--usecode',)] = dict(dest="usecode", action="store_true", + help="Use code module instead of iPython", + default=False) + parser_options[('-P', '--port')] = dict(dest="port", default="24242", + help="TCP port to run jsbridge on.") + + debug_plugins = [os.path.join(parent, 'xpi', 'xush-0.2-fx.xpi')] + + def get_profile(self, *args, **kwargs): + if self.options.debug: + kwargs.setdefault('preferences', + {}).update({'extensions.checkCompatibility':False}) + profile = super(CLI, self).get_profile(*args, **kwargs) + profile.install_plugin(extension_path) + if self.options.debug: + for p in self.debug_plugins: + profile.install_plugin(p) + return profile + + def get_runner(self, *args, **kwargs): + runner = super(CLI, self).get_runner(*args, **kwargs) + if self.options.debug: + runner.cmdargs.append('-jsconsole') + runner.cmdargs += ['-jsbridge', self.options.port] + return runner + + def run(self): + runner = self.parse_and_get_runner() + runner.start() + self.start_jsbridge_network() + if self.options.shell: + self.start_shell(runner) + else: + try: + runner.wait() + except KeyboardInterrupt: + runner.stop() + + runner.profile.cleanup() + + def start_shell(self, runner): + try: + import IPython + except: + IPython = None + jsobj = JSObject(self.bridge, window_string) + + if IPython is None or self.options.usecode: + import code + code.interact(local={"jsobj":jsobj, + "getBrowserWindow":lambda : getBrowserWindow(self.bridge), + "back_channel":self.back_channel, + }) + else: + from IPython.Shell import IPShellEmbed + ipshell = IPShellEmbed([]) + ipshell(local_ns={"jsobj":jsobj, + "getBrowserWindow":lambda : getBrowserWindow(self.bridge), + "back_channel":self.back_channel, + }) + runner.stop() + + def start_jsbridge_network(self, timeout=10): + port = int(self.options.port) + host = '127.0.0.1' + self.back_channel, self.bridge = wait_and_create_network(host, port, timeout) + +def cli(): + CLI().run() + +def getBrowserWindow(bridge): + return JSObject(bridge, "Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('')") + + + + + + + diff --git a/python-modules/jsbridge/extension/chrome.manifest b/python-modules/jsbridge/extension/chrome.manifest new file mode 100644 index 00000000..6d83470b --- /dev/null +++ b/python-modules/jsbridge/extension/chrome.manifest @@ -0,0 +1,10 @@ +resource jsbridge resource/ + +content jsbridge chrome/content/ + +overlay chrome://browser/content/browser.xul chrome://jsbridge/content/overlay.xul +overlay chrome://messenger/content/mailWindowOverlay.xul chrome://jsbridge/content/overlay.xul + +overlay chrome://calendar/content/calendar.xul chrome://jsbridge/content/overlay.xul + +overlay windowtype:Songbird:Main chrome://jsbridge/content/overlay.xul diff --git a/python-modules/jsbridge/extension/chrome/content/overlay.js b/python-modules/jsbridge/extension/chrome/content/overlay.js new file mode 100644 index 00000000..42e59687 --- /dev/null +++ b/python-modules/jsbridge/extension/chrome/content/overlay.js @@ -0,0 +1,40 @@ +// ***** 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 Corporation Code. +// +// The Initial Developer of the Original Code is +// Mikeal Rogers. +// Portions created by the Initial Developer are Copyright (C) 2008 +// the Initial Developer. All Rights Reserved. +// +// Contributor(s): +// Mikeal Rogers +// +// 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 ***** + +var __init = {}; Components.utils.import('resource://jsbridge/modules/init.js', __init); + + diff --git a/python-modules/jsbridge/extension/chrome/content/overlay.xul b/python-modules/jsbridge/extension/chrome/content/overlay.xul new file mode 100644 index 00000000..8cd47244 --- /dev/null +++ b/python-modules/jsbridge/extension/chrome/content/overlay.xul @@ -0,0 +1,5 @@ + + +