[kupfer: 8/13] plugin.google_translate: protection for invalid responses



commit ffd943f0f307c6c6f5b0dd6973ca04c9dbbd0f96
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Fri Oct 30 16:50:41 2009 +0100

    plugin.google_translate: protection for invalid responses

 kupfer/plugin/google_translate.py |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/kupfer/plugin/google_translate.py b/kupfer/plugin/google_translate.py
index 1bbd178..ea18861 100644
--- a/kupfer/plugin/google_translate.py
+++ b/kupfer/plugin/google_translate.py
@@ -54,12 +54,16 @@ def _translate(text, lang):
 		response_data = resp.read()
 		encoding = _parse_encoding_header(resp)
 		response_data = response_data.decode(encoding)
-		result, _lang, other_trans = json_decoder(response_data)
-		yield result
-
-		if other_trans:
-			for translation in other_trans[0]:
-				yield translation
+		resp = json_decoder(response_data)
+		if len(resp) ==  2:
+			yield resp[0]
+		elif len(resp) == 3:
+			result, _lang, other_trans = resp
+			yield result
+
+			if other_trans:
+				for translation in other_trans[0]:
+					yield translation
 
 	except Exception, err:
 		pretty.print_error(__name__, '_translate error', repr(text), lang, err)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]