8000 Merge remote-tracking branch 'origin/main' into main · domdfcoding/circuitpython@34eb2a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 34eb2a5

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents f384367 + 8da98eb commit 34eb2a5

File tree

9 files changed

+201
-1
lines changed

9 files changed

+201
-1
lines changed

locale/circuitpython.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4105,7 +4105,7 @@ msgstr ""
41054105
msgid "stop not reachable from start"
41064106
msgstr ""
41074107

4108-
#: py/stream.c
4108+
#: py/stream.c shared-bindings/getpass/__init__.c
41094109
msgid "stream operation not supported"
41104110
msgstr ""
41114111

ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ CIRCUITPY_PWMIO = 0
1919
CIRCUITPY_ROTARYIO = 0
2020
CIRCUITPY_RTC = 0
2121
CIRCUITPY_USB_MIDI = 0
22+
23+
CIRCUITPY_GETPASS = 0
2224
CIRCUITPY_TRACEBACK = 0
2325

2426
CIRCUITPY_PIXELBUF = 1

ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ CHIP_FAMILY = samd21
99
INTERNAL_FLASH_FILESYSTEM = 1
1010
LONGINT_IMPL = NONE
1111
CIRCUITPY_FULL_BUILD = 0
12+
13+
CIRCUITPY_GETPASS = 0

py/circuitpy_defns.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ endif
188188
ifeq ($(CIRCUITPY_GAMEPADSHIFT),1)
189189
SRC_PATTERNS += gamepadshift/%
190190
endif
191+
ifeq ($(CIRCUITPY_GETPASS),1)
192+
SRC_PATTERNS += getpass/%
193+
endif
191194
ifeq ($(CIRCUITPY_GNSS),1)
192195
SRC_PATTERNS += gnss/%
193196
endif
@@ -519,6 +522,7 @@ SRC_SHARED_MODULE_ALL = \
519522
fontio/__init__.c \
520523
framebufferio/FramebufferDisplay.c \
521524
framebufferio/__init__.c \
525+
getpass/__init__.c \
522526
ipaddress/IPv4Address.c \
523527
ipaddress/__init__.c \
524528
keypad/__init__.c \

py/circuitpy_mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ extern const struct _mp_obj_module_t gamepadshift_module;
483483
#define GAMEPAD_ROOT_POINTERS
484484
#endif
485485

486+
#if CIRCUITPY_GETPASS
487+
extern const struct _mp_obj_module_t getpass_module;
488+
#define GETPASS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_getpass), (mp_obj_t)&getpass_module },
489+
#else
490+
#define GETPASS_MODULE
491+
#endif
492+
486493
#if CIRCUITPY_GNSS
487494
extern const struct _mp_obj_module_t gnss_module;
488495
#define GNSS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_gnss), (mp_obj_t)&gnss_module },
@@ -896,6 +903,7 @@ extern const struct _mp_obj_module_t msgpack_module;
896903
FRAMEBUFFERIO_MODULE \
897904
FREQUENCYIO_MODULE \
898905
GAMEPADSHIFT_MODULE \
906+
GETPASS_MODULE \
899907
GNSS_MODULE \
900908
I2CPERIPHERAL_MODULE \
901909
IPADDRESS_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ CFLAGS += -DCIRCUITPY_FREQUENCYIO=$(CIRCUITPY_FREQUENCYIO)
184184
CIRCUITPY_GAMEPADSHIFT ?= 0
185185
CFLAGS += -DCIRCUITPY_GAMEPADSHIFT=$(CIRCUITPY_GAMEPADSHIFT)
186186

187+
CIRCUITPY_GETPASS ?= 1
188+
CFLAGS += -DCIRCUITPY_GETPASS=$(CIRCUITPY_GETPASS)
189+
187190
CIRCUITPY_GNSS ?= 0
188191
CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS)
189192

