[kupfer] google_translate: Use SSL if we can



commit a6fe65ae02799069afb8374b43a4ed91a4de7114
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Mar 5 23:03:43 2011 +0100

    google_translate: Use SSL if we can

 kupfer/plugin/google_translate.py |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/plugin/google_translate.py b/kupfer/plugin/google_translate.py
index 98dbf2e..81f141a 100644
--- a/kupfer/plugin/google_translate.py
+++ b/kupfer/plugin/google_translate.py
@@ -17,6 +17,7 @@ import socket
 
 from kupfer.objects import Source, Action, TextLeaf, Leaf, UrlLeaf
 from kupfer import icons, utils, pretty
+from kupfer.plugin import ssl_support
 
 
 try:
@@ -60,9 +61,13 @@ def _translate(text, lang):
 		"adjective": _("adjective"),
 	}
 	try:
-		conn = httplib.HTTPConnection(_GOOGLE_TRANSLATE_HOST)
-		conn.connect()
-		conn.sock.settimeout(10) # set timeout to 10 sec
+		if ssl_support.is_supported():
+			conn = ssl_support.VerifiedHTTPSConnection(_GOOGLE_TRANSLATE_HOST,
+			                                           timeout=5)
+			pretty.print_debug(__name__, "Connected to",
+			                   _GOOGLE_TRANSLATE_HOST, "using SSL")
+		else:
+			conn = httplib.HTTPConnection(_GOOGLE_TRANSLATE_HOST, timeout=5)
 		conn.request("POST", _GOOGLE_TRANSLATE_PATH, query_param, _HEADER)
 		resp = conn.getresponse()
 		if resp.status != 200:



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