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.
This commit is contained in:
T. Joseph Carter 2017-07-18 10:21:17 -07:00
parent ed6156c3c6
commit 2c44e50316
1 changed files with 5 additions and 4 deletions

View File

@ -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,