Fix safestr() for Python 3

We don't see an easier and cleaner way than to take exceptions
for every call in Python 3. Fortunately, we do not use safestr()
for bulk data in Glie.