Skip to content

Tweaks for Python 3 compatibility #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Tweaks for Python 3 compatibility
  • Loading branch information
msabramo committed Nov 17, 2014
commit 0d9478947274d9a46262698b9ed5c92b0f101057
4 changes: 2 additions & 2 deletions git/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
14 changes: 9 additions & 5 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -314,7 +318,7 @@ def read(self):
try:
fp = open(file_object)
close_fp = True
except IOError, e:
except IOError:
continue
# END fp handling

Expand Down
2 changes: 1 addition & 1 deletion git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions git/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions git/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
2 changes: 1 addition & 1 deletion git/objects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions git/odict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 10 additions & 7 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down