Make the "name or service not known" message translatable

This commit is contained in:
Jeff Epler 2022-12-26 13:57:15 -06:00
parent 0d3b7770d1
commit 928fb0a9c4
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
5 changed files with 19 additions and 10 deletions

View File

@ -1393,6 +1393,10 @@ msgstr ""
msgid "NVS Error"
msgstr ""
#: shared-bindings/socketpool/SocketPool.c
msgid "Name or service not known"
msgstr ""
#: py/qstr.c
msgid "Name too long"
msgstr ""

View File

@ -369,7 +369,7 @@ void common_hal_socketpool_socket_connect(socketpool_socket_obj_t *self,
struct addrinfo *result_i;
int error = lwip_getaddrinfo(host, NULL, &hints, &result_i);
if (error != 0 || result_i == NULL) {
common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known);
common_hal_socketpool_socketpool_raise_gaierror_noname();
}
// Set parameters
@ -550,7 +550,7 @@ mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t *self,
struct addrinfo *result_i;
int error = lwip_getaddrinfo(host, NULL, &hints, &result_i);
if (error != 0 || result_i == NULL) {
common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known);
common_hal_socketpool_socketpool_raise_gaierror_noname();
}
// Set parameters

View File

@ -98,7 +98,7 @@ void socketpool_resolve_host_raise(socketpool_socketpool_obj_t *self, const char
int result = socketpool_resolve_host(self, host, addr);
if (result < 0) {
printf("socket_resolve_host() returned %d\n", result);
common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known);
common_hal_socketpool_socketpool_raise_gaierror_noname();
mp_raise_OSError(-result);
}
}

View File

@ -198,16 +198,21 @@ MP_WEAK
mp_obj_t common_hal_socketpool_socketpool_gethostbyname_raise(socketpool_socketpool_obj_t *self, const char *host) {
mp_obj_t ip_str = common_hal_socketpool_socketpool_gethostbyname(self, host);
if (ip_str == mp_const_none) {
common_hal_socketpool_socketpool_raise_gaierror(SOCKETPOOL_EAI_NONAME, MP_QSTR_Name_space_or_space_service_space_not_space_known);
common_hal_socketpool_socketpool_raise_gaierror_noname();
}
return ip_str;
}
MP_WEAK NORETURN
void common_hal_socketpool_socketpool_raise_gaierror(int value, qstr name) {
mp_obj_t exc_args[2] = {
MP_OBJ_NEW_SMALL_INT(value),
MP_OBJ_NEW_QSTR(name),
void common_hal_socketpool_socketpool_raise_gaierror_noname(void) {
vstr_t vstr;
mp_print_t print;
vstr_init_print(&vstr, 64, &print);
mp_printf(&print, "%S", translate("Name or service not known"));
mp_obj_t exc_args[] = {
MP_OBJ_NEW_SMALL_INT(SOCKETPOOL_EAI_NONAME),
mp_obj_new_str_from_vstr(&mp_type_str, &vstr),
};
nlr_raise(mp_obj_new_exception_args(&mp_type_gaierror, 2, exc_args));
nlr_raise(mp_obj_new_exception_args(&mp_type_gaierror, MP_ARRAY_SIZE(exc_args), exc_args));
}

View File

@ -73,6 +73,6 @@ bool socketpool_socket(socketpool_socketpool_obj_t *self,
socketpool_socketpool_addressfamily_t family, socketpool_socketpool_sock_t type,
socketpool_socket_obj_t *sock);
NORETURN void common_hal_socketpool_socketpool_raise_gaierror(int value, qstr name);
NORETURN void common_hal_socketpool_socketpool_raise_gaierror_noname(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SOCKETPOOL_SOCKETPOOL_H