Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
evt_name = get_dc_event_name(evt)
event_sig_types = capi.lib.dc_get_event_signature_types(evt)
if data1 and event_sig_types & 1:
data1 = ffi.string(ffi.cast('char*', data1)).decode("utf8")
if data2 and event_sig_types & 2:
try:
data2 = ffi.string(ffi.cast('char*', data2)).decode("utf8")
except UnicodeDecodeError:
# XXX ignoring this error is not quite correct but for now
# i don't want to hunt down encoding problems in the c lib
data2 = ffi.string(ffi.cast('char*', data2))
try:
ret = callback(ctx, evt_name, data1, data2)
if event_sig_types & 4:
return ffi.cast('uintptr_t', ret)
elif event_sig_types & 8:
return ffi.cast('int', ret)
except: # noqa
raise
ret = 0
return ret
if data1 and event_sig_types & 1:
data1 = ffi.string(ffi.cast('char*', data1)).decode("utf8")
if data2 and event_sig_types & 2:
try:
data2 = ffi.string(ffi.cast('char*', data2)).decode("utf8")
except UnicodeDecodeError:
# XXX ignoring this error is not quite correct but for now
# i don't want to hunt down encoding problems in the c lib
data2 = ffi.string(ffi.cast('char*', data2))
try:
ret = callback(ctx, evt_name, data1, data2)
if event_sig_types & 4:
return ffi.cast('uintptr_t', ret)
elif event_sig_types & 8:
return ffi.cast('int', ret)
except: # noqa
raise
ret = 0
return ret