Skip to content

Commit ae2ff0f

Browse files
committed
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.
1 parent f6aa8d1 commit ae2ff0f

21 files changed

+87
-43
lines changed

Diff for: git/cmd.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
stream_copy
2020
)
2121
from .exc import GitCommandError
22-
22+
from git.compat import text_type
2323

2424
execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
2525
'with_exceptions', 'as_process',
@@ -435,15 +435,15 @@ def transform_kwargs(self, split_single_char_options=False, **kwargs):
435435
@classmethod
436436
def __unpack_args(cls, arg_list):
437437
if not isinstance(arg_list, (list, tuple)):
438-
if isinstance(arg_list, unicode):
438+
if isinstance(arg_list, text_type):
439439
return [arg_list.encode('utf-8')]
440440
return [str(arg_list)]
441441

442442
outlist = list()
443443
for arg in arg_list:
444444
if isinstance(arg_list, (list, tuple)):
445445
outlist.extend(cls.__unpack_args(arg))
446-
elif isinstance(arg_list, unicode):
446+
elif isinstance(arg_list, text_type):
447447
outlist.append(arg_list.encode('utf-8'))
448448
# END recursion
449449
else:

Diff for: git/compat.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77
"""utilities to help provide compatibility with python 3"""
8+
# flake8: noqa
89

9-
from gitdb.utils.compat import ( # noqa
10+
from gitdb.utils.compat import (
1011
PY3,
1112
xrange,
1213
MAXSIZE,
1314
izip,
1415
)
1516

16-
from gitdb.utils.encoding import ( # noqa
17+
from gitdb.utils.encoding import (
1718
string_types,
1819
text_type
1920
)
21+
22+
if PY3:
23+
import io
24+
FileType = io.IOBase
25+
else:
26+
FileType = file

Diff for: git/config.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
from git.odict import OrderedDict
1919
from git.util import LockFile
20+
from git.compat import (
21+
string_types,
22+
FileType
23+
)
2024

2125
__all__ = ('GitConfigParser', 'SectionConstraint')
2226

@@ -175,7 +179,7 @@ def __init__(self, file_or_files, read_only=True):
175179
"Write-ConfigParsers can operate on a single file only, multiple files have been passed")
176180
# END single file check
177181

178-
if not isinstance(file_or_files, basestring):
182+
if not isinstance(file_or_files, string_types):
179183
file_or_files = file_or_files.name
180184
# END get filename from handle/stream
181185
# initialize lock base - we want to write
@@ -333,7 +337,7 @@ def write(self):
333337
close_fp = False
334338

335339
# we have a physical file on disk, so get a lock
336-
if isinstance(fp, (basestring, file)):
340+
if isinstance(fp, string_types + (FileType, )):
337341
self._lock._obtain_lock()
338342
# END get lock for physical files
339343

@@ -391,7 +395,7 @@ def get_value(self, section, option, default=None):
391395
return default
392396
raise
393397

394-
types = (long, float)
398+
types = (int, float)
395399
for numtype in types:
396400
try:
397401
val = numtype(valuestr)
@@ -412,7 +416,7 @@ def get_value(self, section, option, default=None):
412416
if vl == 'true':
413417
return True
414418

415-
if not isinstance(valuestr, basestring):
419+
if not isinstance(valuestr, string_types):
416420
raise TypeError("Invalid value type: only int, long, float and str are allowed", valuestr)
417421

418422
return valuestr

Diff for: git/index/base.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
)
4040

4141
from git.objects.util import Serializable
42-
from git.compat import izip
42+
from git.compat import (
43+
izip,
44+
xrange,
45+
string_types,
46+
)
4347

