Added support for yet-unknown error codes

This commit is contained in:
jaseg 2014-08-13 23:51:07 +02:00
parent 2e6516aa32
commit baee4f4e22
1 changed files with 453 additions and 444 deletions

15
mpv.py
View File

@ -46,11 +46,16 @@ class ErrorCode:
-12: lambda *a: SystemError('Error running mpv command', *a)
}
@classmethod
def DEFAULT_ERROR_HANDLER(ec, *args):
return ValueError(_mpv_error_string(ec).encode('utf-8'), ec, *a)
@classmethod
def raise_for_ec(kls, func, *args):
ec = kls.EXCEPTION_DICT[func(*args)]
if ec:
raise ec(*args)
ec = func(*args)
ex = kls.EXCEPTION_DICT.get(ec , kls.DEFAULT_ERROR_HANDLER)
if ex:
raise ex(ec, *args)
class MpvFormat(c_int):
@ -209,6 +214,10 @@ backend.mpv_event_name.restype = c_char_p
backend.mpv_event_name.argtypes = [c_int]
_mpv_event_name = backend.mpv_event_name
backend.mpv_error_string.restype = c_char_p
backend.mpv_error_string.argtypes = [c_int]
_mpv_error_string = backend.mpv_error_string
_handle_func('mpv_request_event', [MpvEventID, c_int])
_handle_func('mpv_request_log_messages', [c_char_p])
_handle_func('mpv_wait_event', [c_double], POINTER(MpvEvent))