Skip to content

Make sure .read() and friends always return bytes #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions git/cmd.py
Original file line number Diff line number Diff line change
@@ -355,7 +355,7 @@ def __init__(self, size, stream):
def read(self, size=-1):
bytes_left = self._size - self._nbr
if bytes_left == 0:
return ''
return b''
if size > -1:
# assure we don't try to read past our limit
size = min(bytes_left, size)
@@ -374,7 +374,7 @@ def read(self, size=-1):

def readline(self, size=-1):
if self._nbr == self._size:
return ''
return b''

# clamp size to lowest allowed value
bytes_left = self._size - self._nbr
6 changes: 3 additions & 3 deletions git/test/test_repo.py
Original file line number Diff line number Diff line change
@@ -454,7 +454,7 @@ def mktiny():
assert s.readline() == l1
assert s.readline() == l2
assert s.readline() == l3
assert s.readline() == ''
assert s.readline() == b''
assert s._stream.tell() == len(d)

# readline limit
@@ -465,13 +465,13 @@ def mktiny():
# readline on tiny section
s = mktiny()
assert s.readline() == l1p
assert s.readline() == ''
assert s.readline() == b''
assert s._stream.tell() == ts + 1

# read no limit
s = mkfull()
assert s.read() == d[:-1]
assert s.read() == ''
assert s.read() == b''
assert s._stream.tell() == len(d)

# read limit