summaryrefslogtreecommitdiff
path: root/trove/module
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2016-05-26 16:29:51 +0200
committerVictor Stinner <vstinner@redhat.com>2016-05-30 10:47:26 +0200
commit61614653d6b35b3d6b4c8802c737c02cb9968f4a (patch)
tree0a89c6bbea03ad559617be2b1359ed157b6980b2 /trove/module
parentf9df5af18dce3a1aad80de9cae56cb7d47ff5b33 (diff)
downloadtrove-61614653d6b35b3d6b4c8802c737c02cb9968f4a.tar.gz
Port more unit tests to Python 3
* Replace string.find(a, b) with a.find(b) * NamedTemporaryFile: open file in text mode rather than opening it in binary mode. * Module.process_contents(): if contents is a Unicode string, first encode it to UTF-8 before hashing the content to MD5. * ClusterController: replace dict.items()[0] with next(iter(dict.items())) * tox: run the following tests on Python 3.4 - mysql/test_common.py - taskmanager/test_models.py - module/test_module_models.py - test_cluster_controller.py Partially implements: blueprint trove-python3 Change-Id: I5372520f9717b4f0279c4b436ca88c160ddf894b
Diffstat (limited to 'trove/module')
-rw-r--r--trove/module/models.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/trove/module/models.py b/trove/module/models.py
index 2558fa9f..c955d4c1 100644
--- a/trove/module/models.py
+++ b/trove/module/models.py
@@ -18,6 +18,7 @@
from datetime import datetime
import hashlib
+import six
from sqlalchemy.sql.expression import or_
from trove.common import cfg
@@ -217,7 +218,10 @@ class Module(object):
# be stored in a text field in the Trove database.
@staticmethod
def process_contents(contents):
- md5 = hashlib.md5(contents).hexdigest()
+ md5 = contents
+ if isinstance(md5, six.text_type):
+ md5 = md5.encode('utf-8')
+ md5 = hashlib.md5(md5).hexdigest()
encrypted_contents = crypto_utils.encrypt_data(
contents, Modules.ENCRYPT_KEY)
return md5, crypto_utils.encode_data(encrypted_contents)