From 77952d769edb287056c748e189d8d3075aca4fde Mon Sep 17 00:00:00 2001 From: Luthaf Date: Mon, 29 Sep 2014 23:41:39 +0200 Subject: [PATCH] Support for Python3 Translation was made with 2to3 script. Python 2.7 is still working --- doc/source/conf.py | 8 ++++---- gitdb/__init__.py | 6 +++--- gitdb/base.py | 4 ++-- gitdb/db/__init__.py | 12 +++++------ gitdb/db/base.py | 1 + gitdb/db/git.py | 8 ++++---- gitdb/db/loose.py | 10 +++++----- gitdb/db/mem.py | 8 ++++---- gitdb/db/pack.py | 5 +++-- gitdb/db/ref.py | 6 +++--- gitdb/exc.py | 2 +- gitdb/fun.py | 17 ++++++++-------- gitdb/pack.py | 20 +++++++++---------- gitdb/stream.py | 8 ++++---- gitdb/test/__init__.py | 2 +- gitdb/test/db/lib.py | 6 +++--- gitdb/test/db/test_git.py | 2 +- gitdb/test/db/test_loose.py | 2 +- gitdb/test/db/test_mem.py | 2 +- gitdb/test/db/test_pack.py | 2 +- gitdb/test/db/test_ref.py | 2 +- gitdb/test/lib.py | 6 +++--- gitdb/test/performance/test_pack.py | 14 ++++++------- gitdb/test/performance/test_pack_streaming.py | 6 +++--- gitdb/test/performance/test_stream.py | 18 ++++++++--------- gitdb/test/test_base.py | 2 +- gitdb/test/test_example.py | 4 ++-- gitdb/test/test_pack.py | 8 ++++---- gitdb/test/test_stream.py | 2 +- gitdb/test/test_util.py | 2 +- gitdb/util.py | 10 +++++----- 31 files changed, 104 insertions(+), 101 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 723a345..6404573 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -37,8 +37,8 @@ master_doc = 'index' # General information about the project. -project = u'GitDB' -copyright = u'2011, Sebastian Thiel' +project = 'GitDB' +copyright = '2011, Sebastian Thiel' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -171,8 +171,8 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'GitDB.tex', u'GitDB Documentation', - u'Sebastian Thiel', 'manual'), + ('index', 'GitDB.tex', 'GitDB Documentation', + 'Sebastian Thiel', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of diff --git a/gitdb/__init__.py b/gitdb/__init__.py index ff750d1..63ffb8b 100644 --- a/gitdb/__init__.py +++ b/gitdb/__init__.py @@ -32,7 +32,7 @@ def _init_externals(): # default imports -from db import * -from base import * -from stream import * +from .db import * +from .base import * +from .stream import * diff --git a/gitdb/base.py b/gitdb/base.py index bad5f74..0417498 100644 --- a/gitdb/base.py +++ b/gitdb/base.py @@ -3,12 +3,12 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Module with basic data structures - they are designed to be lightweight and fast""" -from util import ( +from .util import ( bin_to_hex, zlib ) -from fun import ( +from .fun import ( type_id_to_type_map, type_to_type_id_map ) diff --git a/gitdb/db/__init__.py b/gitdb/db/__init__.py index e5935b7..f690d68 100644 --- a/gitdb/db/__init__.py +++ b/gitdb/db/__init__.py @@ -3,10 +3,10 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from base import * -from loose import * -from mem import * -from pack import * -from git import * -from ref import * +from .base import * +from .loose import * +from .mem import * +from .pack import * +from .git import * +from .ref import * diff --git a/gitdb/db/base.py b/gitdb/db/base.py index 867e93a..154d6ae 100644 --- a/gitdb/db/base.py +++ b/gitdb/db/base.py @@ -20,6 +20,7 @@ ) from itertools import chain +from functools import reduce __all__ = ('ObjectDBR', 'ObjectDBW', 'FileDBBase', 'CompoundDB', 'CachingDB') diff --git a/gitdb/db/git.py b/gitdb/db/git.py index 1d6ad0f..05b2ddf 100644 --- a/gitdb/db/git.py +++ b/gitdb/db/git.py @@ -2,15 +2,15 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from base import ( +from .base import ( CompoundDB, ObjectDBW, FileDBBase ) -from loose import LooseObjectDB -from pack import PackedDB -from ref import ReferenceDB +from .loose import LooseObjectDB +from .pack import PackedDB +from .ref import ReferenceDB from gitdb.util import LazyMixin from gitdb.exc import ( diff --git a/gitdb/db/loose.py b/gitdb/db/loose.py index dc0ea0e..3f267c6 100644 --- a/gitdb/db/loose.py +++ b/gitdb/db/loose.py @@ -2,7 +2,7 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from base import ( +from .base import ( FileDBBase, ObjectDBR, ObjectDBW @@ -69,9 +69,9 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW): # On windows we need to keep it writable, otherwise it cannot be removed # either - new_objects_mode = 0444 + new_objects_mode = 0o444 if os.name == 'nt': - new_objects_mode = 0644 + new_objects_mode = 0o644 def __init__(self, root_path): @@ -133,7 +133,7 @@ def _map_loose_object(self, sha): db_path = self.db_path(self.object_path(bin_to_hex(sha))) try: return file_contents_ro_filepath(db_path, flags=self._fd_open_flags) - except OSError,e: + except OSError as e: if e.errno != ENOENT: # try again without noatime try: @@ -200,7 +200,7 @@ def store(self, istream): if istream.binsha is not None: # copy as much as possible, the actual uncompressed item size might # be smaller than the compressed version - stream_copy(istream.read, writer.write, sys.maxint, self.stream_chunk_size) + stream_copy(istream.read, writer.write, sys.maxsize, self.stream_chunk_size) else: # write object with header, we have to make a new one write_object(istream.type, istream.size, istream.read, writer.write, diff --git a/gitdb/db/mem.py b/gitdb/db/mem.py index b9b2b89..64b0f88 100644 --- a/gitdb/db/mem.py +++ b/gitdb/db/mem.py @@ -3,8 +3,8 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Contains the MemoryDatabase implementation""" -from loose import LooseObjectDB -from base import ( +from .loose import LooseObjectDB +from .base import ( ObjectDBR, ObjectDBW ) @@ -23,7 +23,7 @@ DecompressMemMapReader, ) -from cStringIO import StringIO +from io import StringIO __all__ = ("MemoryDB", ) @@ -85,7 +85,7 @@ def size(self): return len(self._cache) def sha_iter(self): - return self._cache.iterkeys() + return iter(self._cache.keys()) #{ Interface diff --git a/gitdb/db/pack.py b/gitdb/db/pack.py index 9287319..90870e8 100644 --- a/gitdb/db/pack.py +++ b/gitdb/db/pack.py @@ -3,7 +3,7 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Module containing a database to deal with packs""" -from base import ( +from .base import ( FileDBBase, ObjectDBR, CachingDB @@ -21,6 +21,7 @@ import os import glob +from functools import reduce __all__ = ('PackedDB', ) @@ -104,7 +105,7 @@ def sha_iter(self): for entity in self.entities(): index = entity.index() sha_by_index = index.sha - for index in xrange(index.size()): + for index in range(index.size()): yield sha_by_index(index) # END for each index # END for each entity diff --git a/gitdb/db/ref.py b/gitdb/db/ref.py index 60004a7..9ebf173 100644 --- a/gitdb/db/ref.py +++ b/gitdb/db/ref.py @@ -2,7 +2,7 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from base import ( +from .base import ( CompoundDB, ) @@ -33,7 +33,7 @@ def _update_dbs_from_ref_file(self): dbcls = self.ObjectDBCls if dbcls is None: # late import - from git import GitDB + from .git import GitDB dbcls = GitDB # END get db type @@ -68,7 +68,7 @@ def _update_dbs_from_ref_file(self): db.databases() # END verification self._dbs.append(db) - except Exception, e: + except Exception as e: # ignore invalid paths or issues pass # END for each path to add diff --git a/gitdb/exc.py b/gitdb/exc.py index 7180fb5..125a2c3 100644 --- a/gitdb/exc.py +++ b/gitdb/exc.py @@ -3,7 +3,7 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Module with common exceptions""" -from util import to_hex_sha +from .util import to_hex_sha class ODBError(Exception): """All errors thrown by the object database""" diff --git a/gitdb/fun.py b/gitdb/fun.py index c1e73e8..4942813 100644 --- a/gitdb/fun.py +++ b/gitdb/fun.py @@ -6,17 +6,18 @@ Keeping this code separate from the beginning makes it easier to out-source it into c later, if required""" -from exc import ( +from .exc import ( BadObjectType ) -from util import zlib +from .util import zlib +from functools import reduce decompressobj = zlib.decompressobj import mmap -from itertools import islice, izip +from itertools import islice -from cStringIO import StringIO +from io import StringIO # INVARIANTS OFS_DELTA = 6 @@ -249,7 +250,7 @@ def compress(self): #if first_data_index is not None: nd = StringIO() # new data so = self[first_data_index].to # start offset in target buffer - for x in xrange(first_data_index, i-1): + for x in range(first_data_index, i-1): xdc = self[x] nd.write(xdc.data[:xdc.ts]) # END collect data @@ -296,10 +297,10 @@ def check_integrity(self, target_size=-1): left = islice(self, 0, len(self)-1) right = iter(self) - right.next() + next(right) # this is very pythonic - we might have just use index based access here, # but this could actually be faster - for lft,rgt in izip(left, right): + for lft,rgt in zip(left, right): assert lft.rbound() == rgt.to assert lft.to + lft.ts == rgt.to # END for each pair @@ -380,7 +381,7 @@ def is_loose_object(m): """ :return: True the file contained in memory map m appears to be a loose object. Only the first two bytes are needed""" - b0, b1 = map(ord, m[:2]) + b0, b1 = list(map(ord, m[:2])) word = (b0 << 8) + b1 return b0 == 0x78 and (word % 31) == 0 diff --git a/gitdb/pack.py b/gitdb/pack.py index 48121f0..3df561c 100644 --- a/gitdb/pack.py +++ b/gitdb/pack.py @@ -8,7 +8,7 @@ UnsupportedOperation, ParseError ) -from util import ( +from .util import ( zlib, mman, LazyMixin, @@ -16,7 +16,7 @@ bin_to_hex, ) -from fun import ( +from .fun import ( create_pack_object_header, pack_object_header_info, is_equal_canonical_sha, @@ -36,7 +36,7 @@ pass # END try c module -from base import ( # Amazing ! +from .base import ( # Amazing ! OInfo, OStream, OPackInfo, @@ -45,7 +45,7 @@ ODeltaPackInfo, ODeltaPackStream, ) -from stream import ( +from .stream import ( DecompressMemMapReader, DeltaApplyReader, Sha1Writer, @@ -60,7 +60,7 @@ from binascii import crc32 -from itertools import izip + import tempfile import array import os @@ -200,7 +200,7 @@ def write(self, pack_sha, write): for t in self._objs: tmplist[ord(t[0][0])] += 1 #END prepare fanout - for i in xrange(255): + for i in range(255): v = tmplist[i] sha_write(pack('>L', v)) tmplist[i+1] += v @@ -407,7 +407,7 @@ def offsets(self): a.byteswap() return a else: - return tuple(self.offset(index) for index in xrange(self.size())) + return tuple(self.offset(index) for index in range(self.size())) # END handle version def sha_to_index(self, sha): @@ -673,8 +673,8 @@ def _set_cache_(self, attr): else: iter_offsets = iter(offsets_sorted) iter_offsets_plus_one = iter(offsets_sorted) - iter_offsets_plus_one.next() - consecutive = izip(iter_offsets, iter_offsets_plus_one) + next(iter_offsets_plus_one) + consecutive = zip(iter_offsets, iter_offsets_plus_one) offset_map = dict(consecutive) @@ -694,7 +694,7 @@ def _iter_objects(self, as_stream): """Iterate over all objects in our index and yield their OInfo or OStream instences""" _sha = self._index.sha _object = self._object - for index in xrange(self._index.size()): + for index in range(self._index.size()): yield _object(_sha(index), as_stream, index) # END for each index diff --git a/gitdb/stream.py b/gitdb/stream.py index 6441b1e..fc349a3 100644 --- a/gitdb/stream.py +++ b/gitdb/stream.py @@ -3,12 +3,12 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from cStringIO import StringIO +from io import StringIO import errno import mmap import os -from fun import ( +from .fun import ( msb_size, stream_copy, apply_delta_data, @@ -17,7 +17,7 @@ delta_types ) -from util import ( +from .util import ( allocate_memory, LazyMixin, make_sha, @@ -417,7 +417,7 @@ def _set_cache_brute_(self, attr): # For the actual copying, we use a seek and write pattern of buffer # slices. final_target_size = None - for (dbuf, offset, src_size, target_size), dstream in reversed(zip(buffer_info_list, self._dstreams)): + for (dbuf, offset, src_size, target_size), dstream in reversed(list(zip(buffer_info_list, self._dstreams))): # allocate a buffer to hold all delta data - fill in the data for # fast access. We do this as we know that reading individual bytes # from our stream would be slower than necessary ( although possible ) diff --git a/gitdb/test/__init__.py b/gitdb/test/__init__.py index f805944..f75e4e7 100644 --- a/gitdb/test/__init__.py +++ b/gitdb/test/__init__.py @@ -9,7 +9,7 @@ def _init_pool(): """Assure the pool is actually threaded""" size = 2 - print "Setting ThreadPool to %i" % size + print("Setting ThreadPool to %i" % size) gitdb.util.pool.set_size(size) diff --git a/gitdb/test/db/lib.py b/gitdb/test/db/lib.py index 62614ee..e2712a2 100644 --- a/gitdb/test/db/lib.py +++ b/gitdb/test/db/lib.py @@ -23,7 +23,7 @@ from gitdb.typ import str_blob_type from async import IteratorReader -from cStringIO import StringIO +from io import StringIO from struct import pack @@ -40,7 +40,7 @@ def _assert_object_writing_simple(self, db): # write a bunch of objects and query their streams and info null_objs = db.size() ni = 250 - for i in xrange(ni): + for i in range(ni): data = pack(">L", i) istream = IStream(str_blob_type, len(data), StringIO(data)) new_istream = db.store(istream) @@ -129,7 +129,7 @@ def _assert_object_writing_async(self, db): """Test generic object writing using asynchronous access""" ni = 5000 def istream_generator(offset=0, ni=ni): - for data_src in xrange(ni): + for data_src in range(ni): data = str(data_src + offset) yield IStream(str_blob_type, len(data), StringIO(data)) # END for each item diff --git a/gitdb/test/db/test_git.py b/gitdb/test/db/test_git.py index 1ef577a..1d420d3 100644 --- a/gitdb/test/db/test_git.py +++ b/gitdb/test/db/test_git.py @@ -2,7 +2,7 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from lib import * +from .lib import * from gitdb.exc import BadObject from gitdb.db import GitDB from gitdb.base import OStream, OInfo diff --git a/gitdb/test/db/test_loose.py b/gitdb/test/db/test_loose.py index d7e1d01..8f1fccb 100644 --- a/gitdb/test/db/test_loose.py +++ b/gitdb/test/db/test_loose.py @@ -2,7 +2,7 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from lib import * +from .lib import * from gitdb.db import LooseObjectDB from gitdb.exc import BadObject from gitdb.util import bin_to_hex diff --git a/gitdb/test/db/test_mem.py b/gitdb/test/db/test_mem.py index df428e2..1c2ad66 100644 --- a/gitdb/test/db/test_mem.py +++ b/gitdb/test/db/test_mem.py @@ -2,7 +2,7 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from lib import * +from .lib import * from gitdb.db import ( MemoryDB, LooseObjectDB diff --git a/gitdb/test/db/test_pack.py b/gitdb/test/db/test_pack.py index f4cb5bb..d21f357 100644 --- a/gitdb/test/db/test_pack.py +++ b/gitdb/test/db/test_pack.py @@ -2,7 +2,7 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from lib import * +from .lib import * from gitdb.db import PackedDB from gitdb.test.lib import fixture_path diff --git a/gitdb/test/db/test_ref.py b/gitdb/test/db/test_ref.py index 1637bff..7b342dc 100644 --- a/gitdb/test/db/test_ref.py +++ b/gitdb/test/db/test_ref.py @@ -2,7 +2,7 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from lib import * +from .lib import * from gitdb.db import ReferenceDB from gitdb.util import ( diff --git a/gitdb/test/lib.py b/gitdb/test/lib.py index ac8473a..87c411c 100644 --- a/gitdb/test/lib.py +++ b/gitdb/test/lib.py @@ -16,7 +16,7 @@ import sys import random from array import array -from cStringIO import StringIO +from io import StringIO import glob import unittest @@ -47,7 +47,7 @@ def wrapper(self): try: return func(self, path) except Exception: - print >> sys.stderr, "Test %s.%s failed, output is at %r" % (type(self).__name__, func.__name__, path) + print("Test %s.%s failed, output is at %r" % (type(self).__name__, func.__name__, path), file=sys.stderr) keep = True raise finally: @@ -109,7 +109,7 @@ 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 - producer = xrange(actual_size) + producer = range(actual_size) if randomize: producer = list(producer) random.shuffle(producer) diff --git a/gitdb/test/performance/test_pack.py b/gitdb/test/performance/test_pack.py index 63856e2..b498ee6 100644 --- a/gitdb/test/performance/test_pack.py +++ b/gitdb/test/performance/test_pack.py @@ -27,7 +27,7 @@ def test_pack_random_access(self): sha_list = list(pdb.sha_iter()) elapsed = time() - st ns = len(sha_list) - print >> sys.stderr, "PDB: looked up %i shas by index in %f s ( %f shas/s )" % (ns, elapsed, ns / elapsed) + print("PDB: looked up %i shas by index in %f s ( %f shas/s )" % (ns, elapsed, ns / elapsed), file=sys.stderr) # sha lookup: best-case and worst case access pdb_pack_info = pdb._pack_info @@ -41,7 +41,7 @@ def test_pack_random_access(self): # discard cache del(pdb._entities) pdb.entities() - print >> sys.stderr, "PDB: looked up %i sha in %i packs in %f s ( %f shas/s )" % (ns, len(pdb.entities()), elapsed, ns / elapsed) + print("PDB: looked up %i sha in %i packs in %f s ( %f shas/s )" % (ns, len(pdb.entities()), elapsed, ns / elapsed), file=sys.stderr) # END for each random mode # query info and streams only @@ -51,7 +51,7 @@ def test_pack_random_access(self): for sha in sha_list[:max_items]: pdb_fun(sha) elapsed = time() - st - print >> sys.stderr, "PDB: Obtained %i object %s by sha in %f s ( %f items/s )" % (max_items, pdb_fun.__name__.upper(), elapsed, max_items / elapsed) + print("PDB: Obtained %i object %s by sha in %f s ( %f items/s )" % (max_items, pdb_fun.__name__.upper(), elapsed, max_items / elapsed), file=sys.stderr) # END for each function # retrieve stream and read all @@ -65,20 +65,20 @@ def test_pack_random_access(self): total_size += stream.size elapsed = time() - st total_kib = total_size / 1000 - print >> sys.stderr, "PDB: Obtained %i streams by sha and read all bytes totallying %i KiB ( %f KiB / s ) in %f s ( %f streams/s )" % (max_items, total_kib, total_kib/elapsed , elapsed, max_items / elapsed) + print("PDB: Obtained %i streams by sha and read all bytes totallying %i KiB ( %f KiB / s ) in %f s ( %f streams/s )" % (max_items, total_kib, total_kib/elapsed , elapsed, max_items / elapsed), file=sys.stderr) def test_correctness(self): raise SkipTest("Takes too long, enable it if you change the algorithm and want to be sure you decode packs correctly") pdb = PackedDB(os.path.join(self.gitrepopath, "objects/pack")) # disabled for now as it used to work perfectly, checking big repositories takes a long time - print >> sys.stderr, "Endurance run: verify streaming of objects (crc and sha)" + print("Endurance run: verify streaming of objects (crc and sha)", file=sys.stderr) for crc in range(2): count = 0 st = time() for entity in pdb.entities(): pack_verify = entity.is_valid_stream sha_by_index = entity.index().sha - for index in xrange(entity.index().size()): + for index in range(entity.index().size()): try: assert pack_verify(sha_by_index(index), use_crc=crc) count += 1 @@ -88,6 +88,6 @@ def test_correctness(self): # END for each index # END for each entity elapsed = time() - st - print >> sys.stderr, "PDB: verified %i objects (crc=%i) in %f s ( %f objects/s )" % (count, crc, elapsed, count / elapsed) + print("PDB: verified %i objects (crc=%i) in %f s ( %f objects/s )" % (count, crc, elapsed, count / elapsed), file=sys.stderr) # END for each verify mode diff --git a/gitdb/test/performance/test_pack_streaming.py b/gitdb/test/performance/test_pack_streaming.py index c66e60c..55a22cc 100644 --- a/gitdb/test/performance/test_pack_streaming.py +++ b/gitdb/test/performance/test_pack_streaming.py @@ -47,13 +47,13 @@ def test_pack_writing(self): break #END gather objects for pack-writing elapsed = time() - st - print >> sys.stderr, "PDB Streaming: Got %i streams by sha in in %f s ( %f streams/s )" % (ni, elapsed, ni / elapsed) + print("PDB Streaming: Got %i streams by sha in in %f s ( %f streams/s )" % (ni, elapsed, ni / elapsed), file=sys.stderr) st = time() PackEntity.write_pack((pdb.stream(sha) for sha in pdb.sha_iter()), ostream.write, object_count=ni) elapsed = time() - st total_kb = ostream.bytes_written() / 1000 - print >> sys.stderr, "PDB Streaming: Wrote pack of size %i kb in %f s (%f kb/s)" % (total_kb, elapsed, total_kb/elapsed) + print("PDB Streaming: Wrote pack of size %i kb in %f s (%f kb/s)" % (total_kb, elapsed, total_kb/elapsed), file=sys.stderr) def test_stream_reading(self): @@ -75,5 +75,5 @@ def test_stream_reading(self): count += 1 elapsed = time() - st total_kib = total_size / 1000 - print >> sys.stderr, "PDB Streaming: Got %i streams by sha and read all bytes totallying %i KiB ( %f KiB / s ) in %f s ( %f streams/s )" % (ni, total_kib, total_kib/elapsed , elapsed, ni / elapsed) + print("PDB Streaming: Got %i streams by sha and read all bytes totallying %i KiB ( %f KiB / s ) in %f s ( %f streams/s )" % (ni, total_kib, total_kib/elapsed , elapsed, ni / elapsed), file=sys.stderr) diff --git a/gitdb/test/performance/test_stream.py b/gitdb/test/performance/test_stream.py index 010003d..22e993d 100644 --- a/gitdb/test/performance/test_stream.py +++ b/gitdb/test/performance/test_stream.py @@ -19,7 +19,7 @@ ChannelThreadTask, ) -from cStringIO import StringIO +from io import StringIO from time import time import os import sys @@ -71,11 +71,11 @@ def test_large_data_streaming(self, path): # serial mode for randomize in range(2): desc = (randomize and 'random ') or '' - print >> sys.stderr, "Creating %s data ..." % desc + print("Creating %s data ..." % desc, file=sys.stderr) st = time() size, stream = make_memory_file(self.large_data_size_bytes, randomize) elapsed = time() - st - print >> sys.stderr, "Done (in %f s)" % elapsed + print("Done (in %f s)" % elapsed, file=sys.stderr) string_ios.append(stream) # writing - due to the compression it will seem faster than it is @@ -88,7 +88,7 @@ def test_large_data_streaming(self, path): size_kib = size / 1000 - print >> sys.stderr, "Added %i KiB (filesize = %i KiB) of %s data to loose odb in %f s ( %f Write KiB / s)" % (size_kib, fsize_kib, desc, elapsed_add, size_kib / elapsed_add) + print("Added %i KiB (filesize = %i KiB) of %s data to loose odb in %f s ( %f Write KiB / s)" % (size_kib, fsize_kib, desc, elapsed_add, size_kib / elapsed_add), file=sys.stderr) # reading all at once st = time() @@ -98,7 +98,7 @@ def test_large_data_streaming(self, path): stream.seek(0) assert shadata == stream.getvalue() - print >> sys.stderr, "Read %i KiB of %s data at once from loose odb in %f s ( %f Read KiB / s)" % (size_kib, desc, elapsed_readall, size_kib / elapsed_readall) + print("Read %i KiB of %s data at once from loose odb in %f s ( %f Read KiB / s)" % (size_kib, desc, elapsed_readall, size_kib / elapsed_readall), file=sys.stderr) # reading in chunks of 1 MiB @@ -118,7 +118,7 @@ def test_large_data_streaming(self, path): assert ''.join(chunks) == stream.getvalue() cs_kib = cs / 1000 - print >> sys.stderr, "Read %i KiB of %s data in %i KiB chunks from loose odb in %f s ( %f Read KiB / s)" % (size_kib, desc, cs_kib, elapsed_readchunks, size_kib / elapsed_readchunks) + print("Read %i KiB of %s data in %i KiB chunks from loose odb in %f s ( %f Read KiB / s)" % (size_kib, desc, cs_kib, elapsed_readchunks, size_kib / elapsed_readchunks), file=sys.stderr) # del db file so we keep something to do os.remove(db_file) @@ -152,7 +152,7 @@ def istream_iter(): assert len(istreams) == nsios elapsed = time() - st - print >> sys.stderr, "Threads(%i): Compressed %i KiB of data in loose odb in %f s ( %f Write KiB / s)" % (pool.size(), total_kib, elapsed, total_kib / elapsed) + print("Threads(%i): Compressed %i KiB of data in loose odb in %f s ( %f Write KiB / s)" % (pool.size(), total_kib, elapsed, total_kib / elapsed), file=sys.stderr) # decompress multiple at once, by reading them # chunk size is not important as the stream will not really be decompressed @@ -169,7 +169,7 @@ def istream_iter(): assert len(output_reader.read(nsios)) == nsios elapsed = time() - st - print >> sys.stderr, "Threads(%i): Decompressed %i KiB of data in loose odb in %f s ( %f Read KiB / s)" % (pool.size(), total_kib, elapsed, total_kib / elapsed) + print("Threads(%i): Decompressed %i KiB of data in loose odb in %f s ( %f Read KiB / s)" % (pool.size(), total_kib, elapsed, total_kib / elapsed), file=sys.stderr) # store the files, and read them back. For the reading, we use a task # as well which is chunked into one item per task. Reading all will @@ -192,4 +192,4 @@ def istream_iter(): assert len(output_reader.read(nsios)) == nsios elapsed = time() - st - print >> sys.stderr, "Threads(%i): Compressed and decompressed and read %i KiB of data in loose odb in %f s ( %f Combined KiB / s)" % (pool.size(), total_kib, elapsed, total_kib / elapsed) + print("Threads(%i): Compressed and decompressed and read %i KiB of data in loose odb in %f s ( %f Combined KiB / s)" % (pool.size(), total_kib, elapsed, total_kib / elapsed), file=sys.stderr) diff --git a/gitdb/test/test_base.py b/gitdb/test/test_base.py index d4ce428..e82aba7 100644 --- a/gitdb/test/test_base.py +++ b/gitdb/test/test_base.py @@ -3,7 +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 lib import ( +from .lib import ( TestBase, DummyStream, DeriveTest, diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py index 611ae42..1a0c3b0 100644 --- a/gitdb/test/test_example.py +++ b/gitdb/test/test_example.py @@ -3,12 +3,12 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Module with examples from the tutorial section of the docs""" -from lib import * +from .lib import * from gitdb import IStream from gitdb.db import LooseObjectDB from gitdb.util import pool -from cStringIO import StringIO +from io import StringIO from async import IteratorReader diff --git a/gitdb/test/test_pack.py b/gitdb/test/test_pack.py index 779155a..4148169 100644 --- a/gitdb/test/test_pack.py +++ b/gitdb/test/test_pack.py @@ -3,7 +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 everything about packs reading and writing""" -from lib import ( +from .lib import ( TestBase, with_rw_directory, with_packs_rw, @@ -25,7 +25,7 @@ from gitdb.fun import delta_types from gitdb.exc import UnsupportedOperation from gitdb.util import to_bin_sha -from itertools import izip, chain +from itertools import chain from nose import SkipTest import os @@ -57,7 +57,7 @@ def _assert_index_file(self, index, version, size): assert len(index.offsets()) == size # get all data of all objects - for oidx in xrange(index.size()): + for oidx in range(index.size()): sha = index.sha(oidx) assert oidx == index.sha_to_index(sha) @@ -152,7 +152,7 @@ def test_pack_entity(self, rw_dir): pack_objs.extend(entity.stream_iter()) count = 0 - for info, stream in izip(entity.info_iter(), entity.stream_iter()): + for info, stream in zip(entity.info_iter(), entity.stream_iter()): count += 1 assert info.binsha == stream.binsha assert len(info.binsha) == 20 diff --git a/gitdb/test/test_stream.py b/gitdb/test/test_stream.py index 6dc2746..3bf2a74 100644 --- a/gitdb/test/test_stream.py +++ b/gitdb/test/test_stream.py @@ -3,7 +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 lib import ( +from .lib import ( TestBase, DummyStream, Sha1Writer, diff --git a/gitdb/test/test_util.py b/gitdb/test/test_util.py index 35f9f44..7a959a5 100644 --- a/gitdb/test/test_util.py +++ b/gitdb/test/test_util.py @@ -6,7 +6,7 @@ import tempfile import os -from lib import TestBase +from .lib import TestBase from gitdb.util import ( to_hex_sha, to_bin_sha, diff --git a/gitdb/util.py b/gitdb/util.py index 1662b66..866f97a 100644 --- a/gitdb/util.py +++ b/gitdb/util.py @@ -8,12 +8,12 @@ import sys import errno -from cStringIO import StringIO +from io import StringIO # in py 2.4, StringIO is only StringI, without write support. # Hence we must use the python implementation for this if sys.version_info[1] < 5: - from StringIO import StringIO + from io import StringIO # END handle python 2.4 try: @@ -304,7 +304,7 @@ def open(self, write=False, stream=False): binary = getattr(os, 'O_BINARY', 0) lockmode = os.O_WRONLY | os.O_CREAT | os.O_EXCL | binary try: - fd = os.open(self._lockfilepath(), lockmode, 0600) + fd = os.open(self._lockfilepath(), lockmode, 0o600) if not write: os.close(fd) else: @@ -328,7 +328,7 @@ def open(self, write=False, stream=False): if stream: # need delayed import - from stream import FDStream + from .stream import FDStream return FDStream(self._fd) else: return self._fd @@ -373,7 +373,7 @@ def _end_writing(self, successful=True): # assure others can at least read the file - the tmpfile left it at rw-- # We may also write that file, on windows that boils down to a remove- # protection as well - chmod(self._filepath, 0644) + chmod(self._filepath, 0o644) else: # just delete the file so far, we failed os.remove(lockfile)