33# This module is part of GitDB and is released under
44# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
6- try:
7-     from cStringIO import StringIO
8- except ImportError:
9-     try:
10-         from StringIO import StringIO
11-     except ImportError:
12-         from io import StringIO
6+ from io import BytesIO, StringIO
137
148import errno
159import mmap
@@ -106,20 +100,20 @@ def _parse_header_info(self):
106100        self._s = maxb
107101        hdr = self.read(maxb)
108102        hdrend = hdr.find("\0".encode("ascii"))
109-         type , size = hdr[:hdrend].split(" ".encode("ascii"))
103+         typ , size = hdr[:hdrend].split(" ".encode("ascii"))
110104        size = int(size)
111105        self._s = size
112106
113107        # adjust internal state to match actual header length that we ignore
114108        # The buffer will be depleted first on future reads
115109        self._br = 0
116-         hdrend += 1                                 # count terminating \0 
117-         self._buf = StringIO (hdr[hdrend:])
110+         hdrend += 1
111+         self._buf = BytesIO (hdr[hdrend:])
118112        self._buflen = len(hdr) - hdrend
119113
120114        self._phi = True
121115
122-         return type , size
116+         return typ.decode("ascii") , size
123117
124118    #{ Interface
125119
@@ -133,8 +127,8 @@ def new(self, m, close_on_deletion=False):
133127        :param close_on_deletion: if True, the memory map will be closed once we are
134128            being deleted"""
135129        inst = DecompressMemMapReader(m, close_on_deletion, 0)
136-         type , size = inst._parse_header_info()
137-         return type , size, inst
130+         typ , size = inst._parse_header_info()
131+         return typ , size, inst
138132
139133    def data(self):
140134        """:return: random access compatible data we are working on"""
@@ -211,14 +205,14 @@ def read(self, size=-1):
211205        # END clamp size
212206
213207        if size == 0:
214-             return str ()
208+             return bytes ()
215209        # END handle depletion
216210
217211
218212        # deplete the buffer, then just continue using the decompress object
219213        # which has an own buffer. We just need this to transparently parse the
220214        # header from the zlib stream
221-         dat = str ()
215+         dat = bytes ()
222216        if self._buf:
223217            if self._buflen >= size:
224218                # have enough data
@@ -588,7 +582,7 @@ class ZippedStoreShaWriter(Sha1Writer):
588582    __slots__ = ('buf', 'zip')
589583    def __init__(self):
590584        Sha1Writer.__init__(self)
591-         self.buf = StringIO ()
585+         self.buf = BytesIO ()
592586        self.zip = zlib.compressobj(zlib.Z_BEST_SPEED)
593587
594588    def __getattr__(self, attr):
0 commit comments