@@ -2019,6 +2019,45 @@ winreg_EnableReflectionKey_impl(PyObject *module, HKEY key)
20192019 Py_RETURN_NONE ;
20202020}
20212021
2022+ /*[clinic input]
2023+ winreg.DeleteTree
2024+
2025+ key: HKEY
2026+ An already open key, or any one of the predefined HKEY_* constants.
2027+ sub_key: Py_UNICODE(accept={str, NoneType}) = None
2028+ A string that names the subkey to delete. If None, deletes all subkeys
2029+ and values of the specified key.
2030+ /
2031+
2032+ Deletes the specified key and all its subkeys and values recursively.
2033+
2034+ This function deletes a key and all its descendants. If sub_key is None,
2035+ all subkeys and values of the specified key are deleted.
2036+ [clinic start generated code]*/
2037+
2038+ static PyObject *
2039+ winreg_DeleteTree_impl (PyObject * module , HKEY key , const wchar_t * sub_key )
2040+ /*[clinic end generated code: output=c34395ee59290501 input=440b81a7bc3fe183]*/
2041+ {
2042+ LONG rc ;
2043+
2044+ if (PySys_Audit ("winreg.DeleteTree" , "nu" ,
2045+ (Py_ssize_t )key , sub_key ) < 0 ) {
2046+ return NULL ;
2047+ }
2048+
2049+ Py_BEGIN_ALLOW_THREADS
2050+ rc = RegDeleteTreeW (key , sub_key );
2051+ Py_END_ALLOW_THREADS
2052+
2053+ if (rc != ERROR_SUCCESS ) {
2054+ PyErr_SetFromWindowsErrWithFunction (rc , "RegDeleteTreeW" );
2055+ return NULL ;
2056+ }
2057+
2058+ Py_RETURN_NONE ;
2059+ }
2060+
20222061/*[clinic input]
20232062winreg.QueryReflectionKey
20242063
@@ -2077,6 +2116,7 @@ static struct PyMethodDef winreg_methods[] = {
20772116 WINREG_DELETEKEY_METHODDEF
20782117 WINREG_DELETEKEYEX_METHODDEF
20792118 WINREG_DELETEVALUE_METHODDEF
2119+ WINREG_DELETETREE_METHODDEF
20802120 WINREG_DISABLEREFLECTIONKEY_METHODDEF
20812121 WINREG_ENABLEREFLECTIONKEY_METHODDEF
20822122 WINREG_ENUMKEY_METHODDEF
0 commit comments