Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def maybe_string(ptr):
if not ptr:
return None
return ffi.string(ptr).decode('utf8')
"""
cvalue = ffi.new('char **')
err = C.git_attr_get(cvalue, self._repo, flags, to_bytes(path), to_bytes(name))
check_error(err)
# Now let's see if we can figure out what the value is
attr_kind = C.git_attr_value(cvalue[0])
if attr_kind == C.GIT_ATTR_UNSPECIFIED_T:
return None
elif attr_kind == C.GIT_ATTR_TRUE_T:
return True
elif attr_kind == C.GIT_ATTR_FALSE_T:
return False
elif attr_kind == C.GIT_ATTR_VALUE_T:
return ffi.string(cvalue[0]).decode('utf-8')
assert False, "the attribute value from libgit2 is invalid"
def wrap_signature(csig):
if not csig:
return None
return Signature(ffi.string(csig.name).decode('utf-8'),
ffi.string(csig.email).decode('utf-8'),
csig.when.time, csig.when.offset, 'utf-8')
def strarray_to_strings(arr):
l = [None] * arr.count
for i in range(arr.count):
l[i] = ffi.string(arr.strings[i]).decode('utf-8')
return l
def string(self):
"""String which was used to create this refspec"""
return ffi.string(C.git_refspec_string(self._refspec)).decode('utf-8')
def _sideband_progress_cb(string, length, data):
self = ffi.from_handle(data)
progress = getattr(self, 'progress', None)
if not progress:
return 0
try:
s = ffi.string(string, length).decode('utf-8')
progress(s)
except Exception as e:
self._stored_exception = e
return C.GIT_EUSER
return 0
def path(self):
"""Path of the submodule."""
path = C.git_submodule_path(self._subm)
return ffi.string(path).decode('utf-8')
def _certificate_cb(cert_i, valid, host, data):
self = ffi.from_handle(data)
# We want to simulate what should happen if libgit2 supported pass-through for
# this callback. For SSH, 'valid' is always False, because it doesn't look
# at known_hosts, but we do want to let it through in order to do what libgit2 would
# if the callback were not set.
try:
is_ssh = cert_i.cert_type == C.GIT_CERT_HOSTKEY_LIBSSH2
certificate_check = getattr(self, 'certificate_check', None)
if not certificate_check:
raise Passthrough
# python's parsing is deep in the libraries and assumes an OpenSSL-owned cert
val = certificate_check(None, bool(valid), ffi.string(host))
if not val:
return C.GIT_ECERTIFICATE
except Passthrough:
if is_ssh:
return 0
elif valid:
return 0
else:
return C.GIT_ECERTIFICATE
except Exception as e:
self._stored_exception = e
return C.GIT_EUSER
return 0