github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

malept / python-spidermonkey forked from davisp/python-spidermonkey

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 9
  • Source
  • Commits
  • Network (9)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Python/JavaScript bridge module, making use of Mozilla's spidermonkey JavaScript implementation. — Read more

  cancel

http://github.com/davisp/python-spidermonkey

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Build system: rename variable to be consistent with the other flag 
introduced in the merge. 
Mark Lee (author)
Mon May 11 17:29:14 -0700 2009
commit  1cdc257a6c0a31821ea76963dd51066a188c5a31
tree    6bedda535e6bc50a50badd6609f18555884fcace
parent  9853f35e4f726f5e6827fe1703341b35d866132d
python-spidermonkey /
name age
history
message
file .gitignore Thu Apr 02 18:53:24 -0700 2009 Ignore egg files. [Paul Davis]
file LICENSE Wed Jan 28 04:03:52 -0800 2009 Yeah, bad commit policy. But hey, it works now. [davisp]
file MANIFEST.in Loading commit data...
file README.md
file THANKS
file ez_setup.py Fri Jan 30 00:32:01 -0800 2009 Unicode enabled python-spidermonkey. Did I rea... [davisp]
file go Sat May 09 18:17:12 -0700 2009 Initial JS iteration of Python objects. This p... [Paul Davis]
file go.comm Sat May 09 21:49:34 -0700 2009 Add JS_[Begin|End]Request semantics. This shou... [davisp]
directory old-sm/
directory old-t/
file setup.py
directory spidermonkey/
directory tests/
file update-libjs.sh
README.md

Execute arbitrary JavaScript code from Python. Allows you to reference arbitrary Python objects and functions in the JavaScript VM

Requirements

Python Development Files

Mac OS X:

If you installed Python via port then the headers should already be installed. I have not heard reports of problems from people using the bundled interpreters.

Debian/Ubuntu:

$ sudo apt-get install pythonX.X-dev

Where X.X is the version of Python you are using. I have not tested python-spidermonkey on Py3K so it may be horribly broken there.

Gentoo:

If you have python installed, then the headers should already be installed.

Netscape Portable Runtime (nspr)

The nspr library is required for building the Spidermonkey sources. You should be able to grab it from your package manager of choice with something like the following:

Mac OS X:

$ sudo port install nspr

Debian/Ubuntu:

$ sudo apt-get install libnspr4-dev

Gentoo:

$ sudo emerge nspr

Alternatively you can build from source. If you choose this route make sure that the pkg-config command is on your $PATH when running the install commands below. Additionally, make sure that $PKG_CONFIG_PATH is properly set.

XULRunner (optional)

You can optionally build the extension linked to your system's spidermonkey library, which is installed with XULRunner. You should be able to grab it from your package manager of choice with something like the following:

Mac OS X:

$ sudo port install xulrunner

Debian/Ubuntu:

$ sudo apt-get install xulrunner-1.9-dev

Gentoo:

$ sudo emerge xulrunner

Alternatively you can build from source. If you choose this route, make sure that the pkg-config command is on your $PATH when running the install commands below. Additionally, make sure that $PKG_CONFIG_PATH is properly set.

Installation

$ git clone git://github.com/davisp/python-spidermonkey.git
$ cd python-spidermonkey
$ python setup.py build
$ python setup.py test

$ sudo python setup.py install

*OR*

$ sudo python setup.py develop

If you want to build with the system spidermonkey library, replace the build command with the following:

$ python setup.py --system-library build

Having Issues?

Add issues to the Lighthouse project here.

Examples

Basics

>>> import spidermonkey
>>> rt = spidermonkey.Runtime()
>>> cx = rt.new_context()
>>> cx.execute("var x = 3; x *= 4; x;")
12
>>> class Orange(object):
...   def is_ripe(self,arg):
...       return "ripe %s" % arg
...
>>> fruit = Orange()
>>> cx.add_global("apple", fruit)
>>> cx.execute('"Show me the " + apple.is_ripe("raisin");')
Show me the ripe raisin

Playing with Classes

>>> import spidermonkey
>>> class Monkey(object):
...     def __init__(self):
...         self.baz = "blammo"
...     def wrench(self, arg):
...         return "%s now wrenched" % arg
...
>>> rt = spidermonkey.Runtime()
>>> cx = rt.new_context()
>>> cx.add_global(Monkey)
>>> monkey = cx.execute('var x = new Monkey(); x.baz = "schmammo"; x;')
>>> monkey.baz
'schmammo'
>>> monkey.__class__.__name__
'Monkey'

JavaScript Functions

>>> import spidermonkey
>>> rt = spidermonkey.Runtime()
>>> cx = rt.new_context()
>>> func = cx.execute('function(val) {return "whoosh: " + val;}')
>>> func("zipper!");
'whoosh: zipper!'

Previous Authors

  • John J. Lee
  • Atul Varma
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server