```python >>> a = DataBuffer('abcd') >>> str(a) 'abcd' ``` This PR encodes a python3 str to bytes using `charmap`. It verifies that `bytes != str` to only encode a python3 str and not a python2 str.
Diffstat (limited to 'python/databuffer.py')
-rw-r--r--python/databuffer.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/python/databuffer.py b/python/databuffer.py
index 8a862872..8644a75e 100644
--- a/python/databuffer.py
+++ b/python/databuffer.py
@@ -37,6 +37,8 @@ class DataBuffer(object):
elif isinstance(contents, DataBuffer):
self.handle = core.BNDuplicateDataBuffer(contents.handle)
else:
+ if bytes != str and isinstance(contents, str):
+ contents = contents.encode('charmap')
self.handle = core.BNCreateDataBuffer(contents, len(contents))
def __del__(self):