LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0006-Remove-backwards-compatibility-with-python-2.7.patch of Package mycroft-core (Project home:alarrosa:packages)

From 383ebc6273f4450267981e11b874d588fccf48dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=85ke=20Forslund?= <ake.forslund@gmail.com>
Date: Thu, 8 Feb 2018 20:03:46 +0100
Subject: [PATCH 06/13] Remove backwards compatibility with python 2.7

---
 mycroft/api/__init__.py                  |  4 +---
 mycroft/client/enclosure/__init__.py     |  5 +----
 mycroft/client/speech/hotword_factory.py |  6 +-----
 mycroft/client/speech/listener.py        |  5 +----
 mycroft/client/text/main.py              | 11 ++---------
 mycroft/configuration/config.py          | 12 +++---------
 mycroft/messagebus/send.py               |  3 ---
 mycroft/skills/audioservice.py           |  4 +---
 mycroft/skills/core.py                   |  9 +++------
 mycroft/skills/event_scheduler.py        |  6 +-----
 mycroft/skills/intent_service.py         |  5 +----
 mycroft/tts/__init__.py                  |  6 +-----
 mycroft/util/audio_test.py               |  1 -
 13 files changed, 16 insertions(+), 61 deletions(-)

diff --git a/mycroft/api/__init__.py b/mycroft/api/__init__.py
index b00eca1..ed99c80 100644
--- a/mycroft/api/__init__.py
+++ b/mycroft/api/__init__.py
@@ -23,8 +23,6 @@ from mycroft.configuration.config import DEFAULT_CONFIG, SYSTEM_CONFIG, \
 from mycroft.identity import IdentityManager
 from mycroft.version import VersionManager
 from mycroft.util import get_arch
-# python 2/3 compatibility
-from future.utils import iteritems
 
 _paired_cache = False
 
@@ -115,7 +113,7 @@ class Api(object):
     def build_json(self, params):
         json = params.get("json")
         if json and params["headers"]["Content-Type"] == "application/json":
-            for k, v in iteritems(json):
+            for k, v in json.items():
                 if v == "":
                     json[k] = None
             params["json"] = json
diff --git a/mycroft/client/enclosure/__init__.py b/mycroft/client/enclosure/__init__.py
index b2d9d50..20ae054 100644
--- a/mycroft/client/enclosure/__init__.py
+++ b/mycroft/client/enclosure/__init__.py
@@ -35,10 +35,7 @@ from mycroft.util import play_wav, create_signal, connected, \
     wait_while_speaking
 from mycroft.util.audio_test import record
 from mycroft.util.log import LOG
-if sys.version_info[0] < 3:
-    from Queue import Queue
-else:
-    from queue import Queue
+from queue import Queue
 
 
 class EnclosureReader(Thread):
diff --git a/mycroft/client/speech/hotword_factory.py b/mycroft/client/speech/hotword_factory.py
index 6f7ac8d..8f1ebfd 100644
--- a/mycroft/client/speech/hotword_factory.py
+++ b/mycroft/client/speech/hotword_factory.py
@@ -178,11 +178,7 @@ class PreciseHotword(HotWordEngine):
     def download(url, filename):
         import shutil
 
-        # python 2/3 compatibility
-        if sys.version_info[0] >= 3:
-            from urllib.request import urlopen
-        else:
-            from urllib2 import urlopen
+        from urllib.request import urlopen
         LOG.info('Downloading: ' + url)
         req = urlopen(url)
         with open(filename, 'wb') as fp:
diff --git a/mycroft/client/speech/listener.py b/mycroft/client/speech/listener.py
index 357077e..1d65886 100644
--- a/mycroft/client/speech/listener.py
+++ b/mycroft/client/speech/listener.py
@@ -28,10 +28,7 @@ from mycroft.metrics import MetricsAggregator, Stopwatch, report_timing
 from mycroft.session import SessionManager
 from mycroft.stt import STTFactory
 from mycroft.util.log import LOG
-if sys.version_info[0] < 3:
-    from Queue import Queue, Empty
-else:
-    from queue import Queue, Empty
+from queue import Queue, Empty
 
 
 class AudioProducer(Thread):
diff --git a/mycroft/client/text/main.py b/mycroft/client/text/main.py
index 877a1cd..cd05b9d 100644
--- a/mycroft/client/text/main.py
+++ b/mycroft/client/text/main.py
@@ -12,8 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-from __future__ import print_function
-from builtins import str
 import sys
 import io
 
@@ -27,13 +25,8 @@ def custom_except_hook(exctype, value, traceback):           # noqa
 
 sys.excepthook = custom_except_hook  # noqa
 
-# capture any output
-if sys.version_info[0] < 3:  # noqa
-    sys.stdout = io.BytesIO()  # noqa
-    sys.stderr = io.BytesIO()  # noqa
-else:  # noqa
-    sys.stdout = io.StringIO()  # noqa
-    sys.stderr = io.StringIO()  # noqa
+sys.stdout = io.StringIO()  # noqa
+sys.stderr = io.StringIO()  # noqa
 
 import os
 import os.path
