From 2c44e5031649ad425d41a2c8818eb1694a5ed1d4 Mon Sep 17 00:00:00 2001 From: "T. Joseph Carter" Date: Tue, 18 Jul 2017 10:21:17 -0700 Subject: [PATCH] Change ByteBuffer reads on one byte If you read one index from a bytes or bytearray, you get an int, not a single character bytes object. Originally I didn't want to mimic that feature because it's actually somewhat annoying at times. Realizing it was done that way for a reason, and not doing it in ByteBuffer is gonna be even more annoying. --- blocksfree/buffer/bytebuffer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/blocksfree/buffer/bytebuffer.py b/blocksfree/buffer/bytebuffer.py index 68e5dfe..f05528d 100644 --- a/blocksfree/buffer/bytebuffer.py +++ b/blocksfree/buffer/bytebuffer.py @@ -16,9 +16,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from typing import Optional, Union +from typing import Dict, List, Optional, Union from .buffertype import BufferType -from ..util import gen_hexdump +from .. import util class ByteBuffer(BufferType): """ByteBuffer(bytes_or_int[, changed[, locked]]) -> ByteBuffer @@ -45,7 +45,7 @@ class ByteBuffer(BufferType): def read( self, start: int = 0, - count: Optional[int] = None, + count: int = 1, limit: bool = True ) -> bytearray: """Return bytearray of count bytes from buffer beginning at start @@ -63,7 +63,8 @@ class ByteBuffer(BufferType): assert(start + count <= len(self._buf)) except AssertionError: raise IndexError('buffer read with index out of range') - return bytes(self._buf[start:start + count]) + ret = self._buf[start:start + count] + return bytes(ret) if count != 1 else int(ret[0]) def write( self,