--- Begin Message ---
Package: python-toscawidgets
Version: 0.9.7.2-1.1
Severity: normal
Tags: patch upstream
Forwarded: http://toscawidgets.org/trac/tw/ticket/30
Hello,
While trying to use AutoComplete from tw.jquery, I had the issue
reported there[0]. Applying this "patch" seems to fix the issue. I have
attached to this email a patch for the Debian package.
Regards,
Arnaud Fontaine
-- System Information:
Debian Release: squeeze/sid
APT prefers experimental
APT policy: (990, 'experimental'), (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.31-rc6
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages python-toscawidgets depends on:
ii python-formencode 1.2.2-1 validation and form generation Pyt
ii python-simplejson 2.0.9-1 Simple, fast, extensible JSON enco
ii python-support 1.0.3 automated rebuilding support for P
ii python-webob 0.9.6.1-1.1 Python module providing WSGI reque
python-toscawidgets recommends no packages.
Versions of packages python-toscawidgets suggests:
ii python-cheetah 2.2.1-1 text-based template engine and Pyt
ii python-genshi 0.5.1-1 Python XML-based template engine
ii python-kid 0.9.6-1 simple Pythonic template language
-- no debconf information
diff -urN python-toscawidgets-0.9.7.2.orig/debian/patches/00list python-toscawidgets-0.9.7.2/debian/patches/00list
--- python-toscawidgets-0.9.7.2.orig/debian/patches/00list 2009-09-17 17:57:59.000000000 +0100
+++ python-toscawidgets-0.9.7.2/debian/patches/00list 2009-09-17 16:55:33.000000000 +0100
@@ -1 +1,2 @@
force-init_py
+fix-js-quote
diff -urN python-toscawidgets-0.9.7.2.orig/debian/patches/fix-js-quote python-toscawidgets-0.9.7.2/debian/patches/fix-js-quote
--- python-toscawidgets-0.9.7.2.orig/debian/patches/fix-js-quote 1970-01-01 01:00:00.000000000 +0100
+++ python-toscawidgets-0.9.7.2/debian/patches/fix-js-quote 2009-09-17 17:19:39.000000000 +0100
@@ -0,0 +1,173 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## force-init_py.dpatch by srlindermann:
+## http://toscawidgets.org/trac/tw/ticket/30
+##
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: avoid removal of apparently useless __init__.py by pysupport
+
+@DPATCH@
+--- a/ToscaWidgets-0.9.7.2/tw/core/js.py 2009-04-27 19:31:51.000000000 +0100
++++ b/ToscaWidgets-0.9.7.2/tw/core/js.py 2009-09-17 16:56:04.000000000 +0100
+@@ -1,7 +1,7 @@
+ """
+ Python-JS interface to dynamically create JS function calls from your widgets.
+
+-This moudle doesn't aim to serve as a Python-JS "translator". You should code
++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
+@@ -11,9 +11,10 @@
+
+ import logging
+ from itertools import imap
++import re
+ import simplejson.encoder
+
+-__all__ = ["js_callback", "js_function", "js_symbol", "encode"]
++__all__ = ["js_callback", "js_function", "js_symbol"]
+
+ log = logging.getLogger(__name__)
+
+@@ -31,40 +32,56 @@
+ >>> w = Widget("foo")
+ >>> args = {'onLoad': js_callback(js_function('jQuery')(w).click(js_symbol('onClick')))}
+ >>> print encode(args)
+- {"onLoad": function(){jQuery(\\"foo\\").click(onClick)}}
++ {"onLoad": function(){jQuery("foo").click(onClick)}}
+ >>> print encode({'args':args})
+- {"args": {"onLoad": function(){jQuery(\\"foo\\").click(onClick)}}}
+-
+-
++ {"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.
++
+ """
+ def __init__(self, *args, **kw):
+- self.pass_through = (_js_call, js_callback, js_symbol, js_function)
+ super(TWEncoder, self).__init__(*args, **kw)
+
+ def default(self, obj):
+- if isinstance(obj, self.pass_through):
++ if hasattr(obj, 'get_js_repr'):
+ return self.mark_for_escape(obj)
+ elif hasattr(obj, '_id'):
+ return str(obj.id)
+ return super(TWEncoder, self).default(obj)
+
+ def encode(self, obj):
++ self.unescape_symbols = {}
+ encoded = super(TWEncoder, self).encode(obj)
+- return self.unescape_marked(encoded)
++ unescaped = self.unescape_marked(encoded)
++ self.unescape_symbols = {}
++ return unescaped
+
+ def mark_for_escape(self, obj):
+- return '*#*%s*#*' % obj
++ self.unescape_symbols[id(obj)] = obj
++ return 'TWEncoder_unescape_' + str(id(obj))
+
+ def unescape_marked(self, encoded):
+- return encoded.replace('"*#*','').replace('*#*"', '')
+-
++ unescape_pattern = re.compile('"TWEncoder_unescape_([0-9]*)"')
++ def unescape(match):
++ try:
++ obj_id = int(match.group(1))
++ obj = self.unescape_symbols[obj_id]
++ return obj.get_js_repr()
++ except:
++ # Simply return the match if there is a problem
++ return match.group(0)
++ return unescape_pattern.sub(unescape, encoded)
+
+ class js_symbol(object):
+ def __init__(self, name):
+ self._name = name
+- def __str__(self):
++ def get_js_repr(self):
+ return str(self._name)
++ def __str__(self):
++ return self.get_js_repr()
+
+ class js_callback(object):
+ """A js function that can be passed as a callback to be called
+@@ -97,7 +114,7 @@
+ >>> on_doc_load = jQuery('#foo').bind('click', my_cb)
+ >>> call = jQuery(js_callback(on_doc_load))
+ >>> print call
+- jQuery(function(){jQuery(\\"#foo\\").bind(\\"click\\", function() { alert(this.text)})})
++ jQuery(function(){jQuery("#foo").bind("click", function() { alert(this.text)})})
+
+ """
+ def __init__(self, cb, *args):
+@@ -113,9 +130,12 @@
+ def __call__(self, *args):
+ raise TypeError("A js_callback cannot be called from Python")
+
+- def __str__(self):
++ def get_js_repr(self):
+ return self.cb
+
++ def __str__(self):
++ return self.get_js_repr()
++
+ class js_function(object):
+ """A JS function that can be "called" from python and and added to
+ a widget by widget.add_call() so it get's called every time the widget
+@@ -191,6 +211,12 @@
+
+ def __call__(self, *args):
+ return _js_call(self.__name, [], args, called=True)
++
++ def get_js_repr(self):
++ return str(self.__name)
++
++ def __str__(self):
++ return self.get_js_repr()
+
+
+ class _js_call(object):
+@@ -199,8 +225,8 @@
+ def __init__(self, name, call_list, args=None, called=False):
+ self.__name = name
+ self.__args = args
+- call_list.append(self)
+- self.__call_list = call_list
++ self.__call_list = call_list[:]
++ self.__call_list.append(self)
+ self.__called = called
+
+ def __getattr__(self, name):
+@@ -211,19 +237,21 @@
+ self.__called = True
+ return self
+
+- def __get_js_repr(self):
++ def get_js_repr(self):
++ encoder = TWEncoder()
++ return '.'.join(c.__get_js_repr_fragment(encoder) for c in self.__call_list)
++
++ def __get_js_repr_fragment(self, encoder):
+ if self.__called:
+ args = self.__args
+- return '%s(%s)' % (self.__name, ', '.join(imap(encode, args)))
++ return '%s(%s)' % (self.__name, ', '.join(imap(encoder.encode, args)))
+ else:
+ return self.__name
+
+ def __str__(self):
+ if not self.__called:
+ raise TypeError('Last element in the chain has to be called')
+- return '.'.join(c.__get_js_repr() for c in self.__call_list)
++ return self.get_js_repr()
+
+ def __unicode__(self):
+ return str(self).decode(sys.getdefaultencoding())
+-
+-encode = TWEncoder().encode
pgpmXrU3yI27J.pgp
Description: PGP signature
--- End Message ---