Mercurial > cpython-lru_cache-weakref
diff Python/structmember.c @ 19942:8522b022f80a legacy-trunk
Add support for restricting access based on restricted execution mode.
Renamed the 'readonly' field to 'flags' and defined some new flag
bits: READ_RESTRICTED and WRITE_RESTRICTED, as well as a shortcut
RESTRICTED that means both.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 17 Sep 2001 19:28:08 +0000 |
| parents | 7b3476c1382e |
| children | 3faabf54b8b8 |
line wrap: on
line diff
--- a/Python/structmember.c Mon Sep 17 18:08:40 2001 +0000 +++ b/Python/structmember.c Mon Sep 17 19:28:08 2001 +0000 @@ -38,6 +38,12 @@ for (l = mlist; l->name != NULL; l++) { if (strcmp(l->name, name) == 0) { PyObject *v; + if ((l->flags & READ_RESTRICTED) && + PyEval_GetRestricted()) { + PyErr_SetString(PyExc_RuntimeError, + "restricted attribute"); + return NULL; + } addr += l->offset; switch (l->type) { case T_BYTE: @@ -133,17 +139,22 @@ for (l = mlist; l->name != NULL; l++) { if (strcmp(l->name, name) == 0) { + if ((l->flags & READONLY) || l->type == T_STRING #ifdef macintosh - if (l->readonly || l->type == T_STRING || - l->type == T_PSTRING) + || l->type == T_PSTRING +#endif + ) { -#else - if (l->readonly || l->type == T_STRING ) { -#endif /* macintosh */ PyErr_SetString(PyExc_TypeError, "readonly attribute"); return -1; } + if ((l->flags & WRITE_RESTRICTED) && + PyEval_GetRestricted()) { + PyErr_SetString(PyExc_RuntimeError, + "restricted attribute"); + return -1; + } if (v == NULL && l->type != T_OBJECT) { PyErr_SetString(PyExc_TypeError, "can't delete numeric/char attribute");
