diff options
author | Victor Stinner <vstinner@redhat.com> | 2016-05-26 16:29:51 +0200 |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2016-05-30 10:47:26 +0200 |
commit | 61614653d6b35b3d6b4c8802c737c02cb9968f4a (patch) | |
tree | 0a89c6bbea03ad559617be2b1359ed157b6980b2 /trove/module | |
parent | f9df5af18dce3a1aad80de9cae56cb7d47ff5b33 (diff) | |
download | trove-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.py | 6 |
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) |