blob: 2ca47344c47c35c541023dab86d5051374000395 [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 \
Victor Stinner37e4ef72016-09-09 20:00:13 -070080 {"__exit__", (PyCFunction)winreg_HKEYType___exit__, METH_FASTCALL, 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 *
Victor Stinner37e4ef72016-09-09 20:00:13 -070087winreg_HKEYType___exit__(PyHKEYObject *self, PyObject **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 \
Victor Stinner259f0e42017-01-17 01:35:17 +0100137 {"ConnectRegistry", (PyCFunction)winreg_ConnectRegistry, METH_FASTCALL, winreg_ConnectRegistry__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500138
139static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300140winreg_ConnectRegistry_impl(PyObject *module, Py_UNICODE *computer_name,
Zachary Ware77772c02015-05-13 10:58:35 -0500141 HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500142
143static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100144winreg_ConnectRegistry(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500145{
146 PyObject *return_value = NULL;
147 Py_UNICODE *computer_name;
148 HKEY key;
149 HKEY _return_value;
150
Victor Stinner259f0e42017-01-17 01:35:17 +0100151 if (!_PyArg_ParseStack(args, nargs, "ZO&:ConnectRegistry",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300152 &computer_name, clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500153 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300154 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100155
156 if (!_PyArg_NoStackKeywords("ConnectRegistry", kwnames)) {
157 goto exit;
158 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500159 _return_value = winreg_ConnectRegistry_impl(module, computer_name, key);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300160 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500161 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300162 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500163 return_value = PyHKEY_FromHKEY(_return_value);
164
165exit:
166 return return_value;
167}
168
169PyDoc_STRVAR(winreg_CreateKey__doc__,
170"CreateKey($module, key, sub_key, /)\n"
171"--\n"
172"\n"
173"Creates or opens the specified key.\n"
174"\n"
175" key\n"
176" An already open key, or one of the predefined HKEY_* constants.\n"
177" sub_key\n"
178" The name of the key this method opens or creates.\n"
179"\n"
180"If key is one of the predefined keys, sub_key may be None. In that case,\n"
181"the handle returned is the same key handle passed in to the function.\n"
182"\n"
183"If the key already exists, this function opens the existing key.\n"
184"\n"
185"The return value is the handle of the opened key.\n"
186"If the function fails, an OSError exception is raised.");
187
188#define WINREG_CREATEKEY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100189 {"CreateKey", (PyCFunction)winreg_CreateKey, METH_FASTCALL, winreg_CreateKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500190
191static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300192winreg_CreateKey_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500193
194static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100195winreg_CreateKey(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500196{
197 PyObject *return_value = NULL;
198 HKEY key;
199 Py_UNICODE *sub_key;
200 HKEY _return_value;
201
Victor Stinner259f0e42017-01-17 01:35:17 +0100202 if (!_PyArg_ParseStack(args, nargs, "O&Z:CreateKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300203 clinic_HKEY_converter, &key, &sub_key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500204 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300205 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100206
207 if (!_PyArg_NoStackKeywords("CreateKey", kwnames)) {
208 goto exit;
209 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500210 _return_value = winreg_CreateKey_impl(module, key, sub_key);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300211 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500212 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300213 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500214 return_value = PyHKEY_FromHKEY(_return_value);
215
216exit:
217 return return_value;
218}
219
220PyDoc_STRVAR(winreg_CreateKeyEx__doc__,
221"CreateKeyEx($module, /, key, sub_key, reserved=0,\n"
222" access=winreg.KEY_WRITE)\n"
223"--\n"
224"\n"
225"Creates or opens the specified key.\n"
226"\n"
227" key\n"
228" An already open key, or one of the predefined HKEY_* constants.\n"
229" sub_key\n"
230" The name of the key this method opens or creates.\n"
231" reserved\n"
232" A reserved integer, and must be zero. Default is zero.\n"
233" access\n"
234" An integer that specifies an access mask that describes the\n"
235" desired security access for the key. Default is KEY_WRITE.\n"
236"\n"
237"If key is one of the predefined keys, sub_key may be None. In that case,\n"
238"the handle returned is the same key handle passed in to the function.\n"
239"\n"
240"If the key already exists, this function opens the existing key\n"
241"\n"
242"The return value is the handle of the opened key.\n"
243"If the function fails, an OSError exception is raised.");
244
245#define WINREG_CREATEKEYEX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700246 {"CreateKeyEx", (PyCFunction)winreg_CreateKeyEx, METH_FASTCALL, winreg_CreateKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500247
248static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300249winreg_CreateKeyEx_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500250 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500251
252static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700253winreg_CreateKeyEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500254{
255 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300256 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
257 static _PyArg_Parser _parser = {"O&Z|ii:CreateKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500258 HKEY key;
259 Py_UNICODE *sub_key;
260 int reserved = 0;
261 REGSAM access = KEY_WRITE;
262 HKEY _return_value;
263
Victor Stinner3e1fad62017-01-17 01:29:01 +0100264 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300265 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500266 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300267 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500268 _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300269 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500270 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300271 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500272 return_value = PyHKEY_FromHKEY(_return_value);
273
274exit:
275 return return_value;
276}
277
278PyDoc_STRVAR(winreg_DeleteKey__doc__,
279"DeleteKey($module, key, sub_key, /)\n"
280"--\n"
281"\n"
282"Deletes the specified key.\n"
283"\n"
284" key\n"
285" An already open key, or any one of the predefined HKEY_* constants.\n"
286" sub_key\n"
287" A string that must be the name of a subkey of the key identified by\n"
288" the key parameter. This value must not be None, and the key may not\n"
289" have subkeys.\n"
290"\n"
291"This method can not delete keys with subkeys.\n"
292"\n"
293"If the function succeeds, the entire key, including all of its values,\n"
294"is removed. If the function fails, an OSError exception is raised.");
295
296#define WINREG_DELETEKEY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100297 {"DeleteKey", (PyCFunction)winreg_DeleteKey, METH_FASTCALL, winreg_DeleteKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500298
299static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300300winreg_DeleteKey_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500301
302static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100303winreg_DeleteKey(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500304{
305 PyObject *return_value = NULL;
306 HKEY key;
307 Py_UNICODE *sub_key;
308
Victor Stinner259f0e42017-01-17 01:35:17 +0100309 if (!_PyArg_ParseStack(args, nargs, "O&u:DeleteKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300310 clinic_HKEY_converter, &key, &sub_key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500311 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300312 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100313
314 if (!_PyArg_NoStackKeywords("DeleteKey", kwnames)) {
315 goto exit;
316 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500317 return_value = winreg_DeleteKey_impl(module, key, sub_key);
318
319exit:
320 return return_value;
321}
322
323PyDoc_STRVAR(winreg_DeleteKeyEx__doc__,
324"DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n"
325" reserved=0)\n"
326"--\n"
327"\n"
328"Deletes the specified key (64-bit OS only).\n"
329"\n"
330" key\n"
331" An already open key, or any one of the predefined HKEY_* constants.\n"
332" sub_key\n"
333" A string that must be the name of a subkey of the key identified by\n"
334" the key parameter. This value must not be None, and the key may not\n"
335" have subkeys.\n"
336" access\n"
337" An integer that specifies an access mask that describes the\n"
338" desired security access for the key. Default is KEY_WOW64_64KEY.\n"
339" reserved\n"
340" A reserved integer, and must be zero. Default is zero.\n"
341"\n"
342"This method can not delete keys with subkeys.\n"
343"\n"
344"If the function succeeds, the entire key, including all of its values,\n"
345"is removed. If the function fails, an OSError exception is raised.\n"
346"On unsupported Windows versions, NotImplementedError is raised.");
347
348#define WINREG_DELETEKEYEX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700349 {"DeleteKeyEx", (PyCFunction)winreg_DeleteKeyEx, METH_FASTCALL, winreg_DeleteKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500350
351static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300352winreg_DeleteKeyEx_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500353 REGSAM access, int reserved);
Zachary Warefd2d4822015-05-13 01:21:57 -0500354
355static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700356winreg_DeleteKeyEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500357{
358 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300359 static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL};
360 static _PyArg_Parser _parser = {"O&u|ii:DeleteKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500361 HKEY key;
362 Py_UNICODE *sub_key;
363 REGSAM access = KEY_WOW64_64KEY;
364 int reserved = 0;
365
Victor Stinner3e1fad62017-01-17 01:29:01 +0100366 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300367 clinic_HKEY_converter, &key, &sub_key, &access, &reserved)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500368 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300369 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500370 return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
371
372exit:
373 return return_value;
374}
375
376PyDoc_STRVAR(winreg_DeleteValue__doc__,
377"DeleteValue($module, key, value, /)\n"
378"--\n"
379"\n"
380"Removes a named value from a registry key.\n"
381"\n"
382" key\n"
383" An already open key, or any one of the predefined HKEY_* constants.\n"
384" value\n"
385" A string that identifies the value to remove.");
386
387#define WINREG_DELETEVALUE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100388 {"DeleteValue", (PyCFunction)winreg_DeleteValue, METH_FASTCALL, winreg_DeleteValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500389
390static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300391winreg_DeleteValue_impl(PyObject *module, HKEY key, Py_UNICODE *value);
Zachary Warefd2d4822015-05-13 01:21:57 -0500392
393static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100394winreg_DeleteValue(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500395{
396 PyObject *return_value = NULL;
397 HKEY key;
398 Py_UNICODE *value;
399
Victor Stinner259f0e42017-01-17 01:35:17 +0100400 if (!_PyArg_ParseStack(args, nargs, "O&Z:DeleteValue",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300401 clinic_HKEY_converter, &key, &value)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500402 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300403 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100404
405 if (!_PyArg_NoStackKeywords("DeleteValue", kwnames)) {
406 goto exit;
407 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500408 return_value = winreg_DeleteValue_impl(module, key, value);
409
410exit:
411 return return_value;
412}
413
414PyDoc_STRVAR(winreg_EnumKey__doc__,
415"EnumKey($module, key, index, /)\n"
416"--\n"
417"\n"
418"Enumerates subkeys of an open registry key.\n"
419"\n"
420" key\n"
421" An already open key, or any one of the predefined HKEY_* constants.\n"
422" index\n"
423" An integer that identifies the index of the key to retrieve.\n"
424"\n"
425"The function retrieves the name of one subkey each time it is called.\n"
426"It is typically called repeatedly until an OSError exception is\n"
427"raised, indicating no more values are available.");
428
429#define WINREG_ENUMKEY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100430 {"EnumKey", (PyCFunction)winreg_EnumKey, METH_FASTCALL, winreg_EnumKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500431
432static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300433winreg_EnumKey_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500434
435static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100436winreg_EnumKey(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500437{
438 PyObject *return_value = NULL;
439 HKEY key;
440 int index;
441
Victor Stinner259f0e42017-01-17 01:35:17 +0100442 if (!_PyArg_ParseStack(args, nargs, "O&i:EnumKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300443 clinic_HKEY_converter, &key, &index)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500444 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300445 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100446
447 if (!_PyArg_NoStackKeywords("EnumKey", kwnames)) {
448 goto exit;
449 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500450 return_value = winreg_EnumKey_impl(module, key, index);
451
452exit:
453 return return_value;
454}
455
456PyDoc_STRVAR(winreg_EnumValue__doc__,
457"EnumValue($module, key, index, /)\n"
458"--\n"
459"\n"
460"Enumerates values of an open registry key.\n"
461"\n"
462" key\n"
463" An already open key, or any one of the predefined HKEY_* constants.\n"
464" index\n"
465" An integer that identifies the index of the value to retrieve.\n"
466"\n"
467"The function retrieves the name of one subkey each time it is called.\n"
468"It is typically called repeatedly, until an OSError exception\n"
469"is raised, indicating no more values.\n"
470"\n"
471"The result is a tuple of 3 items:\n"
472" value_name\n"
473" A string that identifies the value.\n"
474" value_data\n"
475" An object that holds the value data, and whose type depends\n"
476" on the underlying registry type.\n"
477" data_type\n"
478" An integer that identifies the type of the value data.");
479
480#define WINREG_ENUMVALUE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100481 {"EnumValue", (PyCFunction)winreg_EnumValue, METH_FASTCALL, winreg_EnumValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500482
483static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300484winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500485
486static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100487winreg_EnumValue(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500488{
489 PyObject *return_value = NULL;
490 HKEY key;
491 int index;
492
Victor Stinner259f0e42017-01-17 01:35:17 +0100493 if (!_PyArg_ParseStack(args, nargs, "O&i:EnumValue",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300494 clinic_HKEY_converter, &key, &index)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500495 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300496 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100497
498 if (!_PyArg_NoStackKeywords("EnumValue", kwnames)) {
499 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 Storchaka1a2b24f2016-07-07 17:35:15 +0300517winreg_ExpandEnvironmentStrings_impl(PyObject *module, Py_UNICODE *string);
Zachary Warefd2d4822015-05-13 01:21:57 -0500518
519static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300520winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500521{
522 PyObject *return_value = NULL;
523 Py_UNICODE *string;
524
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300525 if (!PyArg_Parse(arg, "u:ExpandEnvironmentStrings", &string)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500526 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300527 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500528 return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
529
530exit:
531 return return_value;
532}
533
534PyDoc_STRVAR(winreg_FlushKey__doc__,
535"FlushKey($module, key, /)\n"
536"--\n"
537"\n"
538"Writes all the attributes of a key to the registry.\n"
539"\n"
540" key\n"
541" An already open key, or any one of the predefined HKEY_* constants.\n"
542"\n"
543"It is not necessary to call FlushKey to change a key. Registry changes\n"
544"are flushed to disk by the registry using its lazy flusher. Registry\n"
545"changes are also flushed to disk at system shutdown. Unlike\n"
546"CloseKey(), the FlushKey() method returns only when all the data has\n"
547"been written to the registry.\n"
548"\n"
549"An application should only call FlushKey() if it requires absolute\n"
550"certainty that registry changes are on disk. If you don\'t know whether\n"
551"a FlushKey() call is required, it probably isn\'t.");
552
553#define WINREG_FLUSHKEY_METHODDEF \
554 {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__},
555
556static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300557winreg_FlushKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500558
559static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300560winreg_FlushKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500561{
562 PyObject *return_value = NULL;
563 HKEY key;
564
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300565 if (!PyArg_Parse(arg, "O&:FlushKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500566 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300567 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500568 return_value = winreg_FlushKey_impl(module, key);
569
570exit:
571 return return_value;
572}
573
574PyDoc_STRVAR(winreg_LoadKey__doc__,
575"LoadKey($module, key, sub_key, file_name, /)\n"
576"--\n"
577"\n"
578"Insert data into the registry from a file.\n"
579"\n"
580" key\n"
581" An already open key, or any one of the predefined HKEY_* constants.\n"
582" sub_key\n"
583" A string that identifies the sub-key to load.\n"
584" file_name\n"
585" The name of the file to load registry data from. This file must\n"
586" have been created with the SaveKey() function. Under the file\n"
587" allocation table (FAT) file system, the filename may not have an\n"
588" extension.\n"
589"\n"
590"Creates a subkey under the specified key and stores registration\n"
591"information from a specified file into that subkey.\n"
592"\n"
593"A call to LoadKey() fails if the calling process does not have the\n"
594"SE_RESTORE_PRIVILEGE privilege.\n"
595"\n"
596"If key is a handle returned by ConnectRegistry(), then the path\n"
597"specified in fileName is relative to the remote computer.\n"
598"\n"
599"The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n"
600"tree.");
601
602#define WINREG_LOADKEY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100603 {"LoadKey", (PyCFunction)winreg_LoadKey, METH_FASTCALL, winreg_LoadKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500604
605static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300606winreg_LoadKey_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500607 Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500608
609static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100610winreg_LoadKey(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500611{
612 PyObject *return_value = NULL;
613 HKEY key;
614 Py_UNICODE *sub_key;
615 Py_UNICODE *file_name;
616
Victor Stinner259f0e42017-01-17 01:35:17 +0100617 if (!_PyArg_ParseStack(args, nargs, "O&uu:LoadKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300618 clinic_HKEY_converter, &key, &sub_key, &file_name)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500619 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300620 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100621
622 if (!_PyArg_NoStackKeywords("LoadKey", kwnames)) {
623 goto exit;
624 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500625 return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
626
627exit:
628 return return_value;
629}
630
631PyDoc_STRVAR(winreg_OpenKey__doc__,
632"OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
633"--\n"
634"\n"
635"Opens the specified key.\n"
636"\n"
637" key\n"
638" An already open key, or any one of the predefined HKEY_* constants.\n"
639" sub_key\n"
640" A string that identifies the sub_key to open.\n"
641" reserved\n"
642" A reserved integer that must be zero. Default is zero.\n"
643" access\n"
644" An integer that specifies an access mask that describes the desired\n"
645" security access for the key. Default is KEY_READ.\n"
646"\n"
647"The result is a new handle to the specified key.\n"
648"If the function fails, an OSError exception is raised.");
649
650#define WINREG_OPENKEY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700651 {"OpenKey", (PyCFunction)winreg_OpenKey, METH_FASTCALL, winreg_OpenKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500652
653static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300654winreg_OpenKey_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500655 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500656
657static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700658winreg_OpenKey(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500659{
660 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300661 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
662 static _PyArg_Parser _parser = {"O&Z|ii:OpenKey", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500663 HKEY key;
664 Py_UNICODE *sub_key;
665 int reserved = 0;
666 REGSAM access = KEY_READ;
667 HKEY _return_value;
668
Victor Stinner3e1fad62017-01-17 01:29:01 +0100669 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300670 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500671 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300672 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500673 _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300674 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500675 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300676 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500677 return_value = PyHKEY_FromHKEY(_return_value);
678
679exit:
680 return return_value;
681}
682
683PyDoc_STRVAR(winreg_OpenKeyEx__doc__,
684"OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
685"--\n"
686"\n"
687"Opens the specified key.\n"
688"\n"
689" key\n"
690" An already open key, or any one of the predefined HKEY_* constants.\n"
691" sub_key\n"
692" A string that identifies the sub_key to open.\n"
693" reserved\n"
694" A reserved integer that must be zero. Default is zero.\n"
695" access\n"
696" An integer that specifies an access mask that describes the desired\n"
697" security access for the key. Default is KEY_READ.\n"
698"\n"
699"The result is a new handle to the specified key.\n"
700"If the function fails, an OSError exception is raised.");
701
702#define WINREG_OPENKEYEX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700703 {"OpenKeyEx", (PyCFunction)winreg_OpenKeyEx, METH_FASTCALL, winreg_OpenKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500704
705static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300706winreg_OpenKeyEx_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500707 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500708
709static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700710winreg_OpenKeyEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500711{
712 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300713 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
714 static _PyArg_Parser _parser = {"O&Z|ii:OpenKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500715 HKEY key;
716 Py_UNICODE *sub_key;
717 int reserved = 0;
718 REGSAM access = KEY_READ;
719 HKEY _return_value;
720
Victor Stinner3e1fad62017-01-17 01:29:01 +0100721 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300722 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500723 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300724 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500725 _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300726 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500727 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300728 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500729 return_value = PyHKEY_FromHKEY(_return_value);
730
731exit:
732 return return_value;
733}
734
735PyDoc_STRVAR(winreg_QueryInfoKey__doc__,
736"QueryInfoKey($module, key, /)\n"
737"--\n"
738"\n"
739"Returns information about a key.\n"
740"\n"
741" key\n"
742" An already open key, or any one of the predefined HKEY_* constants.\n"
743"\n"
744"The result is a tuple of 3 items:\n"
745"An integer that identifies the number of sub keys this key has.\n"
746"An integer that identifies the number of values this key has.\n"
747"An integer that identifies when the key was last modified (if available)\n"
748"as 100\'s of nanoseconds since Jan 1, 1600.");
749
750#define WINREG_QUERYINFOKEY_METHODDEF \
751 {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__},
752
753static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300754winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500755
756static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300757winreg_QueryInfoKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500758{
759 PyObject *return_value = NULL;
760 HKEY key;
761
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300762 if (!PyArg_Parse(arg, "O&:QueryInfoKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500763 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300764 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500765 return_value = winreg_QueryInfoKey_impl(module, key);
766
767exit:
768 return return_value;
769}
770
771PyDoc_STRVAR(winreg_QueryValue__doc__,
772"QueryValue($module, key, sub_key, /)\n"
773"--\n"
774"\n"
775"Retrieves the unnamed value for a key.\n"
776"\n"
777" key\n"
778" An already open key, or any one of the predefined HKEY_* constants.\n"
779" sub_key\n"
780" A string that holds the name of the subkey with which the value\n"
781" is associated. If this parameter is None or empty, the function\n"
782" retrieves the value set by the SetValue() method for the key\n"
783" identified by key.\n"
784"\n"
785"Values in the registry have name, type, and data components. This method\n"
786"retrieves the data for a key\'s first value that has a NULL name.\n"
787"But since the underlying API call doesn\'t return the type, you\'ll\n"
788"probably be happier using QueryValueEx; this function is just here for\n"
789"completeness.");
790
791#define WINREG_QUERYVALUE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100792 {"QueryValue", (PyCFunction)winreg_QueryValue, METH_FASTCALL, winreg_QueryValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500793
794static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300795winreg_QueryValue_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500796
797static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100798winreg_QueryValue(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500799{
800 PyObject *return_value = NULL;
801 HKEY key;
802 Py_UNICODE *sub_key;
803
Victor Stinner259f0e42017-01-17 01:35:17 +0100804 if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValue",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300805 clinic_HKEY_converter, &key, &sub_key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500806 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300807 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100808
809 if (!_PyArg_NoStackKeywords("QueryValue", kwnames)) {
810 goto exit;
811 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500812 return_value = winreg_QueryValue_impl(module, key, sub_key);
813
814exit:
815 return return_value;
816}
817
818PyDoc_STRVAR(winreg_QueryValueEx__doc__,
819"QueryValueEx($module, key, name, /)\n"
820"--\n"
821"\n"
822"Retrieves the type and value of a specified sub-key.\n"
823"\n"
824" key\n"
825" An already open key, or any one of the predefined HKEY_* constants.\n"
826" name\n"
827" A string indicating the value to query.\n"
828"\n"
829"Behaves mostly like QueryValue(), but also returns the type of the\n"
830"specified value name associated with the given open registry key.\n"
831"\n"
832"The return value is a tuple of the value and the type_id.");
833
834#define WINREG_QUERYVALUEEX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100835 {"QueryValueEx", (PyCFunction)winreg_QueryValueEx, METH_FASTCALL, winreg_QueryValueEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500836
837static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300838winreg_QueryValueEx_impl(PyObject *module, HKEY key, Py_UNICODE *name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500839
840static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100841winreg_QueryValueEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500842{
843 PyObject *return_value = NULL;
844 HKEY key;
845 Py_UNICODE *name;
846
Victor Stinner259f0e42017-01-17 01:35:17 +0100847 if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValueEx",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300848 clinic_HKEY_converter, &key, &name)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500849 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300850 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100851
852 if (!_PyArg_NoStackKeywords("QueryValueEx", kwnames)) {
853 goto exit;
854 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500855 return_value = winreg_QueryValueEx_impl(module, key, name);
856
857exit:
858 return return_value;
859}
860
861PyDoc_STRVAR(winreg_SaveKey__doc__,
862"SaveKey($module, key, file_name, /)\n"
863"--\n"
864"\n"
865"Saves the specified key, and all its subkeys to the specified file.\n"
866"\n"
867" key\n"
868" An already open key, or any one of the predefined HKEY_* constants.\n"
869" file_name\n"
870" The name of the file to save registry data to. This file cannot\n"
871" already exist. If this filename includes an extension, it cannot be\n"
872" used on file allocation table (FAT) file systems by the LoadKey(),\n"
873" ReplaceKey() or RestoreKey() methods.\n"
874"\n"
875"If key represents a key on a remote computer, the path described by\n"
876"file_name is relative to the remote computer.\n"
877"\n"
878"The caller of this method must possess the SeBackupPrivilege\n"
879"security privilege. This function passes NULL for security_attributes\n"
880"to the API.");
881
882#define WINREG_SAVEKEY_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100883 {"SaveKey", (PyCFunction)winreg_SaveKey, METH_FASTCALL, winreg_SaveKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500884
885static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300886winreg_SaveKey_impl(PyObject *module, HKEY key, Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500887
888static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100889winreg_SaveKey(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500890{
891 PyObject *return_value = NULL;
892 HKEY key;
893 Py_UNICODE *file_name;
894
Victor Stinner259f0e42017-01-17 01:35:17 +0100895 if (!_PyArg_ParseStack(args, nargs, "O&u:SaveKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300896 clinic_HKEY_converter, &key, &file_name)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500897 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300898 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100899
900 if (!_PyArg_NoStackKeywords("SaveKey", kwnames)) {
901 goto exit;
902 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500903 return_value = winreg_SaveKey_impl(module, key, file_name);
904
905exit:
906 return return_value;
907}
908
909PyDoc_STRVAR(winreg_SetValue__doc__,
910"SetValue($module, key, sub_key, type, value, /)\n"
911"--\n"
912"\n"
913"Associates a value with a specified key.\n"
914"\n"
915" key\n"
916" An already open key, or any one of the predefined HKEY_* constants.\n"
917" sub_key\n"
918" A string that names the subkey with which the value is associated.\n"
919" type\n"
920" An integer that specifies the type of the data. Currently this must\n"
921" be REG_SZ, meaning only strings are supported.\n"
922" value\n"
923" A string that specifies the new value.\n"
924"\n"
925"If the key specified by the sub_key parameter does not exist, the\n"
926"SetValue function creates it.\n"
927"\n"
928"Value lengths are limited by available memory. Long values (more than\n"
929"2048 bytes) should be stored as files with the filenames stored in\n"
930"the configuration registry to help the registry perform efficiently.\n"
931"\n"
932"The key identified by the key parameter must have been opened with\n"
933"KEY_SET_VALUE access.");
934
935#define WINREG_SETVALUE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100936 {"SetValue", (PyCFunction)winreg_SetValue, METH_FASTCALL, winreg_SetValue__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500937
938static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300939winreg_SetValue_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500940 DWORD type, Py_UNICODE *value,
941 Py_ssize_clean_t value_length);
Zachary Warefd2d4822015-05-13 01:21:57 -0500942
943static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100944winreg_SetValue(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500945{
946 PyObject *return_value = NULL;
947 HKEY key;
948 Py_UNICODE *sub_key;
949 DWORD type;
950 Py_UNICODE *value;
951 Py_ssize_clean_t value_length;
952
Victor Stinner259f0e42017-01-17 01:35:17 +0100953 if (!_PyArg_ParseStack(args, nargs, "O&Zku#:SetValue",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300954 clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500955 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300956 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100957
958 if (!_PyArg_NoStackKeywords("SetValue", kwnames)) {
959 goto exit;
960 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500961 return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length);
962
963exit:
964 return return_value;
965}
966
967PyDoc_STRVAR(winreg_SetValueEx__doc__,
968"SetValueEx($module, key, value_name, reserved, type, value, /)\n"
969"--\n"
970"\n"
971"Stores data in the value field of an open registry key.\n"
972"\n"
973" key\n"
974" An already open key, or any one of the predefined HKEY_* constants.\n"
975" value_name\n"
976" A string containing the name of the value to set, or None.\n"
977" reserved\n"
978" Can be anything - zero is always passed to the API.\n"
979" type\n"
980" An integer that specifies the type of the data, one of:\n"
981" REG_BINARY -- Binary data in any form.\n"
982" REG_DWORD -- A 32-bit number.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300983" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500984" REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
985" REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n"
986" references to environment variables (for example,\n"
987" %PATH%).\n"
988" REG_LINK -- A Unicode symbolic link.\n"
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300989" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500990" by two null characters. Note that Python handles\n"
991" this termination automatically.\n"
992" REG_NONE -- No defined value type.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300993" REG_QWORD -- A 64-bit number.\n"
994" REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500995" REG_RESOURCE_LIST -- A device-driver resource list.\n"
996" REG_SZ -- A null-terminated string.\n"
997" value\n"
998" A string that specifies the new value.\n"
999"\n"
1000"This method can also set additional value and type information for the\n"
1001"specified key. The key identified by the key parameter must have been\n"
1002"opened with KEY_SET_VALUE access.\n"
1003"\n"
1004"To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
1005"\n"
1006"Value lengths are limited by available memory. Long values (more than\n"
1007"2048 bytes) should be stored as files with the filenames stored in\n"
1008"the configuration registry to help the registry perform efficiently.");
1009
1010#define WINREG_SETVALUEEX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +01001011 {"SetValueEx", (PyCFunction)winreg_SetValueEx, METH_FASTCALL, winreg_SetValueEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -05001012
1013static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001014winreg_SetValueEx_impl(PyObject *module, HKEY key, Py_UNICODE *value_name,
Zachary Ware77772c02015-05-13 10:58:35 -05001015 PyObject *reserved, DWORD type, PyObject *value);
Zachary Warefd2d4822015-05-13 01:21:57 -05001016
1017static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +01001018winreg_SetValueEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -05001019{
1020 PyObject *return_value = NULL;
1021 HKEY key;
1022 Py_UNICODE *value_name;
1023 PyObject *reserved;
1024 DWORD type;
1025 PyObject *value;
1026
Victor Stinner259f0e42017-01-17 01:35:17 +01001027 if (!_PyArg_ParseStack(args, nargs, "O&ZOkO:SetValueEx",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001028 clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001029 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001030 }
Victor Stinner259f0e42017-01-17 01:35:17 +01001031
1032 if (!_PyArg_NoStackKeywords("SetValueEx", kwnames)) {
1033 goto exit;
1034 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001035 return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
1036
1037exit:
1038 return return_value;
1039}
1040
1041PyDoc_STRVAR(winreg_DisableReflectionKey__doc__,
1042"DisableReflectionKey($module, key, /)\n"
1043"--\n"
1044"\n"
1045"Disables registry reflection for 32bit processes running on a 64bit OS.\n"
1046"\n"
1047" key\n"
1048" An already open key, or any one of the predefined HKEY_* constants.\n"
1049"\n"
1050"Will generally raise NotImplemented if executed on a 32bit OS.\n"
1051"\n"
1052"If the key is not on the reflection list, the function succeeds but has\n"
1053"no effect. Disabling reflection for a key does not affect reflection\n"
1054"of any subkeys.");
1055
1056#define WINREG_DISABLEREFLECTIONKEY_METHODDEF \
1057 {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__},
1058
1059static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001060winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001061
1062static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001063winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001064{
1065 PyObject *return_value = NULL;
1066 HKEY key;
1067
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001068 if (!PyArg_Parse(arg, "O&:DisableReflectionKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001069 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001070 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001071 return_value = winreg_DisableReflectionKey_impl(module, key);
1072
1073exit:
1074 return return_value;
1075}
1076
1077PyDoc_STRVAR(winreg_EnableReflectionKey__doc__,
1078"EnableReflectionKey($module, key, /)\n"
1079"--\n"
1080"\n"
1081"Restores registry reflection for the specified disabled key.\n"
1082"\n"
1083" key\n"
1084" An already open key, or any one of the predefined HKEY_* constants.\n"
1085"\n"
1086"Will generally raise NotImplemented if executed on a 32bit OS.\n"
1087"Restoring reflection for a key does not affect reflection of any\n"
1088"subkeys.");
1089
1090#define WINREG_ENABLEREFLECTIONKEY_METHODDEF \
1091 {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__},
1092
1093static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001094winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001095
1096static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001097winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001098{
1099 PyObject *return_value = NULL;
1100 HKEY key;
1101
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001102 if (!PyArg_Parse(arg, "O&:EnableReflectionKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001103 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001104 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001105 return_value = winreg_EnableReflectionKey_impl(module, key);
1106
1107exit:
1108 return return_value;
1109}
1110
1111PyDoc_STRVAR(winreg_QueryReflectionKey__doc__,
1112"QueryReflectionKey($module, key, /)\n"
1113"--\n"
1114"\n"
1115"Returns the reflection state for the specified key as a bool.\n"
1116"\n"
1117" key\n"
1118" An already open key, or any one of the predefined HKEY_* constants.\n"
1119"\n"
1120"Will generally raise NotImplemented if executed on a 32bit OS.");
1121
1122#define WINREG_QUERYREFLECTIONKEY_METHODDEF \
1123 {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__},
1124
1125static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001126winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001127
1128static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001129winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001130{
1131 PyObject *return_value = NULL;
1132 HKEY key;
1133
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001134 if (!PyArg_Parse(arg, "O&:QueryReflectionKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001135 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001136 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001137 return_value = winreg_QueryReflectionKey_impl(module, key);
1138
1139exit:
1140 return return_value;
1141}
Victor Stinner259f0e42017-01-17 01:35:17 +01001142/*[clinic end generated code: output=ddc72b006143d33d input=a9049054013a1b77]*/