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

Commitdf2fb54

Browse files
committed
PY2,#519: FIX GitCommandError.tostr() encoding issue
+ PY3 means "PY3 or later" (TODO: fix also for *gitdb* project).
1 parent25a2ebf commitdf2fb54

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

‎git/compat.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
importsys
1212

1313
fromgitdb.utils.compatimport (
14-
PY3,
1514
xrange,
1615
MAXSIZE,
1716
izip,
@@ -24,7 +23,9 @@
2423
force_text
2524
)
2625

26+
PY3=sys.version_info[0]>=3
2727
defenc=sys.getdefaultencoding()
28+
2829
ifPY3:
2930
importio
3031
FileType=io.IOBase
@@ -74,13 +75,8 @@ def __new__(cls, name, nbases, d):
7475
# we set the __metaclass__ attribute explicitly
7576
ifnotPY3and'___metaclass__'notind:
7677
d['__metaclass__']=meta
77-
# end
7878
returnmeta(name,bases,d)
79-
# end
80-
# end metaclass
8179
returnmetaclass(meta.__name__+'Helper',None, {})
82-
# end handle py2
83-
8480

8581
defis_win():
8682
returnos.name=='nt'
@@ -93,3 +89,16 @@ def is_posix():
9389
defis_darwin():
9490
returnos.name=='darwin'
9591

92+
93+
## From https://docs.python.org/3.3/howto/pyporting.html
94+
classUnicodeMixin(object):
95+
96+
"""Mixin class to handle defining the proper __str__/__unicode__
97+
methods in Python 2 or 3."""
98+
99+
ifsys.version_info[0]>=3:# Python 3
100+
def__str__(self):
101+
returnself.__unicode__()
102+
else:# Python 2
103+
def__str__(self):
104+
returnself.__unicode__().encode('utf8')

‎git/exc.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
""" Module containing all exceptions thrown througout the git package, """
77

88
fromgitdb.excimport*# NOQA
9-
10-
fromgit.compatimportdefenc
9+
fromgit.compatimportUnicodeMixin,safe_decode
1110

1211

1312
classInvalidGitRepositoryError(Exception):
@@ -28,7 +27,7 @@ class GitCommandNotFound(Exception):
2827
pass
2928

3029

31-
classGitCommandError(Exception):
30+
classGitCommandError(UnicodeMixin,Exception):
3231
""" Thrown if execution of the git command fails with non-zero status code. """
3332

3433
def__init__(self,command,status,stderr=None,stdout=None):
@@ -37,13 +36,13 @@ def __init__(self, command, status, stderr=None, stdout=None):
3736
self.status=status
3837
self.command=command
3938

40-
def__str__(self):
41-
ret="'%s' returned with exit code %i"% \
42-
(' '.join(str(i)foriinself.command),self.status)
39+
def__unicode__(self):
40+
ret=u"'%s' returned with exit code %s"% \
41+
(u' '.join(safe_decode(i)foriinself.command),self.status)
4342
ifself.stderr:
44-
ret+="\nstderr: '%s'"%self.stderr.decode(defenc)
43+
ret+=u"\nstderr: '%s'"%safe_decode(self.stderr)
4544
ifself.stdout:
46-
ret+="\nstdout: '%s'"%self.stdout.decode(defenc)
45+
ret+=u"\nstdout: '%s'"%safe_decode(self.stdout)
4746
returnret
4847

4948

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp