diff --git a/git/base.py b/git/base.py index a3971ce4f..ed0d88f06 100644 --- a/git/base.py +++ b/git/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 git.util import ( bin_to_hex, zlib ) -from fun import ( +from git.fun import ( type_id_to_type_map, type_to_type_id_map ) diff --git a/git/config.py b/git/config.py index e2b0356f2..2b60c1025 100644 --- a/git/config.py +++ b/git/config.py @@ -8,9 +8,13 @@ import re import os -import ConfigParser as cp +try: + # Python 2 + import ConfigParser as cp +except ImportError: + # Python 3 + import configparser as cp import inspect -import cStringIO from git.odict import OrderedDict from git.util import LockFile @@ -189,8 +193,8 @@ def __del__(self): try: try: self.write() - except IOError, e: - print "Exception during destruction of GitConfigParser: %s" % str(e) + except IOError as e: + print("Exception during destruction of GitConfigParser: %s" % str(e)) finally: self._lock._release_lock() @@ -314,7 +318,7 @@ def read(self): try: fp = open(file_object) close_fp = True - except IOError, e: + except IOError: continue # END fp handling diff --git a/git/exc.py b/git/exc.py index 8667e4b4b..72b4d50fa 100644 --- a/git/exc.py +++ b/git/exc.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php """ Module containing all exceptions thrown througout the git package, """ -from util import to_hex_sha +from git.util import to_hex_sha class GitPythonError(Exception): diff --git a/git/fun.py b/git/fun.py index 5db36f2ce..729d7170d 100644 --- a/git/fun.py +++ b/git/fun.py @@ -6,11 +6,11 @@ Keeping this code separate from the beginning makes it easier to out-source it into c later, if required""" -from exc import ( +from git.exc import ( BadObjectType ) -from util import zlib +from git.util import zlib decompressobj = zlib.decompressobj import mmap diff --git a/git/objects/__init__.py b/git/objects/__init__.py index 0b40934c0..78abb6fc8 100644 --- a/git/objects/__init__.py +++ b/git/objects/__init__.py @@ -2,20 +2,20 @@ Import all submodules main classes into the package space """ import inspect -from base import * +from git.base import * # Fix import dependency - add IndexObject to the util module, so that it can be # imported by the submodule.base -import submodule.util +import git.submodule.util submodule.util.IndexObject = IndexObject submodule.util.Object = Object from submodule.base import * from submodule.root import * # must come after submodule was made available -from tag import * -from blob import * -from commit import * -from tree import * +from git.tag import * +from git.blob import * +from git.commit import * +from git.tree import * __all__ = [name for name, obj in locals().items() if not (name.startswith('_') or inspect.ismodule(obj))] diff --git a/git/objects/base.py b/git/objects/base.py index 584845f87..223617621 100644 --- a/git/objects/base.py +++ b/git/objects/base.py @@ -4,7 +4,7 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -from util import get_object_type_by_name +from git.objects.util import get_object_type_by_name from git.util import ( hex_to_bin, bin_to_hex, diff --git a/git/odict.py b/git/odict.py index ee8afa92c..bf1e49f59 100644 --- a/git/odict.py +++ b/git/odict.py @@ -611,8 +611,8 @@ def pop(self, key, *args): TypeError: pop expected at most 2 arguments, got 3 """ if len(args) > 1: - raise TypeError, ('pop expected at most 2 arguments, got %s' % - (len(args) + 1)) + raise TypeError('pop expected at most 2 arguments, got %s' % + (len(args) + 1)) if key in self: val = self[key] del self[key] diff --git a/git/util.py b/git/util.py index 59b4a6da7..ada2232cf 100644 --- a/git/util.py +++ b/git/util.py @@ -30,11 +30,14 @@ "BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists', 'RepoAliasMixin', 'LockedFD', 'LazyMixin', 'rmtree') -from cStringIO import StringIO +if sys.version_info < (3, ): + from cStringIO import StringIO +else: + 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: +if sys.version_info < (3, ) and sys.version_info[1] < 5: from StringIO import StringIO # END handle python 2.4 @@ -441,7 +444,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: @@ -508,7 +511,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) @@ -558,7 +561,7 @@ def _obtain_lock_or_raise(self): try: fd = os.open(lock_file, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0) os.close(fd) - except OSError, e: + except OSError as e: raise IOError(str(e)) self._owns_lock = True @@ -580,7 +583,7 @@ def _release_lock(self): # on bloody windows, the file needs write permissions to be removable. # Why ... if os.name == 'nt': - os.chmod(lfp, 0777) + os.chmod(lfp, 0o777) # END handle win32 os.remove(lfp) except OSError: @@ -598,7 +601,7 @@ class BlockingLockFile(LockFile): can never be obtained.""" __slots__ = ("_check_interval", "_max_block_time") - def __init__(self, file_path, check_interval_s=0.3, max_block_time_s=sys.maxint): + def __init__(self, file_path, check_interval_s=0.3, max_block_time_s=sys.maxsize): """Configure the instance :parm check_interval_s: