LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0004-Fix-hashes-in-settings-for-python3.patch of Package mycroft-core (Project home:alarrosa:packages)

From 937c6c01d09e32200b0b29080295c8c979c5a2b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=85ke=20Forslund?= <ake.forslund@gmail.com>
Date: Wed, 7 Feb 2018 22:40:16 +0100
Subject: [PATCH 04/13] Fix hashes in settings for python3

convert strings to bytes before hashing
---
 mycroft/skills/settings.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mycroft/skills/settings.py b/mycroft/skills/settings.py
index 26445bd..12bdce4 100644
--- a/mycroft/skills/settings.py
+++ b/mycroft/skills/settings.py
@@ -94,7 +94,7 @@ class SkillSettings(dict):
         self._settings_path = join(directory, 'settings.json')
         self._meta_path = join(directory, 'settingsmeta.json')
         self.is_alive = True
-        self.loaded_hash = hash(str(self))
+        self.loaded_hash = hash(frozenset(self.items()))
         self._complete_intialization = False
         self._device_identity = None
         self._api_path = None
@@ -162,7 +162,7 @@ class SkillSettings(dict):
 
     @property
     def _is_stored(self):
-        return hash(str(self)) == self.loaded_hash
+        return hash(bytes(str(self), 'utf-8')) == self.loaded_hash
 
     def __getitem__(self, key):
         """ Get key """
@@ -305,9 +305,9 @@ class SkillSettings(dict):
             except Exception as e:
                 LOG.error(e)
 
-    def hash(self, str):
+    def hash(self, string):
         """ md5 hasher for consistency across cpu architectures """
-        return hashlib.md5(str).hexdigest()
+        return hashlib.md5(bytes(string, 'utf-8')).hexdigest()
 
     def _get_meta_hash(self, settings_meta):
         """ Get's the hash of skill
@@ -538,7 +538,7 @@ class SkillSettings(dict):
         if force or not self._is_stored:
             with open(self._settings_path, 'w') as f:
                 json.dump(self, f)
-            self.loaded_hash = hash(str(self))
+            self.loaded_hash = hash(bytes(str((self)), 'utf-8'))
 
         if self._should_upload_from_change:
             settings_meta = self._load_settings_meta()
-- 
2.16.2