4448
from git.util import (
4549
LazyMixin,
@@ -541,7 +545,7 @@ def _preprocess_add_items(self, items):
541545
entries = list()
542546

543547
for item in items:
544-
if isinstance(item, basestring):
548+
if isinstance(item, string_types):
545549
paths.append(self._to_relative_path(item))
546550
elif isinstance(item, (Blob, Submodule)):
547551
entries.append(BaseIndexEntry.from_blob(item))
@@ -752,7 +756,7 @@ def _items_to_rela_paths(self, items):
752756
for item in items:
753757
if isinstance(item, (BaseIndexEntry, (Blob, Submodule))):
754758
paths.append(self._to_relative_path(item.path))
755-
elif isinstance(item, basestring):
759+
elif isinstance(item, string_types):
756760
paths.append(self._to_relative_path(item))
757761
else:
758762
raise TypeError("Invalid item type: %r" % item)
@@ -1004,7 +1008,7 @@ def handle_stderr(proc, iter_checked_out_files):
10041008
handle_stderr(proc, rval_iter)
10051009
return rval_iter
10061010
else:
1007-
if isinstance(paths, basestring):
1011+
if isinstance(paths, string_types):
10081012
paths = [paths]
10091013

10101014
# make sure we have our entries loaded before we start checkout_index
@@ -1140,7 +1144,7 @@ def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwar
11401144
# index against anything but None is a reverse diff with the respective
11411145
# item. Handle existing -R flags properly. Transform strings to the object
11421146
# so that we can call diff on it
1143-
if isinstance(other, basestring):
1147+
if isinstance(other, string_types):
11441148
other = self.repo.rev_parse(other)
11451149
# END object conversion
11461150

Diff for: git/objects/commit.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
altz_to_utctz_str,
2424
parse_actor_and_date
2525
)
26+
from git.compat import text_type
2627

2728
from time import (
2829
time,
@@ -378,7 +379,7 @@ def _serialize(self, stream):
378379

379380
a = self.author
380381
aname = a.name
381-
if isinstance(aname, unicode):
382+
if isinstance(aname, text_type):
382383
aname = aname.encode(self.encoding)
383384
# END handle unicode in name
384385

@@ -390,7 +391,7 @@ def _serialize(self, stream):
390391

391392
# encode committer
392393
aname = c.name
393-
if isinstance(aname, unicode):
394+
if isinstance(aname, text_type):
394395
aname = aname.encode(self.encoding)
395396
# END handle unicode in name
396397
write(fmt % ("committer", aname, c.email,
@@ -408,7 +409,7 @@ def _serialize(self, stream):
408409
write("\n")
409410

410411
# write plain bytes, be sure its encoded according to our encoding
411-
if isinstance(self.message, unicode):
412+
if isinstance(self.message, text_type):
412413
write(self.message.encode(self.encoding))
413414
else:
414415
write(self.message)

Diff for: git/objects/fun.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""Module with functions which are supposed to be as fast as possible"""
22
from stat import S_ISDIR
3+
from git.compat import (
4+
xrange,
5+
text_type
6+
)
37

48
__all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive',
59
'traverse_tree_recursive')
@@ -28,7 +32,7 @@ def tree_to_stream(entries, write):
2832
# hence we must convert to an utf8 string for it to work properly.
2933
# According to my tests, this is exactly what git does, that is it just
3034
# takes the input literally, which appears to be utf8 on linux.
31-
if isinstance(name, unicode):
35+
if isinstance(name, text_type):
3236
name = name.encode("utf8")
3337
write("%s %s\0%s" % (mode_str, name, binsha))
3438
# END for each item

Diff for: git/objects/submodule/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
InvalidGitRepositoryError,
2323
NoSuchPathError
2424
)
25+
from git.compat import string_types
2526

2627
import stat
2728
import git
@@ -93,7 +94,7 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit=
9394
if url is not None:
9495
self._url = url
9596
if branch_path is not None:
96-
assert isinstance(branch_path, basestring)
97+
assert isinstance(branch_path, string_types)
9798
self._branch_path = branch_path
9899
if name is not None:
99100
self._name = name

Diff for: git/objects/tree.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .base import IndexObject
1212
from .blob import Blob
1313
from .submodule.base import Submodule
14+
from git.compat import string_types
1415

1516
from .fun import (
1617
tree_entries_from_data,
@@ -232,7 +233,7 @@ def __getitem__(self, item):
232233
info = self._cache[item]
233234
return self._map_id_to_type[info[1] >> 12](self.repo, info[0], info[1], join_path(self.path, info[2]))
234235

235-
if isinstance(item, basestring):
236+
if isinstance(item, string_types):
236237
# compatability
237238
return self.__div__(item)
238239
# END index is basestring

Diff for: git/refs/log.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
Serializable,
1818
altz_to_utctz_str,
1919
)
20+
from git.compat import (
21+
xrange,
22+
string_types
23+
)
2024

2125
import time
2226
import re
@@ -170,7 +174,7 @@ def iter_entries(cls, stream):
170174
:param stream: file-like object containing the revlog in its native format
171175
or basestring instance pointing to a file to read"""
172176
new_entry = RefLogEntry.from_line
173-
if isinstance(stream, basestring):
177+
if isinstance(stream, string_types):
174178
stream = file_contents_ro_filepath(stream)
175179
# END handle stream type
176180
while True:

Diff for: git/refs/symbolic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
hex_to_bin,
2020
LockedFD
2121
)
22+
from git.compat import string_types
2223

2324
from .log import RefLog
2425

@@ -274,7 +275,7 @@ def set_reference(self, ref, logmsg=None):
274275
elif isinstance(ref, Object):
275276
obj = ref
276277
write_value = ref.hexsha
277-
elif isinstance(ref, basestring):
278+
elif isinstance(ref, string_types):
278279
try:
279280
obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags
280281
write_value = obj.hexsha

Diff for: git/repo/base.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
read_gitfile,
4848
touch,
4949
)
50+
from git.compat import text_type
5051

5152
import os
5253
import sys
@@ -176,11 +177,11 @@ def __hash__(self):
176177
# Description property
177178
def _get_description(self):
178179
filename = join(self.git_dir, 'description')
179-
return file(filename).read().rstrip()
180+
return open(filename).read().rstrip()
180181

181182
def _set_description(self, descr):
182183
filename = join(self.git_dir, 'description')
183-
file(filename, 'w').write(descr + '\n')
184+
open(filename, 'w').write(descr + '\n')
184185

185186
description = property(_get_description, _set_description,
186187
doc="the project's description")
@@ -389,7 +390,7 @@ def commit(self, rev=None):
389390
if rev is None:
390391
return self.head.commit
391392
else:
392-
return self.rev_parse(unicode(rev) + "^0")
393+
return self.rev_parse(text_type(rev) + "^0")
393394

394395
def iter_trees(self, *args, **kwargs):
395396
""":return: Iterator yielding Tree objects
@@ -412,7 +413,7 @@ def tree(self, rev=None):
412413
if rev is None:
413414
return self.head.commit.tree
414415
else:
415-
return self.rev_parse(unicode(rev) + "^{tree}")
416+
return self.rev_parse(text_type(rev) + "^{tree}")
416417

417418
def iter_commits(self, rev=None, paths='', **kwargs):
418419
"""A list of Commit objects representing the history of a given ref/commit

Diff for: git/repo/fun.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
hex_to_bin,
1414
bin_to_hex
1515
)
16+
from git.compat import xrange
1617

