LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File skills-fallback-wolfram-alpha.patch of Package mycroft-core (Project home:alarrosa:packages)

From 43fe7f6c6c0fce77c466368a70ba68b868bd2ce5 Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <antonio.larrosa@gmail.com>
Date: Fri, 23 Feb 2018 18:36:35 +0100
Subject: [PATCH] Fix some python2 exclusive code to work also with python3

This allows the skill to run under python2 and python3
---
 __init__.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git fallback-wolfram-alpha/__init__.py fallback-wolfram-alpha.new/__init__.py
index ea4fd48..f1ac403 100644
--- fallback-wolfram-alpha/__init__.py
+++ fallback-wolfram-alpha.new/__init__.py
@@ -12,8 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-from StringIO import StringIO
 
+import sys
 import re
 import wolframalpha
 from os.path import dirname, join
@@ -25,6 +25,11 @@ from mycroft.messagebus.message import Message
 from mycroft.skills.core import FallbackSkill, intent_handler
 from mycroft.util.parse import normalize
 
+if sys.version_info[0] < 3:
+    from StringIO import StringIO
+else:
+    from io import BytesIO
+
 
 class EnglishQuestionParser(object):
     """
@@ -77,7 +82,10 @@ class WAApi(Api):
 
     def query(self, input):
         data = self.request({"query": {"input": input}})
-        return wolframalpha.Result(StringIO(data.content))
+        if sys.version_info[0] < 3:
+            return wolframalpha.Result(StringIO(data.content))
+        else:
+            return wolframalpha.Result(BytesIO(data.content))
 
 
 class WolframAlphaSkill(FallbackSkill):
-- 
2.16.2