blob: 3b100f9bf08aec446a5670bc2d7c3dc797aaa48e [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
Sylvain74453812017-06-10 06:51:48 +0200428 if (!_PyArg_ParseStack(args, nargs, "O&i:EnumKey",
429 clinic_HKEY_converter, &key, &index)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100430 goto exit;
431 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500432 return_value = winreg_EnumKey_impl(module, key, index);
433
434exit:
435 return return_value;
436}
437
438PyDoc_STRVAR(winreg_EnumValue__doc__,
439"EnumValue($module, key, index, /)\n"
440"--\n"
441"\n"
442"Enumerates values of an open registry key.\n"
443"\n"
444" key\n"
445" An already open key, or any one of the predefined HKEY_* constants.\n"
446" index\n"
447" An integer that identifies the index of the value to retrieve.\n"
448"\n"
449"The function retrieves the name of one subkey each time it is called.\n"
450"It is typically called repeatedly, until an OSError exception\n"
451"is raised, indicating no more values.\n"
452"\n"
453"The result is a tuple of 3 items:\n"
454" value_name\n"
455" A string that identifies the value.\n"
456" value_data\n"
457" An object that holds the value data, and whose type depends\n"
458" on the underlying registry type.\n"
459" data_type\n"
460" An integer that identifies the type of the value data.");
461
462#define WINREG_ENUMVALUE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200463 {"EnumValue", (PyCFunction)(void(*)(void))winreg_EnumValue, METH_FASTCALL, winreg_EnumValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500464
465static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300466winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500467
468static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200469winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500470{
471 PyObject *return_value = NULL;
472 HKEY key;
473 int index;
474
Sylvain74453812017-06-10 06:51:48 +0200475 if (!_PyArg_ParseStack(args, nargs, "O&i:EnumValue",
476 clinic_HKEY_converter, &key, &index)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100477 goto exit;
478 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500479 return_value = winreg_EnumValue_impl(module, key, index);
480
481exit:
482 return return_value;
483}
484
485PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__,
486"ExpandEnvironmentStrings($module, string, /)\n"
487"--\n"
488"\n"
489"Expand environment vars.");
490
491#define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF \
492 {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__},
493
494static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200495winreg_ExpandEnvironmentStrings_impl(PyObject *module,
496 const Py_UNICODE *string);
Zachary Warefd2d4822015-05-13 01:21:57 -0500497
498static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300499winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500500{
501 PyObject *return_value = NULL;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200502 const Py_UNICODE *string;
Zachary Warefd2d4822015-05-13 01:21:57 -0500503
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300504 if (!PyArg_Parse(arg, "u:ExpandEnvironmentStrings", &string)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500505 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300506 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500507 return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
508
509exit:
510 return return_value;
511}
512
513PyDoc_STRVAR(winreg_FlushKey__doc__,
514"FlushKey($module, key, /)\n"
515"--\n"
516"\n"
517"Writes all the attributes of a key to the registry.\n"
518"\n"
519" key\n"
520" An already open key, or any one of the predefined HKEY_* constants.\n"
521"\n"
522"It is not necessary to call FlushKey to change a key. Registry changes\n"
523"are flushed to disk by the registry using its lazy flusher. Registry\n"
524"changes are also flushed to disk at system shutdown. Unlike\n"
525"CloseKey(), the FlushKey() method returns only when all the data has\n"
526"been written to the registry.\n"
527"\n"
528"An application should only call FlushKey() if it requires absolute\n"
529"certainty that registry changes are on disk. If you don\'t know whether\n"
530"a FlushKey() call is required, it probably isn\'t.");
531
532#define WINREG_FLUSHKEY_METHODDEF \
533 {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__},
534
535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300536winreg_FlushKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500537
538static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300539winreg_FlushKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500540{
541 PyObject *return_value = NULL;
542 HKEY key;
543
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200544 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500545 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300546 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500547 return_value = winreg_FlushKey_impl(module, key);
548
549exit:
550 return return_value;
551}
552
553PyDoc_STRVAR(winreg_LoadKey__doc__,
554"LoadKey($module, key, sub_key, file_name, /)\n"
555"--\n"
556"\n"
557"Insert data into the registry from a file.\n"
558"\n"
559" key\n"
560" An already open key, or any one of the predefined HKEY_* constants.\n"
561" sub_key\n"
562" A string that identifies the sub-key to load.\n"
563" file_name\n"
564" The name of the file to load registry data from. This file must\n"
565" have been created with the SaveKey() function. Under the file\n"
566" allocation table (FAT) file system, the filename may not have an\n"
567" extension.\n"
568"\n"
569"Creates a subkey under the specified key and stores registration\n"
570"information from a specified file into that subkey.\n"
571"\n"
572"A call to LoadKey() fails if the calling process does not have the\n"
573"SE_RESTORE_PRIVILEGE privilege.\n"
574"\n"
575"If key is a handle returned by ConnectRegistry(), then the path\n"
576"specified in fileName is relative to the remote computer.\n"
577"\n"
578"The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n"
579"tree.");
580
581#define WINREG_LOADKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200582 {"LoadKey", (PyCFunction)(void(*)(void))winreg_LoadKey, METH_FASTCALL, winreg_LoadKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500583
584static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200585winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
586 const Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500587
588static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200589winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500590{
591 PyObject *return_value = NULL;
592 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200593 const Py_UNICODE *sub_key;
594 const Py_UNICODE *file_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500595
Sylvain74453812017-06-10 06:51:48 +0200596 if (!_PyArg_ParseStack(args, nargs, "O&uu:LoadKey",
597 clinic_HKEY_converter, &key, &sub_key, &file_name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100598 goto exit;
599 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500600 return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
601
602exit:
603 return return_value;
604}
605
606PyDoc_STRVAR(winreg_OpenKey__doc__,
607"OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
608"--\n"
609"\n"
610"Opens the specified key.\n"
611"\n"
612" key\n"
613" An already open key, or any one of the predefined HKEY_* constants.\n"
614" sub_key\n"
615" A string that identifies the sub_key to open.\n"
616" reserved\n"
617" A reserved integer that must be zero. Default is zero.\n"
618" access\n"
619" An integer that specifies an access mask that describes the desired\n"
620" security access for the key. Default is KEY_READ.\n"
621"\n"
622"The result is a new handle to the specified key.\n"
623"If the function fails, an OSError exception is raised.");
624
625#define WINREG_OPENKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200626 {"OpenKey", (PyCFunction)(void(*)(void))winreg_OpenKey, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500627
628static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200629winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500630 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500631
632static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200633winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500634{
635 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300636 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
637 static _PyArg_Parser _parser = {"O&Z|ii:OpenKey", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500638 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200639 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500640 int reserved = 0;
641 REGSAM access = KEY_READ;
642 HKEY _return_value;
643
Victor Stinner3e1fad62017-01-17 01:29:01 +0100644 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300645 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500646 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300647 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500648 _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300649 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500650 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300651 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500652 return_value = PyHKEY_FromHKEY(_return_value);
653
654exit:
655 return return_value;
656}
657
658PyDoc_STRVAR(winreg_OpenKeyEx__doc__,
659"OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
660"--\n"
661"\n"
662"Opens the specified key.\n"
663"\n"
664" key\n"
665" An already open key, or any one of the predefined HKEY_* constants.\n"
666" sub_key\n"
667" A string that identifies the sub_key to open.\n"
668" reserved\n"
669" A reserved integer that must be zero. Default is zero.\n"
670" access\n"
671" An integer that specifies an access mask that describes the desired\n"
672" security access for the key. Default is KEY_READ.\n"
673"\n"
674"The result is a new handle to the specified key.\n"
675"If the function fails, an OSError exception is raised.");
676
677#define WINREG_OPENKEYEX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200678 {"OpenKeyEx", (PyCFunction)(void(*)(void))winreg_OpenKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500679
680static HKEY
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200681winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500682 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500683
684static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200685winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500686{
687 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300688 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
689 static _PyArg_Parser _parser = {"O&Z|ii:OpenKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500690 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200691 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500692 int reserved = 0;
693 REGSAM access = KEY_READ;
694 HKEY _return_value;
695
Victor Stinner3e1fad62017-01-17 01:29:01 +0100696 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300697 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500698 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300699 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500700 _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300701 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500702 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300703 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500704 return_value = PyHKEY_FromHKEY(_return_value);
705
706exit:
707 return return_value;
708}
709
710PyDoc_STRVAR(winreg_QueryInfoKey__doc__,
711"QueryInfoKey($module, key, /)\n"
712"--\n"
713"\n"
714"Returns information about a key.\n"
715"\n"
716" key\n"
717" An already open key, or any one of the predefined HKEY_* constants.\n"
718"\n"
719"The result is a tuple of 3 items:\n"
720"An integer that identifies the number of sub keys this key has.\n"
721"An integer that identifies the number of values this key has.\n"
722"An integer that identifies when the key was last modified (if available)\n"
723"as 100\'s of nanoseconds since Jan 1, 1600.");
724
725#define WINREG_QUERYINFOKEY_METHODDEF \
726 {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__},
727
728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300729winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500730
731static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300732winreg_QueryInfoKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500733{
734 PyObject *return_value = NULL;
735 HKEY key;
736
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200737 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500738 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300739 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500740 return_value = winreg_QueryInfoKey_impl(module, key);
741
742exit:
743 return return_value;
744}
745
746PyDoc_STRVAR(winreg_QueryValue__doc__,
747"QueryValue($module, key, sub_key, /)\n"
748"--\n"
749"\n"
750"Retrieves the unnamed value for a key.\n"
751"\n"
752" key\n"
753" An already open key, or any one of the predefined HKEY_* constants.\n"
754" sub_key\n"
755" A string that holds the name of the subkey with which the value\n"
756" is associated. If this parameter is None or empty, the function\n"
757" retrieves the value set by the SetValue() method for the key\n"
758" identified by key.\n"
759"\n"
760"Values in the registry have name, type, and data components. This method\n"
761"retrieves the data for a key\'s first value that has a NULL name.\n"
762"But since the underlying API call doesn\'t return the type, you\'ll\n"
763"probably be happier using QueryValueEx; this function is just here for\n"
764"completeness.");
765
766#define WINREG_QUERYVALUE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200767 {"QueryValue", (PyCFunction)(void(*)(void))winreg_QueryValue, METH_FASTCALL, winreg_QueryValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500768
769static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200770winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500771
772static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200773winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500774{
775 PyObject *return_value = NULL;
776 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200777 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500778
Sylvain74453812017-06-10 06:51:48 +0200779 if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValue",
780 clinic_HKEY_converter, &key, &sub_key)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100781 goto exit;
782 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500783 return_value = winreg_QueryValue_impl(module, key, sub_key);
784
785exit:
786 return return_value;
787}
788
789PyDoc_STRVAR(winreg_QueryValueEx__doc__,
790"QueryValueEx($module, key, name, /)\n"
791"--\n"
792"\n"
793"Retrieves the type and value of a specified sub-key.\n"
794"\n"
795" key\n"
796" An already open key, or any one of the predefined HKEY_* constants.\n"
797" name\n"
798" A string indicating the value to query.\n"
799"\n"
800"Behaves mostly like QueryValue(), but also returns the type of the\n"
801"specified value name associated with the given open registry key.\n"
802"\n"
803"The return value is a tuple of the value and the type_id.");
804
805#define WINREG_QUERYVALUEEX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200806 {"QueryValueEx", (PyCFunction)(void(*)(void))winreg_QueryValueEx, METH_FASTCALL, winreg_QueryValueEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500807
808static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200809winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500810
811static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200812winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500813{
814 PyObject *return_value = NULL;
815 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200816 const Py_UNICODE *name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500817
Sylvain74453812017-06-10 06:51:48 +0200818 if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValueEx",
819 clinic_HKEY_converter, &key, &name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100820 goto exit;
821 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500822 return_value = winreg_QueryValueEx_impl(module, key, name);
823
824exit:
825 return return_value;
826}
827
828PyDoc_STRVAR(winreg_SaveKey__doc__,
829"SaveKey($module, key, file_name, /)\n"
830"--\n"
831"\n"
832"Saves the specified key, and all its subkeys to the specified file.\n"
833"\n"
834" key\n"
835" An already open key, or any one of the predefined HKEY_* constants.\n"
836" file_name\n"
837" The name of the file to save registry data to. This file cannot\n"
838" already exist. If this filename includes an extension, it cannot be\n"
839" used on file allocation table (FAT) file systems by the LoadKey(),\n"
840" ReplaceKey() or RestoreKey() methods.\n"
841"\n"
842"If key represents a key on a remote computer, the path described by\n"
843"file_name is relative to the remote computer.\n"
844"\n"
845"The caller of this method must possess the SeBackupPrivilege\n"
846"security privilege. This function passes NULL for security_attributes\n"
847"to the API.");
848
849#define WINREG_SAVEKEY_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200850 {"SaveKey", (PyCFunction)(void(*)(void))winreg_SaveKey, METH_FASTCALL, winreg_SaveKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500851
852static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200853winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500854
855static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200856winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500857{
858 PyObject *return_value = NULL;
859 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200860 const Py_UNICODE *file_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500861
Sylvain74453812017-06-10 06:51:48 +0200862 if (!_PyArg_ParseStack(args, nargs, "O&u:SaveKey",
863 clinic_HKEY_converter, &key, &file_name)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100864 goto exit;
865 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500866 return_value = winreg_SaveKey_impl(module, key, file_name);
867
868exit:
869 return return_value;
870}
871
872PyDoc_STRVAR(winreg_SetValue__doc__,
873"SetValue($module, key, sub_key, type, value, /)\n"
874"--\n"
875"\n"
876"Associates a value with a specified key.\n"
877"\n"
878" key\n"
879" An already open key, or any one of the predefined HKEY_* constants.\n"
880" sub_key\n"
881" A string that names the subkey with which the value is associated.\n"
882" type\n"
883" An integer that specifies the type of the data. Currently this must\n"
884" be REG_SZ, meaning only strings are supported.\n"
885" value\n"
886" A string that specifies the new value.\n"
887"\n"
888"If the key specified by the sub_key parameter does not exist, the\n"
889"SetValue function creates it.\n"
890"\n"
891"Value lengths are limited by available memory. Long values (more than\n"
892"2048 bytes) should be stored as files with the filenames stored in\n"
893"the configuration registry to help the registry perform efficiently.\n"
894"\n"
895"The key identified by the key parameter must have been opened with\n"
896"KEY_SET_VALUE access.");
897
898#define WINREG_SETVALUE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200899 {"SetValue", (PyCFunction)(void(*)(void))winreg_SetValue, METH_FASTCALL, winreg_SetValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500900
901static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200902winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
903 DWORD type, const Py_UNICODE *value,
Zachary Ware77772c02015-05-13 10:58:35 -0500904 Py_ssize_clean_t value_length);
Zachary Warefd2d4822015-05-13 01:21:57 -0500905
906static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200907winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500908{
909 PyObject *return_value = NULL;
910 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200911 const Py_UNICODE *sub_key;
Zachary Warefd2d4822015-05-13 01:21:57 -0500912 DWORD type;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200913 const Py_UNICODE *value;
Zachary Warefd2d4822015-05-13 01:21:57 -0500914 Py_ssize_clean_t value_length;
915
Sylvain74453812017-06-10 06:51:48 +0200916 if (!_PyArg_ParseStack(args, nargs, "O&Zku#:SetValue",
917 clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100918 goto exit;
919 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500920 return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length);
921
922exit:
923 return return_value;
924}
925
926PyDoc_STRVAR(winreg_SetValueEx__doc__,
927"SetValueEx($module, key, value_name, reserved, type, value, /)\n"
928"--\n"
929"\n"
930"Stores data in the value field of an open registry key.\n"
931"\n"
932" key\n"
933" An already open key, or any one of the predefined HKEY_* constants.\n"
934" value_name\n"
935" A string containing the name of the value to set, or None.\n"
936" reserved\n"
937" Can be anything - zero is always passed to the API.\n"
938" type\n"
939" An integer that specifies the type of the data, one of:\n"
940" REG_BINARY -- Binary data in any form.\n"
941" REG_DWORD -- A 32-bit number.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300942" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500943" REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
944" REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n"
945" references to environment variables (for example,\n"
946" %PATH%).\n"
947" REG_LINK -- A Unicode symbolic link.\n"
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300948" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500949" by two null characters. Note that Python handles\n"
950" this termination automatically.\n"
951" REG_NONE -- No defined value type.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300952" REG_QWORD -- A 64-bit number.\n"
953" REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500954" REG_RESOURCE_LIST -- A device-driver resource list.\n"
955" REG_SZ -- A null-terminated string.\n"
956" value\n"
957" A string that specifies the new value.\n"
958"\n"
959"This method can also set additional value and type information for the\n"
960"specified key. The key identified by the key parameter must have been\n"
961"opened with KEY_SET_VALUE access.\n"
962"\n"
963"To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
964"\n"
965"Value lengths are limited by available memory. Long values (more than\n"
966"2048 bytes) should be stored as files with the filenames stored in\n"
967"the configuration registry to help the registry perform efficiently.");
968
969#define WINREG_SETVALUEEX_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200970 {"SetValueEx", (PyCFunction)(void(*)(void))winreg_SetValueEx, METH_FASTCALL, winreg_SetValueEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500971
972static PyObject *
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200973winreg_SetValueEx_impl(PyObject *module, HKEY key,
974 const Py_UNICODE *value_name, PyObject *reserved,
975 DWORD type, PyObject *value);
Zachary Warefd2d4822015-05-13 01:21:57 -0500976
977static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200978winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Warefd2d4822015-05-13 01:21:57 -0500979{
980 PyObject *return_value = NULL;
981 HKEY key;
Serhiy Storchakaafb3e712018-12-14 11:19:51 +0200982 const Py_UNICODE *value_name;
Zachary Warefd2d4822015-05-13 01:21:57 -0500983 PyObject *reserved;
984 DWORD type;
985 PyObject *value;
986
Sylvain74453812017-06-10 06:51:48 +0200987 if (!_PyArg_ParseStack(args, nargs, "O&ZOkO:SetValueEx",
988 clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100989 goto exit;
990 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500991 return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
992
993exit:
994 return return_value;
995}
996
997PyDoc_STRVAR(winreg_DisableReflectionKey__doc__,
998"DisableReflectionKey($module, key, /)\n"
999"--\n"
1000"\n"
1001"Disables registry reflection for 32bit processes running on a 64bit OS.\n"
1002"\n"
1003" key\n"
1004" An already open key, or any one of the predefined HKEY_* constants.\n"
1005"\n"
1006"Will generally raise NotImplemented if executed on a 32bit OS.\n"
1007"\n"
1008"If the key is not on the reflection list, the function succeeds but has\n"
1009"no effect. Disabling reflection for a key does not affect reflection\n"
1010"of any subkeys.");
1011
1012#define WINREG_DISABLEREFLECTIONKEY_METHODDEF \
1013 {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__},
1014
1015static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001016winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001017
1018static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001019winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001020{
1021 PyObject *return_value = NULL;
1022 HKEY key;
1023
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001024 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001025 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001026 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001027 return_value = winreg_DisableReflectionKey_impl(module, key);
1028
1029exit:
1030 return return_value;
1031}
1032
1033PyDoc_STRVAR(winreg_EnableReflectionKey__doc__,
1034"EnableReflectionKey($module, key, /)\n"
1035"--\n"
1036"\n"
1037"Restores registry reflection for the specified disabled key.\n"
1038"\n"
1039" key\n"
1040" An already open key, or any one of the predefined HKEY_* constants.\n"
1041"\n"
1042"Will generally raise NotImplemented if executed on a 32bit OS.\n"
1043"Restoring reflection for a key does not affect reflection of any\n"
1044"subkeys.");
1045
1046#define WINREG_ENABLEREFLECTIONKEY_METHODDEF \
1047 {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__},
1048
1049static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001050winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001051
1052static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001053winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001054{
1055 PyObject *return_value = NULL;
1056 HKEY key;
1057
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001058 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001059 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001060 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001061 return_value = winreg_EnableReflectionKey_impl(module, key);
1062
1063exit:
1064 return return_value;
1065}
1066
1067PyDoc_STRVAR(winreg_QueryReflectionKey__doc__,
1068"QueryReflectionKey($module, key, /)\n"
1069"--\n"
1070"\n"
1071"Returns the reflection state for the specified key as a bool.\n"
1072"\n"
1073" key\n"
1074" An already open key, or any one of the predefined HKEY_* constants.\n"
1075"\n"
1076"Will generally raise NotImplemented if executed on a 32bit OS.");
1077
1078#define WINREG_QUERYREFLECTIONKEY_METHODDEF \
1079 {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__},
1080
1081static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001082winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001083
1084static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001085winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001086{
1087 PyObject *return_value = NULL;
1088 HKEY key;
1089
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001090 if (!clinic_HKEY_converter(arg, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001091 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001092 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001093 return_value = winreg_QueryReflectionKey_impl(module, key);
1094
1095exit:
1096 return return_value;
1097}
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02001098/*[clinic end generated code: output=82bd56c524c6c3dd input=a9049054013a1b77]*/