```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.
| -rw-r--r-- | python/databuffer.py | 2 |
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): |