blob: b7af1855ac5456b79c1a3445ab921dcd8518c844 [file] [log] [blame]
Zachary Warefd2d4822015-05-13 01:21:57 -05001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
16static PyObject *
17winreg_HKEYType_Close_impl(PyHKEYObject *self);
18
19static PyObject *
20winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
21{
22 return winreg_HKEYType_Close_impl(self);
23}
24
25PyDoc_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
42static PyObject *
43winreg_HKEYType_Detach_impl(PyHKEYObject *self);
44
45static PyObject *
46winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
47{
48 return winreg_HKEYType_Detach_impl(self);
49}
50
51PyDoc_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
59static PyHKEYObject *
60winreg_HKEYType___enter___impl(PyHKEYObject *self);
61
62static PyObject *
63winreg_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
74PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +020080 {"__exit__", (PyCFunction)(void(*)(void))winreg_HKEYType___exit__, METH_FASTCALL|METH_KEYWORDS, winreg_HKEYType___exit____doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -050081
82static PyObject *
Zachary Ware77772c02015-05-13 10:58:35 -050083winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type,
84 PyObject *exc_value, PyObject *traceback);
Zachary Warefd2d4822015-05-13 01:21:57 -050085
86static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020087winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -050088{
89 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030090 static const char * const _keywords[] = {"exc_type", "exc_value", "traceback", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020091 static _PyArg_Parser _parser = {NULL, _keywords, "__exit__", 0};
92 PyObject *argsbuf[3];
Zachary Warefd2d4822015-05-13 01:21:57 -050093 PyObject *exc_type;
94 PyObject *exc_value;
95 PyObject *traceback;
96
Serhiy Storchaka31913912019-03-14 10:32:22 +020097 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
98 if (!args) {
Zachary Warefd2d4822015-05-13 01:21:57 -050099 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300100 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200101 exc_type = args[0];
102 exc_value = args[1];
103 traceback = args[2];
Zachary Warefd2d4822015-05-13 01:21:57 -0500104 return_value = winreg_HKEYType___exit___impl(self, exc_type, exc_value, traceback);
105
106exit:
107 return return_value;
108}
109
110PyDoc_STRVAR(winreg_CloseKey__doc__,
111"CloseKey($module, hkey, /)\n"
112"--\n"
113"\n"
114"Closes a previously opened registry key.\n"
115"\n"
116" hkey\n"
117" A previously opened key.\n"
118"\n"
119"Note that if the key is not closed using this method, it will be\n"
120"closed when the hkey object is destroyed by Python.");
121
122#define WINREG_CLOSEKEY_METHODDEF \
123 {"CloseKey", (PyCFunction)winreg_CloseKey, METH_O, winreg_CloseKey__doc__},
124
125PyDoc_STRVAR(winreg_ConnectRegistry__doc__,
126"ConnectRegistry($module, computer_name, key, /)\n"
127"--\n"
128"\n"
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300129"Establishes a connection to the registry on another computer.\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500130"\n"
131" computer_name\n"
132" The name of the remote computer, of the form r\"\\\\computername\". If\n"
133" None, the local computer is used.\n"
134" key\n"
135" The predefined key to connect to.\n"
136"\n"
137"The return value is the handle of the opened key.\n"
138"If the function fails, an OSError exception is raised.");
139
140#define WINREG_CONNECTREGISTRY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200141 {"ConnectRegistry", (PyCFunction)(void(*)(void))winreg_ConnectRegistry, METH_FASTCALL, winreg_ConnectRegistry__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500142
143static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200144winreg_ConnectRegistry_impl(PyObject *module,
145 const Py_UNICODE *computer_name, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500146
147static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200148winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500149{
150 PyObject *return_value = NULL;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200151 const Py_UNICODE *computer_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500152 HKEY key;
153 HKEY _return_value;
154
Sylvain74453812017-06-10 06:51:48 +0200155 if (!_PyArg_ParseStack(args, nargs, "ZO&:ConnectRegistry",
156 &computer_name, clinic_HKEY_converter, &key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100157 goto exit;
158 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500159 _return_value = winreg_ConnectRegistry_impl(module, computer_name, key);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300160 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500161 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300162 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500163 return_value = PyHKEY_FromHKEY(_return_value);
164
165exit:
166 return return_value;
167}
168
169PyDoc_STRVAR(winreg_CreateKey__doc__,
170"CreateKey($module, key, sub_key, /)\n"
171"--\n"
172"\n"
173"Creates or opens the specified key.\n"
174"\n"
175" key\n"
176" An already open key, or one of the predefined HKEY_* constants.\n"
177" sub_key\n"
178" The name of the key this method opens or creates.\n"
179"\n"
180"If key is one of the predefined keys, sub_key may be None. In that case,\n"
181"the handle returned is the same key handle passed in to the function.\n"
182"\n"
183"If the key already exists, this function opens the existing key.\n"
184"\n"
185"The return value is the handle of the opened key.\n"
186"If the function fails, an OSError exception is raised.");
187
188#define WINREG_CREATEKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200189 {"CreateKey", (PyCFunction)(void(*)(void))winreg_CreateKey, METH_FASTCALL, winreg_CreateKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500190
191static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200192winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500193
194static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200195winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500196{
197 PyObject *return_value = NULL;
198 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200199 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500200 HKEY _return_value;
201
Sylvain74453812017-06-10 06:51:48 +0200202 if (!_PyArg_ParseStack(args, nargs, "O&Z:CreateKey",
203 clinic_HKEY_converter, &key, &sub_key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100204 goto exit;
205 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500206 _return_value = winreg_CreateKey_impl(module, key, sub_key);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300207 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500208 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300209 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500210 return_value = PyHKEY_FromHKEY(_return_value);
211
212exit:
213 return return_value;
214}
215
216PyDoc_STRVAR(winreg_CreateKeyEx__doc__,
217"CreateKeyEx($module, /, key, sub_key, reserved=0,\n"
218" access=winreg.KEY_WRITE)\n"
219"--\n"
220"\n"
221"Creates or opens the specified key.\n"
222"\n"
223" key\n"
224" An already open key, or one of the predefined HKEY_* constants.\n"
225" sub_key\n"
226" The name of the key this method opens or creates.\n"
227" reserved\n"
228" A reserved integer, and must be zero. Default is zero.\n"
229" access\n"
230" An integer that specifies an access mask that describes the\n"
231" desired security access for the key. Default is KEY_WRITE.\n"
232"\n"
233"If key is one of the predefined keys, sub_key may be None. In that case,\n"
234"the handle returned is the same key handle passed in to the function.\n"
235"\n"
236"If the key already exists, this function opens the existing key\n"
237"\n"
238"The return value is the handle of the opened key.\n"
239"If the function fails, an OSError exception is raised.");
240
241#define WINREG_CREATEKEYEX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200242 {"CreateKeyEx", (PyCFunction)(void(*)(void))winreg_CreateKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_CreateKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500243
244static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200245winreg_CreateKeyEx_impl(PyObject *module, HKEY key,
246 const Py_UNICODE *sub_key, int reserved,
247 REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500248
249static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200250winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500251{
252 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300253 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
254 static _PyArg_Parser _parser = {"O&Z|ii:CreateKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500255 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200256 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500257 int reserved = 0;
258 REGSAM access = KEY_WRITE;
259 HKEY _return_value;
260
Victor Stinner3e1fad62017-01-17 01:29:01 +0100261 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300262 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500263 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300264 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500265 _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300266 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500267 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300268 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500269 return_value = PyHKEY_FromHKEY(_return_value);
270
271exit:
272 return return_value;
273}
274
275PyDoc_STRVAR(winreg_DeleteKey__doc__,
276"DeleteKey($module, key, sub_key, /)\n"
277"--\n"
278"\n"
279"Deletes the specified key.\n"
280"\n"
281" key\n"
282" An already open key, or any one of the predefined HKEY_* constants.\n"
283" sub_key\n"
284" A string that must be the name of a subkey of the key identified by\n"
285" the key parameter. This value must not be None, and the key may not\n"
286" have subkeys.\n"
287"\n"
288"This method can not delete keys with subkeys.\n"
289"\n"
290"If the function succeeds, the entire key, including all of its values,\n"
291"is removed. If the function fails, an OSError exception is raised.");
292
293#define WINREG_DELETEKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200294 {"DeleteKey", (PyCFunction)(void(*)(void))winreg_DeleteKey, METH_FASTCALL, winreg_DeleteKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500295
296static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200297winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500298
299static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200300winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500301{
302 PyObject *return_value = NULL;
303 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200304 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500305
Sylvain74453812017-06-10 06:51:48 +0200306 if (!_PyArg_ParseStack(args, nargs, "O&u:DeleteKey",
307 clinic_HKEY_converter, &key, &sub_key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100308 goto exit;
309 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500310 return_value = winreg_DeleteKey_impl(module, key, sub_key);
311
312exit:
313 return return_value;
314}
315
316PyDoc_STRVAR(winreg_DeleteKeyEx__doc__,
317"DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n"
318" reserved=0)\n"
319"--\n"
320"\n"
321"Deletes the specified key (64-bit OS only).\n"
322"\n"
323" key\n"
324" An already open key, or any one of the predefined HKEY_* constants.\n"
325" sub_key\n"
326" A string that must be the name of a subkey of the key identified by\n"
327" the key parameter. This value must not be None, and the key may not\n"
328" have subkeys.\n"
329" access\n"
330" An integer that specifies an access mask that describes the\n"
331" desired security access for the key. Default is KEY_WOW64_64KEY.\n"
332" reserved\n"
333" A reserved integer, and must be zero. Default is zero.\n"
334"\n"
335"This method can not delete keys with subkeys.\n"
336"\n"
337"If the function succeeds, the entire key, including all of its values,\n"
338"is removed. If the function fails, an OSError exception is raised.\n"
339"On unsupported Windows versions, NotImplementedError is raised.");
340
341#define WINREG_DELETEKEYEX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200342 {"DeleteKeyEx", (PyCFunction)(void(*)(void))winreg_DeleteKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_DeleteKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500343
344static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200345winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
346 const Py_UNICODE *sub_key, REGSAM access,
347 int reserved);
Zachary Warefd2d4822015-05-13 01:21:57 -0500348
349static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200350winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500351{
352 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300353 static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL};
354 static _PyArg_Parser _parser = {"O&u|ii:DeleteKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500355 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200356 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500357 REGSAM access = KEY_WOW64_64KEY;
358 int reserved = 0;
359
Victor Stinner3e1fad62017-01-17 01:29:01 +0100360 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300361 clinic_HKEY_converter, &key, &sub_key, &access, &reserved)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500362 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300363 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500364 return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
365
366exit:
367 return return_value;
368}
369
370PyDoc_STRVAR(winreg_DeleteValue__doc__,
371"DeleteValue($module, key, value, /)\n"
372"--\n"
373"\n"
374"Removes a named value from a registry key.\n"
375"\n"
376" key\n"
377" An already open key, or any one of the predefined HKEY_* constants.\n"
378" value\n"
379" A string that identifies the value to remove.");
380
381#define WINREG_DELETEVALUE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200382 {"DeleteValue", (PyCFunction)(void(*)(void))winreg_DeleteValue, METH_FASTCALL, winreg_DeleteValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500383
384static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200385winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value);
Zachary Warefd2d4822015-05-13 01:21:57 -0500386
387static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200388winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500389{
390 PyObject *return_value = NULL;
391 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200392 const Py_UNICODE *value;
Zachary Warefd2d4822015-05-13 01:21:57 -0500393
Sylvain74453812017-06-10 06:51:48 +0200394 if (!_PyArg_ParseStack(args, nargs, "O&Z:DeleteValue",
395 clinic_HKEY_converter, &key, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100396 goto exit;
397 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500398 return_value = winreg_DeleteValue_impl(module, key, value);
399
400exit:
401 return return_value;
402}
403
404PyDoc_STRVAR(winreg_EnumKey__doc__,
405"EnumKey($module, key, index, /)\n"
406"--\n"
407"\n"
408"Enumerates subkeys of an open registry key.\n"
409"\n"
410" key\n"
411" An already open key, or any one of the predefined HKEY_* constants.\n"
412" index\n"
413" An integer that identifies the index of the key to retrieve.\n"
414"\n"
415"The function retrieves the name of one subkey each time it is called.\n"
416"It is typically called repeatedly until an OSError exception is\n"
417"raised, indicating no more values are available.");
418
419#define WINREG_ENUMKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200420 {"EnumKey", (PyCFunction)(void(*)(void))winreg_EnumKey, METH_FASTCALL, winreg_EnumKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500421
422static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300423winreg_EnumKey_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500424
425static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200426winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500427{
428 PyObject *return_value = NULL;
429 HKEY key;
430 int index;
431
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200432 if (!_PyArg_CheckPositional("EnumKey", nargs, 2, 2)) {
433 goto exit;
434 }
435 if (!clinic_HKEY_converter(args[0], &key)) {
436 goto exit;
437 }
438 if (PyFloat_Check(args[1])) {
439 PyErr_SetString(PyExc_TypeError,
440 "integer argument expected, got float" );
441 goto exit;
442 }
443 index = _PyLong_AsInt(args[1]);
444 if (index == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100445 goto exit;
446 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500447 return_value = winreg_EnumKey_impl(module, key, index);
448
449exit:
450 return return_value;
451}
452
453PyDoc_STRVAR(winreg_EnumValue__doc__,
454"EnumValue($module, key, index, /)\n"
455"--\n"
456"\n"
457"Enumerates values of an open registry key.\n"
458"\n"
459" key\n"
460" An already open key, or any one of the predefined HKEY_* constants.\n"
461" index\n"
462" An integer that identifies the index of the value to retrieve.\n"
463"\n"
464"The function retrieves the name of one subkey each time it is called.\n"
465"It is typically called repeatedly, until an OSError exception\n"
466"is raised, indicating no more values.\n"
467"\n"
468"The result is a tuple of 3 items:\n"
469" value_name\n"
470" A string that identifies the value.\n"
471" value_data\n"
472" An object that holds the value data, and whose type depends\n"
473" on the underlying registry type.\n"
474" data_type\n"
475" An integer that identifies the type of the value data.");
476
477#define WINREG_ENUMVALUE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200478 {"EnumValue", (PyCFunction)(void(*)(void))winreg_EnumValue, METH_FASTCALL, winreg_EnumValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500479
480static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300481winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500482
483static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200484winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500485{
486 PyObject *return_value = NULL;
487 HKEY key;
488 int index;
489
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200490 if (!_PyArg_CheckPositional("EnumValue", nargs, 2, 2)) {
491 goto exit;
492 }
493 if (!clinic_HKEY_converter(args[0], &key)) {
494 goto exit;
495 }
496 if (PyFloat_Check(args[1])) {
497 PyErr_SetString(PyExc_TypeError,
498 "integer argument expected, got float" );
499 goto exit;
500 }
501 index = _PyLong_AsInt(args[1]);
502 if (index == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100503 goto exit;
504 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500505 return_value = winreg_EnumValue_impl(module, key, index);
506
507exit:
508 return return_value;
509}
510
511PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__,
512"ExpandEnvironmentStrings($module, string, /)\n"
513"--\n"
514"\n"
515"Expand environment vars.");
516
517#define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF \
518 {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__},
519
520static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200521winreg_ExpandEnvironmentStrings_impl(PyObject *module,
522 const Py_UNICODE *string);
Zachary Warefd2d4822015-05-13 01:21:57 -0500523
524static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300525winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500526{
527 PyObject *return_value = NULL;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200528 const Py_UNICODE *string;
Zachary Warefd2d4822015-05-13 01:21:57 -0500529
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300530 if (!PyArg_Parse(arg, "u:ExpandEnvironmentStrings", &string)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500531 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300532 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500533 return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
534
535exit:
536 return return_value;
537}
538
539PyDoc_STRVAR(winreg_FlushKey__doc__,
540"FlushKey($module, key, /)\n"
541"--\n"
542"\n"
543"Writes all the attributes of a key to the registry.\n"
544"\n"
545" key\n"
546" An already open key, or any one of the predefined HKEY_* constants.\n"
547"\n"
548"It is not necessary to call FlushKey to change a key. Registry changes\n"
549"are flushed to disk by the registry using its lazy flusher. Registry\n"
550"changes are also flushed to disk at system shutdown. Unlike\n"
551"CloseKey(), the FlushKey() method returns only when all the data has\n"
552"been written to the registry.\n"
553"\n"
554"An application should only call FlushKey() if it requires absolute\n"
555"certainty that registry changes are on disk. If you don\'t know whether\n"
556"a FlushKey() call is required, it probably isn\'t.");
557
558#define WINREG_FLUSHKEY_METHODDEF \
559 {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__},
560
561static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300562winreg_FlushKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500563
564static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300565winreg_FlushKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500566{
567 PyObject *return_value = NULL;
568 HKEY key;
569
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200570 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500571 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300572 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500573 return_value = winreg_FlushKey_impl(module, key);
574
575exit:
576 return return_value;
577}
578
579PyDoc_STRVAR(winreg_LoadKey__doc__,
580"LoadKey($module, key, sub_key, file_name, /)\n"
581"--\n"
582"\n"
583"Insert data into the registry from a file.\n"
584"\n"
585" key\n"
586" An already open key, or any one of the predefined HKEY_* constants.\n"
587" sub_key\n"
588" A string that identifies the sub-key to load.\n"
589" file_name\n"
590" The name of the file to load registry data from. This file must\n"
591" have been created with the SaveKey() function. Under the file\n"
592" allocation table (FAT) file system, the filename may not have an\n"
593" extension.\n"
594"\n"
595"Creates a subkey under the specified key and stores registration\n"
596"information from a specified file into that subkey.\n"
597"\n"
598"A call to LoadKey() fails if the calling process does not have the\n"
599"SE_RESTORE_PRIVILEGE privilege.\n"
600"\n"
601"If key is a handle returned by ConnectRegistry(), then the path\n"
602"specified in fileName is relative to the remote computer.\n"
603"\n"
604"The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n"
605"tree.");
606
607#define WINREG_LOADKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200608 {"LoadKey", (PyCFunction)(void(*)(void))winreg_LoadKey, METH_FASTCALL, winreg_LoadKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500609
610static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200611winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
612 const Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500613
614static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200615winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500616{
617 PyObject *return_value = NULL;
618 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200619 const Py_UNICODE *sub_key;
620 const Py_UNICODE *file_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500621
Sylvain74453812017-06-10 06:51:48 +0200622 if (!_PyArg_ParseStack(args, nargs, "O&uu:LoadKey",
623 clinic_HKEY_converter, &key, &sub_key, &file_name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100624 goto exit;
625 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500626 return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
627
628exit:
629 return return_value;
630}
631
632PyDoc_STRVAR(winreg_OpenKey__doc__,
633"OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
634"--\n"
635"\n"
636"Opens the specified key.\n"
637"\n"
638" key\n"
639" An already open key, or any one of the predefined HKEY_* constants.\n"
640" sub_key\n"
641" A string that identifies the sub_key to open.\n"
642" reserved\n"
643" A reserved integer that must be zero. Default is zero.\n"
644" access\n"
645" An integer that specifies an access mask that describes the desired\n"
646" security access for the key. Default is KEY_READ.\n"
647"\n"
648"The result is a new handle to the specified key.\n"
649"If the function fails, an OSError exception is raised.");
650
651#define WINREG_OPENKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200652 {"OpenKey", (PyCFunction)(void(*)(void))winreg_OpenKey, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500653
654static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200655winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500656 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500657
658static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200659winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500660{
661 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300662 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
663 static _PyArg_Parser _parser = {"O&Z|ii:OpenKey", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500664 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200665 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500666 int reserved = 0;
667 REGSAM access = KEY_READ;
668 HKEY _return_value;
669
Victor Stinner3e1fad62017-01-17 01:29:01 +0100670 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300671 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500672 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300673 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500674 _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300675 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500676 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300677 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500678 return_value = PyHKEY_FromHKEY(_return_value);
679
680exit:
681 return return_value;
682}
683
684PyDoc_STRVAR(winreg_OpenKeyEx__doc__,
685"OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
686"--\n"
687"\n"
688"Opens the specified key.\n"
689"\n"
690" key\n"
691" An already open key, or any one of the predefined HKEY_* constants.\n"
692" sub_key\n"
693" A string that identifies the sub_key to open.\n"
694" reserved\n"
695" A reserved integer that must be zero. Default is zero.\n"
696" access\n"
697" An integer that specifies an access mask that describes the desired\n"
698" security access for the key. Default is KEY_READ.\n"
699"\n"
700"The result is a new handle to the specified key.\n"
701"If the function fails, an OSError exception is raised.");
702
703#define WINREG_OPENKEYEX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200704 {"OpenKeyEx", (PyCFunction)(void(*)(void))winreg_OpenKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500705
706static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200707winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500708 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500709
710static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200711winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500712{
713 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300714 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
715 static _PyArg_Parser _parser = {"O&Z|ii:OpenKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500716 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200717 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500718 int reserved = 0;
719 REGSAM access = KEY_READ;
720 HKEY _return_value;
721
Victor Stinner3e1fad62017-01-17 01:29:01 +0100722 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300723 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500724 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300725 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500726 _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300727 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500728 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300729 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500730 return_value = PyHKEY_FromHKEY(_return_value);
731
732exit:
733 return return_value;
734}
735
736PyDoc_STRVAR(winreg_QueryInfoKey__doc__,
737"QueryInfoKey($module, key, /)\n"
738"--\n"
739"\n"
740"Returns information about a key.\n"
741"\n"
742" key\n"
743" An already open key, or any one of the predefined HKEY_* constants.\n"
744"\n"
745"The result is a tuple of 3 items:\n"
746"An integer that identifies the number of sub keys this key has.\n"
747"An integer that identifies the number of values this key has.\n"
748"An integer that identifies when the key was last modified (if available)\n"
749"as 100\'s of nanoseconds since Jan 1, 1600.");
750
751#define WINREG_QUERYINFOKEY_METHODDEF \
752 {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__},
753
754static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300755winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500756
757static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300758winreg_QueryInfoKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500759{
760 PyObject *return_value = NULL;
761 HKEY key;
762
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200763 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500764 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300765 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500766 return_value = winreg_QueryInfoKey_impl(module, key);
767
768exit:
769 return return_value;
770}
771
772PyDoc_STRVAR(winreg_QueryValue__doc__,
773"QueryValue($module, key, sub_key, /)\n"
774"--\n"
775"\n"
776"Retrieves the unnamed value for a key.\n"
777"\n"
778" key\n"
779" An already open key, or any one of the predefined HKEY_* constants.\n"
780" sub_key\n"
781" A string that holds the name of the subkey with which the value\n"
782" is associated. If this parameter is None or empty, the function\n"
783" retrieves the value set by the SetValue() method for the key\n"
784" identified by key.\n"
785"\n"
786"Values in the registry have name, type, and data components. This method\n"
787"retrieves the data for a key\'s first value that has a NULL name.\n"
788"But since the underlying API call doesn\'t return the type, you\'ll\n"
789"probably be happier using QueryValueEx; this function is just here for\n"
790"completeness.");
791
792#define WINREG_QUERYVALUE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200793 {"QueryValue", (PyCFunction)(void(*)(void))winreg_QueryValue, METH_FASTCALL, winreg_QueryValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500794
795static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200796winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500797
798static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200799winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500800{
801 PyObject *return_value = NULL;
802 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200803 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500804
Sylvain74453812017-06-10 06:51:48 +0200805 if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValue",
806 clinic_HKEY_converter, &key, &sub_key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100807 goto exit;
808 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500809 return_value = winreg_QueryValue_impl(module, key, sub_key);
810
811exit:
812 return return_value;
813}
814
815PyDoc_STRVAR(winreg_QueryValueEx__doc__,
816"QueryValueEx($module, key, name, /)\n"
817"--\n"
818"\n"
819"Retrieves the type and value of a specified sub-key.\n"
820"\n"
821" key\n"
822" An already open key, or any one of the predefined HKEY_* constants.\n"
823" name\n"
824" A string indicating the value to query.\n"
825"\n"
826"Behaves mostly like QueryValue(), but also returns the type of the\n"
827"specified value name associated with the given open registry key.\n"
828"\n"
829"The return value is a tuple of the value and the type_id.");
830
831#define WINREG_QUERYVALUEEX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200832 {"QueryValueEx", (PyCFunction)(void(*)(void))winreg_QueryValueEx, METH_FASTCALL, winreg_QueryValueEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500833
834static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200835winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500836
837static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200838winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500839{
840 PyObject *return_value = NULL;
841 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200842 const Py_UNICODE *name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500843
Sylvain74453812017-06-10 06:51:48 +0200844 if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValueEx",
845 clinic_HKEY_converter, &key, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100846 goto exit;
847 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500848 return_value = winreg_QueryValueEx_impl(module, key, name);
849
850exit:
851 return return_value;
852}
853
854PyDoc_STRVAR(winreg_SaveKey__doc__,
855"SaveKey($module, key, file_name, /)\n"
856"--\n"
857"\n"
858"Saves the specified key, and all its subkeys to the specified file.\n"
859"\n"
860" key\n"
861" An already open key, or any one of the predefined HKEY_* constants.\n"
862" file_name\n"
863" The name of the file to save registry data to. This file cannot\n"
864" already exist. If this filename includes an extension, it cannot be\n"
865" used on file allocation table (FAT) file systems by the LoadKey(),\n"
866" ReplaceKey() or RestoreKey() methods.\n"
867"\n"
868"If key represents a key on a remote computer, the path described by\n"
869"file_name is relative to the remote computer.\n"
870"\n"
871"The caller of this method must possess the SeBackupPrivilege\n"
872"security privilege. This function passes NULL for security_attributes\n"
873"to the API.");
874
875#define WINREG_SAVEKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200876 {"SaveKey", (PyCFunction)(void(*)(void))winreg_SaveKey, METH_FASTCALL, winreg_SaveKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500877
878static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200879winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500880
881static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200882winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500883{
884 PyObject *return_value = NULL;
885 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200886 const Py_UNICODE *file_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500887
Sylvain74453812017-06-10 06:51:48 +0200888 if (!_PyArg_ParseStack(args, nargs, "O&u:SaveKey",
889 clinic_HKEY_converter, &key, &file_name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100890 goto exit;
891 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500892 return_value = winreg_SaveKey_impl(module, key, file_name);
893
894exit:
895 return return_value;
896}
897
898PyDoc_STRVAR(winreg_SetValue__doc__,
899"SetValue($module, key, sub_key, type, value, /)\n"
900"--\n"
901"\n"
902"Associates a value with a specified key.\n"
903"\n"
904" key\n"
905" An already open key, or any one of the predefined HKEY_* constants.\n"
906" sub_key\n"
907" A string that names the subkey with which the value is associated.\n"
908" type\n"
909" An integer that specifies the type of the data. Currently this must\n"
910" be REG_SZ, meaning only strings are supported.\n"
911" value\n"
912" A string that specifies the new value.\n"
913"\n"
914"If the key specified by the sub_key parameter does not exist, the\n"
915"SetValue function creates it.\n"
916"\n"
917"Value lengths are limited by available memory. Long values (more than\n"
918"2048 bytes) should be stored as files with the filenames stored in\n"
919"the configuration registry to help the registry perform efficiently.\n"
920"\n"
921"The key identified by the key parameter must have been opened with\n"
922"KEY_SET_VALUE access.");
923
924#define WINREG_SETVALUE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200925 {"SetValue", (PyCFunction)(void(*)(void))winreg_SetValue, METH_FASTCALL, winreg_SetValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500926
927static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200928winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
929 DWORD type, const Py_UNICODE *value,
Zachary Ware77772c02015-05-13 10:58:35 -0500930 Py_ssize_clean_t value_length);
Zachary Warefd2d4822015-05-13 01:21:57 -0500931
932static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200933winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500934{
935 PyObject *return_value = NULL;
936 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200937 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500938 DWORD type;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200939 const Py_UNICODE *value;
Zachary Warefd2d4822015-05-13 01:21:57 -0500940 Py_ssize_clean_t value_length;
941
Sylvain74453812017-06-10 06:51:48 +0200942 if (!_PyArg_ParseStack(args, nargs, "O&Zku#:SetValue",
943 clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100944 goto exit;
945 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500946 return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length);
947
948exit:
949 return return_value;
950}
951
952PyDoc_STRVAR(winreg_SetValueEx__doc__,
953"SetValueEx($module, key, value_name, reserved, type, value, /)\n"
954"--\n"
955"\n"
956"Stores data in the value field of an open registry key.\n"
957"\n"
958" key\n"
959" An already open key, or any one of the predefined HKEY_* constants.\n"
960" value_name\n"
961" A string containing the name of the value to set, or None.\n"
962" reserved\n"
963" Can be anything - zero is always passed to the API.\n"
964" type\n"
965" An integer that specifies the type of the data, one of:\n"
966" REG_BINARY -- Binary data in any form.\n"
967" REG_DWORD -- A 32-bit number.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300968" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500969" REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
970" REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n"
971" references to environment variables (for example,\n"
972" %PATH%).\n"
973" REG_LINK -- A Unicode symbolic link.\n"
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300974" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500975" by two null characters. Note that Python handles\n"
976" this termination automatically.\n"
977" REG_NONE -- No defined value type.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300978" REG_QWORD -- A 64-bit number.\n"
979" REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500980" REG_RESOURCE_LIST -- A device-driver resource list.\n"
981" REG_SZ -- A null-terminated string.\n"
982" value\n"
983" A string that specifies the new value.\n"
984"\n"
985"This method can also set additional value and type information for the\n"
986"specified key. The key identified by the key parameter must have been\n"
987"opened with KEY_SET_VALUE access.\n"
988"\n"
989"To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
990"\n"
991"Value lengths are limited by available memory. Long values (more than\n"
992"2048 bytes) should be stored as files with the filenames stored in\n"
993"the configuration registry to help the registry perform efficiently.");
994
995#define WINREG_SETVALUEEX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200996 {"SetValueEx", (PyCFunction)(void(*)(void))winreg_SetValueEx, METH_FASTCALL, winreg_SetValueEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500997
998static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200999winreg_SetValueEx_impl(PyObject *module, HKEY key,
1000 const Py_UNICODE *value_name, PyObject *reserved,
1001 DWORD type, PyObject *value);
Zachary Warefd2d4822015-05-13 01:21:57 -05001002
1003static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001004winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -05001005{
1006 PyObject *return_value = NULL;
1007 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001008 const Py_UNICODE *value_name;
Zachary Warefd2d4822015-05-13 01:21:57 -05001009 PyObject *reserved;
1010 DWORD type;
1011 PyObject *value;
1012
Sylvain74453812017-06-10 06:51:48 +02001013 if (!_PyArg_ParseStack(args, nargs, "O&ZOkO:SetValueEx",
1014 clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001015 goto exit;
1016 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001017 return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
1018
1019exit:
1020 return return_value;
1021}
1022
1023PyDoc_STRVAR(winreg_DisableReflectionKey__doc__,
1024"DisableReflectionKey($module, key, /)\n"
1025"--\n"
1026"\n"
1027"Disables registry reflection for 32bit processes running on a 64bit OS.\n"
1028"\n"
1029" key\n"
1030" An already open key, or any one of the predefined HKEY_* constants.\n"
1031"\n"
David Hed5e8e02019-07-31 23:49:55 +01001032"Will generally raise NotImplementedError if executed on a 32bit OS.\n"
Zachary Warefd2d4822015-05-13 01:21:57 -05001033"\n"
1034"If the key is not on the reflection list, the function succeeds but has\n"
1035"no effect. Disabling reflection for a key does not affect reflection\n"
1036"of any subkeys.");
1037
1038#define WINREG_DISABLEREFLECTIONKEY_METHODDEF \
1039 {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__},
1040
1041static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001042winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001043
1044static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001045winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001046{
1047 PyObject *return_value = NULL;
1048 HKEY key;
1049
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001050 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001051 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001052 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001053 return_value = winreg_DisableReflectionKey_impl(module, key);
1054
1055exit:
1056 return return_value;
1057}
1058
1059PyDoc_STRVAR(winreg_EnableReflectionKey__doc__,
1060"EnableReflectionKey($module, key, /)\n"
1061"--\n"
1062"\n"
1063"Restores registry reflection for the specified disabled key.\n"
1064"\n"
1065" key\n"
1066" An already open key, or any one of the predefined HKEY_* constants.\n"
1067"\n"
David Hed5e8e02019-07-31 23:49:55 +01001068"Will generally raise NotImplementedError if executed on a 32bit OS.\n"
Zachary Warefd2d4822015-05-13 01:21:57 -05001069"Restoring reflection for a key does not affect reflection of any\n"
1070"subkeys.");
1071
1072#define WINREG_ENABLEREFLECTIONKEY_METHODDEF \
1073 {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__},
1074
1075static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001076winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001077
1078static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001079winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001080{
1081 PyObject *return_value = NULL;
1082 HKEY key;
1083
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001084 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001085 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001086 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001087 return_value = winreg_EnableReflectionKey_impl(module, key);
1088
1089exit:
1090 return return_value;
1091}
1092
1093PyDoc_STRVAR(winreg_QueryReflectionKey__doc__,
1094"QueryReflectionKey($module, key, /)\n"
1095"--\n"
1096"\n"
1097"Returns the reflection state for the specified key as a bool.\n"
1098"\n"
1099" key\n"
1100" An already open key, or any one of the predefined HKEY_* constants.\n"
1101"\n"
David Hed5e8e02019-07-31 23:49:55 +01001102"Will generally raise NotImplementedError if executed on a 32bit OS.");
Zachary Warefd2d4822015-05-13 01:21:57 -05001103
1104#define WINREG_QUERYREFLECTIONKEY_METHODDEF \
1105 {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__},
1106
1107static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001108winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001109
1110static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001111winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001112{
1113 PyObject *return_value = NULL;
1114 HKEY key;
1115
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001116 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001117 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001118 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001119 return_value = winreg_QueryReflectionKey_impl(module, key);
1120
1121exit:
1122 return return_value;
1123}
David Hed5e8e02019-07-31 23:49:55 +01001124/*[clinic end generated code: output=015afbbd690eb59d input=a9049054013a1b77]*/