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

Commitbc8c912

Browse files
committed
Fixed io types to make tests work on PY2 once again.
Now it's about going through PY3 issues
1 parentae2ff0f commitbc8c912

File tree

16 files changed

+45
-41
lines changed

16 files changed

+45
-41
lines changed

‎git/compat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
fromgitdb.utils.encodingimport (
1818
string_types,
19-
text_type
19+
text_type,
20+
force_bytes
2021
)
2122

2223
ifPY3:

‎git/index/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
importsys
99
importsubprocess
1010
importglob
11-
fromioimportStringIO
11+
fromioimportBytesIO
1212

1313
fromstatimportS_ISLNK
1414

@@ -43,6 +43,7 @@
4343
izip,
4444
xrange,
4545
string_types,
46+
force_bytes
4647
)
4748

4849
fromgit.utilimport (
@@ -562,7 +563,8 @@ def _store_path(self, filepath, fprogress):
562563
st=os.lstat(filepath)# handles non-symlinks as well
563564
stream=None
564565
ifS_ISLNK(st.st_mode):
565-
stream=StringIO(os.readlink(filepath))
566+
# in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8
567+
stream=BytesIO(force_bytes(os.readlink(filepath),encoding='utf-8'))
566568
else:
567569
stream=open(filepath,'rb')
568570
# END handle stream

‎git/index/fun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
S_IFGITLINK=S_IFLNK|S_IFDIR# a submodule
1414

15-
fromioimportStringIO
15+
fromioimportBytesIO
1616

1717
fromgit.utilimportIndexFileSHA1Writer
1818
fromgit.excimportUnmergedEntriesError
@@ -218,7 +218,7 @@ def write_tree_from_cache(entries, odb, sl, si=0):
218218
# END for each entry
219219

220220
# finally create the tree
221-
sio=StringIO()
221+
sio=BytesIO()
222222
tree_to_stream(tree_items,sio.write)
223223
sio.seek(0)
224224

‎git/objects/commit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
altzone
3131
)
3232
importos
33-
fromioimportStringIO
33+
fromioimportBytesIO
3434
importlogging
3535

3636
log=logging.getLogger('git.objects.commit')
@@ -133,7 +133,7 @@ def _set_cache_(self, attr):
133133
ifattrinCommit.__slots__:
134134
# read the data in a chunk, its faster - then provide a file wrapper
135135
binsha,typename,self.size,stream=self.repo.odb.stream(self.binsha)
136-
self._deserialize(StringIO(stream.read()))
136+
self._deserialize(BytesIO(stream.read()))
137137
else:
138138
super(Commit,self)._set_cache_(attr)
139139
# END handle attrs
@@ -345,7 +345,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
345345
committer,committer_time,committer_offset,
346346
message,parent_commits,conf_encoding)
347347

348-
stream=StringIO()
348+
stream=BytesIO()
349349
new_commit._serialize(stream)
350350
streamlen=stream.tell()
351351
stream.seek(0)