1718

1819
__all__ = ('rev_parse', 'is_git_dir', 'touch', 'read_gitfile', 'find_git_dir', 'name_to_object',

Diff for: git/test/lib/helper.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
from __future__ import print_function
77
import os
88
import sys
9-
from git import Repo, Remote, GitCommandError, Git
109
from unittest import TestCase
1110
import time
1211
import tempfile
1312
import shutil
1413
import io
1514

15+
from git import Repo, Remote, GitCommandError, Git
16+
from git.compat import string_types
17+
1618
GIT_REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
1719

1820
__all__ = (
@@ -89,7 +91,7 @@ def with_rw_repo(working_tree_ref, bare=False):
8991
To make working with relative paths easier, the cwd will be set to the working
9092
dir of the repository.
9193
"""
92-
assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout"
94+
assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
9395

9496
def argument_passer(func):
9597
def repo_creator(self):
@@ -152,7 +154,7 @@ def case(self, rw_repo, rw_remote_repo)
152154
See working dir info in with_rw_repo
153155
:note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
154156
"""
155-
assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout"
157+
assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
156158

157159
def argument_passer(func):
158160
def remote_repo_creator(self):

Diff for: git/test/performance/test_commit.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
from __future__ import print_function
7+
from io import StringIO
8+
from time import time
9+
import sys
10+
711
from .lib import TestBigRepoRW
812
from git import Commit
913
from gitdb import IStream
14+
from git.compat import xrange
1015
from git.test.test_commit import assert_commit_serialization
11-
from io import StringIO
12-
from time import time
13-
import sys
16+
1417

1518

1619
class TestPerformance(TestBigRepoRW):

0 commit comments

Comments
 (0)