diff --git a/mycroft/configuration/config.py b/mycroft/configuration/config.py
index f299708..df2fd5f 100644
--- a/mycroft/configuration/config.py
+++ b/mycroft/configuration/config.py
@@ -23,12 +23,6 @@ from requests import HTTPError
 from mycroft.util.json_helper import load_commented_json
 from mycroft.util.log import LOG
 
-# Python 2+3 compatibility
-import sys
-from future.utils import iteritems
-if sys.version_info[0] >= 3:
-    basestring = str
-
 
 def merge_dict(base, delta):
     """
@@ -39,7 +33,7 @@ def merge_dict(base, delta):
             delta: Dictionary to merge into base
     """
 
-    for k, dv in iteritems(delta):
+    for k, dv in delta.items():
         bv = base.get(k)
         if isinstance(dv, dict) and isinstance(bv, dict):
             merge_dict(bv, dv)
@@ -69,7 +63,7 @@ def translate_remote(config, setting):
     """
     IGNORED_SETTINGS = ["uuid", "@type", "active", "user", "device"]
 
-    for k, v in iteritems(setting):
+    for k, v in setting.items():
         if k not in IGNORED_SETTINGS:
             # Translate the CamelCase values stored remotely into the
             # Python-style names used within mycroft-core.
@@ -226,7 +220,7 @@ class Configuration(object):
         else:
             # Handle strings in stack
             for index, item in enumerate(configs):
-                if isinstance(item, basestring):
+                if isinstance(item, str):
                     configs[index] = LocalConf(item)
 
         # Merge all configs into one
diff --git a/mycroft/messagebus/send.py b/mycroft/messagebus/send.py
index 3cc7d0c..fe1ee3e 100644
--- a/mycroft/messagebus/send.py
+++ b/mycroft/messagebus/send.py
@@ -12,9 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-# Backport python 3 print function
-from __future__ import print_function
-
 import sys
 import json
 from mycroft.messagebus.client.ws import WebsocketClient
diff --git a/mycroft/skills/audioservice.py b/mycroft/skills/audioservice.py
index 37a2a37..47d5a7b 100644
--- a/mycroft/skills/audioservice.py
+++ b/mycroft/skills/audioservice.py
@@ -16,8 +16,6 @@ import time
 from os.path import abspath
 
 from mycroft.messagebus.message import Message
-# Python 2+3 compatibility
-from past.builtins import basestring
 
 
 def ensure_uri(s):
@@ -63,7 +61,7 @@ class AudioService():
                 tracks: track uri or list of track uri's
         """
         tracks = tracks or []
-        if isinstance(tracks, basestring):
+        if isinstance(tracks, str):
             tracks = [tracks]
         elif not isinstance(tracks, list):
             raise ValueError
diff --git a/mycroft/skills/event_scheduler.py b/mycroft/skills/event_scheduler.py
index 2180598..701705e 100644
--- a/mycroft/skills/event_scheduler.py
+++ b/mycroft/skills/event_scheduler.py
@@ -20,11 +20,7 @@ from os.path import isfile
 
 from mycroft.messagebus.message import Message
 from mycroft.util.log import LOG
-import sys
-if sys.version_info[0] < 3:
-    from Queue import Queue
-else:
-    from queue import Queue
+from queue import Queue
 
 
 def repeat_time(sched_time, repeat):
diff --git a/mycroft/skills/intent_service.py b/mycroft/skills/intent_service.py
index fceb383..34dba9d 100644
--- a/mycroft/skills/intent_service.py
+++ b/mycroft/skills/intent_service.py
@@ -22,9 +22,6 @@ from mycroft.skills.core import open_intent_envelope
 from mycroft.util.log import LOG
 from mycroft.util.parse import normalize
 from mycroft.metrics import report_timing, Stopwatch
-# python 2+3 compatibility
-from past.builtins import basestring
-from future.builtins import range
 
 
 class ContextManager(object):
@@ -389,7 +386,7 @@ class IntentService(object):
         context = message.data.get('context')
         word = message.data.get('word') or ''
         # if not a string type try creating a string from it
-        if not isinstance(word, basestring):
+        if not isinstance(word, str):
             word = str(word)
         entity['data'] = [(word, context)]
         entity['match'] = word
diff --git a/mycroft/tts/__init__.py b/mycroft/tts/__init__.py
index 88ff97e..e215af2 100644
--- a/mycroft/tts/__init__.py
+++ b/mycroft/tts/__init__.py
@@ -32,11 +32,7 @@ from mycroft.util import (
 )
 from mycroft.util.log import LOG
 from mycroft.metrics import report_timing, Stopwatch
-import sys
-if sys.version_info[0] < 3:
-    from Queue import Queue, Empty
-else:
-    from queue import Queue, Empty
+from queue import Queue, Empty
 
 
 def send_playback_metric(stopwatch, ident):
diff --git a/mycroft/util/audio_test.py b/mycroft/util/audio_test.py
index eaa04e2..9e7accc 100644
--- a/mycroft/util/audio_test.py
+++ b/mycroft/util/audio_test.py
@@ -12,7 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-from __future__ import print_function
 import argparse
 
 from speech_recognition import Recognizer
-- 
2.16.2