Some python3 fixes

This commit is contained in:
Carlos Martín Nieto
2014-04-12 23:30:00 +02:00
parent 072b038210
commit 674546bbb5
3 changed files with 12 additions and 11 deletions

View File

@@ -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

View File

@@ -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 <git2.h>", libraries=["git2"])

View File

@@ -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