Fix repository crash if path passed is not a str
Tries to decode any non-string objects (such as bytes) Introduces `six` as a dependency Closes #588
This commit is contained in:
@@ -37,6 +37,8 @@ if sys.version_info[0] < 3:
|
|||||||
else:
|
else:
|
||||||
from io import BytesIO as StringIO
|
from io import BytesIO as StringIO
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
# Import from pygit2
|
# Import from pygit2
|
||||||
from _pygit2 import Repository as _Repository
|
from _pygit2 import Repository as _Repository
|
||||||
from _pygit2 import Oid, GIT_OID_HEXSZ, GIT_OID_MINPREFIXLEN
|
from _pygit2 import Oid, GIT_OID_HEXSZ, GIT_OID_MINPREFIXLEN
|
||||||
@@ -56,8 +58,10 @@ from .submodule import Submodule
|
|||||||
|
|
||||||
class Repository(_Repository):
|
class Repository(_Repository):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, path, *args, **kwargs):
|
||||||
super(Repository, self).__init__(*args, **kwargs)
|
if not isinstance(path, six.string_types):
|
||||||
|
path = path.decode('utf-8')
|
||||||
|
super(Repository, self).__init__(path, *args, **kwargs)
|
||||||
self._common_init()
|
self._common_init()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
5
setup.py
5
setup.py
@@ -63,6 +63,7 @@ del sys.path[0]
|
|||||||
|
|
||||||
# Python 2 support
|
# Python 2 support
|
||||||
# See https://github.com/libgit2/pygit2/pull/180 for a discussion about this.
|
# See https://github.com/libgit2/pygit2/pull/180 for a discussion about this.
|
||||||
|
# Using six isn't an option here yet, we don't necessarily have six installed
|
||||||
if sys.version_info[0] == 2:
|
if sys.version_info[0] == 2:
|
||||||
u = lambda s: unicode(s, 'utf-8')
|
u = lambda s: unicode(s, 'utf-8')
|
||||||
else:
|
else:
|
||||||
@@ -186,7 +187,7 @@ extra_args = {
|
|||||||
if cffi_major_version == 0:
|
if cffi_major_version == 0:
|
||||||
extra_args['ext_modules'].append(ffi.verifier.get_extension())
|
extra_args['ext_modules'].append(ffi.verifier.get_extension())
|
||||||
else:
|
else:
|
||||||
extra_args['cffi_modules']=['pygit2/_run.py:ffi']
|
extra_args['cffi_modules'] = ['pygit2/_run.py:ffi']
|
||||||
|
|
||||||
|
|
||||||
setup(name='pygit2',
|
setup(name='pygit2',
|
||||||
@@ -202,7 +203,7 @@ setup(name='pygit2',
|
|||||||
packages=['pygit2'],
|
packages=['pygit2'],
|
||||||
package_data={'pygit2': ['decl.h']},
|
package_data={'pygit2': ['decl.h']},
|
||||||
setup_requires=['cffi'],
|
setup_requires=['cffi'],
|
||||||
install_requires=['cffi'],
|
install_requires=['cffi', 'six'],
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
cmdclass=cmdclass,
|
cmdclass=cmdclass,
|
||||||
**extra_args)
|
**extra_args)
|
||||||
|
Reference in New Issue
Block a user