diff options
author | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-09-27 17:23:53 +0200 |
---|---|---|
committer | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-09-28 03:35:38 +0200 |
commit | df2fb548040c8313f4bb98870788604bc973fa18 (patch) | |
tree | 4c11a309cfc6821b5ecd847592a451820c303463 /git/compat.py | |
parent | 25a2ebfa684f7ef37a9298c5ded2fc5af190cb42 (diff) | |
download | gitpython-df2fb548040c8313f4bb98870788604bc973fa18.tar.gz |
PY2, #519: FIX GitCommandError.tostr() encoding issue
+ PY3 means "PY3 or later" (TODO: fix also for *gitdb* project).
Diffstat (limited to 'git/compat.py')
-rw-r--r-- | git/compat.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/git/compat.py b/git/compat.py index ff382ce8..8c5036c6 100644 --- a/git/compat.py +++ b/git/compat.py @@ -11,7 +11,6 @@ import os import sys from gitdb.utils.compat import ( - PY3, xrange, MAXSIZE, izip, @@ -24,7 +23,9 @@ from gitdb.utils.encoding import ( force_text ) +PY3 = sys.version_info[0] >= 3 defenc = sys.getdefaultencoding() + if PY3: import io FileType = io.IOBase @@ -74,13 +75,8 @@ def with_metaclass(meta, *bases): # we set the __metaclass__ attribute explicitly if not PY3 and '___metaclass__' not in d: d['__metaclass__'] = meta - # end return meta(name, bases, d) - # end - # end metaclass return metaclass(meta.__name__ + 'Helper', None, {}) - # end handle py2 - def is_win(): return os.name == 'nt' @@ -93,3 +89,16 @@ def is_posix(): def is_darwin(): return os.name == 'darwin' + +## From https://docs.python.org/3.3/howto/pyporting.html +class UnicodeMixin(object): + + """Mixin class to handle defining the proper __str__/__unicode__ + methods in Python 2 or 3.""" + + if sys.version_info[0] >= 3: # Python 3 + def __str__(self): + return self.__unicode__() + else: # Python 2 + def __str__(self): + return self.__unicode__().encode('utf8') |