‎git/objects/submodule/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
find_first_remote_branch
99
)
1010
fromgit.objects.utilimportTraversable
11-
fromioimportStringIO# need a dict to set bloody .name field
11+
fromioimportBytesIO# need a dict to set bloody .name field
1212
fromgit.utilimport (
1313
Iterable,
1414
join_path_native,
@@ -187,8 +187,8 @@ def _clear_cache(self):
187187

188188
@classmethod
189189
def_sio_modules(cls,parent_commit):
190-
""":return: Configuration file asStringIO - we only access it through the respective blob's data"""
191-
sio=StringIO(parent_commit.tree[cls.k_modules_file].data_stream.read())
190+
""":return: Configuration file asBytesIO - we only access it through the respective blob's data"""
191+
sio=BytesIO(parent_commit.tree[cls.k_modules_file].data_stream.read())
192192
sio.name=cls.k_modules_file
193193
returnsio
194194

‎git/objects/submodule/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
importgit
22
fromgit.excimportInvalidGitRepositoryError
33
fromgit.configimportGitConfigParser
4-
fromioimportStringIO
4+
fromioimportBytesIO
55
importweakref
66

77
__all__= ('sm_section','sm_name','mkhead','unbare_repo','find_first_remote_branch',
@@ -83,7 +83,7 @@ def flush_to_index(self):
8383
"""Flush changes in our configuration file to the index"""
8484
assertself._smrefisnotNone
8585
# should always have a file here
86-
assertnotisinstance(self._file_or_files,StringIO)
86+
assertnotisinstance(self._file_or_files,BytesIO)
8787

8888
sm=self._smref()
8989
ifsmisnotNone:

‎git/refs/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def from_line(cls, line):
8585
:param line: line without trailing newline
8686
:raise ValueError: If line could not be parsed"""
8787
try:
88-
info,msg=line.split('\t',2)
88+
info,msg=line.split('\t',1)
8989
exceptValueError:
9090
raiseValueError("line is missing tab separator")
9191
# END handle first plit

‎git/test/fixtures/git_config_global

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# just a comment
12
[alias]
23
st = status
34
ci = commit

‎git/test/lib/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class StringProcessAdapter(object):
4848
Its tailored to work with the test system only"""
4949

5050
def__init__(self,input_string):
51-
self.stdout=io.StringIO(input_string)
52-
self.stderr=io.StringIO()
51+
self.stdout=io.BytesIO(input_string)
52+
self.stderr=io.BytesIO()
5353

5454
defwait(self):
5555
return0

‎git/test/performance/test_commit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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
7+
fromioimportBytesIO
88
fromtimeimporttime
99
importsys
1010

@@ -93,7 +93,7 @@ def test_commit_serialization(self):
9393
hc.committer,hc.committed_date,hc.committer_tz_offset,
9494
str(i),parents=hc.parents,encoding=hc.encoding)
9595

96-
stream=StringIO()
96+
stream=BytesIO()
9797
cm._serialize(stream)
9898
slen=stream.tell()
9999
stream.seek(0)

‎git/test/test_commit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
text_type
2626
)
2727

28-
fromioimportStringIO
28+
fromioimportBytesIO
2929
importtime
3030
importsys
3131
importre
@@ -44,7 +44,7 @@ def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False)
4444

4545
# assert that we deserialize commits correctly, hence we get the same
4646
# sha on serialization
47-
stream=StringIO()
47+
stream=BytesIO()
4848
cm._serialize(stream)
4949
ns+=1
5050
streamlen=stream.tell()
@@ -59,7 +59,7 @@ def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False)
5959
cm.message,cm.parents,cm.encoding)
6060

6161
assertnc.parents==cm.parents
62-
stream=StringIO()
62+
stream=BytesIO()
6363
nc._serialize(stream)
6464
ns+=1
6565
streamlen=stream.tell()
@@ -276,7 +276,7 @@ def test_serialization_unicode_support(self):
276276
cmt.author.name="äüß".decode("utf-8")
277277
assertlen(cmt.author.name)==3
278278

279-
cstream=StringIO()
279+
cstream=BytesIO()
280280
cmt._serialize(cstream)
281281
cstream.seek(0)
282282
assertlen(cstream.getvalue())
@@ -316,7 +316,7 @@ def test_gpgsig(self):
316316
cmt.gpgsig="<test\ndummy\nsig>"
317317
assertcmt.gpgsig!=fixture_sig
318318

319-
cstream=StringIO()
319+
cstream=BytesIO()
320320
cmt._serialize(cstream)
321321
assertre.search(r"^gpgsig <test\n dummy\n sig>$",cstream.getvalue(),re.MULTILINE)
322322

@@ -326,6 +326,6 @@ def test_gpgsig(self):
326326
assertcmt.gpgsig=="<test\ndummy\nsig>"
327327

328328
cmt.gpgsig=None
329-
cstream=StringIO()
329+
cstream=BytesIO()
330330
cmt._serialize(cstream)
331331
assertnotre.search(r"^gpgsig ",cstream.getvalue(),re.MULTILINE)

‎git/test/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
GitConfigParser
1313
)
1414
fromgit.compatimportstring_types
15-
importStringIO
15+
importio
1616
fromcopyimportcopy
1717
fromConfigParserimportNoSectionError
1818

