Fix decode_string()/encode_string() (pattern.helpers)
@@ -18,10 +18,10 @@ def decode_string(v, encoding="utf-8"):
encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore"))
if isinstance(v, bytes):
for e in encoding:
- try: return v.decode(*e)
+ try: return str(v.decode(*e))
except:
pass
- return v
+ return str(v)
return str(v)
def encode_string(v, encoding="utf-8"):
@@ -31,10 +31,10 @@ def encode_string(v, encoding="utf-8"):
encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore"))
if isinstance(v, str):
for e in encoding:
- try: return v.encode(*e)
+ try: return bytes(v.encode(*e))
except:
pass
- return v
+ return bytes(v)
return bytes(v)
decode_utf8 = decode_string
