Skip to content

Commit 0cf09d3

Browse files
committed
Fix Python 2 failures
1 parent 087803e commit 0cf09d3

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

gitdb/db/loose.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def set_ostream(self, stream):
161161
def info(self, sha):
162162
m = self._map_loose_object(sha)
163163
try:
164-
type, size = loose_object_header_info(m)
165-
return OInfo(sha, type, size)
164+
typ, size = loose_object_header_info(m)
165+
return OInfo(sha, typ, size)
166166
finally:
167167
m.close()
168168
# END assure release of system resources

gitdb/db/mem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
DecompressMemMapReader,
2525
)
2626

27-
from io import StringIO
27+
from io import BytesIO
2828

2929
__all__ = ("MemoryDB", )
3030

@@ -104,7 +104,7 @@ def stream_copy(self, sha_iter, odb):
104104

105105
ostream = self.stream(sha)
106106
# compressed data including header
107-
sio = StringIO(ostream.stream.data())
107+
sio = BytesIO(ostream.stream.data())
108108
istream = IStream(ostream.type, ostream.size, sio, sha)
109109

110110
odb.store(istream)

gitdb/fun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def loose_object_header_info(m):
397397
decompress_size = 8192 # is used in cgit as well
398398
hdr = decompressobj().decompress(m, decompress_size)
399399
type_name, size = hdr[:hdr.find("\0".encode("ascii"))].split(" ".encode("ascii"))
400-
return type_name, int(size)
400+
return type_name.decode("ascii"), int(size)
401401

402402
def pack_object_header_info(data):
403403
"""

gitdb/test/db/lib.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from async import IteratorReader
2626

27-
from io import StringIO
27+
from io import BytesIO
2828

2929
from struct import pack
3030

@@ -44,7 +44,7 @@ def _assert_object_writing_simple(self, db):
4444
ni = 250
4545
for i in range(ni):
4646
data = pack(">L", i)
47-
istream = IStream(str_blob_type, len(data), StringIO(data))
47+
istream = IStream(str_blob_type, len(data), BytesIO(data))
4848
new_istream = db.store(istream)
4949
assert new_istream is istream
5050
assert db.has_object(istream.binsha)
@@ -82,7 +82,7 @@ def _assert_object_writing(self, db):
8282
prev_ostream = db.set_ostream(ostream)
8383
assert type(prev_ostream) in ostreams or prev_ostream in ostreams
8484

85-
istream = IStream(str_blob_type, len(data), StringIO(data))
85+
istream = IStream(str_blob_type, len(data), BytesIO(data))
8686

8787
# store returns same istream instance, with new sha set
8888
my_istream = db.store(istream)
@@ -132,8 +132,9 @@ def _assert_object_writing_async(self, db):
132132
ni = 5000
133133
def istream_generator(offset=0, ni=ni):
134134
for data_src in xrange(ni):
135-
data = str(data_src + offset)
136-
yield IStream(str_blob_type, len(data), StringIO(data))
135+
print(type(data_src), type(offset))
136+
data = bytes(data_src + offset)
137+
yield IStream(str_blob_type, len(data), BytesIO(data))
137138
# END for each item
138139
# END generator utility
139140

gitdb/test/test_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from gitdb.db import LooseObjectDB
99
from gitdb.util import pool
1010

11-
from io import StringIO
11+
from io import BytesIO
1212

1313
from async import IteratorReader
1414

@@ -33,8 +33,8 @@ def test_base(self):
3333
pass
3434
# END ignore exception if there are no loose objects
3535

36-
data = "my data"
37-
istream = IStream("blob", len(data), StringIO(data))
36+
data = "my data".encode("ascii")
37+
istream = IStream("blob", len(data), BytesIO(data))
3838

3939
# the object does not yet have a sha
4040
assert istream.binsha is None

0 commit comments

Comments
 (0)