Skip to content

Commit ecdae96

Browse files
committed
Fixed a few more encoding issues
Bytes should always be returned from the streams, so the tests should be checking against byte strings instead of text strings. This also fixes the `sha_iter` as it relied on the Python 2 `iterkeys` which has been renamed to `keys` in Python 3.
1 parent 0465cf3 commit ecdae96

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

gitdb/db/loose.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
)
5353

5454
from gitdb.utils.compat import MAXSIZE
55+
from gitdb.utils.encoding import force_bytes
5556

5657
import tempfile
5758
import mmap
@@ -116,7 +117,7 @@ def partial_to_complete_sha_hex(self, partial_hexsha):
116117
:raise BadObject: """
117118
candidate = None
118119
for binsha in self.sha_iter():
119-
if bin_to_hex(binsha).startswith(partial_hexsha):
120+
if bin_to_hex(binsha).startswith(force_bytes(partial_hexsha)):
120121
# it can't ever find the same object twice
121122
if candidate is not None:
122123
raise AmbiguousObjectName(partial_hexsha)

gitdb/db/mem.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ def size(self):
8686
return len(self._cache)
8787

8888
def sha_iter(self):
89-
return self._cache.iterkeys()
89+
try:
90+
return self._cache.iterkeys()
91+
except AttributeError:
92+
return self._cache.keys()
9093

9194

9295
#{ Interface

gitdb/test/db/lib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from gitdb.exc import BadObject
2323
from gitdb.typ import str_blob_type
24+
from gitdb.utils.encoding import force_bytes
2425

2526
from async import IteratorReader
2627

@@ -97,7 +98,7 @@ def _assert_object_writing(self, db):
9798
assert info.size == len(data)
9899

99100
ostream = db.stream(sha)
100-
assert ostream.read() == data
101+
assert ostream.read() == force_bytes(data)
101102
assert ostream.type == str_blob_type
102103
assert ostream.size == len(data)
103104
else:

0 commit comments

Comments
 (0)