def proto_progress_to_native(progress: pb.Progress) -> Progress: kind = progress.WhichOneof("value") if kind == "media_sync": return Progress(kind=ProgressKind.MediaSync, val=progress.media_sync) elif kind == "media_check": return Progress(kind=ProgressKind.MediaCheck, val=progress.media_check) else: assert_impossible_literal(kind)
def proto_exception_to_native(err: pb.BackendError) -> Exception: val = err.WhichOneof("value") if val == "interrupted": return Interrupted() elif val == "network_error": return NetworkError(err.localized, err.network_error.kind) elif val == "sync_error": return SyncError(err.localized, err.sync_error.kind) elif val == "io_error": return IOError(err.localized) elif val == "db_error": return DBError(err.localized) elif val == "template_parse": return TemplateError(err.localized) elif val == "invalid_input": return StringError(err.localized) else: assert_impossible_literal(val)