diff --git a/pygit2/__init__.py b/pygit2/__init__.py index df3a898..2dbda72 100644 --- a/pygit2/__init__.py +++ b/pygit2/__init__.py @@ -59,7 +59,7 @@ def _credentials_cb(cred_out, url, username_from_url, allowed, data): try: ccred = get_credentials(d['callback'], url, username_from_url, allowed) cred_out[0] = ccred[0] - except Exception, e: + except Exception as e: d['exception'] = e return C.GIT_EUSER diff --git a/pygit2/ffi.py b/pygit2/ffi.py index ce25ff0..10762b6 100644 --- a/pygit2/ffi.py +++ b/pygit2/ffi.py @@ -29,7 +29,8 @@ from __future__ import absolute_import import inspect -from os import path +import codecs +from os import path, getenv from cffi import FFI import sys @@ -51,10 +52,10 @@ else: if sys.version_info.major < 3: def is_string(s): - return isinstance(s, str) + return isinstance(s, basestring) else: def is_string(s): - return isinstance(s, basestring) + return isinstance(s, str) ffi = FFI() @@ -88,7 +89,7 @@ def strings_to_strarray(l): if not is_string(l[i]): raise TypeError("Value must be a string") - s = ffi.new('char []', l[i]) + s = ffi.new('char []', to_str(l[i])) refs[i] = s strings[i] = s @@ -100,7 +101,7 @@ def strings_to_strarray(l): dir_path = path.dirname(path.abspath(inspect.getfile(inspect.currentframe()))) decl_path = path.join(dir_path, 'decl.h') -with open(decl_path, 'rb') as f: - ffi.cdef(f.read()) +with codecs.open(decl_path, 'r', 'utf-8') as header: + ffi.cdef(header.read()) C = ffi.verify("#include ", libraries=["git2"]) diff --git a/pygit2/remote.py b/pygit2/remote.py index 40e6dda..07614d3 100644 --- a/pygit2/remote.py +++ b/pygit2/remote.py @@ -303,7 +303,7 @@ class Remote(object): try: self.transfer_progress(TransferProgress(stats_ptr)) - except Exception, e: + except Exception as e: self._stored_exception = e return C.GIT_EUSER @@ -319,7 +319,7 @@ class Remote(object): try: s = ffi.string(string, length).decode() self.progress(s) - except Exception, e: + except Exception as e: self._stored_exception = e return C.GIT_EUSER @@ -338,7 +338,7 @@ class Remote(object): b = Oid(raw=bytes(ffi.buffer(b))) self.update_tips(s, a, b) - except Exception, e: + except Exception as e: self._stored_exception = e return C.GIT_EUSER @@ -355,7 +355,7 @@ class Remote(object): ccred = get_credentials(self.credentials, url, username, allowed) cred_out[0] = ccred[0] - except Exception, e: + except Exception as e: self._stored_exception = e return C.GIT_EUSER