This repository has been archived on 2024-12-11. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-11/src/dbcompat.py
Kashiko Koibumi 96c764bd94
refined: read from and write to SQLite database in binary mode
This modification is a preparation for migration to Python3.
2024-05-27 22:43:01 +09:00

23 lines
691 B
Python

import logging
import six
logger = logging.getLogger("default")
def dbstr(v):
if six.PY3:
if isinstance(v, str):
return v
elif isinstance(v, bytes):
return v.decode("utf-8", "replace")
logger.debug("unexpected type in dbstr(): {}".format(type(v)))
return v # hope this never happens..
else: # assume six.PY2
if isinstance(v, unicode):
return v.encode("utf-8", "replace")
elif isinstance(v, str):
return v
elif isinstance(v, bytes):
return str(v)
logger.debug("unexpected type in dbstr(): {}".format(type(v)))
return v # hope this never happens..