On 10/31/06, Gary Poster <[EMAIL PROTECTED]> wrote:
> I do a lot inline in my Python code, using our nevow.Stan inspired tag
> generation system and little bits and pieces I threw together to ease
> in generating short bits of JS from within Python. In particular,
> marshalling of basic Python structures to Javascript using a modified
> `jsonencode` module from the `simplejson` package.

What are the modifications?  The things you list below all sound like
normal simplejson stuff.

The main modification is that it pass over 'raw' JS Code - statements
that have already been encoded, function calls, raw names, etc. I
think I did some tweaks to its string quoting system as well, but I
don't recall.


   >>> print js.encode('raw')
   >>> print js.encode(js.raw('raw'))

This gets to be handy when generating function calls. `js.call` str's
the first option, and then encodes the rest to create an arguments
list, which it returns as a `js.raw` object so that it won't be quoted
as a string::

   >>> dumbalert = js.call('window.alert', 'Stupid simple example')
   >>> print dumbalert
   window.alert('Stupid simple example')
   >>> print js.anonymous(js.expr(dumbalert))
   function() {window.alert('Stupid simple example');}
   >>> print js.call('setTimeout', js.anonymous(js.expr(dumbalert)), 5*1000)
   setTimeout(function() {window.alert('Stupid simple example');}, 5000)

It's simple, but helpful, especially as calls and data build up. But
even without building up a little system like this, it's probably good
to use tools like `simplejson` to keep javascript data pretty, even in
generated strings such as in TAL/TALES, just as it's good practice to
use SQL Quoting.

>> Other JS-related bits to know about (you'll have to do your own
>> reading sometime :-): http://zif.hill-street.net/headincludes (WSGI
>> variation on resourcelibrary), http://zif.hill-street.net/gzipper/
>> (WSGI, gzips all output for smaller browser page sizes), http://
>> zif.hill-street.net/jsmin/ (WSGI, compresses JS for smaller browser
>> page sizes), and http://svn.zope.org/z3c.javascript/
>> (resourcelibrary-
>> aware collection of mochikit, dojo, et al).
> Ah, the real reason for my response here: how does one use third party
> WSGI "Middleware" with Zope?

zope.paste, maybe (http://svn.zope.org/zope.paste/)?  I think that's
what Jim Washington has used.

Ahh, thanks, I'll take a look.

Jeff Shell
Zope3-users mailing list

Reply via email to