Ñò
ʹJc @ sÜ d Z d d k Z d d k Z d d k l Z d d k Z d d k Z d d d g Z e i e
ƒ Z d e i i
f d „ ƒ YZ d e f d „ ƒ YZ d e f d
„ ƒ YZ d e f d „ ƒ YZ d e f d
„ ƒ YZ d S( s³
Python-JS interface to dynamically create JS function calls from your widgets.
This module doesn't aim to serve as a Python-JS "translator". You should code
your client-side code in JavaScript and make it available in static files which
you include as JSLinks or inline using JSSources. This module is only intended
as a "bridge" or interface between Python and JavaScript so JS function
**calls** can be generated programatically.
iÿÿÿÿN( t imapt js_callbackt js_functiont js_symbolt TWEncoderc B s; e Z d Z d „ Z d „ Z d „ Z d „ Z d „ Z RS( sŽ A JSON encoder that can encode Widgets, js_calls, js_symbols and
js_callbacks.
Example::
>>> encode = TWEncoder().encode
>>> print encode({'onLoad': js_function("do_something")(js_symbol("this"))})
{"onLoad": do_something(this)}
>>> from tw.api import Widget
>>> w = Widget("foo")
>>> args = {'onLoad': js_callback(js_function('jQuery')(w).click(js_symbol('onClick')))}
>>> print encode(args)
{"onLoad": function(){jQuery("foo").click(onClick)}}
>>> print encode({'args':args})
{"args": {"onLoad": function(){jQuery("foo").click(onClick)}}}
Technical note: simplejson does not support arbitrary js injection, which
is needed in this module. We work around this by inserting distinct
tokens into the JSON encoding stream that can later be replaced with the
objects' js representations.
c O s t t | ƒ i | | Ž d S( N( t superR t __init__( t selft argst kw( ( s. /usr/lib/python2.6/site-packages/tw/core/js.pyR - s c C sR t | d ƒ o | i | ƒ St | d ƒ o t | i ƒ St t | ƒ i | ƒ S( Nt get_js_reprt _id( t hasattrt mark_for_escapet strt idR R t default( R t obj( ( s. /usr/lib/python2.6/site-packages/tw/core/js.pyR 0 s
c C s= h | _ t t | ƒ i | ƒ } | i | ƒ } h | _ | S( N( t unescape_symbolsR R t encodet unescape_marked( R R t encodedt unescaped( ( s. /usr/lib/python2.6/site-packages/tw/core/js.pyR 7 s
c C s' | | i t | ƒ