diff options
| author | Jordan Wiens <jordan@psifertex.com> | 2020-09-09 14:56:55 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2020-09-16 22:50:21 +0000 |
| commit | c18b89e4cabfc28081a7893ccd4cf8956c9a797f (patch) | |
| tree | a660548d8556f3364e27d65478555d98bf9572f3 /python | |
| parent | 0fa07f755371447b9d733c6f89bb93f1ece5e7e1 (diff) | |
add support to databuffers, cstr helper, and bv.write for bytearrays
Diffstat (limited to 'python')
| -rw-r--r-- | python/binaryview.py | 2 | ||||
| -rw-r--r-- | python/compatibility.py | 2 | ||||
| -rw-r--r-- | python/databuffer.py | 3 |
3 files changed, 6 insertions, 1 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 49a80a4a..4a73a5a7 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -2680,7 +2680,7 @@ class BinaryView(object): >>> bv.read(0,4) 'AAAA' """ - if not isinstance(data, bytes): + if not (isinstance(data, bytes) or isinstance(data, bytearray)): if isinstance(data, str): buf = databuffer.DataBuffer(data.encode()) else: diff --git a/python/compatibility.py b/python/compatibility.py index 99411605..ccb185f8 100644 --- a/python/compatibility.py +++ b/python/compatibility.py @@ -83,6 +83,8 @@ def with_metaclass(meta, *bases): def cstr(arg): if isinstance(arg, bytes) or arg is None: return arg + elif isinstance(arg, bytearray): + return bytes(arg) else: try: return arg.encode('charmap') diff --git a/python/databuffer.py b/python/databuffer.py index d05ad1f5..26347101 100644 --- a/python/databuffer.py +++ b/python/databuffer.py @@ -39,6 +39,9 @@ class DataBuffer(object): else: if bytes != str and isinstance(contents, str): contents = contents.encode('charmap') + else: + if isinstance(contents, bytearray): + contents = bytes(contents) self.handle = core.BNCreateDataBuffer(contents, len(contents)) def __del__(self): |
