blob: c7d5b9e452b3a571b44c8b5502ca54d1d542a664 [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 Stinner37e4ef72016-09-09 20:00:13 -070096 if (!_PyArg_ParseStack(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 \
137 {"ConnectRegistry", (PyCFunction)winreg_ConnectRegistry, METH_VARARGS, winreg_ConnectRegistry__doc__},
138
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 *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300144winreg_ConnectRegistry(PyObject *module, PyObject *args)
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
Zachary Ware77772c02015-05-13 10:58:35 -0500151 if (!PyArg_ParseTuple(args, "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 }
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 \
185 {"CreateKey", (PyCFunction)winreg_CreateKey, METH_VARARGS, winreg_CreateKey__doc__},
186
187static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300188winreg_CreateKey_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500189
190static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300191winreg_CreateKey(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500192{
193 PyObject *return_value = NULL;
194 HKEY key;
195 Py_UNICODE *sub_key;
196 HKEY _return_value;
197
Zachary Ware77772c02015-05-13 10:58:35 -0500198 if (!PyArg_ParseTuple(args, "O&Z:CreateKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300199 clinic_HKEY_converter, &key, &sub_key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500200 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300201 }
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 \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700238 {"CreateKeyEx", (PyCFunction)winreg_CreateKeyEx, METH_FASTCALL, winreg_CreateKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500239
240static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300241winreg_CreateKeyEx_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500242 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500243
244static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700245winreg_CreateKeyEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500246{
247 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300248 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
249 static _PyArg_Parser _parser = {"O&Z|ii:CreateKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500250 HKEY key;
251 Py_UNICODE *sub_key;
252 int reserved = 0;
253 REGSAM access = KEY_WRITE;
254 HKEY _return_value;
255
Victor Stinner37e4ef72016-09-09 20:00:13 -0700256 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300257 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500258 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300259 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500260 _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300261 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500262 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300263 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500264 return_value = PyHKEY_FromHKEY(_return_value);
265
266exit:
267 return return_value;
268}
269
270PyDoc_STRVAR(winreg_DeleteKey__doc__,
271"DeleteKey($module, key, sub_key, /)\n"
272"--\n"
273"\n"
274"Deletes the specified key.\n"
275"\n"
276" key\n"
277" An already open key, or any one of the predefined HKEY_* constants.\n"
278" sub_key\n"
279" A string that must be the name of a subkey of the key identified by\n"
280" the key parameter. This value must not be None, and the key may not\n"
281" have subkeys.\n"
282"\n"
283"This method can not delete keys with subkeys.\n"
284"\n"
285"If the function succeeds, the entire key, including all of its values,\n"
286"is removed. If the function fails, an OSError exception is raised.");
287
288#define WINREG_DELETEKEY_METHODDEF \
289 {"DeleteKey", (PyCFunction)winreg_DeleteKey, METH_VARARGS, winreg_DeleteKey__doc__},
290
291static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300292winreg_DeleteKey_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500293
294static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300295winreg_DeleteKey(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500296{
297 PyObject *return_value = NULL;
298 HKEY key;
299 Py_UNICODE *sub_key;
300
Zachary Ware77772c02015-05-13 10:58:35 -0500301 if (!PyArg_ParseTuple(args, "O&u:DeleteKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300302 clinic_HKEY_converter, &key, &sub_key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500303 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300304 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500305 return_value = winreg_DeleteKey_impl(module, key, sub_key);
306
307exit:
308 return return_value;
309}
310
311PyDoc_STRVAR(winreg_DeleteKeyEx__doc__,
312"DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n"
313" reserved=0)\n"
314"--\n"
315"\n"
316"Deletes the specified key (64-bit OS only).\n"
317"\n"
318" key\n"
319" An already open key, or any one of the predefined HKEY_* constants.\n"
320" sub_key\n"
321" A string that must be the name of a subkey of the key identified by\n"
322" the key parameter. This value must not be None, and the key may not\n"
323" have subkeys.\n"
324" access\n"
325" An integer that specifies an access mask that describes the\n"
326" desired security access for the key. Default is KEY_WOW64_64KEY.\n"
327" reserved\n"
328" A reserved integer, and must be zero. Default is zero.\n"
329"\n"
330"This method can not delete keys with subkeys.\n"
331"\n"
332"If the function succeeds, the entire key, including all of its values,\n"
333"is removed. If the function fails, an OSError exception is raised.\n"
334"On unsupported Windows versions, NotImplementedError is raised.");
335
336#define WINREG_DELETEKEYEX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700337 {"DeleteKeyEx", (PyCFunction)winreg_DeleteKeyEx, METH_FASTCALL, winreg_DeleteKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500338
339static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300340winreg_DeleteKeyEx_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500341 REGSAM access, int reserved);
Zachary Warefd2d4822015-05-13 01:21:57 -0500342
343static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700344winreg_DeleteKeyEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500345{
346 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300347 static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL};
348 static _PyArg_Parser _parser = {"O&u|ii:DeleteKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500349 HKEY key;
350 Py_UNICODE *sub_key;
351 REGSAM access = KEY_WOW64_64KEY;
352 int reserved = 0;
353
Victor Stinner37e4ef72016-09-09 20:00:13 -0700354 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300355 clinic_HKEY_converter, &key, &sub_key, &access, &reserved)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500356 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300357 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500358 return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
359
360exit:
361 return return_value;
362}
363
364PyDoc_STRVAR(winreg_DeleteValue__doc__,
365"DeleteValue($module, key, value, /)\n"
366"--\n"
367"\n"
368"Removes a named value from a registry key.\n"
369"\n"
370" key\n"
371" An already open key, or any one of the predefined HKEY_* constants.\n"
372" value\n"
373" A string that identifies the value to remove.");
374
375#define WINREG_DELETEVALUE_METHODDEF \
376 {"DeleteValue", (PyCFunction)winreg_DeleteValue, METH_VARARGS, winreg_DeleteValue__doc__},
377
378static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300379winreg_DeleteValue_impl(PyObject *module, HKEY key, Py_UNICODE *value);
Zachary Warefd2d4822015-05-13 01:21:57 -0500380
381static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300382winreg_DeleteValue(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500383{
384 PyObject *return_value = NULL;
385 HKEY key;
386 Py_UNICODE *value;
387
Zachary Ware77772c02015-05-13 10:58:35 -0500388 if (!PyArg_ParseTuple(args, "O&Z:DeleteValue",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300389 clinic_HKEY_converter, &key, &value)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500390 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300391 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500392 return_value = winreg_DeleteValue_impl(module, key, value);
393
394exit:
395 return return_value;
396}
397
398PyDoc_STRVAR(winreg_EnumKey__doc__,
399"EnumKey($module, key, index, /)\n"
400"--\n"
401"\n"
402"Enumerates subkeys of an open registry key.\n"
403"\n"
404" key\n"
405" An already open key, or any one of the predefined HKEY_* constants.\n"
406" index\n"
407" An integer that identifies the index of the key to retrieve.\n"
408"\n"
409"The function retrieves the name of one subkey each time it is called.\n"
410"It is typically called repeatedly until an OSError exception is\n"
411"raised, indicating no more values are available.");
412
413#define WINREG_ENUMKEY_METHODDEF \
414 {"EnumKey", (PyCFunction)winreg_EnumKey, METH_VARARGS, winreg_EnumKey__doc__},
415
416static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300417winreg_EnumKey_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500418
419static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300420winreg_EnumKey(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500421{
422 PyObject *return_value = NULL;
423 HKEY key;
424 int index;
425
Zachary Ware77772c02015-05-13 10:58:35 -0500426 if (!PyArg_ParseTuple(args, "O&i:EnumKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300427 clinic_HKEY_converter, &key, &index)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500428 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300429 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500430 return_value = winreg_EnumKey_impl(module, key, index);
431
432exit:
433 return return_value;
434}
435
436PyDoc_STRVAR(winreg_EnumValue__doc__,
437"EnumValue($module, key, index, /)\n"
438"--\n"
439"\n"
440"Enumerates values of an open registry key.\n"
441"\n"
442" key\n"
443" An already open key, or any one of the predefined HKEY_* constants.\n"
444" index\n"
445" An integer that identifies the index of the value to retrieve.\n"
446"\n"
447"The function retrieves the name of one subkey each time it is called.\n"
448"It is typically called repeatedly, until an OSError exception\n"
449"is raised, indicating no more values.\n"
450"\n"
451"The result is a tuple of 3 items:\n"
452" value_name\n"
453" A string that identifies the value.\n"
454" value_data\n"
455" An object that holds the value data, and whose type depends\n"
456" on the underlying registry type.\n"
457" data_type\n"
458" An integer that identifies the type of the value data.");
459
460#define WINREG_ENUMVALUE_METHODDEF \
461 {"EnumValue", (PyCFunction)winreg_EnumValue, METH_VARARGS, winreg_EnumValue__doc__},
462
463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300464winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
Zachary Warefd2d4822015-05-13 01:21:57 -0500465
466static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300467winreg_EnumValue(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500468{
469 PyObject *return_value = NULL;
470 HKEY key;
471 int index;
472
Zachary Ware77772c02015-05-13 10:58:35 -0500473 if (!PyArg_ParseTuple(args, "O&i:EnumValue",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300474 clinic_HKEY_converter, &key, &index)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500475 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300476 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500477 return_value = winreg_EnumValue_impl(module, key, index);
478
479exit:
480 return return_value;
481}
482
483PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__,
484"ExpandEnvironmentStrings($module, string, /)\n"
485"--\n"
486"\n"
487"Expand environment vars.");
488
489#define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF \
490 {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__},
491
492static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300493winreg_ExpandEnvironmentStrings_impl(PyObject *module, Py_UNICODE *string);
Zachary Warefd2d4822015-05-13 01:21:57 -0500494
495static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300496winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500497{
498 PyObject *return_value = NULL;
499 Py_UNICODE *string;
500
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300501 if (!PyArg_Parse(arg, "u:ExpandEnvironmentStrings", &string)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500502 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300503 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500504 return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
505
506exit:
507 return return_value;
508}
509
510PyDoc_STRVAR(winreg_FlushKey__doc__,
511"FlushKey($module, key, /)\n"
512"--\n"
513"\n"
514"Writes all the attributes of a key to the registry.\n"
515"\n"
516" key\n"
517" An already open key, or any one of the predefined HKEY_* constants.\n"
518"\n"
519"It is not necessary to call FlushKey to change a key. Registry changes\n"
520"are flushed to disk by the registry using its lazy flusher. Registry\n"
521"changes are also flushed to disk at system shutdown. Unlike\n"
522"CloseKey(), the FlushKey() method returns only when all the data has\n"
523"been written to the registry.\n"
524"\n"
525"An application should only call FlushKey() if it requires absolute\n"
526"certainty that registry changes are on disk. If you don\'t know whether\n"
527"a FlushKey() call is required, it probably isn\'t.");
528
529#define WINREG_FLUSHKEY_METHODDEF \
530 {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__},
531
532static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300533winreg_FlushKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500534
535static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300536winreg_FlushKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500537{
538 PyObject *return_value = NULL;
539 HKEY key;
540
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300541 if (!PyArg_Parse(arg, "O&:FlushKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500542 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300543 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500544 return_value = winreg_FlushKey_impl(module, key);
545
546exit:
547 return return_value;
548}
549
550PyDoc_STRVAR(winreg_LoadKey__doc__,
551"LoadKey($module, key, sub_key, file_name, /)\n"
552"--\n"
553"\n"
554"Insert data into the registry from a file.\n"
555"\n"
556" key\n"
557" An already open key, or any one of the predefined HKEY_* constants.\n"
558" sub_key\n"
559" A string that identifies the sub-key to load.\n"
560" file_name\n"
561" The name of the file to load registry data from. This file must\n"
562" have been created with the SaveKey() function. Under the file\n"
563" allocation table (FAT) file system, the filename may not have an\n"
564" extension.\n"
565"\n"
566"Creates a subkey under the specified key and stores registration\n"
567"information from a specified file into that subkey.\n"
568"\n"
569"A call to LoadKey() fails if the calling process does not have the\n"
570"SE_RESTORE_PRIVILEGE privilege.\n"
571"\n"
572"If key is a handle returned by ConnectRegistry(), then the path\n"
573"specified in fileName is relative to the remote computer.\n"
574"\n"
575"The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n"
576"tree.");
577
578#define WINREG_LOADKEY_METHODDEF \
579 {"LoadKey", (PyCFunction)winreg_LoadKey, METH_VARARGS, winreg_LoadKey__doc__},
580
581static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300582winreg_LoadKey_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500583 Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500584
585static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300586winreg_LoadKey(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500587{
588 PyObject *return_value = NULL;
589 HKEY key;
590 Py_UNICODE *sub_key;
591 Py_UNICODE *file_name;
592
Zachary Ware77772c02015-05-13 10:58:35 -0500593 if (!PyArg_ParseTuple(args, "O&uu:LoadKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300594 clinic_HKEY_converter, &key, &sub_key, &file_name)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500595 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300596 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500597 return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
598
599exit:
600 return return_value;
601}
602
603PyDoc_STRVAR(winreg_OpenKey__doc__,
604"OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
605"--\n"
606"\n"
607"Opens the specified key.\n"
608"\n"
609" key\n"
610" An already open key, or any one of the predefined HKEY_* constants.\n"
611" sub_key\n"
612" A string that identifies the sub_key to open.\n"
613" reserved\n"
614" A reserved integer that must be zero. Default is zero.\n"
615" access\n"
616" An integer that specifies an access mask that describes the desired\n"
617" security access for the key. Default is KEY_READ.\n"
618"\n"
619"The result is a new handle to the specified key.\n"
620"If the function fails, an OSError exception is raised.");
621
622#define WINREG_OPENKEY_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700623 {"OpenKey", (PyCFunction)winreg_OpenKey, METH_FASTCALL, winreg_OpenKey__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500624
625static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300626winreg_OpenKey_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500627 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500628
629static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700630winreg_OpenKey(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500631{
632 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300633 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
634 static _PyArg_Parser _parser = {"O&Z|ii:OpenKey", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500635 HKEY key;
636 Py_UNICODE *sub_key;
637 int reserved = 0;
638 REGSAM access = KEY_READ;
639 HKEY _return_value;
640
Victor Stinner37e4ef72016-09-09 20:00:13 -0700641 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300642 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500643 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300644 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500645 _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300646 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500647 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300648 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500649 return_value = PyHKEY_FromHKEY(_return_value);
650
651exit:
652 return return_value;
653}
654
655PyDoc_STRVAR(winreg_OpenKeyEx__doc__,
656"OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
657"--\n"
658"\n"
659"Opens the specified key.\n"
660"\n"
661" key\n"
662" An already open key, or any one of the predefined HKEY_* constants.\n"
663" sub_key\n"
664" A string that identifies the sub_key to open.\n"
665" reserved\n"
666" A reserved integer that must be zero. Default is zero.\n"
667" access\n"
668" An integer that specifies an access mask that describes the desired\n"
669" security access for the key. Default is KEY_READ.\n"
670"\n"
671"The result is a new handle to the specified key.\n"
672"If the function fails, an OSError exception is raised.");
673
674#define WINREG_OPENKEYEX_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700675 {"OpenKeyEx", (PyCFunction)winreg_OpenKeyEx, METH_FASTCALL, winreg_OpenKeyEx__doc__},
Zachary Warefd2d4822015-05-13 01:21:57 -0500676
677static HKEY
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300678winreg_OpenKeyEx_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500679 int reserved, REGSAM access);
Zachary Warefd2d4822015-05-13 01:21:57 -0500680
681static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700682winreg_OpenKeyEx(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Zachary Warefd2d4822015-05-13 01:21:57 -0500683{
684 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300685 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
686 static _PyArg_Parser _parser = {"O&Z|ii:OpenKeyEx", _keywords, 0};
Zachary Warefd2d4822015-05-13 01:21:57 -0500687 HKEY key;
688 Py_UNICODE *sub_key;
689 int reserved = 0;
690 REGSAM access = KEY_READ;
691 HKEY _return_value;
692
Victor Stinner37e4ef72016-09-09 20:00:13 -0700693 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300694 clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500695 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300696 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500697 _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300698 if (_return_value == NULL) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500699 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300700 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500701 return_value = PyHKEY_FromHKEY(_return_value);
702
703exit:
704 return return_value;
705}
706
707PyDoc_STRVAR(winreg_QueryInfoKey__doc__,
708"QueryInfoKey($module, key, /)\n"
709"--\n"
710"\n"
711"Returns information about a key.\n"
712"\n"
713" key\n"
714" An already open key, or any one of the predefined HKEY_* constants.\n"
715"\n"
716"The result is a tuple of 3 items:\n"
717"An integer that identifies the number of sub keys this key has.\n"
718"An integer that identifies the number of values this key has.\n"
719"An integer that identifies when the key was last modified (if available)\n"
720"as 100\'s of nanoseconds since Jan 1, 1600.");
721
722#define WINREG_QUERYINFOKEY_METHODDEF \
723 {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__},
724
725static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300726winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500727
728static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300729winreg_QueryInfoKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -0500730{
731 PyObject *return_value = NULL;
732 HKEY key;
733
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300734 if (!PyArg_Parse(arg, "O&:QueryInfoKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500735 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300736 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500737 return_value = winreg_QueryInfoKey_impl(module, key);
738
739exit:
740 return return_value;
741}
742
743PyDoc_STRVAR(winreg_QueryValue__doc__,
744"QueryValue($module, key, sub_key, /)\n"
745"--\n"
746"\n"
747"Retrieves the unnamed value for a key.\n"
748"\n"
749" key\n"
750" An already open key, or any one of the predefined HKEY_* constants.\n"
751" sub_key\n"
752" A string that holds the name of the subkey with which the value\n"
753" is associated. If this parameter is None or empty, the function\n"
754" retrieves the value set by the SetValue() method for the key\n"
755" identified by key.\n"
756"\n"
757"Values in the registry have name, type, and data components. This method\n"
758"retrieves the data for a key\'s first value that has a NULL name.\n"
759"But since the underlying API call doesn\'t return the type, you\'ll\n"
760"probably be happier using QueryValueEx; this function is just here for\n"
761"completeness.");
762
763#define WINREG_QUERYVALUE_METHODDEF \
764 {"QueryValue", (PyCFunction)winreg_QueryValue, METH_VARARGS, winreg_QueryValue__doc__},
765
766static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300767winreg_QueryValue_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key);
Zachary Warefd2d4822015-05-13 01:21:57 -0500768
769static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300770winreg_QueryValue(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500771{
772 PyObject *return_value = NULL;
773 HKEY key;
774 Py_UNICODE *sub_key;
775
Zachary Ware77772c02015-05-13 10:58:35 -0500776 if (!PyArg_ParseTuple(args, "O&Z:QueryValue",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300777 clinic_HKEY_converter, &key, &sub_key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500778 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300779 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500780 return_value = winreg_QueryValue_impl(module, key, sub_key);
781
782exit:
783 return return_value;
784}
785
786PyDoc_STRVAR(winreg_QueryValueEx__doc__,
787"QueryValueEx($module, key, name, /)\n"
788"--\n"
789"\n"
790"Retrieves the type and value of a specified sub-key.\n"
791"\n"
792" key\n"
793" An already open key, or any one of the predefined HKEY_* constants.\n"
794" name\n"
795" A string indicating the value to query.\n"
796"\n"
797"Behaves mostly like QueryValue(), but also returns the type of the\n"
798"specified value name associated with the given open registry key.\n"
799"\n"
800"The return value is a tuple of the value and the type_id.");
801
802#define WINREG_QUERYVALUEEX_METHODDEF \
803 {"QueryValueEx", (PyCFunction)winreg_QueryValueEx, METH_VARARGS, winreg_QueryValueEx__doc__},
804
805static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300806winreg_QueryValueEx_impl(PyObject *module, HKEY key, Py_UNICODE *name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500807
808static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300809winreg_QueryValueEx(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500810{
811 PyObject *return_value = NULL;
812 HKEY key;
813 Py_UNICODE *name;
814
Zachary Ware77772c02015-05-13 10:58:35 -0500815 if (!PyArg_ParseTuple(args, "O&Z:QueryValueEx",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300816 clinic_HKEY_converter, &key, &name)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500817 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300818 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500819 return_value = winreg_QueryValueEx_impl(module, key, name);
820
821exit:
822 return return_value;
823}
824
825PyDoc_STRVAR(winreg_SaveKey__doc__,
826"SaveKey($module, key, file_name, /)\n"
827"--\n"
828"\n"
829"Saves the specified key, and all its subkeys to the specified file.\n"
830"\n"
831" key\n"
832" An already open key, or any one of the predefined HKEY_* constants.\n"
833" file_name\n"
834" The name of the file to save registry data to. This file cannot\n"
835" already exist. If this filename includes an extension, it cannot be\n"
836" used on file allocation table (FAT) file systems by the LoadKey(),\n"
837" ReplaceKey() or RestoreKey() methods.\n"
838"\n"
839"If key represents a key on a remote computer, the path described by\n"
840"file_name is relative to the remote computer.\n"
841"\n"
842"The caller of this method must possess the SeBackupPrivilege\n"
843"security privilege. This function passes NULL for security_attributes\n"
844"to the API.");
845
846#define WINREG_SAVEKEY_METHODDEF \
847 {"SaveKey", (PyCFunction)winreg_SaveKey, METH_VARARGS, winreg_SaveKey__doc__},
848
849static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300850winreg_SaveKey_impl(PyObject *module, HKEY key, Py_UNICODE *file_name);
Zachary Warefd2d4822015-05-13 01:21:57 -0500851
852static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300853winreg_SaveKey(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500854{
855 PyObject *return_value = NULL;
856 HKEY key;
857 Py_UNICODE *file_name;
858
Zachary Ware77772c02015-05-13 10:58:35 -0500859 if (!PyArg_ParseTuple(args, "O&u:SaveKey",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300860 clinic_HKEY_converter, &key, &file_name)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500861 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300862 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500863 return_value = winreg_SaveKey_impl(module, key, file_name);
864
865exit:
866 return return_value;
867}
868
869PyDoc_STRVAR(winreg_SetValue__doc__,
870"SetValue($module, key, sub_key, type, value, /)\n"
871"--\n"
872"\n"
873"Associates a value with a specified key.\n"
874"\n"
875" key\n"
876" An already open key, or any one of the predefined HKEY_* constants.\n"
877" sub_key\n"
878" A string that names the subkey with which the value is associated.\n"
879" type\n"
880" An integer that specifies the type of the data. Currently this must\n"
881" be REG_SZ, meaning only strings are supported.\n"
882" value\n"
883" A string that specifies the new value.\n"
884"\n"
885"If the key specified by the sub_key parameter does not exist, the\n"
886"SetValue function creates it.\n"
887"\n"
888"Value lengths are limited by available memory. Long values (more than\n"
889"2048 bytes) should be stored as files with the filenames stored in\n"
890"the configuration registry to help the registry perform efficiently.\n"
891"\n"
892"The key identified by the key parameter must have been opened with\n"
893"KEY_SET_VALUE access.");
894
895#define WINREG_SETVALUE_METHODDEF \
896 {"SetValue", (PyCFunction)winreg_SetValue, METH_VARARGS, winreg_SetValue__doc__},
897
898static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300899winreg_SetValue_impl(PyObject *module, HKEY key, Py_UNICODE *sub_key,
Zachary Ware77772c02015-05-13 10:58:35 -0500900 DWORD type, Py_UNICODE *value,
901 Py_ssize_clean_t value_length);
Zachary Warefd2d4822015-05-13 01:21:57 -0500902
903static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300904winreg_SetValue(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500905{
906 PyObject *return_value = NULL;
907 HKEY key;
908 Py_UNICODE *sub_key;
909 DWORD type;
910 Py_UNICODE *value;
911 Py_ssize_clean_t value_length;
912
Zachary Ware77772c02015-05-13 10:58:35 -0500913 if (!PyArg_ParseTuple(args, "O&Zku#:SetValue",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300914 clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500915 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300916 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500917 return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length);
918
919exit:
920 return return_value;
921}
922
923PyDoc_STRVAR(winreg_SetValueEx__doc__,
924"SetValueEx($module, key, value_name, reserved, type, value, /)\n"
925"--\n"
926"\n"
927"Stores data in the value field of an open registry key.\n"
928"\n"
929" key\n"
930" An already open key, or any one of the predefined HKEY_* constants.\n"
931" value_name\n"
932" A string containing the name of the value to set, or None.\n"
933" reserved\n"
934" Can be anything - zero is always passed to the API.\n"
935" type\n"
936" An integer that specifies the type of the data, one of:\n"
937" REG_BINARY -- Binary data in any form.\n"
938" REG_DWORD -- A 32-bit number.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300939" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500940" REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
941" REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n"
942" references to environment variables (for example,\n"
943" %PATH%).\n"
944" REG_LINK -- A Unicode symbolic link.\n"
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300945" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500946" by two null characters. Note that Python handles\n"
947" this termination automatically.\n"
948" REG_NONE -- No defined value type.\n"
Serhiy Storchaka877826a2016-06-09 16:01:19 +0300949" REG_QWORD -- A 64-bit number.\n"
950" REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n"
Zachary Warefd2d4822015-05-13 01:21:57 -0500951" REG_RESOURCE_LIST -- A device-driver resource list.\n"
952" REG_SZ -- A null-terminated string.\n"
953" value\n"
954" A string that specifies the new value.\n"
955"\n"
956"This method can also set additional value and type information for the\n"
957"specified key. The key identified by the key parameter must have been\n"
958"opened with KEY_SET_VALUE access.\n"
959"\n"
960"To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
961"\n"
962"Value lengths are limited by available memory. Long values (more than\n"
963"2048 bytes) should be stored as files with the filenames stored in\n"
964"the configuration registry to help the registry perform efficiently.");
965
966#define WINREG_SETVALUEEX_METHODDEF \
967 {"SetValueEx", (PyCFunction)winreg_SetValueEx, METH_VARARGS, winreg_SetValueEx__doc__},
968
969static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300970winreg_SetValueEx_impl(PyObject *module, HKEY key, Py_UNICODE *value_name,
Zachary Ware77772c02015-05-13 10:58:35 -0500971 PyObject *reserved, DWORD type, PyObject *value);
Zachary Warefd2d4822015-05-13 01:21:57 -0500972
973static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300974winreg_SetValueEx(PyObject *module, PyObject *args)
Zachary Warefd2d4822015-05-13 01:21:57 -0500975{
976 PyObject *return_value = NULL;
977 HKEY key;
978 Py_UNICODE *value_name;
979 PyObject *reserved;
980 DWORD type;
981 PyObject *value;
982
Zachary Ware77772c02015-05-13 10:58:35 -0500983 if (!PyArg_ParseTuple(args, "O&ZOkO:SetValueEx",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300984 clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) {
Zachary Warefd2d4822015-05-13 01:21:57 -0500985 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300986 }
Zachary Warefd2d4822015-05-13 01:21:57 -0500987 return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
988
989exit:
990 return return_value;
991}
992
993PyDoc_STRVAR(winreg_DisableReflectionKey__doc__,
994"DisableReflectionKey($module, key, /)\n"
995"--\n"
996"\n"
997"Disables registry reflection for 32bit processes running on a 64bit OS.\n"
998"\n"
999" key\n"
1000" An already open key, or any one of the predefined HKEY_* constants.\n"
1001"\n"
1002"Will generally raise NotImplemented if executed on a 32bit OS.\n"
1003"\n"
1004"If the key is not on the reflection list, the function succeeds but has\n"
1005"no effect. Disabling reflection for a key does not affect reflection\n"
1006"of any subkeys.");
1007
1008#define WINREG_DISABLEREFLECTIONKEY_METHODDEF \
1009 {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__},
1010
1011static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001012winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001013
1014static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001015winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001016{
1017 PyObject *return_value = NULL;
1018 HKEY key;
1019
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001020 if (!PyArg_Parse(arg, "O&:DisableReflectionKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001021 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001022 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001023 return_value = winreg_DisableReflectionKey_impl(module, key);
1024
1025exit:
1026 return return_value;
1027}
1028
1029PyDoc_STRVAR(winreg_EnableReflectionKey__doc__,
1030"EnableReflectionKey($module, key, /)\n"
1031"--\n"
1032"\n"
1033"Restores registry reflection for the specified disabled key.\n"
1034"\n"
1035" key\n"
1036" An already open key, or any one of the predefined HKEY_* constants.\n"
1037"\n"
1038"Will generally raise NotImplemented if executed on a 32bit OS.\n"
1039"Restoring reflection for a key does not affect reflection of any\n"
1040"subkeys.");
1041
1042#define WINREG_ENABLEREFLECTIONKEY_METHODDEF \
1043 {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__},
1044
1045static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001046winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001047
1048static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001049winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001050{
1051 PyObject *return_value = NULL;
1052 HKEY key;
1053
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001054 if (!PyArg_Parse(arg, "O&:EnableReflectionKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001055 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001056 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001057 return_value = winreg_EnableReflectionKey_impl(module, key);
1058
1059exit:
1060 return return_value;
1061}
1062
1063PyDoc_STRVAR(winreg_QueryReflectionKey__doc__,
1064"QueryReflectionKey($module, key, /)\n"
1065"--\n"
1066"\n"
1067"Returns the reflection state for the specified key as a bool.\n"
1068"\n"
1069" key\n"
1070" An already open key, or any one of the predefined HKEY_* constants.\n"
1071"\n"
1072"Will generally raise NotImplemented if executed on a 32bit OS.");
1073
1074#define WINREG_QUERYREFLECTIONKEY_METHODDEF \
1075 {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__},
1076
1077static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001078winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
Zachary Warefd2d4822015-05-13 01:21:57 -05001079
1080static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001081winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
Zachary Warefd2d4822015-05-13 01:21:57 -05001082{
1083 PyObject *return_value = NULL;
1084 HKEY key;
1085
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001086 if (!PyArg_Parse(arg, "O&:QueryReflectionKey", clinic_HKEY_converter, &key)) {
Zachary Warefd2d4822015-05-13 01:21:57 -05001087 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001088 }
Zachary Warefd2d4822015-05-13 01:21:57 -05001089 return_value = winreg_QueryReflectionKey_impl(module, key);
1090
1091exit:
1092 return return_value;
1093}
Victor Stinner37e4ef72016-09-09 20:00:13 -07001094/*[clinic end generated code: output=16dd06be6e14b86e input=a9049054013a1b77]*/