summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-04 19:50:28 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-04 19:50:28 +0100
commitae2ff0f9d704dc776a1934f72a339da206a9fff4 (patch)
tree53b7cb30f47c60bdf38d824f1c729191d1f1f2d9
parentf6aa8d116eb33293c0a9d6d600eb7c32832758b9 (diff)
downloadgitpython-ae2ff0f9d704dc776a1934f72a339da206a9fff4.tar.gz
Dum brute force conversion of all types.
However, StringIO really is ByteIO in most cases, and py2.7 should run but doesn't. This should be made work first.
-rw-r--r--git/cmd.py6
-rw-r--r--git/compat.py11
-rw-r--r--git/config.py12
-rw-r--r--git/index/base.py14
-rw-r--r--git/objects/commit.py7
-rw-r--r--git/objects/fun.py6
-rw-r--r--git/objects/submodule/base.py3
-rw-r--r--git/objects/tree.py3
-rw-r--r--git/refs/log.py6
-rw-r--r--git/refs/symbolic.py3
-rw-r--r--git/repo/base.py9
-rw-r--r--git/repo/fun.py1
-rw-r--r--git/test/lib/helper.py8
-rw-r--r--git/test/performance/test_commit.py9
-rw-r--r--git/test/test_commit.py12
-rw-r--r--git/test/test_config.py3
-rw-r--r--git/test/test_index.py3
-rw-r--r--git/test/test_remote.py5
-rw-r--r--git/test/test_repo.py3
-rw-r--r--git/test/test_submodule.py3
-rw-r--r--git/test/test_util.py3
21 files changed, 87 insertions, 43 deletions
diff --git a/git/cmd.py b/git/cmd.py
index b9e4bc09..aa5e3a25 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -19,7 +19,7 @@ from .util import (
stream_copy
)
from .exc import GitCommandError
-
+from git.compat import text_type
execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
'with_exceptions', 'as_process',
@@ -435,7 +435,7 @@ class Git(LazyMixin):
@classmethod
def __unpack_args(cls, arg_list):
if not isinstance(arg_list, (list, tuple)):
- if isinstance(arg_list, unicode):
+ if isinstance(arg_list, text_type):
return [arg_list.encode('utf-8')]
return [str(arg_list)]
@@ -443,7 +443,7 @@ class Git(LazyMixin):
for arg in arg_list:
if isinstance(arg_list, (list, tuple)):
outlist.extend(cls.__unpack_args(arg))
- elif isinstance(arg_list, unicode):
+ elif isinstance(arg_list, text_type):
outlist.append(arg_list.encode('utf-8'))
# END recursion
else:
diff --git a/git/compat.py b/git/compat.py
index 52fc599c..611005a1 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -5,15 +5,22 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
"""utilities to help provide compatibility with python 3"""
+# flake8: noqa
-from gitdb.utils.compat import ( # noqa
+from gitdb.utils.compat import (
PY3,
xrange,
MAXSIZE,
izip,
)
-from gitdb.utils.encoding import ( # noqa
+from gitdb.utils.encoding import (
string_types,
text_type
)
+
+if PY3:
+ import io
+ FileType = io.IOBase
+else:
+ FileType = file
diff --git a/git/config.py b/git/config.py
index 685dbed8..34fe290b 100644
--- a/git/config.py
+++ b/git/config.py
@@ -17,6 +17,10 @@ import logging
from git.odict import OrderedDict
from git.util import LockFile
+from git.compat import (
+ string_types,
+ FileType
+)
__all__ = ('GitConfigParser', 'SectionConstraint')
@@ -175,7 +179,7 @@ class GitConfigParser(cp.RawConfigParser, object):
"Write-ConfigParsers can operate on a single file only, multiple files have been passed")
# END single file check
- if not isinstance(file_or_files, basestring):
+ if not isinstance(file_or_files, string_types):
file_or_files = file_or_files.name
# END get filename from handle/stream
# initialize lock base - we want to write
@@ -333,7 +337,7 @@ class GitConfigParser(cp.RawConfigParser, object):
close_fp = False
# we have a physical file on disk, so get a lock
- if isinstance(fp, (basestring, file)):
+ if isinstance(fp, string_types + (FileType, )):
self._lock._obtain_lock()
# END get lock for physical files
@@ -391,7 +395,7 @@ class GitConfigParser(cp.RawConfigParser, object):
return default
raise
- types = (long, float)
+ types = (int, float)
for numtype in types:
try:
val = numtype(valuestr)
@@ -412,7 +416,7 @@ class GitConfigParser(cp.RawConfigParser, object):
if vl == 'true':
return True
- if not isinstance(valuestr, basestring):
+ if not isinstance(valuestr, string_types):
raise TypeError("Invalid value type: only int, long, float and str are allowed", valuestr)
return valuestr
diff --git a/git/index/base.py b/git/index/base.py
index 91dcea42..25ac121c 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -39,7 +39,11 @@ from git.objects import (
)
from git.objects.util import Serializable
-from git.compat import izip
+from git.compat import (
+ izip,
+ xrange,
+ string_types,
+)
from git.util import (
LazyMixin,
@@ -541,7 +545,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
entries = list()
for item in items:
- if isinstance(item, basestring):
+ if isinstance(item, string_types):
paths.append(self._to_relative_path(item))
elif isinstance(item, (Blob, Submodule)):
entries.append(BaseIndexEntry.from_blob(item))
@@ -752,7 +756,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
for item in items:
if isinstance(item, (BaseIndexEntry, (Blob, Submodule))):
paths.append(self._to_relative_path(item.path))
- elif isinstance(item, basestring):
+ elif isinstance(item, string_types):
paths.append(self._to_relative_path(item))
else:
raise TypeError("Invalid item type: %r" % item)
@@ -1004,7 +1008,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
handle_stderr(proc, rval_iter)
return rval_iter
else:
- if isinstance(paths, basestring):
+ if isinstance(paths, string_types):
paths = [paths]
# make sure we have our entries loaded before we start checkout_index
@@ -1140,7 +1144,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# index against anything but None is a reverse diff with the respective
# item. Handle existing -R flags properly. Transform strings to the object
# so that we can call diff on it
- if isinstance(other, basestring):
+ if isinstance(other, string_types):
other = self.repo.rev_parse(other)
# END object conversion
diff --git a/git/objects/commit.py b/git/objects/commit.py
index 5b6b9a33..c9d7ddc8 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -23,6 +23,7 @@ from .util import (
altz_to_utctz_str,
parse_actor_and_date
)
+from git.compat import text_type
from time import (
time,
@@ -378,7 +379,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
a = self.author
aname = a.name
- if isinstance(aname, unicode):
+ if isinstance(aname, text_type):
aname = aname.encode(self.encoding)
# END handle unicode in name
@@ -390,7 +391,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# encode committer
aname = c.name
- if isinstance(aname, unicode):
+ if isinstance(aname, text_type):
aname = aname.encode(self.encoding)
# END handle unicode in name
write(fmt % ("committer", aname, c.email,
@@ -408,7 +409,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
write("\n")
# write plain bytes, be sure its encoded according to our encoding
- if isinstance(self.message, unicode):
+ if isinstance(self.message, text_type):
write(self.message.encode(self.encoding))
else:
write(self.message)
diff --git a/git/objects/fun.py b/git/objects/fun.py
index 416a52e6..db2ec7c2 100644
--- a/git/objects/fun.py
+++ b/git/objects/fun.py
@@ -1,5 +1,9 @@
"""Module with functions which are supposed to be as fast as possible"""
from stat import S_ISDIR
+from git.compat import (
+ xrange,
+ text_type
+)
__all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive',
'traverse_tree_recursive')
@@ -28,7 +32,7 @@ def tree_to_stream(entries, write):
# hence we must convert to an utf8 string for it to work properly.
# According to my tests, this is exactly what git does, that is it just
# takes the input literally, which appears to be utf8 on linux.
- if isinstance(name, unicode):
+ if isinstance(name, text_type):
name = name.encode("utf8")
write("%s %s\0%s" % (mode_str, name, binsha))
# END for each item
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 5ccebd4c..69bf748a 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -22,6 +22,7 @@ from git.exc import (
InvalidGitRepositoryError,
NoSuchPathError
)
+from git.compat import string_types
import stat
import git
@@ -93,7 +94,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
if url is not None:
self._url = url
if branch_path is not None:
- assert isinstance(branch_path, basestring)
+ assert isinstance(branch_path, string_types)
self._branch_path = branch_path
if name is not None:
self._name = name
diff --git a/git/objects/tree.py b/git/objects/tree.py
index a216322b..6776a15e 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -11,6 +11,7 @@ from . import util
from .base import IndexObject
from .blob import Blob
from .submodule.base import Submodule
+from git.compat import string_types
from .fun import (
tree_entries_from_data,
@@ -232,7 +233,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
info = self._cache[item]
return self._map_id_to_type[info[1] >> 12](self.repo, info[0], info[1], join_path(self.path, info[2]))
- if isinstance(item, basestring):
+ if isinstance(item, string_types):
# compatability
return self.__div__(item)
# END index is basestring
diff --git a/git/refs/log.py b/git/refs/log.py
index e3f3363c..94e07104 100644
--- a/git/refs/log.py
+++ b/git/refs/log.py
@@ -17,6 +17,10 @@ from git.objects.util import (
Serializable,
altz_to_utctz_str,
)
+from git.compat import (
+ xrange,
+ string_types
+)
import time
import re
@@ -170,7 +174,7 @@ class RefLog(list, Serializable):
:param stream: file-like object containing the revlog in its native format
or basestring instance pointing to a file to read"""
new_entry = RefLogEntry.from_line
- if isinstance(stream, basestring):
+ if isinstance(stream, string_types):
stream = file_contents_ro_filepath(stream)
# END handle stream type
while True:
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index 0cd04e07..624b1a09 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -19,6 +19,7 @@ from gitdb.util import (
hex_to_bin,
LockedFD
)
+from git.compat import string_types
from .log import RefLog
@@ -274,7 +275,7 @@ class SymbolicReference(object):
elif isinstance(ref, Object):
obj = ref
write_value = ref.hexsha
- elif isinstance(ref, basestring):
+ elif isinstance(ref, string_types):
try:
obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags
write_value = obj.hexsha
diff --git a/git/repo/base.py b/git/repo/base.py
index e5ae7623..f92a85ce 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -47,6 +47,7 @@ from .fun import (
read_gitfile,
touch,
)
+from git.compat import text_type
import os
import sys
@@ -176,11 +177,11 @@ class Repo(object):
# Description property
def _get_description(self):
filename = join(self.git_dir, 'description')
- return file(filename).read().rstrip()
+ return open(filename).read().rstrip()
def _set_description(self, descr):
filename = join(self.git_dir, 'description')
- file(filename, 'w').write(descr + '\n')
+ open(filename, 'w').write(descr + '\n')
description = property(_get_description, _set_description,
doc="the project's description")
@@ -389,7 +390,7 @@ class Repo(object):
if rev is None:
return self.head.commit
else:
- return self.rev_parse(unicode(rev) + "^0")
+ return self.rev_parse(text_type(rev) + "^0")
def iter_trees(self, *args, **kwargs):
""":return: Iterator yielding Tree objects
@@ -412,7 +413,7 @@ class Repo(object):
if rev is None:
return self.head.commit.tree
else:
- return self.rev_parse(unicode(rev) + "^{tree}")
+ return self.rev_parse(text_type(rev) + "^{tree}")
def iter_commits(self, rev=None, paths='', **kwargs):
"""A list of Commit objects representing the history of a given ref/commit
diff --git a/git/repo/fun.py b/git/repo/fun.py
index d08e5fed..64b9b4a9 100644
--- a/git/repo/fun.py
+++ b/git/repo/fun.py
@@ -13,6 +13,7 @@ from gitdb.util import (
hex_to_bin,
bin_to_hex
)
+from git.compat import xrange
__all__ = ('rev_parse', 'is_git_dir', 'touch', 'read_gitfile', 'find_git_dir', 'name_to_object',
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 0ea4fc7e..43079dbe 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -6,13 +6,15 @@
from __future__ import print_function
import os
import sys
-from git import Repo, Remote, GitCommandError, Git
from unittest import TestCase
import time
import tempfile
import shutil
import io
+from git import Repo, Remote, GitCommandError, Git
+from git.compat import string_types
+
GIT_REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
__all__ = (
@@ -89,7 +91,7 @@ def with_rw_repo(working_tree_ref, bare=False):
To make working with relative paths easier, the cwd will be set to the working
dir of the repository.
"""
- assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout"
+ assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
def repo_creator(self):
@@ -152,7 +154,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
See working dir info in with_rw_repo
:note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
"""
- assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout"
+ assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
def remote_repo_creator(self):
diff --git a/git/test/performance/test_commit.py b/git/test/performance/test_commit.py
index fed6ef18..a55b6d43 100644
--- a/git/test/performance/test_commit.py
+++ b/git/test/performance/test_commit.py
@@ -4,13 +4,16 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
from __future__ import print_function
+from io import StringIO
+from time import time
+import sys
+
from .lib import TestBigRepoRW
from git import Commit
from gitdb import IStream
+from git.compat import xrange
from git.test.test_commit import assert_commit_serialization
-from io import StringIO
-from time import time
-import sys
+
class TestPerformance(TestBigRepoRW):
diff --git a/git/test/test_commit.py b/git/test/test_commit.py
index 84f81f21..adf1cb10 100644
--- a/git/test/test_commit.py
+++ b/git/test/test_commit.py
@@ -20,6 +20,10 @@ from git import (
)
from gitdb import IStream
from gitdb.util import hex_to_bin
+from git.compat import (
+ string_types,
+ text_type
+)
from io import StringIO
import time
@@ -129,7 +133,7 @@ class TestCommit(TestBase):
assert len(name) == 9
special = Actor._from_string(u"%s <something@this.com>" % name)
assert special.name == name
- assert isinstance(special.name, unicode)
+ assert isinstance(special.name, text_type)
def test_traversal(self):
start = self.rorepo.commit("a4d06724202afccd2b5c54f81bcf2bf26dea7fff")
@@ -250,7 +254,7 @@ class TestCommit(TestBase):
def test_base(self):
name_rev = self.rorepo.head.commit.name_rev
- assert isinstance(name_rev, basestring)
+ assert isinstance(name_rev, string_types)
@with_rw_repo('HEAD', bare=True)
def test_serialization(self, rwrepo):
@@ -263,8 +267,8 @@ class TestCommit(TestBase):
# create a commit with unicode in the message, and the author's name
# Verify its serialization and deserialization
cmt = self.rorepo.commit('0.1.6')
- assert isinstance(cmt.message, unicode) # it automatically decodes it as such
- assert isinstance(cmt.author.name, unicode) # same here
+ assert isinstance(cmt.message, text_type) # it automatically decodes it as such
+ assert isinstance(cmt.author.name, text_type) # same here
cmt.message = "üäêèß".decode("utf-8")
assert len(cmt.message) == 5
diff --git a/git/test/test_config.py b/git/test/test_config.py
index d1c8e72f..ef0707e9 100644
--- a/git/test/test_config.py
+++ b/git/test/test_config.py
@@ -11,6 +11,7 @@ from git.test.lib import (
from git import (
GitConfigParser
)
+from git.compat import string_types
import StringIO
from copy import copy
from ConfigParser import NoSectionError
@@ -85,7 +86,7 @@ class TestBase(TestCase):
num_options += 1
val = r_config.get(section, option)
val_typed = r_config.get_value(section, option)
- assert isinstance(val_typed, (bool, long, float, basestring))
+ assert isinstance(val_typed, (bool, int, float, ) + string_types)
assert val
assert "\n" not in option
assert "\n" not in val
diff --git a/git/test/test_index.py b/git/test/test_index.py
index 74bdac53..70d70a05 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -20,6 +20,7 @@ from git import (
GitCommandError,
CheckoutError,
)
+from git.compat import string_types
from gitdb.util import hex_to_bin
import os
import sys
@@ -343,7 +344,7 @@ class TestIndex(TestBase):
index.checkout(test_file)
except CheckoutError as e:
assert len(e.failed_files) == 1 and e.failed_files[0] == os.path.basename(test_file)
- assert (len(e.failed_files) == len(e.failed_reasons)) and isinstance(e.failed_reasons[0], basestring)
+ assert (len(e.failed_files) == len(e.failed_reasons)) and isinstance(e.failed_reasons[0], string_types)
assert len(e.valid_files) == 0
assert open(test_file).read().endswith(append_data)
else:
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index a8d5179a..75dc19c5 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -23,6 +23,7 @@ from git import (
GitCommandError
)
from git.util import IterableList
+from git.compat import string_types
import tempfile
import shutil
import os
@@ -97,7 +98,7 @@ class TestRemote(TestBase):
# self._print_fetchhead(remote.repo)
assert len(results) > 0 and isinstance(results[0], FetchInfo)
for info in results:
- assert isinstance(info.note, basestring)
+ assert isinstance(info.note, string_types)
if isinstance(info.ref, Reference):
assert info.flags != 0
# END reference type flags handling
@@ -113,7 +114,7 @@ class TestRemote(TestBase):
assert len(results) > 0 and isinstance(results[0], PushInfo)
for info in results:
assert info.flags
- assert isinstance(info.summary, basestring)
+ assert isinstance(info.summary, string_types)
if info.old_commit is not None:
assert isinstance(info.old_commit, Commit)
if info.flags & info.ERROR:
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 41c1c8f1..f33fe467 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -30,6 +30,7 @@ from git import (
from git.util import join_path_native
from git.exc import BadObject
from gitdb.util import bin_to_hex
+from git.compat import string_types
import os
import sys
@@ -286,7 +287,7 @@ class TestRepo(TestBase):
# test the 'lines per commit' entries
tlist = b[0][1]
assert_true(tlist)
- assert_true(isinstance(tlist[0], basestring))
+ assert_true(isinstance(tlist[0], string_types))
assert_true(len(tlist) < sum(len(t) for t in tlist)) # test for single-char bug
def test_blame_real(self):
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index ec3459e4..8c1580fe 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -9,6 +9,7 @@ from git.exc import InvalidGitRepositoryError
from git.objects.submodule.base import Submodule
from git.objects.submodule.root import RootModule, RootUpdateProgress
from git.util import to_native_path_linux, join_path_native
+from git.compat import string_types
import shutil
import git
import sys
@@ -76,7 +77,7 @@ class TestSubmodule(TestBase):
self.failUnlessRaises(InvalidGitRepositoryError, getattr, sm, 'branch')
# branch_path works, as its just a string
- assert isinstance(sm.branch_path, basestring)
+ assert isinstance(sm.branch_path, string_types)
# some commits earlier we still have a submodule, but its at a different commit
smold = Submodule.iter_items(rwrepo, self.k_subm_changed).next()
diff --git a/git/test/test_util.py b/git/test/test_util.py
index 888eb4ee..c6ca6920 100644
--- a/git/test/test_util.py
+++ b/git/test/test_util.py
@@ -24,6 +24,7 @@ from git.objects.util import (
parse_date,
)
from git.cmd import dashify
+from git.compat import string_types
import time
@@ -104,7 +105,7 @@ class TestUtils(TestBase):
# now that we are here, test our conversion functions as well
utctz = altz_to_utctz_str(offset)
- assert isinstance(utctz, basestring)
+ assert isinstance(utctz, string_types)
assert utctz_to_altz(verify_utctz(utctz)) == offset
# END assert rval utility