Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae2ff0f

Browse files
committed
Dum brute force conversion of all types.
However, StringIO really is ByteIO in most cases, and py2.7 shouldrun but doesn't.This should be made work first.
1 parentf6aa8d1 commitae2ff0f

21 files changed

+87
-43
lines changed

‎git/cmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
stream_copy
2020
)
2121
from .excimportGitCommandError
22-
22+
fromgit.compatimporttext_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
ifnotisinstance(arg_list, (list,tuple)):
438-
ifisinstance(arg_list,unicode):
438+
ifisinstance(arg_list,text_type):
439439
return [arg_list.encode('utf-8')]
440440
return [str(arg_list)]
441441

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

‎git/compat.py

Lines changed: 9 additions & 2 deletions
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-
fromgitdb.utils.compatimport (# noqa
10+
fromgitdb.utils.compatimport (
1011
PY3,
1112
xrange,
1213
MAXSIZE,
1314
izip,
1415
)
1516

16-
fromgitdb.utils.encodingimport (# noqa
17+
fromgitdb.utils.encodingimport (
1718
string_types,
1819
text_type
1920
)
21+
22+
ifPY3:
23+
importio
24+
FileType=io.IOBase
25+
else:
26+
FileType=file

‎git/config.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
fromgit.odictimportOrderedDict
1919
fromgit.utilimportLockFile
20+
fromgit.compatimport (
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-
ifnotisinstance(file_or_files,basestring):
182+
ifnotisinstance(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-
ifisinstance(fp,(basestring,file)):
340+
ifisinstance(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
returndefault
392396
raise
393397

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

415-
ifnotisinstance(valuestr,basestring):
419+
ifnotisinstance(valuestr,string_types):
416420
raiseTypeError("Invalid value type: only int, long, float and str are allowed",valuestr)
417421

418422
returnvaluestr

‎git/index/base.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
)
4040

4141
fromgit.objects.utilimportSerializable
42-
fromgit.compatimportizip
42+
fromgit.compatimport (
43+
izip,
44+
xrange,
45+
string_types,
46+
)
4347

4448
fromgit.utilimport (
4549
LazyMixin,
@@ -541,7 +545,7 @@ def _preprocess_add_items(self, items):
541545
entries=list()
542546

543547
foriteminitems:
544-
ifisinstance(item,basestring):
548+
ifisinstance(item,string_types):
545549
paths.append(self._to_relative_path(item))
546550
elifisinstance(item, (Blob,Submodule)):
547551
entries.append(BaseIndexEntry.from_blob(item))
@@ -752,7 +756,7 @@ def _items_to_rela_paths(self, items):
752756
foriteminitems:
753757
ifisinstance(item, (BaseIndexEntry, (Blob,Submodule))):
754758
paths.append(self._to_relative_path(item.path))
755-
elifisinstance(item,basestring):
759+
elifisinstance(item,string_types):
756760
paths.append(self._to_relative_path(item))
757761
else:
758762
raiseTypeError("Invalid item type: %r"%item)
@@ -1004,7 +1008,7 @@ def handle_stderr(proc, iter_checked_out_files):
10041008
handle_stderr(proc,rval_iter)
10051009
returnrval_iter
10061010
else:
1007-
ifisinstance(paths,basestring):
1011+
ifisinstance(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-
ifisinstance(other,basestring):
1147+
ifisinstance(other,string_types):
11441148
other=self.repo.rev_parse(other)
11451149
# END object conversion
11461150

‎git/objects/commit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
altz_to_utctz_str,
2424
parse_actor_and_date
2525
)
26+
fromgit.compatimporttext_type
2627

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

379380
a=self.author
380381
aname=a.name
381-
ifisinstance(aname,unicode):
382+
ifisinstance(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-
ifisinstance(aname,unicode):
394+
ifisinstance(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-
ifisinstance(self.message,unicode):
412+
ifisinstance(self.message,text_type):
412413
write(self.message.encode(self.encoding))
413414
else:
414415
write(self.message)

‎git/objects/fun.py

Lines changed: 5 additions & 1 deletion
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
fromstatimportS_ISDIR
3+
fromgit.compatimport (
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-
ifisinstance(name,unicode):
35+
ifisinstance(name,text_type):
3236
name=name.encode("utf8")
3337
write("%s %s\0%s"% (mode_str,name,binsha))
3438
# END for each item

‎git/objects/submodule/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
InvalidGitRepositoryError,
2323
NoSuchPathError
2424
)
25+
fromgit.compatimportstring_types
2526

2627
importstat
2728
importgit
@@ -93,7 +94,7 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit=
9394
ifurlisnotNone:
9495
self._url=url
9596
ifbranch_pathisnotNone:
96-
assertisinstance(branch_path,basestring)
97+
assertisinstance(branch_path,string_types)
9798
self._branch_path=branch_path
9899
ifnameisnotNone:
99100
self._name=name

‎git/objects/tree.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .baseimportIndexObject
1212
from .blobimportBlob
1313
from .submodule.baseimportSubmodule
14+
fromgit.compatimportstring_types
1415

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

235-
ifisinstance(item,basestring):
236+
ifisinstance(item,string_types):
236237
# compatability
237238
returnself.__div__(item)
238239
# END index is basestring

‎git/refs/log.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
Serializable,
1818
altz_to_utctz_str,
1919
)
20+
fromgit.compatimport (
21+
xrange,
22+
string_types
23+
)
2024

2125
importtime
2226
importre
@@ -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-
ifisinstance(stream,basestring):
177+
ifisinstance(stream,string_types):
174178
stream=file_contents_ro_filepath(stream)
175179
# END handle stream type
176180
whileTrue:

‎git/refs/symbolic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
hex_to_bin,
2020
LockedFD
2121
)
22+
fromgit.compatimportstring_types
2223

2324
from .logimportRefLog
2425

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

‎git/repo/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
read_gitfile,
4848
touch,
4949
)
50+
fromgit.compatimporttext_type
5051

5152
importos
5253
importsys
@@ -176,11 +177,11 @@ def __hash__(self):
176177
# Description property
177178
def_get_description(self):
178179
filename=join(self.git_dir,'description')
179-
returnfile(filename).read().rstrip()
180+
returnopen(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
ifrevisNone:
390391
returnself.head.commit
391392
else:
392-
returnself.rev_parse(unicode(rev)+"^0")
393+
returnself.rev_parse(text_type(rev)+"^0")
393394

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

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

‎git/repo/fun.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
hex_to_bin,
1414
bin_to_hex
1515
)
16+
fromgit.compatimportxrange
1617

1718

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

‎git/test/lib/helper.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
from __future__importprint_function
77
importos
88
importsys
9-
fromgitimportRepo,Remote,GitCommandError,Git
109
fromunittestimportTestCase
1110
importtime
1211
importtempfile
1312
importshutil
1413
importio
1514

15+
fromgitimportRepo,Remote,GitCommandError,Git
16+
fromgit.compatimportstring_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-
assertisinstance(working_tree_ref,basestring),"Decorator requires ref name for working tree checkout"
94+
assertisinstance(working_tree_ref,string_types),"Decorator requires ref name for working tree checkout"
9395

9496
defargument_passer(func):
9597
defrepo_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-
assertisinstance(working_tree_ref,basestring),"Decorator requires ref name for working tree checkout"
157+
assertisinstance(working_tree_ref,string_types),"Decorator requires ref name for working tree checkout"
156158

157159
defargument_passer(func):
158160
defremote_repo_creator(self):

‎git/test/performance/test_commit.py

Lines changed: 6 additions & 3 deletions
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__importprint_function
7+
fromioimportStringIO
8+
fromtimeimporttime
9+
importsys
10+
711
from .libimportTestBigRepoRW
812
fromgitimportCommit
913
fromgitdbimportIStream
14+
fromgit.compatimportxrange
1015
fromgit.test.test_commitimportassert_commit_serialization
11-
fromioimportStringIO
12-
fromtimeimporttime
13-
importsys
16+
1417

1518

1619
classTestPerformance(TestBigRepoRW):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp