changeset 8f32c19838fa in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=8f32c19838fa
description: fix a bug in ged that prevent callback to be called in the correct order.
diffstat:
src/common/ged.py | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diffs (13 lines):
diff -r 8accbba869c0 -r 8f32c19838fa src/common/ged.py
--- a/src/common/ged.py Fri Sep 17 10:00:25 2010 +0200
+++ b/src/common/ged.py Fri Sep 17 12:41:00 2010 +0200
@@ -46,6 +46,9 @@
for i, h in enumerate(handlers_list):
if priority < h[0]:
break
+ else:
+ # no event with smaller prio found, put it at the end
+ i += 1
handlers_list.insert(i, (priority, handler))
else:
changeset 6132de77f21c in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=6132de77f21c
description: [Dicson] Handle non-Latin text and errors in google translate plugin. Fixes #5904
diffstat:
plugins/google_translation/plugin.py | 64 +++++++++++++++++++----------------
1 files changed, 35 insertions(+), 29 deletions(-)
diffs (99 lines):
diff -r db8ada40b491 -r 6132de77f21c plugins/google_translation/plugin.py
--- a/plugins/google_translation/plugin.py Sat Sep 11 15:32:44 2010 +0200
+++ b/plugins/google_translation/plugin.py Sun Sep 12 17:14:44 2010 +0200
@@ -30,6 +30,7 @@
import urllib2
import new
from pprint import pformat
+from sys import getfilesystemencoding
from common import helpers
from common import gajim
@@ -51,45 +52,49 @@
def init(self):
self.config_dialog = None
#self.gui_extension_points = {}
- self.config_default_values = {'from_lang' : (u'en', _(u'Language of text to be translated')),
- 'to_lang' : (u'fr', _(u'Language to which translation will be made')),
- 'user_agent' : (u'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20080213 Firefox/2.0.0.11',
- _(u'User Agent data to be used with urllib2 when connecting to Google Translate service'))}
+ self.config_default_values = {
+ 'from_lang' :
+ (u'en', _(u'Language of text to be translated')),
+ 'to_lang' :
+ (u'fr', _(u'Language to which translation will be made')),
+ 'user_agent' :
+ (u'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) '
+ 'Gecko/20080213 Firefox/2.0.0.11',
+ _(u'User Agent data to be used with urllib2 '
+ 'when connecting to Google Translate service'))}
#self.events_handlers = {}
self.events = [GoogleTranslateMessageReceivedEvent]
- self.translated_text_re = \
- re.compile(r'google.language.callbacks.id100\(\'22\',{"translatedText":"(?P<text>[^"]*)"}, 200, null, 200\)')
+ self.translated_text_re = re.compile(
+ r'google.language.callbacks.id100\(\'22\','
+ '{"translatedText":"(?P<text>[^"]*)"}, 200, null, 200\)')
@log_calls('GoogleTranslationPlugin')
def translate_text(self, text, from_lang, to_lang):
- text = self.prepare_text_for_url(text)
+ # Converts text so it can be used within URL as query to Google
+ # Translate.
+ quoted_text = urllib2.quote(text.encode(getfilesystemencoding()))
+ # prepare url
headers = { 'User-Agent' : self.config['user_agent'] }
- translation_url = u'http://www.google.com/uds/Gtranslate?callback=google.language.callbacks.id1…'%locals()
+ translation_url = u'http://www.google.com/uds/Gtranslate?callback='\
+ 'google.language.callbacks.id100&context=22&q=%(quoted_text)s&'\
+ 'langpair=%(from_lang)s%%7C%(to_lang)s&key=notsupplied&v=1.0' % \
+ locals()
+ request = urllib2.Request(translation_url, headers=headers)
- request = urllib2.Request(translation_url, headers=headers)
- response = urllib2.urlopen(request)
+ try:
+ response = urllib2.urlopen(request)
+ except urllib2.URLError, e:
+ # print e
+ return text
+
results = response.read()
-
translated_text = self.translated_text_re.search(results).group('text')
- return translated_text
-
- @log_calls('GoogleTranslationPlugin')
- def prepare_text_for_url(self, text):
- '''
- Converts text so it can be used within URL as query to Google Translate.
- '''
-
- # There should be more replacements for plugin to work in any case:
- char_replacements = { ' ' : '%20',
- '+' : '%2B'}
-
- for char, replacement in char_replacements.iteritems():
- text = text.replace(char, replacement)
-
+ if translated_text:
+ return translated_text
return text
@log_calls('GoogleTranslationPlugin')
@@ -112,7 +117,8 @@
from_lang = self.plugin.config['from_lang']
to_lang = self.plugin.config['to_lang']
self.base_event.xmpp_msg.kids[0].setData(
- self.plugin.translate_text(msg_text, from_lang, to_lang))
+ self.plugin.translate_text(msg_text, from_lang, to_lang))
- return False # We only want to modify old event, not emit another,
- # so we return False here.
+ # We only want to modify old event, not emit another, so we return False
+ # here.
+ return False