From df6cb5718ad119a15184c9a37ce0c8b67ca8fd79 Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 6 Nov 2018 12:41:06 +0100 Subject: [PATCH] Fix casting of int/float to str or unicode --- resources/lib/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/resources/lib/utils.py b/resources/lib/utils.py index b49b5505..12baf3a7 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -328,9 +328,15 @@ def cast(func, value): if func == bool: return bool(int(value)) elif func == unicode: - return value.decode('utf-8') + if isinstance(value, (int, long, float)): + return unicode(value) + else: + return value.decode('utf-8') elif func == str: - return value.encode('utf-8') + if isinstance(value, (int, long, float)): + return str(value) + else: + return value.encode('utf-8') elif func in (int, float): try: return func(value)