Fix regression in v0.21.1, IndexEntry.path returns str
And str in Python 2 means bytes. Recall, we are supposed to give a native experience to both Python 2 and 3 users.
This commit is contained in:
@@ -32,7 +32,7 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
from _pygit2 import Oid, Tree, Diff
|
from _pygit2 import Oid, Tree, Diff
|
||||||
from .errors import check_error
|
from .errors import check_error
|
||||||
from .ffi import ffi, C
|
from .ffi import ffi, C
|
||||||
from .utils import to_bytes, is_string, strings_to_strarray
|
from .utils import is_string, strings_to_strarray, to_bytes, to_str
|
||||||
|
|
||||||
|
|
||||||
class Index(object):
|
class Index(object):
|
||||||
@@ -357,7 +357,7 @@ class IndexEntry(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
entry = cls.__new__(cls)
|
entry = cls.__new__(cls)
|
||||||
entry.path = ffi.string(centry.path).decode()
|
entry.path = to_str(ffi.string(centry.path))
|
||||||
entry.mode = centry.mode
|
entry.mode = centry.mode
|
||||||
entry.id = Oid(raw=bytes(ffi.buffer(ffi.addressof(centry, 'id'))[:]))
|
entry.id = Oid(raw=bytes(ffi.buffer(ffi.addressof(centry, 'id'))[:]))
|
||||||
|
|
||||||
|
@@ -45,3 +45,13 @@ def to_bytes(s, encoding='utf-8', errors='strict'):
|
|||||||
|
|
||||||
def is_string(s):
|
def is_string(s):
|
||||||
return isinstance(s, basestring)
|
return isinstance(s, basestring)
|
||||||
|
|
||||||
|
|
||||||
|
def to_str(s):
|
||||||
|
if type(s) is str:
|
||||||
|
return s
|
||||||
|
|
||||||
|
if type(s) is unicode:
|
||||||
|
return s.encode()
|
||||||
|
|
||||||
|
raise TypeError, 'unexpected type "%s"' % repr(s)
|
||||||
|
@@ -44,3 +44,13 @@ def to_bytes(s, encoding='utf-8', errors='strict'):
|
|||||||
|
|
||||||
def is_string(s):
|
def is_string(s):
|
||||||
return isinstance(s, str)
|
return isinstance(s, str)
|
||||||
|
|
||||||
|
|
||||||
|
def to_str(s):
|
||||||
|
if type(s) is str:
|
||||||
|
return s
|
||||||
|
|
||||||
|
if type(s) is bytes:
|
||||||
|
return s.decode()
|
||||||
|
|
||||||
|
raise TypeError('unexpected type "%s"' % repr(s))
|
||||||
|
@@ -36,9 +36,9 @@ from .ffi import ffi
|
|||||||
|
|
||||||
|
|
||||||
if version_info[0] < 3:
|
if version_info[0] < 3:
|
||||||
from .py2 import to_bytes, is_string
|
from .py2 import is_string, to_bytes, to_str
|
||||||
else:
|
else:
|
||||||
from .py3 import to_bytes, is_string
|
from .py3 import is_string, to_bytes, to_str
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user