Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(winreg_HKEYType_Close__doc__, |
| 6 | "Close($self, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "Closes the underlying Windows handle.\n" |
| 10 | "\n" |
| 11 | "If the handle is already closed, no error is raised."); |
| 12 | |
| 13 | #define WINREG_HKEYTYPE_CLOSE_METHODDEF \ |
| 14 | {"Close", (PyCFunction)winreg_HKEYType_Close, METH_NOARGS, winreg_HKEYType_Close__doc__}, |
| 15 | |
| 16 | static PyObject * |
| 17 | winreg_HKEYType_Close_impl(PyHKEYObject *self); |
| 18 | |
| 19 | static PyObject * |
| 20 | winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) |
| 21 | { |
| 22 | return winreg_HKEYType_Close_impl(self); |
| 23 | } |
| 24 | |
| 25 | PyDoc_STRVAR(winreg_HKEYType_Detach__doc__, |
| 26 | "Detach($self, /)\n" |
| 27 | "--\n" |
| 28 | "\n" |
| 29 | "Detaches the Windows handle from the handle object.\n" |
| 30 | "\n" |
| 31 | "The result is the value of the handle before it is detached. If the\n" |
| 32 | "handle is already detached, this will return zero.\n" |
| 33 | "\n" |
| 34 | "After calling this function, the handle is effectively invalidated,\n" |
| 35 | "but the handle is not closed. You would call this function when you\n" |
| 36 | "need the underlying win32 handle to exist beyond the lifetime of the\n" |
| 37 | "handle object."); |
| 38 | |
| 39 | #define WINREG_HKEYTYPE_DETACH_METHODDEF \ |
| 40 | {"Detach", (PyCFunction)winreg_HKEYType_Detach, METH_NOARGS, winreg_HKEYType_Detach__doc__}, |
| 41 | |
| 42 | static PyObject * |
| 43 | winreg_HKEYType_Detach_impl(PyHKEYObject *self); |
| 44 | |
| 45 | static PyObject * |
| 46 | winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) |
| 47 | { |
| 48 | return winreg_HKEYType_Detach_impl(self); |
| 49 | } |
| 50 | |
| 51 | PyDoc_STRVAR(winreg_HKEYType___enter____doc__, |
| 52 | "__enter__($self, /)\n" |
| 53 | "--\n" |
| 54 | "\n"); |
| 55 | |
| 56 | #define WINREG_HKEYTYPE___ENTER___METHODDEF \ |
| 57 | {"__enter__", (PyCFunction)winreg_HKEYType___enter__, METH_NOARGS, winreg_HKEYType___enter____doc__}, |
| 58 | |
| 59 | static PyHKEYObject * |
| 60 | winreg_HKEYType___enter___impl(PyHKEYObject *self); |
| 61 | |
| 62 | static PyObject * |
| 63 | winreg_HKEYType___enter__(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) |
| 64 | { |
| 65 | PyObject *return_value = NULL; |
| 66 | PyHKEYObject *_return_value; |
| 67 | |
| 68 | _return_value = winreg_HKEYType___enter___impl(self); |
| 69 | return_value = (PyObject *)_return_value; |
| 70 | |
| 71 | return return_value; |
| 72 | } |
| 73 | |
| 74 | PyDoc_STRVAR(winreg_HKEYType___exit____doc__, |
| 75 | "__exit__($self, /, exc_type, exc_value, traceback)\n" |
| 76 | "--\n" |
| 77 | "\n"); |
| 78 | |
| 79 | #define WINREG_HKEYTYPE___EXIT___METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 80 | {"__exit__", (PyCFunction)(void(*)(void))winreg_HKEYType___exit__, METH_FASTCALL|METH_KEYWORDS, winreg_HKEYType___exit____doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 81 | |
| 82 | static PyObject * |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 83 | winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type, |
| 84 | PyObject *exc_value, PyObject *traceback); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 85 | |
| 86 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 87 | winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 88 | { |
| 89 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 90 | static const char * const _keywords[] = {"exc_type", "exc_value", "traceback", NULL}; |
| 91 | static _PyArg_Parser _parser = {"OOO:__exit__", _keywords, 0}; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 92 | PyObject *exc_type; |
| 93 | PyObject *exc_value; |
| 94 | PyObject *traceback; |
| 95 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 96 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 97 | &exc_type, &exc_value, &traceback)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 98 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 99 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 100 | return_value = winreg_HKEYType___exit___impl(self, exc_type, exc_value, traceback); |
| 101 | |
| 102 | exit: |
| 103 | return return_value; |
| 104 | } |
| 105 | |
| 106 | PyDoc_STRVAR(winreg_CloseKey__doc__, |
| 107 | "CloseKey($module, hkey, /)\n" |
| 108 | "--\n" |
| 109 | "\n" |
| 110 | "Closes a previously opened registry key.\n" |
| 111 | "\n" |
| 112 | " hkey\n" |
| 113 | " A previously opened key.\n" |
| 114 | "\n" |
| 115 | "Note that if the key is not closed using this method, it will be\n" |
| 116 | "closed when the hkey object is destroyed by Python."); |
| 117 | |
| 118 | #define WINREG_CLOSEKEY_METHODDEF \ |
| 119 | {"CloseKey", (PyCFunction)winreg_CloseKey, METH_O, winreg_CloseKey__doc__}, |
| 120 | |
| 121 | PyDoc_STRVAR(winreg_ConnectRegistry__doc__, |
| 122 | "ConnectRegistry($module, computer_name, key, /)\n" |
| 123 | "--\n" |
| 124 | "\n" |
Serhiy Storchaka | 6a7b3a7 | 2016-04-17 08:32:47 +0300 | [diff] [blame] | 125 | "Establishes a connection to the registry on another computer.\n" |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 126 | "\n" |
| 127 | " computer_name\n" |
| 128 | " The name of the remote computer, of the form r\"\\\\computername\". If\n" |
| 129 | " None, the local computer is used.\n" |
| 130 | " key\n" |
| 131 | " The predefined key to connect to.\n" |
| 132 | "\n" |
| 133 | "The return value is the handle of the opened key.\n" |
| 134 | "If the function fails, an OSError exception is raised."); |
| 135 | |
| 136 | #define WINREG_CONNECTREGISTRY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 137 | {"ConnectRegistry", (PyCFunction)(void(*)(void))winreg_ConnectRegistry, METH_FASTCALL, winreg_ConnectRegistry__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 138 | |
| 139 | static HKEY |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 140 | winreg_ConnectRegistry_impl(PyObject *module, |
| 141 | const Py_UNICODE *computer_name, HKEY key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 142 | |
| 143 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 144 | winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 145 | { |
| 146 | PyObject *return_value = NULL; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 147 | const Py_UNICODE *computer_name; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 148 | HKEY key; |
| 149 | HKEY _return_value; |
| 150 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 151 | if (!_PyArg_ParseStack(args, nargs, "ZO&:ConnectRegistry", |
| 152 | &computer_name, clinic_HKEY_converter, &key)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 153 | goto exit; |
| 154 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 155 | _return_value = winreg_ConnectRegistry_impl(module, computer_name, key); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 156 | if (_return_value == NULL) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 157 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 158 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 159 | return_value = PyHKEY_FromHKEY(_return_value); |
| 160 | |
| 161 | exit: |
| 162 | return return_value; |
| 163 | } |
| 164 | |
| 165 | PyDoc_STRVAR(winreg_CreateKey__doc__, |
| 166 | "CreateKey($module, key, sub_key, /)\n" |
| 167 | "--\n" |
| 168 | "\n" |
| 169 | "Creates or opens the specified key.\n" |
| 170 | "\n" |
| 171 | " key\n" |
| 172 | " An already open key, or one of the predefined HKEY_* constants.\n" |
| 173 | " sub_key\n" |
| 174 | " The name of the key this method opens or creates.\n" |
| 175 | "\n" |
| 176 | "If key is one of the predefined keys, sub_key may be None. In that case,\n" |
| 177 | "the handle returned is the same key handle passed in to the function.\n" |
| 178 | "\n" |
| 179 | "If the key already exists, this function opens the existing key.\n" |
| 180 | "\n" |
| 181 | "The return value is the handle of the opened key.\n" |
| 182 | "If the function fails, an OSError exception is raised."); |
| 183 | |
| 184 | #define WINREG_CREATEKEY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 185 | {"CreateKey", (PyCFunction)(void(*)(void))winreg_CreateKey, METH_FASTCALL, winreg_CreateKey__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 186 | |
| 187 | static HKEY |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 188 | winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 189 | |
| 190 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 191 | winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 192 | { |
| 193 | PyObject *return_value = NULL; |
| 194 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 195 | const Py_UNICODE *sub_key; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 196 | HKEY _return_value; |
| 197 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 198 | if (!_PyArg_ParseStack(args, nargs, "O&Z:CreateKey", |
| 199 | clinic_HKEY_converter, &key, &sub_key)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 200 | goto exit; |
| 201 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 202 | _return_value = winreg_CreateKey_impl(module, key, sub_key); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 203 | if (_return_value == NULL) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 204 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 205 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 206 | return_value = PyHKEY_FromHKEY(_return_value); |
| 207 | |
| 208 | exit: |
| 209 | return return_value; |
| 210 | } |
| 211 | |
| 212 | PyDoc_STRVAR(winreg_CreateKeyEx__doc__, |
| 213 | "CreateKeyEx($module, /, key, sub_key, reserved=0,\n" |
| 214 | " access=winreg.KEY_WRITE)\n" |
| 215 | "--\n" |
| 216 | "\n" |
| 217 | "Creates or opens the specified key.\n" |
| 218 | "\n" |
| 219 | " key\n" |
| 220 | " An already open key, or one of the predefined HKEY_* constants.\n" |
| 221 | " sub_key\n" |
| 222 | " The name of the key this method opens or creates.\n" |
| 223 | " reserved\n" |
| 224 | " A reserved integer, and must be zero. Default is zero.\n" |
| 225 | " access\n" |
| 226 | " An integer that specifies an access mask that describes the\n" |
| 227 | " desired security access for the key. Default is KEY_WRITE.\n" |
| 228 | "\n" |
| 229 | "If key is one of the predefined keys, sub_key may be None. In that case,\n" |
| 230 | "the handle returned is the same key handle passed in to the function.\n" |
| 231 | "\n" |
| 232 | "If the key already exists, this function opens the existing key\n" |
| 233 | "\n" |
| 234 | "The return value is the handle of the opened key.\n" |
| 235 | "If the function fails, an OSError exception is raised."); |
| 236 | |
| 237 | #define WINREG_CREATEKEYEX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 238 | {"CreateKeyEx", (PyCFunction)(void(*)(void))winreg_CreateKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_CreateKeyEx__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 239 | |
| 240 | static HKEY |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 241 | winreg_CreateKeyEx_impl(PyObject *module, HKEY key, |
| 242 | const Py_UNICODE *sub_key, int reserved, |
| 243 | REGSAM access); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 244 | |
| 245 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 246 | winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 247 | { |
| 248 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 249 | static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL}; |
| 250 | static _PyArg_Parser _parser = {"O&Z|ii:CreateKeyEx", _keywords, 0}; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 251 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 252 | const Py_UNICODE *sub_key; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 253 | int reserved = 0; |
| 254 | REGSAM access = KEY_WRITE; |
| 255 | HKEY _return_value; |
| 256 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 257 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 258 | clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 259 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 260 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 261 | _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 262 | if (_return_value == NULL) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 263 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 264 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 265 | return_value = PyHKEY_FromHKEY(_return_value); |
| 266 | |
| 267 | exit: |
| 268 | return return_value; |
| 269 | } |
| 270 | |
| 271 | PyDoc_STRVAR(winreg_DeleteKey__doc__, |
| 272 | "DeleteKey($module, key, sub_key, /)\n" |
| 273 | "--\n" |
| 274 | "\n" |
| 275 | "Deletes the specified key.\n" |
| 276 | "\n" |
| 277 | " key\n" |
| 278 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 279 | " sub_key\n" |
| 280 | " A string that must be the name of a subkey of the key identified by\n" |
| 281 | " the key parameter. This value must not be None, and the key may not\n" |
| 282 | " have subkeys.\n" |
| 283 | "\n" |
| 284 | "This method can not delete keys with subkeys.\n" |
| 285 | "\n" |
| 286 | "If the function succeeds, the entire key, including all of its values,\n" |
| 287 | "is removed. If the function fails, an OSError exception is raised."); |
| 288 | |
| 289 | #define WINREG_DELETEKEY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 290 | {"DeleteKey", (PyCFunction)(void(*)(void))winreg_DeleteKey, METH_FASTCALL, winreg_DeleteKey__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 291 | |
| 292 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 293 | winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 294 | |
| 295 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 296 | winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 297 | { |
| 298 | PyObject *return_value = NULL; |
| 299 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 300 | const Py_UNICODE *sub_key; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 301 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 302 | if (!_PyArg_ParseStack(args, nargs, "O&u:DeleteKey", |
| 303 | clinic_HKEY_converter, &key, &sub_key)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 304 | goto exit; |
| 305 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 306 | return_value = winreg_DeleteKey_impl(module, key, sub_key); |
| 307 | |
| 308 | exit: |
| 309 | return return_value; |
| 310 | } |
| 311 | |
| 312 | PyDoc_STRVAR(winreg_DeleteKeyEx__doc__, |
| 313 | "DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n" |
| 314 | " reserved=0)\n" |
| 315 | "--\n" |
| 316 | "\n" |
| 317 | "Deletes the specified key (64-bit OS only).\n" |
| 318 | "\n" |
| 319 | " key\n" |
| 320 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 321 | " sub_key\n" |
| 322 | " A string that must be the name of a subkey of the key identified by\n" |
| 323 | " the key parameter. This value must not be None, and the key may not\n" |
| 324 | " have subkeys.\n" |
| 325 | " access\n" |
| 326 | " An integer that specifies an access mask that describes the\n" |
| 327 | " desired security access for the key. Default is KEY_WOW64_64KEY.\n" |
| 328 | " reserved\n" |
| 329 | " A reserved integer, and must be zero. Default is zero.\n" |
| 330 | "\n" |
| 331 | "This method can not delete keys with subkeys.\n" |
| 332 | "\n" |
| 333 | "If the function succeeds, the entire key, including all of its values,\n" |
| 334 | "is removed. If the function fails, an OSError exception is raised.\n" |
| 335 | "On unsupported Windows versions, NotImplementedError is raised."); |
| 336 | |
| 337 | #define WINREG_DELETEKEYEX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 338 | {"DeleteKeyEx", (PyCFunction)(void(*)(void))winreg_DeleteKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_DeleteKeyEx__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 339 | |
| 340 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 341 | winreg_DeleteKeyEx_impl(PyObject *module, HKEY key, |
| 342 | const Py_UNICODE *sub_key, REGSAM access, |
| 343 | int reserved); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 344 | |
| 345 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 346 | winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 347 | { |
| 348 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 349 | static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL}; |
| 350 | static _PyArg_Parser _parser = {"O&u|ii:DeleteKeyEx", _keywords, 0}; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 351 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 352 | const Py_UNICODE *sub_key; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 353 | REGSAM access = KEY_WOW64_64KEY; |
| 354 | int reserved = 0; |
| 355 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 356 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 357 | clinic_HKEY_converter, &key, &sub_key, &access, &reserved)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 358 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 359 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 360 | return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved); |
| 361 | |
| 362 | exit: |
| 363 | return return_value; |
| 364 | } |
| 365 | |
| 366 | PyDoc_STRVAR(winreg_DeleteValue__doc__, |
| 367 | "DeleteValue($module, key, value, /)\n" |
| 368 | "--\n" |
| 369 | "\n" |
| 370 | "Removes a named value from a registry key.\n" |
| 371 | "\n" |
| 372 | " key\n" |
| 373 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 374 | " value\n" |
| 375 | " A string that identifies the value to remove."); |
| 376 | |
| 377 | #define WINREG_DELETEVALUE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 378 | {"DeleteValue", (PyCFunction)(void(*)(void))winreg_DeleteValue, METH_FASTCALL, winreg_DeleteValue__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 379 | |
| 380 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 381 | winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 382 | |
| 383 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 384 | winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 385 | { |
| 386 | PyObject *return_value = NULL; |
| 387 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 388 | const Py_UNICODE *value; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 389 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 390 | if (!_PyArg_ParseStack(args, nargs, "O&Z:DeleteValue", |
| 391 | clinic_HKEY_converter, &key, &value)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 392 | goto exit; |
| 393 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 394 | return_value = winreg_DeleteValue_impl(module, key, value); |
| 395 | |
| 396 | exit: |
| 397 | return return_value; |
| 398 | } |
| 399 | |
| 400 | PyDoc_STRVAR(winreg_EnumKey__doc__, |
| 401 | "EnumKey($module, key, index, /)\n" |
| 402 | "--\n" |
| 403 | "\n" |
| 404 | "Enumerates subkeys of an open registry key.\n" |
| 405 | "\n" |
| 406 | " key\n" |
| 407 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 408 | " index\n" |
| 409 | " An integer that identifies the index of the key to retrieve.\n" |
| 410 | "\n" |
| 411 | "The function retrieves the name of one subkey each time it is called.\n" |
| 412 | "It is typically called repeatedly until an OSError exception is\n" |
| 413 | "raised, indicating no more values are available."); |
| 414 | |
| 415 | #define WINREG_ENUMKEY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 416 | {"EnumKey", (PyCFunction)(void(*)(void))winreg_EnumKey, METH_FASTCALL, winreg_EnumKey__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 417 | |
| 418 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 419 | winreg_EnumKey_impl(PyObject *module, HKEY key, int index); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 420 | |
| 421 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 422 | winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 423 | { |
| 424 | PyObject *return_value = NULL; |
| 425 | HKEY key; |
| 426 | int index; |
| 427 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 428 | if (!_PyArg_CheckPositional("EnumKey", nargs, 2, 2)) { |
| 429 | goto exit; |
| 430 | } |
| 431 | if (!clinic_HKEY_converter(args[0], &key)) { |
| 432 | goto exit; |
| 433 | } |
| 434 | if (PyFloat_Check(args[1])) { |
| 435 | PyErr_SetString(PyExc_TypeError, |
| 436 | "integer argument expected, got float" ); |
| 437 | goto exit; |
| 438 | } |
| 439 | index = _PyLong_AsInt(args[1]); |
| 440 | if (index == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 441 | goto exit; |
| 442 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 443 | return_value = winreg_EnumKey_impl(module, key, index); |
| 444 | |
| 445 | exit: |
| 446 | return return_value; |
| 447 | } |
| 448 | |
| 449 | PyDoc_STRVAR(winreg_EnumValue__doc__, |
| 450 | "EnumValue($module, key, index, /)\n" |
| 451 | "--\n" |
| 452 | "\n" |
| 453 | "Enumerates values of an open registry key.\n" |
| 454 | "\n" |
| 455 | " key\n" |
| 456 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 457 | " index\n" |
| 458 | " An integer that identifies the index of the value to retrieve.\n" |
| 459 | "\n" |
| 460 | "The function retrieves the name of one subkey each time it is called.\n" |
| 461 | "It is typically called repeatedly, until an OSError exception\n" |
| 462 | "is raised, indicating no more values.\n" |
| 463 | "\n" |
| 464 | "The result is a tuple of 3 items:\n" |
| 465 | " value_name\n" |
| 466 | " A string that identifies the value.\n" |
| 467 | " value_data\n" |
| 468 | " An object that holds the value data, and whose type depends\n" |
| 469 | " on the underlying registry type.\n" |
| 470 | " data_type\n" |
| 471 | " An integer that identifies the type of the value data."); |
| 472 | |
| 473 | #define WINREG_ENUMVALUE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 474 | {"EnumValue", (PyCFunction)(void(*)(void))winreg_EnumValue, METH_FASTCALL, winreg_EnumValue__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 475 | |
| 476 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 477 | winreg_EnumValue_impl(PyObject *module, HKEY key, int index); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 478 | |
| 479 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 480 | winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 481 | { |
| 482 | PyObject *return_value = NULL; |
| 483 | HKEY key; |
| 484 | int index; |
| 485 | |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 486 | if (!_PyArg_CheckPositional("EnumValue", nargs, 2, 2)) { |
| 487 | goto exit; |
| 488 | } |
| 489 | if (!clinic_HKEY_converter(args[0], &key)) { |
| 490 | goto exit; |
| 491 | } |
| 492 | if (PyFloat_Check(args[1])) { |
| 493 | PyErr_SetString(PyExc_TypeError, |
| 494 | "integer argument expected, got float" ); |
| 495 | goto exit; |
| 496 | } |
| 497 | index = _PyLong_AsInt(args[1]); |
| 498 | if (index == -1 && PyErr_Occurred()) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 499 | goto exit; |
| 500 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 501 | return_value = winreg_EnumValue_impl(module, key, index); |
| 502 | |
| 503 | exit: |
| 504 | return return_value; |
| 505 | } |
| 506 | |
| 507 | PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__, |
| 508 | "ExpandEnvironmentStrings($module, string, /)\n" |
| 509 | "--\n" |
| 510 | "\n" |
| 511 | "Expand environment vars."); |
| 512 | |
| 513 | #define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF \ |
| 514 | {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__}, |
| 515 | |
| 516 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 517 | winreg_ExpandEnvironmentStrings_impl(PyObject *module, |
| 518 | const Py_UNICODE *string); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 519 | |
| 520 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 521 | winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 522 | { |
| 523 | PyObject *return_value = NULL; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 524 | const Py_UNICODE *string; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 525 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 526 | if (!PyArg_Parse(arg, "u:ExpandEnvironmentStrings", &string)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 527 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 528 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 529 | return_value = winreg_ExpandEnvironmentStrings_impl(module, string); |
| 530 | |
| 531 | exit: |
| 532 | return return_value; |
| 533 | } |
| 534 | |
| 535 | PyDoc_STRVAR(winreg_FlushKey__doc__, |
| 536 | "FlushKey($module, key, /)\n" |
| 537 | "--\n" |
| 538 | "\n" |
| 539 | "Writes all the attributes of a key to the registry.\n" |
| 540 | "\n" |
| 541 | " key\n" |
| 542 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 543 | "\n" |
| 544 | "It is not necessary to call FlushKey to change a key. Registry changes\n" |
| 545 | "are flushed to disk by the registry using its lazy flusher. Registry\n" |
| 546 | "changes are also flushed to disk at system shutdown. Unlike\n" |
| 547 | "CloseKey(), the FlushKey() method returns only when all the data has\n" |
| 548 | "been written to the registry.\n" |
| 549 | "\n" |
| 550 | "An application should only call FlushKey() if it requires absolute\n" |
| 551 | "certainty that registry changes are on disk. If you don\'t know whether\n" |
| 552 | "a FlushKey() call is required, it probably isn\'t."); |
| 553 | |
| 554 | #define WINREG_FLUSHKEY_METHODDEF \ |
| 555 | {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__}, |
| 556 | |
| 557 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 558 | winreg_FlushKey_impl(PyObject *module, HKEY key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 559 | |
| 560 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 561 | winreg_FlushKey(PyObject *module, PyObject *arg) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 562 | { |
| 563 | PyObject *return_value = NULL; |
| 564 | HKEY key; |
| 565 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 566 | if (!clinic_HKEY_converter(arg, &key)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 567 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 568 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 569 | return_value = winreg_FlushKey_impl(module, key); |
| 570 | |
| 571 | exit: |
| 572 | return return_value; |
| 573 | } |
| 574 | |
| 575 | PyDoc_STRVAR(winreg_LoadKey__doc__, |
| 576 | "LoadKey($module, key, sub_key, file_name, /)\n" |
| 577 | "--\n" |
| 578 | "\n" |
| 579 | "Insert data into the registry from a file.\n" |
| 580 | "\n" |
| 581 | " key\n" |
| 582 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 583 | " sub_key\n" |
| 584 | " A string that identifies the sub-key to load.\n" |
| 585 | " file_name\n" |
| 586 | " The name of the file to load registry data from. This file must\n" |
| 587 | " have been created with the SaveKey() function. Under the file\n" |
| 588 | " allocation table (FAT) file system, the filename may not have an\n" |
| 589 | " extension.\n" |
| 590 | "\n" |
| 591 | "Creates a subkey under the specified key and stores registration\n" |
| 592 | "information from a specified file into that subkey.\n" |
| 593 | "\n" |
| 594 | "A call to LoadKey() fails if the calling process does not have the\n" |
| 595 | "SE_RESTORE_PRIVILEGE privilege.\n" |
| 596 | "\n" |
| 597 | "If key is a handle returned by ConnectRegistry(), then the path\n" |
| 598 | "specified in fileName is relative to the remote computer.\n" |
| 599 | "\n" |
| 600 | "The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n" |
| 601 | "tree."); |
| 602 | |
| 603 | #define WINREG_LOADKEY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 604 | {"LoadKey", (PyCFunction)(void(*)(void))winreg_LoadKey, METH_FASTCALL, winreg_LoadKey__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 605 | |
| 606 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 607 | winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, |
| 608 | const Py_UNICODE *file_name); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 609 | |
| 610 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 611 | winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 612 | { |
| 613 | PyObject *return_value = NULL; |
| 614 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 615 | const Py_UNICODE *sub_key; |
| 616 | const Py_UNICODE *file_name; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 617 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 618 | if (!_PyArg_ParseStack(args, nargs, "O&uu:LoadKey", |
| 619 | clinic_HKEY_converter, &key, &sub_key, &file_name)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 620 | goto exit; |
| 621 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 622 | return_value = winreg_LoadKey_impl(module, key, sub_key, file_name); |
| 623 | |
| 624 | exit: |
| 625 | return return_value; |
| 626 | } |
| 627 | |
| 628 | PyDoc_STRVAR(winreg_OpenKey__doc__, |
| 629 | "OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" |
| 630 | "--\n" |
| 631 | "\n" |
| 632 | "Opens the specified key.\n" |
| 633 | "\n" |
| 634 | " key\n" |
| 635 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 636 | " sub_key\n" |
| 637 | " A string that identifies the sub_key to open.\n" |
| 638 | " reserved\n" |
| 639 | " A reserved integer that must be zero. Default is zero.\n" |
| 640 | " access\n" |
| 641 | " An integer that specifies an access mask that describes the desired\n" |
| 642 | " security access for the key. Default is KEY_READ.\n" |
| 643 | "\n" |
| 644 | "The result is a new handle to the specified key.\n" |
| 645 | "If the function fails, an OSError exception is raised."); |
| 646 | |
| 647 | #define WINREG_OPENKEY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 648 | {"OpenKey", (PyCFunction)(void(*)(void))winreg_OpenKey, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKey__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 649 | |
| 650 | static HKEY |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 651 | winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 652 | int reserved, REGSAM access); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 653 | |
| 654 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 655 | winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 656 | { |
| 657 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 658 | static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL}; |
| 659 | static _PyArg_Parser _parser = {"O&Z|ii:OpenKey", _keywords, 0}; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 660 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 661 | const Py_UNICODE *sub_key; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 662 | int reserved = 0; |
| 663 | REGSAM access = KEY_READ; |
| 664 | HKEY _return_value; |
| 665 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 666 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 667 | clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 668 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 669 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 670 | _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 671 | if (_return_value == NULL) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 672 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 673 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 674 | return_value = PyHKEY_FromHKEY(_return_value); |
| 675 | |
| 676 | exit: |
| 677 | return return_value; |
| 678 | } |
| 679 | |
| 680 | PyDoc_STRVAR(winreg_OpenKeyEx__doc__, |
| 681 | "OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" |
| 682 | "--\n" |
| 683 | "\n" |
| 684 | "Opens the specified key.\n" |
| 685 | "\n" |
| 686 | " key\n" |
| 687 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 688 | " sub_key\n" |
| 689 | " A string that identifies the sub_key to open.\n" |
| 690 | " reserved\n" |
| 691 | " A reserved integer that must be zero. Default is zero.\n" |
| 692 | " access\n" |
| 693 | " An integer that specifies an access mask that describes the desired\n" |
| 694 | " security access for the key. Default is KEY_READ.\n" |
| 695 | "\n" |
| 696 | "The result is a new handle to the specified key.\n" |
| 697 | "If the function fails, an OSError exception is raised."); |
| 698 | |
| 699 | #define WINREG_OPENKEYEX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 700 | {"OpenKeyEx", (PyCFunction)(void(*)(void))winreg_OpenKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKeyEx__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 701 | |
| 702 | static HKEY |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 703 | winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 704 | int reserved, REGSAM access); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 705 | |
| 706 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 707 | winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 708 | { |
| 709 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 710 | static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL}; |
| 711 | static _PyArg_Parser _parser = {"O&Z|ii:OpenKeyEx", _keywords, 0}; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 712 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 713 | const Py_UNICODE *sub_key; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 714 | int reserved = 0; |
| 715 | REGSAM access = KEY_READ; |
| 716 | HKEY _return_value; |
| 717 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 718 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 719 | clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 720 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 721 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 722 | _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 723 | if (_return_value == NULL) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 724 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 725 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 726 | return_value = PyHKEY_FromHKEY(_return_value); |
| 727 | |
| 728 | exit: |
| 729 | return return_value; |
| 730 | } |
| 731 | |
| 732 | PyDoc_STRVAR(winreg_QueryInfoKey__doc__, |
| 733 | "QueryInfoKey($module, key, /)\n" |
| 734 | "--\n" |
| 735 | "\n" |
| 736 | "Returns information about a key.\n" |
| 737 | "\n" |
| 738 | " key\n" |
| 739 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 740 | "\n" |
| 741 | "The result is a tuple of 3 items:\n" |
| 742 | "An integer that identifies the number of sub keys this key has.\n" |
| 743 | "An integer that identifies the number of values this key has.\n" |
| 744 | "An integer that identifies when the key was last modified (if available)\n" |
| 745 | "as 100\'s of nanoseconds since Jan 1, 1600."); |
| 746 | |
| 747 | #define WINREG_QUERYINFOKEY_METHODDEF \ |
| 748 | {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__}, |
| 749 | |
| 750 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 751 | winreg_QueryInfoKey_impl(PyObject *module, HKEY key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 752 | |
| 753 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 754 | winreg_QueryInfoKey(PyObject *module, PyObject *arg) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 755 | { |
| 756 | PyObject *return_value = NULL; |
| 757 | HKEY key; |
| 758 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 759 | if (!clinic_HKEY_converter(arg, &key)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 760 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 761 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 762 | return_value = winreg_QueryInfoKey_impl(module, key); |
| 763 | |
| 764 | exit: |
| 765 | return return_value; |
| 766 | } |
| 767 | |
| 768 | PyDoc_STRVAR(winreg_QueryValue__doc__, |
| 769 | "QueryValue($module, key, sub_key, /)\n" |
| 770 | "--\n" |
| 771 | "\n" |
| 772 | "Retrieves the unnamed value for a key.\n" |
| 773 | "\n" |
| 774 | " key\n" |
| 775 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 776 | " sub_key\n" |
| 777 | " A string that holds the name of the subkey with which the value\n" |
| 778 | " is associated. If this parameter is None or empty, the function\n" |
| 779 | " retrieves the value set by the SetValue() method for the key\n" |
| 780 | " identified by key.\n" |
| 781 | "\n" |
| 782 | "Values in the registry have name, type, and data components. This method\n" |
| 783 | "retrieves the data for a key\'s first value that has a NULL name.\n" |
| 784 | "But since the underlying API call doesn\'t return the type, you\'ll\n" |
| 785 | "probably be happier using QueryValueEx; this function is just here for\n" |
| 786 | "completeness."); |
| 787 | |
| 788 | #define WINREG_QUERYVALUE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 789 | {"QueryValue", (PyCFunction)(void(*)(void))winreg_QueryValue, METH_FASTCALL, winreg_QueryValue__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 790 | |
| 791 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 792 | winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 793 | |
| 794 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 795 | winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 796 | { |
| 797 | PyObject *return_value = NULL; |
| 798 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 799 | const Py_UNICODE *sub_key; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 800 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 801 | if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValue", |
| 802 | clinic_HKEY_converter, &key, &sub_key)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 803 | goto exit; |
| 804 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 805 | return_value = winreg_QueryValue_impl(module, key, sub_key); |
| 806 | |
| 807 | exit: |
| 808 | return return_value; |
| 809 | } |
| 810 | |
| 811 | PyDoc_STRVAR(winreg_QueryValueEx__doc__, |
| 812 | "QueryValueEx($module, key, name, /)\n" |
| 813 | "--\n" |
| 814 | "\n" |
| 815 | "Retrieves the type and value of a specified sub-key.\n" |
| 816 | "\n" |
| 817 | " key\n" |
| 818 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 819 | " name\n" |
| 820 | " A string indicating the value to query.\n" |
| 821 | "\n" |
| 822 | "Behaves mostly like QueryValue(), but also returns the type of the\n" |
| 823 | "specified value name associated with the given open registry key.\n" |
| 824 | "\n" |
| 825 | "The return value is a tuple of the value and the type_id."); |
| 826 | |
| 827 | #define WINREG_QUERYVALUEEX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 828 | {"QueryValueEx", (PyCFunction)(void(*)(void))winreg_QueryValueEx, METH_FASTCALL, winreg_QueryValueEx__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 829 | |
| 830 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 831 | winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 832 | |
| 833 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 834 | winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 835 | { |
| 836 | PyObject *return_value = NULL; |
| 837 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 838 | const Py_UNICODE *name; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 839 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 840 | if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValueEx", |
| 841 | clinic_HKEY_converter, &key, &name)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 842 | goto exit; |
| 843 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 844 | return_value = winreg_QueryValueEx_impl(module, key, name); |
| 845 | |
| 846 | exit: |
| 847 | return return_value; |
| 848 | } |
| 849 | |
| 850 | PyDoc_STRVAR(winreg_SaveKey__doc__, |
| 851 | "SaveKey($module, key, file_name, /)\n" |
| 852 | "--\n" |
| 853 | "\n" |
| 854 | "Saves the specified key, and all its subkeys to the specified file.\n" |
| 855 | "\n" |
| 856 | " key\n" |
| 857 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 858 | " file_name\n" |
| 859 | " The name of the file to save registry data to. This file cannot\n" |
| 860 | " already exist. If this filename includes an extension, it cannot be\n" |
| 861 | " used on file allocation table (FAT) file systems by the LoadKey(),\n" |
| 862 | " ReplaceKey() or RestoreKey() methods.\n" |
| 863 | "\n" |
| 864 | "If key represents a key on a remote computer, the path described by\n" |
| 865 | "file_name is relative to the remote computer.\n" |
| 866 | "\n" |
| 867 | "The caller of this method must possess the SeBackupPrivilege\n" |
| 868 | "security privilege. This function passes NULL for security_attributes\n" |
| 869 | "to the API."); |
| 870 | |
| 871 | #define WINREG_SAVEKEY_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 872 | {"SaveKey", (PyCFunction)(void(*)(void))winreg_SaveKey, METH_FASTCALL, winreg_SaveKey__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 873 | |
| 874 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 875 | winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 876 | |
| 877 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 878 | winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 879 | { |
| 880 | PyObject *return_value = NULL; |
| 881 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 882 | const Py_UNICODE *file_name; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 883 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 884 | if (!_PyArg_ParseStack(args, nargs, "O&u:SaveKey", |
| 885 | clinic_HKEY_converter, &key, &file_name)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 886 | goto exit; |
| 887 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 888 | return_value = winreg_SaveKey_impl(module, key, file_name); |
| 889 | |
| 890 | exit: |
| 891 | return return_value; |
| 892 | } |
| 893 | |
| 894 | PyDoc_STRVAR(winreg_SetValue__doc__, |
| 895 | "SetValue($module, key, sub_key, type, value, /)\n" |
| 896 | "--\n" |
| 897 | "\n" |
| 898 | "Associates a value with a specified key.\n" |
| 899 | "\n" |
| 900 | " key\n" |
| 901 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 902 | " sub_key\n" |
| 903 | " A string that names the subkey with which the value is associated.\n" |
| 904 | " type\n" |
| 905 | " An integer that specifies the type of the data. Currently this must\n" |
| 906 | " be REG_SZ, meaning only strings are supported.\n" |
| 907 | " value\n" |
| 908 | " A string that specifies the new value.\n" |
| 909 | "\n" |
| 910 | "If the key specified by the sub_key parameter does not exist, the\n" |
| 911 | "SetValue function creates it.\n" |
| 912 | "\n" |
| 913 | "Value lengths are limited by available memory. Long values (more than\n" |
| 914 | "2048 bytes) should be stored as files with the filenames stored in\n" |
| 915 | "the configuration registry to help the registry perform efficiently.\n" |
| 916 | "\n" |
| 917 | "The key identified by the key parameter must have been opened with\n" |
| 918 | "KEY_SET_VALUE access."); |
| 919 | |
| 920 | #define WINREG_SETVALUE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 921 | {"SetValue", (PyCFunction)(void(*)(void))winreg_SetValue, METH_FASTCALL, winreg_SetValue__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 922 | |
| 923 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 924 | winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, |
| 925 | DWORD type, const Py_UNICODE *value, |
Zachary Ware | 77772c0 | 2015-05-13 10:58:35 -0500 | [diff] [blame] | 926 | Py_ssize_clean_t value_length); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 927 | |
| 928 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 929 | winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 930 | { |
| 931 | PyObject *return_value = NULL; |
| 932 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 933 | const Py_UNICODE *sub_key; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 934 | DWORD type; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 935 | const Py_UNICODE *value; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 936 | Py_ssize_clean_t value_length; |
| 937 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 938 | if (!_PyArg_ParseStack(args, nargs, "O&Zku#:SetValue", |
| 939 | clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 940 | goto exit; |
| 941 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 942 | return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length); |
| 943 | |
| 944 | exit: |
| 945 | return return_value; |
| 946 | } |
| 947 | |
| 948 | PyDoc_STRVAR(winreg_SetValueEx__doc__, |
| 949 | "SetValueEx($module, key, value_name, reserved, type, value, /)\n" |
| 950 | "--\n" |
| 951 | "\n" |
| 952 | "Stores data in the value field of an open registry key.\n" |
| 953 | "\n" |
| 954 | " key\n" |
| 955 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 956 | " value_name\n" |
| 957 | " A string containing the name of the value to set, or None.\n" |
| 958 | " reserved\n" |
| 959 | " Can be anything - zero is always passed to the API.\n" |
| 960 | " type\n" |
| 961 | " An integer that specifies the type of the data, one of:\n" |
| 962 | " REG_BINARY -- Binary data in any form.\n" |
| 963 | " REG_DWORD -- A 32-bit number.\n" |
Serhiy Storchaka | 877826a | 2016-06-09 16:01:19 +0300 | [diff] [blame] | 964 | " REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n" |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 965 | " REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n" |
| 966 | " REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n" |
| 967 | " references to environment variables (for example,\n" |
| 968 | " %PATH%).\n" |
| 969 | " REG_LINK -- A Unicode symbolic link.\n" |
Serhiy Storchaka | 6a7b3a7 | 2016-04-17 08:32:47 +0300 | [diff] [blame] | 970 | " REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n" |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 971 | " by two null characters. Note that Python handles\n" |
| 972 | " this termination automatically.\n" |
| 973 | " REG_NONE -- No defined value type.\n" |
Serhiy Storchaka | 877826a | 2016-06-09 16:01:19 +0300 | [diff] [blame] | 974 | " REG_QWORD -- A 64-bit number.\n" |
| 975 | " REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n" |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 976 | " REG_RESOURCE_LIST -- A device-driver resource list.\n" |
| 977 | " REG_SZ -- A null-terminated string.\n" |
| 978 | " value\n" |
| 979 | " A string that specifies the new value.\n" |
| 980 | "\n" |
| 981 | "This method can also set additional value and type information for the\n" |
| 982 | "specified key. The key identified by the key parameter must have been\n" |
| 983 | "opened with KEY_SET_VALUE access.\n" |
| 984 | "\n" |
| 985 | "To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n" |
| 986 | "\n" |
| 987 | "Value lengths are limited by available memory. Long values (more than\n" |
| 988 | "2048 bytes) should be stored as files with the filenames stored in\n" |
| 989 | "the configuration registry to help the registry perform efficiently."); |
| 990 | |
| 991 | #define WINREG_SETVALUEEX_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 992 | {"SetValueEx", (PyCFunction)(void(*)(void))winreg_SetValueEx, METH_FASTCALL, winreg_SetValueEx__doc__}, |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 993 | |
| 994 | static PyObject * |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 995 | winreg_SetValueEx_impl(PyObject *module, HKEY key, |
| 996 | const Py_UNICODE *value_name, PyObject *reserved, |
| 997 | DWORD type, PyObject *value); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 998 | |
| 999 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 1000 | winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1001 | { |
| 1002 | PyObject *return_value = NULL; |
| 1003 | HKEY key; |
Serhiy Storchaka | afb3e71 | 2018-12-14 11:19:51 +0200 | [diff] [blame] | 1004 | const Py_UNICODE *value_name; |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1005 | PyObject *reserved; |
| 1006 | DWORD type; |
| 1007 | PyObject *value; |
| 1008 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 1009 | if (!_PyArg_ParseStack(args, nargs, "O&ZOkO:SetValueEx", |
| 1010 | clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 1011 | goto exit; |
| 1012 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1013 | return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value); |
| 1014 | |
| 1015 | exit: |
| 1016 | return return_value; |
| 1017 | } |
| 1018 | |
| 1019 | PyDoc_STRVAR(winreg_DisableReflectionKey__doc__, |
| 1020 | "DisableReflectionKey($module, key, /)\n" |
| 1021 | "--\n" |
| 1022 | "\n" |
| 1023 | "Disables registry reflection for 32bit processes running on a 64bit OS.\n" |
| 1024 | "\n" |
| 1025 | " key\n" |
| 1026 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 1027 | "\n" |
| 1028 | "Will generally raise NotImplemented if executed on a 32bit OS.\n" |
| 1029 | "\n" |
| 1030 | "If the key is not on the reflection list, the function succeeds but has\n" |
| 1031 | "no effect. Disabling reflection for a key does not affect reflection\n" |
| 1032 | "of any subkeys."); |
| 1033 | |
| 1034 | #define WINREG_DISABLEREFLECTIONKEY_METHODDEF \ |
| 1035 | {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__}, |
| 1036 | |
| 1037 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1038 | winreg_DisableReflectionKey_impl(PyObject *module, HKEY key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1039 | |
| 1040 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1041 | winreg_DisableReflectionKey(PyObject *module, PyObject *arg) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1042 | { |
| 1043 | PyObject *return_value = NULL; |
| 1044 | HKEY key; |
| 1045 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1046 | if (!clinic_HKEY_converter(arg, &key)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1047 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1048 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1049 | return_value = winreg_DisableReflectionKey_impl(module, key); |
| 1050 | |
| 1051 | exit: |
| 1052 | return return_value; |
| 1053 | } |
| 1054 | |
| 1055 | PyDoc_STRVAR(winreg_EnableReflectionKey__doc__, |
| 1056 | "EnableReflectionKey($module, key, /)\n" |
| 1057 | "--\n" |
| 1058 | "\n" |
| 1059 | "Restores registry reflection for the specified disabled key.\n" |
| 1060 | "\n" |
| 1061 | " key\n" |
| 1062 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 1063 | "\n" |
| 1064 | "Will generally raise NotImplemented if executed on a 32bit OS.\n" |
| 1065 | "Restoring reflection for a key does not affect reflection of any\n" |
| 1066 | "subkeys."); |
| 1067 | |
| 1068 | #define WINREG_ENABLEREFLECTIONKEY_METHODDEF \ |
| 1069 | {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__}, |
| 1070 | |
| 1071 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1072 | winreg_EnableReflectionKey_impl(PyObject *module, HKEY key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1073 | |
| 1074 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1075 | winreg_EnableReflectionKey(PyObject *module, PyObject *arg) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1076 | { |
| 1077 | PyObject *return_value = NULL; |
| 1078 | HKEY key; |
| 1079 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1080 | if (!clinic_HKEY_converter(arg, &key)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1081 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1082 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1083 | return_value = winreg_EnableReflectionKey_impl(module, key); |
| 1084 | |
| 1085 | exit: |
| 1086 | return return_value; |
| 1087 | } |
| 1088 | |
| 1089 | PyDoc_STRVAR(winreg_QueryReflectionKey__doc__, |
| 1090 | "QueryReflectionKey($module, key, /)\n" |
| 1091 | "--\n" |
| 1092 | "\n" |
| 1093 | "Returns the reflection state for the specified key as a bool.\n" |
| 1094 | "\n" |
| 1095 | " key\n" |
| 1096 | " An already open key, or any one of the predefined HKEY_* constants.\n" |
| 1097 | "\n" |
| 1098 | "Will generally raise NotImplemented if executed on a 32bit OS."); |
| 1099 | |
| 1100 | #define WINREG_QUERYREFLECTIONKEY_METHODDEF \ |
| 1101 | {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__}, |
| 1102 | |
| 1103 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1104 | winreg_QueryReflectionKey_impl(PyObject *module, HKEY key); |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1105 | |
| 1106 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 1107 | winreg_QueryReflectionKey(PyObject *module, PyObject *arg) |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1108 | { |
| 1109 | PyObject *return_value = NULL; |
| 1110 | HKEY key; |
| 1111 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 1112 | if (!clinic_HKEY_converter(arg, &key)) { |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1113 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 1114 | } |
Zachary Ware | fd2d482 | 2015-05-13 01:21:57 -0500 | [diff] [blame] | 1115 | return_value = winreg_QueryReflectionKey_impl(module, key); |
| 1116 | |
| 1117 | exit: |
| 1118 | return return_value; |
| 1119 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame^] | 1120 | /*[clinic end generated code: output=bd491131d343ae7a input=a9049054013a1b77]*/ |