shared-bindings/getpass/__init__.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/stream.h"
28+
#include "shared-module/getpass/__init__.h"
29+
30+
//| """Getpass Module
31+
//|
32+
//| This module provides a way to get input from user without echoing it.
33+
//|
34+
//| """
35+
//| ...
36+
//|
37+
38+
//| def getpass(prompt: Optional[str] = 'Password: ', stream: Optional[io.FileIO] = None) -> str:
39+
//|
40+
//| """Prompt the user without echoing.
41+
//|
42+
//| :param str prompt: The user is prompted using the string ``prompt``, which defaults to ``'Password: '``.
43+
//| :param io.FileIO stream: The ``prompt`` is written to the file-like object ``stream`` if provided.
44+
//|
45+
//| """
46+
//| ...
47+
//|
48+
STATIC mp_obj_t getpass_getpass(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
49+
enum { ARG_prompt, ARG_stream };
50+
static const mp_arg_t allowed_args[] = {
51+
{ MP_QSTR_prompt, MP_ARG_OBJ, {.u_obj = mp_const_none} },
52+
{ MP_QSTR_stream, MP_ARG_OBJ, {.u_obj = mp_const_none} },
53+
};
54+
55+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
56+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
57+
58+
const char *prompt = (args[ARG_prompt].u_obj == mp_const_none) ? "Password: " : mp_obj_str_get_str(args[ARG_prompt].u_obj);
59+
60+
mp_print_t print = {.data = NULL};
61+
if (args[ARG_stream].u_obj != mp_const_none) {
62+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
63+
mp_get_stream_raise(args[ARG_stream].u_obj, MP_STREAM_OP_WRITE);
64+
print.data = MP_OBJ_TO_PTR(args[ARG_stream].u_obj);
65+
print.print_strn = mp_stream_write_adaptor;
66+
#else
67+
mp_raise_NotImplementedError(translate("stream operation not supported"));
68+
#endif
69+
}
70+
71+
return shared_module_getpass_getpass(prompt, ((print.data) ? &print : NULL));
72+
}
73+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(getpass_getpass_obj, 0, getpass_getpass);
74+
75+
STATIC const mp_rom_map_elem_t getpass_module_globals_table[] = {
76+
// module name
77+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_getpass) },
78+
// module functions
79+
{ MP_ROM_QSTR(MP_QSTR_getpass), MP_ROM_PTR(&getpass_getpass_obj) },
80+
};
81+
STATIC MP_DEFINE_CONST_DICT(getpass_module_globals, getpass_module_globals_table);
82+
83+
const mp_obj_module_t getpass_module = {
84+
.base = { &mp_type_module },
85+
.globals = (mp_obj_dict_t *)&getpass_module_globals,
86+
};

shared-module/getpass/__init__.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/mphal.h"
28+
#include "lib/mp-readline/readline.h"
29+
#include "shared-module/getpass/__init__.h"
30+
31+
mp_obj_t shared_module_getpass_getpass(const char *prompt, mp_print_t *print) {
32+
vstr_t vstr;
33+
vstr_init(&vstr, 16);
34+
35+
if (print == NULL) {
36+
mp_hal_stdout_tx_str(prompt);
37+
} else {
38+
mp_printf(print, prompt);
39+
}
40+
41+
for (;;) {
42+
int c = mp_hal_stdin_rx_chr();
43+
if (c == CHAR_CTRL_C) {
44+
mp_raise_type(&mp_type_KeyboardInterrupt);
45+
} else if (c == CHAR_CTRL_D && vstr.len == 0) {
46+
mp_raise_type(&mp_type_EOFError);
47+
} else if (c == 8 || c == 127) {
48+
// backspace
49+
vstr_cut_tail_bytes(&vstr, 1);
50+
} else if (c >= 32) {
51+
// printable character
52+
vstr_ins_char(&vstr, vstr.len, c);
53+
} else if (c == '\r') {
54+
// newline
55+
mp_hal_stdout_tx_str("\r\n");
56+
break;
57+
}
58+
}
59+
60+
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
61+
}

shared-module/getpass/__init__.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_SHARED_MODULE_GETPASS___INIT___H
28+
#define MICROPY_INCLUDED_SHARED_MODULE_GETPASS___INIT___H
29+
30+
#include "py/runtime.h"
31+
32+
extern mp_obj_t shared_module_getpass_getpass(const char *prompt, mp_print_t *print);
33+
34+
#endif // MICROPY_INCLUDED_SHARED_MODULE_GETPASS___INIT___H

0 commit comments

Comments
 (0)
0