This repository has been archived on 2024-12-18. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-18/src/unqstr.py

24 lines
499 B
Python
Raw Normal View History

2024-05-23 06:28:40 +02:00
import sys
2024-05-26 03:18:08 +02:00
import six
2024-05-23 06:28:40 +02:00
def ustr(v):
2024-05-26 03:18:08 +02:00
if six.PY3:
2024-05-23 06:28:40 +02:00
if isinstance(v, str):
return v
2024-05-30 19:52:00 +02:00
elif isinstance(v, bytes):
return v.decode("utf-8", "replace")
2024-05-23 06:28:40 +02:00
else:
return str(v)
2024-05-26 03:18:08 +02:00
# assume six.PY2
2024-05-23 06:28:40 +02:00
if isinstance(v, unicode):
return v.encode("utf-8", "replace")
return str(v)
def unic(v):
2024-05-26 03:18:08 +02:00
if six.PY3:
2024-05-23 06:28:40 +02:00
return v
2024-05-26 03:18:08 +02:00
# assume six.PY2
2024-05-23 06:28:40 +02:00
if isinstance(v, unicode):
return v
return unicode(v, "utf-8", "replace")