2018-11-27 09:38:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2018 The go-python Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
## py2/py3 compat
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
2018-12-13 17:26:03 +00:00
|
|
|
import sys
|
|
|
|
|
2018-11-27 09:38:18 +00:00
|
|
|
import encoding
|
|
|
|
|
2018-12-13 17:26:03 +00:00
|
|
|
# There is no portable way of outputting Unicode in Python 2/3 -- we encode
|
|
|
|
# them manually and sidestep the builtin encoding machinery
|
|
|
|
try:
|
|
|
|
binary_stdout = sys.stdout.buffer # Python 3
|
|
|
|
except AttributeError:
|
|
|
|
binary_stdout = sys.stdout # Python 2
|
|
|
|
|
2018-11-27 09:38:18 +00:00
|
|
|
bytestr = b"Python byte string"
|
|
|
|
unicodestr = u"Python Unicode string 🐱"
|
|
|
|
|
2019-06-07 09:55:03 +00:00
|
|
|
# TODO: need conversion from bytestr to string -- not sure pybindgen can do it?
|
2019-03-06 10:41:03 +00:00
|
|
|
#bytestr_ret = encoding.HandleString(bytestr)
|
2018-11-27 09:38:18 +00:00
|
|
|
unicodestr_ret = encoding.HandleString(unicodestr)
|
|
|
|
|
2019-03-06 10:41:03 +00:00
|
|
|
# binary_stdout.write(b"encoding.HandleString(bytestr) -> ")
|
|
|
|
# binary_stdout.write(bytestr_ret.encode('UTF-8'))
|
|
|
|
# binary_stdout.write(b'\n')
|
2018-12-13 17:26:03 +00:00
|
|
|
binary_stdout.write(b"encoding.HandleString(unicodestr) -> ")
|
|
|
|
binary_stdout.write(unicodestr_ret.encode('UTF-8'))
|
|
|
|
binary_stdout.write(b'\n')
|
2018-11-27 09:38:18 +00:00
|
|
|
|
|
|
|
gostring_ret = encoding.GetString()
|
2018-12-13 17:26:03 +00:00
|
|
|
binary_stdout.write(b"encoding.GetString() -> ")
|
|
|
|
binary_stdout.write(gostring_ret.encode("UTF-8"))
|
|
|
|
binary_stdout.write(b"\n")
|
2018-11-27 09:38:18 +00:00
|
|
|
|
2019-01-16 13:47:57 +00:00
|
|
|
print("OK")
|