diff options
| author | Kevin Brown <kevin@kevinbrown.in> | 2014-07-13 16:10:54 -0400 |
|---|---|---|
| committer | Kevin Brown <kevin@kevinbrown.in> | 2014-07-13 17:28:08 -0400 |
| commit | b881134ec816d2a54f6e8deced8db25b4bd5baa7 (patch) | |
| tree | d94089705a227b20e14edfdb71e68ca7232104e1 /gitdb | |
| parent | 85f2b9baf1c6a5738967f8e77d2a65a1a842bde3 (diff) | |
| download | gitdb-b881134ec816d2a54f6e8deced8db25b4bd5baa7.tar.gz | |
Convert strings to bytes for PY3
In Python 3, the default string type is now the Python 2 unicode
strings. The unicode strings cannot be converted to a byte stream,
so we have to convert it before writing to the streams.
Diffstat (limited to 'gitdb')
| -rw-r--r-- | gitdb/test/lib.py | 6 | ||||
| -rw-r--r-- | gitdb/test/test_stream.py | 9 | ||||
| -rw-r--r-- | gitdb/test/test_util.py | 13 | ||||
| -rw-r--r-- | gitdb/util.py | 2 |
4 files changed, 15 insertions, 15 deletions
diff --git a/gitdb/test/lib.py b/gitdb/test/lib.py index 3ac7142..f52cf79 100644 --- a/gitdb/test/lib.py +++ b/gitdb/test/lib.py @@ -54,7 +54,7 @@ def with_rw_directory(func): try: return func(self, path) except Exception: - print >> sys.stderr, "Test %s.%s failed, output is at %r" % (type(self).__name__, func.__name__, path) + sys.stderr.write("Test %s.%s failed, output is at %r\n" % (type(self).__name__, func.__name__, path)) keep = True raise finally: @@ -115,7 +115,7 @@ def copy_files_globbed(source_glob, target_dir, hard_link_ok=False): def make_bytes(size_in_bytes, randomize=False): """:return: string with given size in bytes :param randomize: try to produce a very random stream""" - actual_size = size_in_bytes / 4 + actual_size = size_in_bytes // 4 producer = range(actual_size) if randomize: producer = list(producer) @@ -127,7 +127,7 @@ def make_bytes(size_in_bytes, randomize=False): def make_object(type, data): """:return: bytes resembling an uncompressed object""" odata = "blob %i\0" % len(data) - return odata + data + return odata.encode("ascii") + data def make_memory_file(size_in_bytes, randomize=False): """:return: tuple(size_of_stream, stream) diff --git a/gitdb/test/test_stream.py b/gitdb/test/test_stream.py index 53aa8e2..f6eb371 100644 --- a/gitdb/test/test_stream.py +++ b/gitdb/test/test_stream.py @@ -3,6 +3,7 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Test for object db""" + from gitdb.test.lib import ( TestBase, DummyStream, @@ -16,20 +17,18 @@ from gitdb import * from gitdb.util import ( NULL_HEX_SHA, hex_to_bin - ) +) from gitdb.util import zlib from gitdb.typ import ( str_blob_type - ) +) import time import tempfile import os - - class TestStream(TestBase): """Test stream classes""" @@ -45,7 +44,7 @@ class TestStream(TestBase): assert len(cdata) > ns-1, "Data must be larger than %i, was %i" % (ns, len(cdata)) # read in small steps - ss = len(cdata) / ns + ss = len(cdata) // ns for i in range(ns): data = stream.read(ss) chunk = cdata[i*ss:(i+1)*ss] diff --git a/gitdb/test/test_util.py b/gitdb/test/test_util.py index 4672dd6..ec9a86c 100644 --- a/gitdb/test/test_util.py +++ b/gitdb/test/test_util.py @@ -5,6 +5,7 @@ """Test for object db""" import tempfile import os +import sys from gitdb.test.lib import TestBase from gitdb.util import ( @@ -19,14 +20,14 @@ class TestUtils(TestBase): def test_basics(self): assert to_hex_sha(NULL_HEX_SHA) == NULL_HEX_SHA assert len(to_bin_sha(NULL_HEX_SHA)) == 20 - assert to_hex_sha(to_bin_sha(NULL_HEX_SHA)) == NULL_HEX_SHA + assert to_hex_sha(to_bin_sha(NULL_HEX_SHA)) == NULL_HEX_SHA.encode("ascii") def _cmp_contents(self, file_path, data): # raise if data from file at file_path # does not match data string fp = open(file_path, "rb") try: - assert fp.read() == data + assert fp.read() == data.encode("ascii") finally: fp.close() @@ -35,7 +36,7 @@ class TestUtils(TestBase): orig_data = "hello" new_data = "world" my_file_fp = open(my_file, "wb") - my_file_fp.write(orig_data) + my_file_fp.write(orig_data.encode("ascii")) my_file_fp.close() try: @@ -53,7 +54,7 @@ class TestUtils(TestBase): assert os.path.isfile(lockfilepath) # write data and fail - os.write(wfd, new_data) + os.write(wfd, new_data.encode("ascii")) lfd.rollback() assert lfd._fd is None self._cmp_contents(my_file, orig_data) @@ -66,7 +67,7 @@ class TestUtils(TestBase): # test reading lfd = LockedFD(my_file) rfd = lfd.open(write=False) - assert os.read(rfd, len(orig_data)) == orig_data + assert os.read(rfd, len(orig_data)) == orig_data.encode("ascii") assert os.path.isfile(lockfilepath) # deletion rolls back @@ -83,7 +84,7 @@ class TestUtils(TestBase): # another one fails self.failUnlessRaises(IOError, olfd.open) - wfdstream.write(new_data) + wfdstream.write(new_data.encode("ascii")) lfd.commit() assert not os.path.isfile(lockfilepath) self._cmp_contents(my_file, new_data) diff --git a/gitdb/util.py b/gitdb/util.py index 3dcf3d7..5ea26d5 100644 --- a/gitdb/util.py +++ b/gitdb/util.py @@ -327,7 +327,7 @@ class LockedFD(object): if stream: # need delayed import - from stream import FDStream + from gitdb.stream import FDStream return FDStream(self._fd) else: return self._fd |
