Mercurial > pydertron
changeset 28:d28100e071a7
Rebuilt HTML docs.
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Mon, 10 May 2010 00:59:19 -0700 |
parents | 0b00162939ae |
children | 296aba0e0a17 |
files | docs.html |
diffstat | 1 files changed, 26 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/docs.html Mon May 10 00:56:56 2010 -0700 +++ b/docs.html Mon May 10 00:59:19 2010 -0700 @@ -3,14 +3,15 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> -<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" /> +<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" /> <title>Pydertron</title> <link rel="stylesheet" href="docs.css" type="text/css" /> </head> <body> <div class="document" id="pydertron"> <h1 class="title">Pydertron</h1> -<p>Pydertron is an experimental high-level wrapper for <a class="reference" href="http://code.google.com/p/pydermonkey">Pydermonkey</a> + +<p>Pydertron is an experimental high-level wrapper for <a class="reference external" href="http://code.google.com/p/pydermonkey">Pydermonkey</a> that provides convenient, secure object wrapping between JS and Python space.</p> <p>Note that Pydertron is just one example of a high-level interface @@ -18,17 +19,17 @@ code it executes isn't trusted, which affects the nature of the inter-language interaction.</p> <p>Pydertron is currently hosted at -<a class="reference" href="http://hg.toolness.com/pydertron">http://hg.toolness.com/pydertron</a>. Please feel free to send any -questions or comments to <a class="reference" href="mailto:atul@mozilla.com">atul@mozilla.com</a>.</p> -<div class="section"> -<h1><a id="the-basics" name="the-basics">The Basics</a></h1> -<p>The <tt class="docutils literal"><span class="pre">JsSandbox</span></tt> class encapsulates a JavaScript runtime, context, global -object, and a simple <a class="reference" href="http://wiki.commonjs.org/wiki/CommonJS/Modules/SecurableModules">SecurableModule</a> implementation that complies -with the <a class="reference" href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> standard. It also provides a high-level bridge between +<a class="reference external" href="http://hg.toolness.com/pydertron">http://hg.toolness.com/pydertron</a>. Please feel free to send any +questions or comments to <a class="reference external" href="mailto:atul@mozilla.com">atul@mozilla.com</a>.</p> +<div class="section" id="the-basics"> +<h1>The Basics</h1> +<p>The <tt class="docutils literal">JsSandbox</tt> class encapsulates a JavaScript runtime, context, global +object, and a simple <a class="reference external" href="http://wiki.commonjs.org/wiki/CommonJS/Modules/SecurableModules">SecurableModule</a> implementation that complies +with the <a class="reference external" href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> standard. It also provides a high-level bridge between Python and JavaScript so that you don't need to deal with any of the low-level details of the Pydermonkey API.</p> -<p>For instance, here we'll create a <tt class="docutils literal"><span class="pre">JsSandbox</span></tt> whose module root -points to the <a class="reference" href="http://interoperablejs.googlecode.com/svn/trunk/compliance/monkeys/">monkeys</a> SecurableModule compliance test over HTTP:</p> +<p>For instance, here we'll create a <tt class="docutils literal">JsSandbox</tt> whose module root +points to the <a class="reference external" href="http://interoperablejs.googlecode.com/svn/trunk/compliance/monkeys/">monkeys</a> SecurableModule compliance test over HTTP:</p> <blockquote> <pre class="doctest-block"> >>> url = ("http://interoperablejs.googlecode.com/svn/trunk/" @@ -36,9 +37,9 @@ >>> sandbox = JsSandbox(HttpFileSystem(url)) </pre> </blockquote> -<p>This compliance test requires a global <tt class="docutils literal"><span class="pre">sys</span></tt> object that contains one -method, <tt class="docutils literal"><span class="pre">print()</span></tt>, that takes two arguments. First, we'll create the -<tt class="docutils literal"><span class="pre">print()</span></tt> function and prepare it for exposure to JS code:</p> +<p>This compliance test requires a global <tt class="docutils literal">sys</tt> object that contains one +method, <tt class="docutils literal">print()</tt>, that takes two arguments. First, we'll create the +<tt class="docutils literal">print()</tt> function and prepare it for exposure to JS code:</p> <blockquote> <pre class="doctest-block"> >>> @jsexposed @@ -46,8 +47,8 @@ ... print message, label </pre> </blockquote> -<p>Note the use of the <tt class="docutils literal"><span class="pre">@jsexposed</span></tt> decorator: all this does is set -the function's <tt class="docutils literal"><span class="pre">__jsexposed__</span></tt> attribute to <tt class="docutils literal"><span class="pre">True</span></tt>. This is +<p>Note the use of the <tt class="docutils literal">@jsexposed</tt> decorator: all this does is set +the function's <tt class="docutils literal">__jsexposed__</tt> attribute to <tt class="docutils literal">True</tt>. This is done for security purposes: only Python callables satisfying this criteria will be exposed to JavaScript code, to ensure that untrusted JS can't accidentally gain access to privileged Python @@ -60,14 +61,14 @@ </blockquote> <p>We can now access and set properties on this object via either item or attribute lookup, just like in JavaScript. Because -<tt class="docutils literal"><span class="pre">print</span></tt> is a reserved word in Python, though, we'll use item +<tt class="docutils literal">print</tt> is a reserved word in Python, though, we'll use item lookup to set the property here:</p> <blockquote> <pre class="doctest-block"> >>> system['print'] = jsprint </pre> </blockquote> -<p>Now we tell the sandbox that we want the <tt class="docutils literal"><span class="pre">sys</span></tt> object to be a +<p>Now we tell the sandbox that we want the <tt class="docutils literal">sys</tt> object to be a global:</p> <blockquote> <pre class="doctest-block"> @@ -84,8 +85,8 @@ 0 </pre> </blockquote> -<p>Note the <tt class="docutils literal"><span class="pre">0</span></tt> in the last line: this is the return value of -<tt class="docutils literal"><span class="pre">sandbox.run_script()</span></tt>, which returns <tt class="docutils literal"><span class="pre">0</span></tt> on success, and +<p>Note the <tt class="docutils literal">0</tt> in the last line: this is the return value of +<tt class="docutils literal">sandbox.run_script()</tt>, which returns <tt class="docutils literal">0</tt> on success, and <tt class="docutils literal"><span class="pre">-1</span></tt> if an exception was raised. For instance, the output of bad code looks like this:</p> <blockquote> @@ -103,10 +104,10 @@ code: one of Pydertron's aims is to make debugging JS code as much like debugging Python code as possible.</p> </div> -<div class="section"> -<h1><a id="exceptions" name="exceptions">Exceptions</a></h1> +<div class="section" id="exceptions"> +<h1>Exceptions</h1> <p>Any exceptions raised by wrapped Python functions need to be of type -<tt class="docutils literal"><span class="pre">pydermonkey.error</span></tt> to be propagated into calling JavaScript code; +<tt class="docutils literal">pydermonkey.ScriptError</tt> to be propagated into calling JavaScript code; if they're not, then for security purposes, the entire JavaScript call stack is unrolled.</p> <p>For example, here's a function that's bound to fail:</p> @@ -132,13 +133,13 @@ -1 </pre> </blockquote> -<p>Note that a <tt class="docutils literal"><span class="pre">KeyboardInterrupt</span></tt> triggered while JS is executing will +<p>Note that a <tt class="docutils literal">KeyboardInterrupt</tt> triggered while JS is executing will have similar effect.</p> </div> </div> <div class="footer"> <hr class="footer" /> -<a class="reference" href="docs.txt">View document source</a>. +<a class="reference external" href="docs.txt">View document source</a>. </div> </body>