mirror of
https://github.com/python/cpython.git
synced 2026-02-13 19:04:37 +00:00
gh-77188: Add support for pickling private methods and nested classes (GH-21480)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
4644fed819
commit
01a1dd283b
9 changed files with 174 additions and 1 deletions
|
|
@ -3183,6 +3183,27 @@ _Py_MaybeMangle(PyObject *privateobj, PySTEntryObject *ste, PyObject *name)
|
|||
return _Py_Mangle(privateobj, name);
|
||||
}
|
||||
|
||||
int
|
||||
_Py_IsPrivateName(PyObject *ident)
|
||||
{
|
||||
if (!PyUnicode_Check(ident)) {
|
||||
return 0;
|
||||
}
|
||||
Py_ssize_t nlen = PyUnicode_GET_LENGTH(ident);
|
||||
if (nlen < 3 ||
|
||||
PyUnicode_READ_CHAR(ident, 0) != '_' ||
|
||||
PyUnicode_READ_CHAR(ident, 1) != '_')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (PyUnicode_READ_CHAR(ident, nlen-1) == '_' &&
|
||||
PyUnicode_READ_CHAR(ident, nlen-2) == '_')
|
||||
{
|
||||
return 0; /* Don't mangle __whatever__ */
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_Py_Mangle(PyObject *privateobj, PyObject *ident)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue