blob: 21a9302d0af77e1f06ad7fec7b43d4e215efd1e2 [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};
91 static _PyArg_Parser _parser = {"OOO:__exit__", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -050092 PyObject *exc_type;
93 PyObject *exc_value;
94 PyObject *traceback;
95
Victor Stinner3e1fad62017-01-17 01:29:01 +010096 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030097 &exc_type, &exc_value, &traceback)) {
Zachary Warefd2d4822015-05-13 01:21:57 -050098 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030099 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500100 return_value = winreg_HKEYType___exit___impl(self, exc_type, exc_value, traceback);
101
102exit:
103 return return_value;
104}
105
106PyDoc_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
121PyDoc_STRVAR(winreg_ConnectRegistry__doc__,
122"ConnectRegistry($module, computer_name, key, /)\n"
123"--\n"
124"\n"
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300125"Establishes a connection to the registry on another computer.\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500126"\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 Storchaka4a934d42018-11-27 11:27:36 +0200137 {"ConnectRegistry", (PyCFunction)(void(*)(void))winreg_ConnectRegistry, METH_FASTCALL, winreg_ConnectRegistry__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500138
139static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200140winreg_ConnectRegistry_impl(PyObject *module,
141 const Py_UNICODE *computer_name, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500142
143static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200144winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500145{
146 PyObject *return_value = NULL;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200147 const Py_UNICODE *computer_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500148 HKEY key;
149 HKEY _return_value;
150
Sylvain74453812017-06-10 06:51:48 +0200151 if (!_PyArg_ParseStack(args, nargs, "ZO&:ConnectRegistry",
152 &computer_name, clinic_HKEY_converter, &key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100153 goto exit;
154 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500155 _return_value = winreg_ConnectRegistry_impl(module, computer_name, key);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300156 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500157 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300158 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500159 return_value = PyHKEY_FromHKEY(_return_value);
160
161exit:
162 return return_value;
163}
164
165PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200185 {"CreateKey", (PyCFunction)(void(*)(void))winreg_CreateKey, METH_FASTCALL, winreg_CreateKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500186
187static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200188winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500189
190static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200191winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500192{
193 PyObject *return_value = NULL;
194 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200195 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500196 HKEY _return_value;
197
Sylvain74453812017-06-10 06:51:48 +0200198 if (!_PyArg_ParseStack(args, nargs, "O&Z:CreateKey",
199 clinic_HKEY_converter, &key, &sub_key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100200 goto exit;
201 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500202 _return_value = winreg_CreateKey_impl(module, key, sub_key);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300203 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500204 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300205 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500206 return_value = PyHKEY_FromHKEY(_return_value);
207
208exit:
209 return return_value;
210}
211
212PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200238 {"CreateKeyEx", (PyCFunction)(void(*)(void))winreg_CreateKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_CreateKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500239
240static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200241winreg_CreateKeyEx_impl(PyObject *module, HKEY key,
242 const Py_UNICODE *sub_key, int reserved,
243 REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500244
245static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200246winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500247{
248 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300249 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
250 static _PyArg_Parser _parser = {"O&Z|ii:CreateKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500251 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200252 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500253 int reserved = 0;
254 REGSAM access = KEY_WRITE;
255 HKEY _return_value;
256
Victor Stinner3e1fad62017-01-17 01:29:01 +0100257 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300258 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500259 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300260 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500261 _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300262 if (_return_value == NULL) {
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 = PyHKEY_FromHKEY(_return_value);
266
267exit:
268 return return_value;
269}
270
271PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200290 {"DeleteKey", (PyCFunction)(void(*)(void))winreg_DeleteKey, METH_FASTCALL, winreg_DeleteKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500291
292static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200293winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500294
295static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200296winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500297{
298 PyObject *return_value = NULL;
299 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200300 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500301
Sylvain74453812017-06-10 06:51:48 +0200302 if (!_PyArg_ParseStack(args, nargs, "O&u:DeleteKey",
303 clinic_HKEY_converter, &key, &sub_key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100304 goto exit;
305 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500306 return_value = winreg_DeleteKey_impl(module, key, sub_key);
307
308exit:
309 return return_value;
310}
311
312PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200338 {"DeleteKeyEx", (PyCFunction)(void(*)(void))winreg_DeleteKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_DeleteKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500339
340static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200341winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
342 const Py_UNICODE *sub_key, REGSAM access,
343 int reserved);
Zachary Warefd2d4822015-05-13 01:21:57 -0500344
345static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200346winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500347{
348 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300349 static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL};
350 static _PyArg_Parser _parser = {"O&u|ii:DeleteKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500351 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200352 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500353 REGSAM access = KEY_WOW64_64KEY;
354 int reserved = 0;
355
Victor Stinner3e1fad62017-01-17 01:29:01 +0100356 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300357 clinic_HKEY_converter, &key, &sub_key, &access, &reserved)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500358 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300359 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500360 return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
361
362exit:
363 return return_value;
364}
365
366PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200378 {"DeleteValue", (PyCFunction)(void(*)(void))winreg_DeleteValue, METH_FASTCALL, winreg_DeleteValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500379
380static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200381winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value);
Zachary Warefd2d4822015-05-13 01:21:57 -0500382
383static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200384winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500385{
386 PyObject *return_value = NULL;
387 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200388 const Py_UNICODE *value;
Zachary Warefd2d4822015-05-13 01:21:57 -0500389
Sylvain74453812017-06-10 06:51:48 +0200390 if (!_PyArg_ParseStack(args, nargs, "O&Z:DeleteValue",
391 clinic_HKEY_converter, &key, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100392 goto exit;
393 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500394 return_value = winreg_DeleteValue_impl(module, key, value);
395
396exit:
397 return return_value;
398}
399
400PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200416 {"EnumKey", (PyCFunction)(void(*)(void))winreg_EnumKey, METH_FASTCALL, winreg_EnumKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500417
418static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300419winreg_EnumKey_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500420
421static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200422winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500423{
424 PyObject *return_value = NULL;
425 HKEY key;
426 int index;
427
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200428 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 Stinner259f0e42017-01-17 01:35:17 +0100441 goto exit;
442 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500443 return_value = winreg_EnumKey_impl(module, key, index);
444
445exit:
446 return return_value;
447}
448
449PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200474 {"EnumValue", (PyCFunction)(void(*)(void))winreg_EnumValue, METH_FASTCALL, winreg_EnumValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500475
476static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300477winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500478
479static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200480winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500481{
482 PyObject *return_value = NULL;
483 HKEY key;
484 int index;
485
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200486 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 Stinner259f0e42017-01-17 01:35:17 +0100499 goto exit;
500 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500501 return_value = winreg_EnumValue_impl(module, key, index);
502
503exit:
504 return return_value;
505}
506
507PyDoc_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
516static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200517winreg_ExpandEnvironmentStrings_impl(PyObject *module,
518 const Py_UNICODE *string);
Zachary Warefd2d4822015-05-13 01:21:57 -0500519
520static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300521winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500522{
523 PyObject *return_value = NULL;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200524 const Py_UNICODE *string;
Zachary Warefd2d4822015-05-13 01:21:57 -0500525
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300526 if (!PyArg_Parse(arg, "u:ExpandEnvironmentStrings", &string)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500527 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300528 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500529 return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
530
531exit:
532 return return_value;
533}
534
535PyDoc_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
557static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300558winreg_FlushKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500559
560static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300561winreg_FlushKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500562{
563 PyObject *return_value = NULL;
564 HKEY key;
565
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200566 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500567 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300568 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500569 return_value = winreg_FlushKey_impl(module, key);
570
571exit:
572 return return_value;
573}
574
575PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200604 {"LoadKey", (PyCFunction)(void(*)(void))winreg_LoadKey, METH_FASTCALL, winreg_LoadKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500605
606static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200607winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
608 const Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500609
610static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200611winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500612{
613 PyObject *return_value = NULL;
614 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200615 const Py_UNICODE *sub_key;
616 const Py_UNICODE *file_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500617
Sylvain74453812017-06-10 06:51:48 +0200618 if (!_PyArg_ParseStack(args, nargs, "O&uu:LoadKey",
619 clinic_HKEY_converter, &key, &sub_key, &file_name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100620 goto exit;
621 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500622 return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
623
624exit:
625 return return_value;
626}
627
628PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200648 {"OpenKey", (PyCFunction)(void(*)(void))winreg_OpenKey, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500649
650static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200651winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500652 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500653
654static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200655winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500656{
657 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300658 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
659 static _PyArg_Parser _parser = {"O&Z|ii:OpenKey", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500660 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200661 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500662 int reserved = 0;
663 REGSAM access = KEY_READ;
664 HKEY _return_value;
665
Victor Stinner3e1fad62017-01-17 01:29:01 +0100666 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300667 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500668 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300669 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500670 _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300671 if (_return_value == NULL) {
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 = PyHKEY_FromHKEY(_return_value);
675
676exit:
677 return return_value;
678}
679
680PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200700 {"OpenKeyEx", (PyCFunction)(void(*)(void))winreg_OpenKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500701
702static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200703winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500704 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500705
706static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200707winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500708{
709 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300710 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
711 static _PyArg_Parser _parser = {"O&Z|ii:OpenKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500712 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200713 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500714 int reserved = 0;
715 REGSAM access = KEY_READ;
716 HKEY _return_value;
717
Victor Stinner3e1fad62017-01-17 01:29:01 +0100718 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300719 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500720 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300721 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500722 _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300723 if (_return_value == NULL) {
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 = PyHKEY_FromHKEY(_return_value);
727
728exit:
729 return return_value;
730}
731
732PyDoc_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
750static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300751winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500752
753static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300754winreg_QueryInfoKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500755{
756 PyObject *return_value = NULL;
757 HKEY key;
758
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200759 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500760 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300761 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500762 return_value = winreg_QueryInfoKey_impl(module, key);
763
764exit:
765 return return_value;
766}
767
768PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200789 {"QueryValue", (PyCFunction)(void(*)(void))winreg_QueryValue, METH_FASTCALL, winreg_QueryValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500790
791static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200792winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500793
794static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200795winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500796{
797 PyObject *return_value = NULL;
798 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200799 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500800
Sylvain74453812017-06-10 06:51:48 +0200801 if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValue",
802 clinic_HKEY_converter, &key, &sub_key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100803 goto exit;
804 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500805 return_value = winreg_QueryValue_impl(module, key, sub_key);
806
807exit:
808 return return_value;
809}
810
811PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200828 {"QueryValueEx", (PyCFunction)(void(*)(void))winreg_QueryValueEx, METH_FASTCALL, winreg_QueryValueEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500829
830static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200831winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500832
833static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200834winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500835{
836 PyObject *return_value = NULL;
837 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200838 const Py_UNICODE *name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500839
Sylvain74453812017-06-10 06:51:48 +0200840 if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValueEx",
841 clinic_HKEY_converter, &key, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100842 goto exit;
843 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500844 return_value = winreg_QueryValueEx_impl(module, key, name);
845
846exit:
847 return return_value;
848}
849
850PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200872 {"SaveKey", (PyCFunction)(void(*)(void))winreg_SaveKey, METH_FASTCALL, winreg_SaveKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500873
874static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200875winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500876
877static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200878winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500879{
880 PyObject *return_value = NULL;
881 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200882 const Py_UNICODE *file_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500883
Sylvain74453812017-06-10 06:51:48 +0200884 if (!_PyArg_ParseStack(args, nargs, "O&u:SaveKey",
885 clinic_HKEY_converter, &key, &file_name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100886 goto exit;
887 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500888 return_value = winreg_SaveKey_impl(module, key, file_name);
889
890exit:
891 return return_value;
892}
893
894PyDoc_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 Storchaka4a934d42018-11-27 11:27:36 +0200921 {"SetValue", (PyCFunction)(void(*)(void))winreg_SetValue, METH_FASTCALL, winreg_SetValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500922
923static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200924winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
925 DWORD type, const Py_UNICODE *value,
Zachary Ware77772c02015-05-13 10:58:35 -0500926 Py_ssize_clean_t value_length);
Zachary Warefd2d4822015-05-13 01:21:57 -0500927
928static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200929winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500930{
931 PyObject *return_value = NULL;
932 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200933 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500934 DWORD type;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200935 const Py_UNICODE *value;
Zachary Warefd2d4822015-05-13 01:21:57 -0500936 Py_ssize_clean_t value_length;
937
Sylvain74453812017-06-10 06:51:48 +0200938 if (!_PyArg_ParseStack(args, nargs, "O&Zku#:SetValue",
939 clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100940 goto exit;
941 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500942 return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length);
943
944exit:
945 return return_value;
946}
947
948PyDoc_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 Storchaka877826a2016-06-09 16:01:19 +0300964" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500965" 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 Storchaka6a7b3a72016-04-17 08:32:47 +0300970" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500971" by two null characters. Note that Python handles\n"
972" this termination automatically.\n"
973" REG_NONE -- No defined value type.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300974" 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 Warefd2d4822015-05-13 01:21:57 -0500976" 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 Storchaka4a934d42018-11-27 11:27:36 +0200992 {"SetValueEx", (PyCFunction)(void(*)(void))winreg_SetValueEx, METH_FASTCALL, winreg_SetValueEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500993
994static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200995winreg_SetValueEx_impl(PyObject *module, HKEY key,
996 const Py_UNICODE *value_name, PyObject *reserved,
997 DWORD type, PyObject *value);
Zachary Warefd2d4822015-05-13 01:21:57 -0500998
999static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001000winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -05001001{
1002 PyObject *return_value = NULL;
1003 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +02001004 const Py_UNICODE *value_name;
Zachary Warefd2d4822015-05-13 01:21:57 -05001005 PyObject *reserved;
1006 DWORD type;
1007 PyObject *value;
1008
Sylvain74453812017-06-10 06:51:48 +02001009 if (!_PyArg_ParseStack(args, nargs, "O&ZOkO:SetValueEx",
1010 clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001011 goto exit;
1012 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001013 return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
1014
1015exit:
1016 return return_value;
1017}
1018
1019PyDoc_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
1037static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001038winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001039
1040static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001041winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001042{
1043 PyObject *return_value = NULL;
1044 HKEY key;
1045
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001046 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001047 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001048 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001049 return_value = winreg_DisableReflectionKey_impl(module, key);
1050
1051exit:
1052 return return_value;
1053}
1054
1055PyDoc_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
1071static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001072winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001073
1074static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001075winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001076{
1077 PyObject *return_value = NULL;
1078 HKEY key;
1079
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001080 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001081 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001082 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001083 return_value = winreg_EnableReflectionKey_impl(module, key);
1084
1085exit:
1086 return return_value;
1087}
1088
1089PyDoc_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
1103static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001104winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001105
1106static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001107winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001108{
1109 PyObject *return_value = NULL;
1110 HKEY key;
1111
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001112 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001113 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001114 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001115 return_value = winreg_QueryReflectionKey_impl(module, key);
1116
1117exit:
1118 return return_value;
1119}
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001120/*[clinic end generated code: output=bd491131d343ae7a input=a9049054013a1b77]*/