@@ -21,7 +21,7 @@ class TestBase(TestCase):
2121

2222
def_to_memcache(self,file_path):
2323
fp=open(file_path,"r")
24-
sio=StringIO.StringIO(fp.read())
24+
sio=io.BytesIO(fp.read())
2525
sio.name=file_path
2626
returnsio
2727

‎git/test/test_fun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525

2626
fromgit.indeximportIndexFile
27-
fromioimportStringIO
27+
fromioimportBytesIO
2828

2929

3030
classTestFun(TestBase):
@@ -72,7 +72,7 @@ def test_aggressive_tree_merge(self):
7272

7373
defmktree(self,odb,entries):
7474
"""create a tree from the given tree entries and safe it to the database"""
75-
sio=StringIO()
75+
sio=BytesIO()
7676
tree_to_stream(entries,sio.write)
7777
sio.seek(0)
7878
istream=odb.store(IStream(str_tree_type,len(sio.getvalue()),sio))

‎git/test/test_index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
ST_MODE
3232
)
3333

34-
fromioimportStringIO
34+
fromioimportBytesIO
3535
fromgitdb.baseimportIStream
3636
fromgit.objectsimportBlob
3737
fromgit.index.typimport (
@@ -698,9 +698,9 @@ def test_index_bare_add(self, rw_bare_repo):
698698
# instead of throwing the Exception we are expecting. This is
699699
# a quick hack to make this test fail when expected.
700700
rw_bare_repo._working_tree_dir=None
701-
contents='This is aStringIO file'
701+
contents=b'This is aBytesIO file'
702702
filesize=len(contents)
703-
fileobj=StringIO(contents)
703+
fileobj=BytesIO(contents)
704704
filename='my-imaginary-file'
705705
istream=rw_bare_repo.odb.store(
706706
IStream(Blob.type,filesize,fileobj))

‎git/test/test_repo.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
importsys
3737
importtempfile
3838
importshutil
39-
fromioimportStringIO
39+
fromioimportBytesIO
4040

4141

4242
classTestRepo(TestBase):
@@ -362,22 +362,22 @@ def test_comparison_and_hash(self):
362362
deftest_git_cmd(self):
363363
# test CatFileContentStream, just to be very sure we have no fencepost errors
364364
# last \n is the terminating newline that it expects
365-
l1="0123456789\n"
366-
l2="abcdefghijklmnopqrstxy\n"
367-
l3="z\n"
368-
d="%s%s%s\n"% (l1,l2,l3)
365+
l1=b"0123456789\n"
366+
l2=b"abcdefghijklmnopqrstxy\n"
367+
l3=b"z\n"
368+
d=b"%s%s%s\n"% (l1,l2,l3)
369369

370370
l1p=l1[:5]
371371

372372
# full size
373373
# size is without terminating newline
374374
defmkfull():
375-
returnGit.CatFileContentStream(len(d)-1,StringIO(d))
375+
returnGit.CatFileContentStream(len(d)-1,BytesIO(d))
376376

377377
ts=5
378378

379379
defmktiny():
380-
returnGit.CatFileContentStream(ts,StringIO(d))
380+
returnGit.CatFileContentStream(ts,BytesIO(d))
381381

382382
# readlines no limit
383383
s=mkfull()

‎git/test/test_tree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Blob
1212
)
1313

14-
fromioimportStringIO
14+
fromioimportBytesIO
1515

1616

1717
classTestTree(TestBase):
@@ -30,7 +30,7 @@ def test_serializable(self):
3030
orig_data=tree.data_stream.read()
3131
orig_cache=tree._cache
3232

33-
stream=StringIO()
33+
stream=BytesIO()
3434
tree._serialize(stream)
3535
assertstream.getvalue()==orig_data
3636

@@ -82,7 +82,7 @@ def test_serializable(self):
8282
mod.set_done()# multiple times are okay
8383

8484
# serialize, its different now
85-
stream=StringIO()
85+
stream=BytesIO()
8686
testtree._serialize(stream)
8787
stream.seek(0)
8888
assertstream.getvalue()!=orig_data

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp