1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_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
16 static PyObject *
17 winreg_HKEYType_Close_impl(PyHKEYObject *self);
18
19 static PyObject *
winreg_HKEYType_Close(PyHKEYObject * self,PyObject * Py_UNUSED (ignored))20 winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
21 {
22 return winreg_HKEYType_Close_impl(self);
23 }
24
25 PyDoc_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
42 static PyObject *
43 winreg_HKEYType_Detach_impl(PyHKEYObject *self);
44
45 static PyObject *
winreg_HKEYType_Detach(PyHKEYObject * self,PyObject * Py_UNUSED (ignored))46 winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
47 {
48 return winreg_HKEYType_Detach_impl(self);
49 }
50
51 PyDoc_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
59 static PyHKEYObject *
60 winreg_HKEYType___enter___impl(PyHKEYObject *self);
61
62 static PyObject *
winreg_HKEYType___enter__(PyHKEYObject * self,PyObject * Py_UNUSED (ignored))63 winreg_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
74 PyDoc_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 \
80 {"__exit__", _PyCFunction_CAST(winreg_HKEYType___exit__), METH_FASTCALL|METH_KEYWORDS, winreg_HKEYType___exit____doc__},
81
82 static PyObject *
83 winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type,
84 PyObject *exc_value, PyObject *traceback);
85
86 static PyObject *
winreg_HKEYType___exit__(PyHKEYObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)87 winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
88 {
89 PyObject *return_value = NULL;
90 static const char * const _keywords[] = {"exc_type", "exc_value", "traceback", NULL};
91 static _PyArg_Parser _parser = {NULL, _keywords, "__exit__", 0};
92 PyObject *argsbuf[3];
93 PyObject *exc_type;
94 PyObject *exc_value;
95 PyObject *traceback;
96
97 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
98 if (!args) {
99 goto exit;
100 }
101 exc_type = args[0];
102 exc_value = args[1];
103 traceback = args[2];
104 return_value = winreg_HKEYType___exit___impl(self, exc_type, exc_value, traceback);
105
106 exit:
107 return return_value;
108 }
109
110 PyDoc_STRVAR(winreg_CloseKey__doc__,
111 "CloseKey($module, hkey, /)\n"
112 "--\n"
113 "\n"
114 "Closes a previously opened registry key.\n"
115 "\n"
116 " hkey\n"
117 " A previously opened key.\n"
118 "\n"
119 "Note that if the key is not closed using this method, it will be\n"
120 "closed when the hkey object is destroyed by Python.");
121
122 #define WINREG_CLOSEKEY_METHODDEF \
123 {"CloseKey", (PyCFunction)winreg_CloseKey, METH_O, winreg_CloseKey__doc__},
124
125 PyDoc_STRVAR(winreg_ConnectRegistry__doc__,
126 "ConnectRegistry($module, computer_name, key, /)\n"
127 "--\n"
128 "\n"
129 "Establishes a connection to the registry on another computer.\n"
130 "\n"
131 " computer_name\n"
132 " The name of the remote computer, of the form r\"\\\\computername\". If\n"
133 " None, the local computer is used.\n"
134 " key\n"
135 " The predefined key to connect to.\n"
136 "\n"
137 "The return value is the handle of the opened key.\n"
138 "If the function fails, an OSError exception is raised.");
139
140 #define WINREG_CONNECTREGISTRY_METHODDEF \
141 {"ConnectRegistry", _PyCFunction_CAST(winreg_ConnectRegistry), METH_FASTCALL, winreg_ConnectRegistry__doc__},
142
143 static HKEY
144 winreg_ConnectRegistry_impl(PyObject *module,
145 const Py_UNICODE *computer_name, HKEY key);
146
147 static PyObject *
winreg_ConnectRegistry(PyObject * module,PyObject * const * args,Py_ssize_t nargs)148 winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
149 {
150 PyObject *return_value = NULL;
151 const Py_UNICODE *computer_name = NULL;
152 HKEY key;
153 HKEY _return_value;
154
155 if (!_PyArg_CheckPositional("ConnectRegistry", nargs, 2, 2)) {
156 goto exit;
157 }
158 if (args[0] == Py_None) {
159 computer_name = NULL;
160 }
161 else if (PyUnicode_Check(args[0])) {
162 #if USE_UNICODE_WCHAR_CACHE
163 computer_name = _PyUnicode_AsUnicode(args[0]);
164 #else /* USE_UNICODE_WCHAR_CACHE */
165 computer_name = PyUnicode_AsWideCharString(args[0], NULL);
166 #endif /* USE_UNICODE_WCHAR_CACHE */
167 if (computer_name == NULL) {
168 goto exit;
169 }
170 }
171 else {
172 _PyArg_BadArgument("ConnectRegistry", "argument 1", "str or None", args[0]);
173 goto exit;
174 }
175 if (!clinic_HKEY_converter(args[1], &key)) {
176 goto exit;
177 }
178 _return_value = winreg_ConnectRegistry_impl(module, computer_name, key);
179 if (_return_value == NULL) {
180 goto exit;
181 }
182 return_value = PyHKEY_FromHKEY(_return_value);
183
184 exit:
185 /* Cleanup for computer_name */
186 #if !USE_UNICODE_WCHAR_CACHE
187 PyMem_Free((void *)computer_name);
188 #endif /* USE_UNICODE_WCHAR_CACHE */
189
190 return return_value;
191 }
192
193 PyDoc_STRVAR(winreg_CreateKey__doc__,
194 "CreateKey($module, key, sub_key, /)\n"
195 "--\n"
196 "\n"
197 "Creates or opens the specified key.\n"
198 "\n"
199 " key\n"
200 " An already open key, or one of the predefined HKEY_* constants.\n"
201 " sub_key\n"
202 " The name of the key this method opens or creates.\n"
203 "\n"
204 "If key is one of the predefined keys, sub_key may be None. In that case,\n"
205 "the handle returned is the same key handle passed in to the function.\n"
206 "\n"
207 "If the key already exists, this function opens the existing key.\n"
208 "\n"
209 "The return value is the handle of the opened key.\n"
210 "If the function fails, an OSError exception is raised.");
211
212 #define WINREG_CREATEKEY_METHODDEF \
213 {"CreateKey", _PyCFunction_CAST(winreg_CreateKey), METH_FASTCALL, winreg_CreateKey__doc__},
214
215 static HKEY
216 winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
217
218 static PyObject *
winreg_CreateKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)219 winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
220 {
221 PyObject *return_value = NULL;
222 HKEY key;
223 const Py_UNICODE *sub_key = NULL;
224 HKEY _return_value;
225
226 if (!_PyArg_CheckPositional("CreateKey", nargs, 2, 2)) {
227 goto exit;
228 }
229 if (!clinic_HKEY_converter(args[0], &key)) {
230 goto exit;
231 }
232 if (args[1] == Py_None) {
233 sub_key = NULL;
234 }
235 else if (PyUnicode_Check(args[1])) {
236 #if USE_UNICODE_WCHAR_CACHE
237 sub_key = _PyUnicode_AsUnicode(args[1]);
238 #else /* USE_UNICODE_WCHAR_CACHE */
239 sub_key = PyUnicode_AsWideCharString(args[1], NULL);
240 #endif /* USE_UNICODE_WCHAR_CACHE */
241 if (sub_key == NULL) {
242 goto exit;
243 }
244 }
245 else {
246 _PyArg_BadArgument("CreateKey", "argument 2", "str or None", args[1]);
247 goto exit;
248 }
249 _return_value = winreg_CreateKey_impl(module, key, sub_key);
250 if (_return_value == NULL) {
251 goto exit;
252 }
253 return_value = PyHKEY_FromHKEY(_return_value);
254
255 exit:
256 /* Cleanup for sub_key */
257 #if !USE_UNICODE_WCHAR_CACHE
258 PyMem_Free((void *)sub_key);
259 #endif /* USE_UNICODE_WCHAR_CACHE */
260
261 return return_value;
262 }
263
264 PyDoc_STRVAR(winreg_CreateKeyEx__doc__,
265 "CreateKeyEx($module, /, key, sub_key, reserved=0,\n"
266 " access=winreg.KEY_WRITE)\n"
267 "--\n"
268 "\n"
269 "Creates or opens the specified key.\n"
270 "\n"
271 " key\n"
272 " An already open key, or one of the predefined HKEY_* constants.\n"
273 " sub_key\n"
274 " The name of the key this method opens or creates.\n"
275 " reserved\n"
276 " A reserved integer, and must be zero. Default is zero.\n"
277 " access\n"
278 " An integer that specifies an access mask that describes the\n"
279 " desired security access for the key. Default is KEY_WRITE.\n"
280 "\n"
281 "If key is one of the predefined keys, sub_key may be None. In that case,\n"
282 "the handle returned is the same key handle passed in to the function.\n"
283 "\n"
284 "If the key already exists, this function opens the existing key\n"
285 "\n"
286 "The return value is the handle of the opened key.\n"
287 "If the function fails, an OSError exception is raised.");
288
289 #define WINREG_CREATEKEYEX_METHODDEF \
290 {"CreateKeyEx", _PyCFunction_CAST(winreg_CreateKeyEx), METH_FASTCALL|METH_KEYWORDS, winreg_CreateKeyEx__doc__},
291
292 static HKEY
293 winreg_CreateKeyEx_impl(PyObject *module, HKEY key,
294 const Py_UNICODE *sub_key, int reserved,
295 REGSAM access);
296
297 static PyObject *
winreg_CreateKeyEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)298 winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
299 {
300 PyObject *return_value = NULL;
301 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
302 static _PyArg_Parser _parser = {"O&O&|ii:CreateKeyEx", _keywords, 0};
303 HKEY key;
304 const Py_UNICODE *sub_key = NULL;
305 int reserved = 0;
306 REGSAM access = KEY_WRITE;
307 HKEY _return_value;
308
309 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
310 clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
311 goto exit;
312 }
313 _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
314 if (_return_value == NULL) {
315 goto exit;
316 }
317 return_value = PyHKEY_FromHKEY(_return_value);
318
319 exit:
320 /* Cleanup for sub_key */
321 #if !USE_UNICODE_WCHAR_CACHE
322 PyMem_Free((void *)sub_key);
323 #endif /* USE_UNICODE_WCHAR_CACHE */
324
325 return return_value;
326 }
327
328 PyDoc_STRVAR(winreg_DeleteKey__doc__,
329 "DeleteKey($module, key, sub_key, /)\n"
330 "--\n"
331 "\n"
332 "Deletes the specified key.\n"
333 "\n"
334 " key\n"
335 " An already open key, or any one of the predefined HKEY_* constants.\n"
336 " sub_key\n"
337 " A string that must be the name of a subkey of the key identified by\n"
338 " the key parameter. This value must not be None, and the key may not\n"
339 " have subkeys.\n"
340 "\n"
341 "This method can not delete keys with subkeys.\n"
342 "\n"
343 "If the function succeeds, the entire key, including all of its values,\n"
344 "is removed. If the function fails, an OSError exception is raised.");
345
346 #define WINREG_DELETEKEY_METHODDEF \
347 {"DeleteKey", _PyCFunction_CAST(winreg_DeleteKey), METH_FASTCALL, winreg_DeleteKey__doc__},
348
349 static PyObject *
350 winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
351
352 static PyObject *
winreg_DeleteKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)353 winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
354 {
355 PyObject *return_value = NULL;
356 HKEY key;
357 const Py_UNICODE *sub_key = NULL;
358
359 if (!_PyArg_CheckPositional("DeleteKey", nargs, 2, 2)) {
360 goto exit;
361 }
362 if (!clinic_HKEY_converter(args[0], &key)) {
363 goto exit;
364 }
365 if (!PyUnicode_Check(args[1])) {
366 _PyArg_BadArgument("DeleteKey", "argument 2", "str", args[1]);
367 goto exit;
368 }
369 #if USE_UNICODE_WCHAR_CACHE
370 sub_key = _PyUnicode_AsUnicode(args[1]);
371 #else /* USE_UNICODE_WCHAR_CACHE */
372 sub_key = PyUnicode_AsWideCharString(args[1], NULL);
373 #endif /* USE_UNICODE_WCHAR_CACHE */
374 if (sub_key == NULL) {
375 goto exit;
376 }
377 return_value = winreg_DeleteKey_impl(module, key, sub_key);
378
379 exit:
380 /* Cleanup for sub_key */
381 #if !USE_UNICODE_WCHAR_CACHE
382 PyMem_Free((void *)sub_key);
383 #endif /* USE_UNICODE_WCHAR_CACHE */
384
385 return return_value;
386 }
387
388 PyDoc_STRVAR(winreg_DeleteKeyEx__doc__,
389 "DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n"
390 " reserved=0)\n"
391 "--\n"
392 "\n"
393 "Deletes the specified key (intended for 64-bit OS).\n"
394 "\n"
395 " key\n"
396 " An already open key, or any one of the predefined HKEY_* constants.\n"
397 " sub_key\n"
398 " A string that must be the name of a subkey of the key identified by\n"
399 " the key parameter. This value must not be None, and the key may not\n"
400 " have subkeys.\n"
401 " access\n"
402 " An integer that specifies an access mask that describes the\n"
403 " desired security access for the key. Default is KEY_WOW64_64KEY.\n"
404 " reserved\n"
405 " A reserved integer, and must be zero. Default is zero.\n"
406 "\n"
407 "While this function is intended to be used for 64-bit OS, it is also\n"
408 " available on 32-bit systems.\n"
409 "\n"
410 "This method can not delete keys with subkeys.\n"
411 "\n"
412 "If the function succeeds, the entire key, including all of its values,\n"
413 "is removed. If the function fails, an OSError exception is raised.\n"
414 "On unsupported Windows versions, NotImplementedError is raised.");
415
416 #define WINREG_DELETEKEYEX_METHODDEF \
417 {"DeleteKeyEx", _PyCFunction_CAST(winreg_DeleteKeyEx), METH_FASTCALL|METH_KEYWORDS, winreg_DeleteKeyEx__doc__},
418
419 static PyObject *
420 winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
421 const Py_UNICODE *sub_key, REGSAM access,
422 int reserved);
423
424 static PyObject *
winreg_DeleteKeyEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)425 winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
426 {
427 PyObject *return_value = NULL;
428 static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL};
429 static _PyArg_Parser _parser = {"O&O&|ii:DeleteKeyEx", _keywords, 0};
430 HKEY key;
431 const Py_UNICODE *sub_key = NULL;
432 REGSAM access = KEY_WOW64_64KEY;
433 int reserved = 0;
434
435 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
436 clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Converter, &sub_key, &access, &reserved)) {
437 goto exit;
438 }
439 return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
440
441 exit:
442 /* Cleanup for sub_key */
443 #if !USE_UNICODE_WCHAR_CACHE
444 PyMem_Free((void *)sub_key);
445 #endif /* USE_UNICODE_WCHAR_CACHE */
446
447 return return_value;
448 }
449
450 PyDoc_STRVAR(winreg_DeleteValue__doc__,
451 "DeleteValue($module, key, value, /)\n"
452 "--\n"
453 "\n"
454 "Removes a named value from a registry key.\n"
455 "\n"
456 " key\n"
457 " An already open key, or any one of the predefined HKEY_* constants.\n"
458 " value\n"
459 " A string that identifies the value to remove.");
460
461 #define WINREG_DELETEVALUE_METHODDEF \
462 {"DeleteValue", _PyCFunction_CAST(winreg_DeleteValue), METH_FASTCALL, winreg_DeleteValue__doc__},
463
464 static PyObject *
465 winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value);
466
467 static PyObject *
winreg_DeleteValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)468 winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
469 {
470 PyObject *return_value = NULL;
471 HKEY key;
472 const Py_UNICODE *value = NULL;
473
474 if (!_PyArg_CheckPositional("DeleteValue", nargs, 2, 2)) {
475 goto exit;
476 }
477 if (!clinic_HKEY_converter(args[0], &key)) {
478 goto exit;
479 }
480 if (args[1] == Py_None) {
481 value = NULL;
482 }
483 else if (PyUnicode_Check(args[1])) {
484 #if USE_UNICODE_WCHAR_CACHE
485 value = _PyUnicode_AsUnicode(args[1]);
486 #else /* USE_UNICODE_WCHAR_CACHE */
487 value = PyUnicode_AsWideCharString(args[1], NULL);
488 #endif /* USE_UNICODE_WCHAR_CACHE */
489 if (value == NULL) {
490 goto exit;
491 }
492 }
493 else {
494 _PyArg_BadArgument("DeleteValue", "argument 2", "str or None", args[1]);
495 goto exit;
496 }
497 return_value = winreg_DeleteValue_impl(module, key, value);
498
499 exit:
500 /* Cleanup for value */
501 #if !USE_UNICODE_WCHAR_CACHE
502 PyMem_Free((void *)value);
503 #endif /* USE_UNICODE_WCHAR_CACHE */
504
505 return return_value;
506 }
507
508 PyDoc_STRVAR(winreg_EnumKey__doc__,
509 "EnumKey($module, key, index, /)\n"
510 "--\n"
511 "\n"
512 "Enumerates subkeys of an open registry key.\n"
513 "\n"
514 " key\n"
515 " An already open key, or any one of the predefined HKEY_* constants.\n"
516 " index\n"
517 " An integer that identifies the index of the key to retrieve.\n"
518 "\n"
519 "The function retrieves the name of one subkey each time it is called.\n"
520 "It is typically called repeatedly until an OSError exception is\n"
521 "raised, indicating no more values are available.");
522
523 #define WINREG_ENUMKEY_METHODDEF \
524 {"EnumKey", _PyCFunction_CAST(winreg_EnumKey), METH_FASTCALL, winreg_EnumKey__doc__},
525
526 static PyObject *
527 winreg_EnumKey_impl(PyObject *module, HKEY key, int index);
528
529 static PyObject *
winreg_EnumKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)530 winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
531 {
532 PyObject *return_value = NULL;
533 HKEY key;
534 int index;
535
536 if (!_PyArg_CheckPositional("EnumKey", nargs, 2, 2)) {
537 goto exit;
538 }
539 if (!clinic_HKEY_converter(args[0], &key)) {
540 goto exit;
541 }
542 index = _PyLong_AsInt(args[1]);
543 if (index == -1 && PyErr_Occurred()) {
544 goto exit;
545 }
546 return_value = winreg_EnumKey_impl(module, key, index);
547
548 exit:
549 return return_value;
550 }
551
552 PyDoc_STRVAR(winreg_EnumValue__doc__,
553 "EnumValue($module, key, index, /)\n"
554 "--\n"
555 "\n"
556 "Enumerates values of an open registry key.\n"
557 "\n"
558 " key\n"
559 " An already open key, or any one of the predefined HKEY_* constants.\n"
560 " index\n"
561 " An integer that identifies the index of the value to retrieve.\n"
562 "\n"
563 "The function retrieves the name of one subkey each time it is called.\n"
564 "It is typically called repeatedly, until an OSError exception\n"
565 "is raised, indicating no more values.\n"
566 "\n"
567 "The result is a tuple of 3 items:\n"
568 " value_name\n"
569 " A string that identifies the value.\n"
570 " value_data\n"
571 " An object that holds the value data, and whose type depends\n"
572 " on the underlying registry type.\n"
573 " data_type\n"
574 " An integer that identifies the type of the value data.");
575
576 #define WINREG_ENUMVALUE_METHODDEF \
577 {"EnumValue", _PyCFunction_CAST(winreg_EnumValue), METH_FASTCALL, winreg_EnumValue__doc__},
578
579 static PyObject *
580 winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
581
582 static PyObject *
winreg_EnumValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)583 winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
584 {
585 PyObject *return_value = NULL;
586 HKEY key;
587 int index;
588
589 if (!_PyArg_CheckPositional("EnumValue", nargs, 2, 2)) {
590 goto exit;
591 }
592 if (!clinic_HKEY_converter(args[0], &key)) {
593 goto exit;
594 }
595 index = _PyLong_AsInt(args[1]);
596 if (index == -1 && PyErr_Occurred()) {
597 goto exit;
598 }
599 return_value = winreg_EnumValue_impl(module, key, index);
600
601 exit:
602 return return_value;
603 }
604
605 PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__,
606 "ExpandEnvironmentStrings($module, string, /)\n"
607 "--\n"
608 "\n"
609 "Expand environment vars.");
610
611 #define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF \
612 {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__},
613
614 static PyObject *
615 winreg_ExpandEnvironmentStrings_impl(PyObject *module,
616 const Py_UNICODE *string);
617
618 static PyObject *
winreg_ExpandEnvironmentStrings(PyObject * module,PyObject * arg)619 winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
620 {
621 PyObject *return_value = NULL;
622 const Py_UNICODE *string = NULL;
623
624 if (!PyUnicode_Check(arg)) {
625 _PyArg_BadArgument("ExpandEnvironmentStrings", "argument", "str", arg);
626 goto exit;
627 }
628 #if USE_UNICODE_WCHAR_CACHE
629 string = _PyUnicode_AsUnicode(arg);
630 #else /* USE_UNICODE_WCHAR_CACHE */
631 string = PyUnicode_AsWideCharString(arg, NULL);
632 #endif /* USE_UNICODE_WCHAR_CACHE */
633 if (string == NULL) {
634 goto exit;
635 }
636 return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
637
638 exit:
639 /* Cleanup for string */
640 #if !USE_UNICODE_WCHAR_CACHE
641 PyMem_Free((void *)string);
642 #endif /* USE_UNICODE_WCHAR_CACHE */
643
644 return return_value;
645 }
646
647 PyDoc_STRVAR(winreg_FlushKey__doc__,
648 "FlushKey($module, key, /)\n"
649 "--\n"
650 "\n"
651 "Writes all the attributes of a key to the registry.\n"
652 "\n"
653 " key\n"
654 " An already open key, or any one of the predefined HKEY_* constants.\n"
655 "\n"
656 "It is not necessary to call FlushKey to change a key. Registry changes\n"
657 "are flushed to disk by the registry using its lazy flusher. Registry\n"
658 "changes are also flushed to disk at system shutdown. Unlike\n"
659 "CloseKey(), the FlushKey() method returns only when all the data has\n"
660 "been written to the registry.\n"
661 "\n"
662 "An application should only call FlushKey() if it requires absolute\n"
663 "certainty that registry changes are on disk. If you don\'t know whether\n"
664 "a FlushKey() call is required, it probably isn\'t.");
665
666 #define WINREG_FLUSHKEY_METHODDEF \
667 {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__},
668
669 static PyObject *
670 winreg_FlushKey_impl(PyObject *module, HKEY key);
671
672 static PyObject *
winreg_FlushKey(PyObject * module,PyObject * arg)673 winreg_FlushKey(PyObject *module, PyObject *arg)
674 {
675 PyObject *return_value = NULL;
676 HKEY key;
677
678 if (!clinic_HKEY_converter(arg, &key)) {
679 goto exit;
680 }
681 return_value = winreg_FlushKey_impl(module, key);
682
683 exit:
684 return return_value;
685 }
686
687 PyDoc_STRVAR(winreg_LoadKey__doc__,
688 "LoadKey($module, key, sub_key, file_name, /)\n"
689 "--\n"
690 "\n"
691 "Insert data into the registry from a file.\n"
692 "\n"
693 " key\n"
694 " An already open key, or any one of the predefined HKEY_* constants.\n"
695 " sub_key\n"
696 " A string that identifies the sub-key to load.\n"
697 " file_name\n"
698 " The name of the file to load registry data from. This file must\n"
699 " have been created with the SaveKey() function. Under the file\n"
700 " allocation table (FAT) file system, the filename may not have an\n"
701 " extension.\n"
702 "\n"
703 "Creates a subkey under the specified key and stores registration\n"
704 "information from a specified file into that subkey.\n"
705 "\n"
706 "A call to LoadKey() fails if the calling process does not have the\n"
707 "SE_RESTORE_PRIVILEGE privilege.\n"
708 "\n"
709 "If key is a handle returned by ConnectRegistry(), then the path\n"
710 "specified in fileName is relative to the remote computer.\n"
711 "\n"
712 "The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n"
713 "tree.");
714
715 #define WINREG_LOADKEY_METHODDEF \
716 {"LoadKey", _PyCFunction_CAST(winreg_LoadKey), METH_FASTCALL, winreg_LoadKey__doc__},
717
718 static PyObject *
719 winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
720 const Py_UNICODE *file_name);
721
722 static PyObject *
winreg_LoadKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)723 winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
724 {
725 PyObject *return_value = NULL;
726 HKEY key;
727 const Py_UNICODE *sub_key = NULL;
728 const Py_UNICODE *file_name = NULL;
729
730 if (!_PyArg_CheckPositional("LoadKey", nargs, 3, 3)) {
731 goto exit;
732 }
733 if (!clinic_HKEY_converter(args[0], &key)) {
734 goto exit;
735 }
736 if (!PyUnicode_Check(args[1])) {
737 _PyArg_BadArgument("LoadKey", "argument 2", "str", args[1]);
738 goto exit;
739 }
740 #if USE_UNICODE_WCHAR_CACHE
741 sub_key = _PyUnicode_AsUnicode(args[1]);
742 #else /* USE_UNICODE_WCHAR_CACHE */
743 sub_key = PyUnicode_AsWideCharString(args[1], NULL);
744 #endif /* USE_UNICODE_WCHAR_CACHE */
745 if (sub_key == NULL) {
746 goto exit;
747 }
748 if (!PyUnicode_Check(args[2])) {
749 _PyArg_BadArgument("LoadKey", "argument 3", "str", args[2]);
750 goto exit;
751 }
752 #if USE_UNICODE_WCHAR_CACHE
753 file_name = _PyUnicode_AsUnicode(args[2]);
754 #else /* USE_UNICODE_WCHAR_CACHE */
755 file_name = PyUnicode_AsWideCharString(args[2], NULL);
756 #endif /* USE_UNICODE_WCHAR_CACHE */
757 if (file_name == NULL) {
758 goto exit;
759 }
760 return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
761
762 exit:
763 /* Cleanup for sub_key */
764 #if !USE_UNICODE_WCHAR_CACHE
765 PyMem_Free((void *)sub_key);
766 #endif /* USE_UNICODE_WCHAR_CACHE */
767 /* Cleanup for file_name */
768 #if !USE_UNICODE_WCHAR_CACHE
769 PyMem_Free((void *)file_name);
770 #endif /* USE_UNICODE_WCHAR_CACHE */
771
772 return return_value;
773 }
774
775 PyDoc_STRVAR(winreg_OpenKey__doc__,
776 "OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
777 "--\n"
778 "\n"
779 "Opens the specified key.\n"
780 "\n"
781 " key\n"
782 " An already open key, or any one of the predefined HKEY_* constants.\n"
783 " sub_key\n"
784 " A string that identifies the sub_key to open.\n"
785 " reserved\n"
786 " A reserved integer that must be zero. Default is zero.\n"
787 " access\n"
788 " An integer that specifies an access mask that describes the desired\n"
789 " security access for the key. Default is KEY_READ.\n"
790 "\n"
791 "The result is a new handle to the specified key.\n"
792 "If the function fails, an OSError exception is raised.");
793
794 #define WINREG_OPENKEY_METHODDEF \
795 {"OpenKey", _PyCFunction_CAST(winreg_OpenKey), METH_FASTCALL|METH_KEYWORDS, winreg_OpenKey__doc__},
796
797 static HKEY
798 winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
799 int reserved, REGSAM access);
800
801 static PyObject *
winreg_OpenKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)802 winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
803 {
804 PyObject *return_value = NULL;
805 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
806 static _PyArg_Parser _parser = {"O&O&|ii:OpenKey", _keywords, 0};
807 HKEY key;
808 const Py_UNICODE *sub_key = NULL;
809 int reserved = 0;
810 REGSAM access = KEY_READ;
811 HKEY _return_value;
812
813 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
814 clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
815 goto exit;
816 }
817 _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
818 if (_return_value == NULL) {
819 goto exit;
820 }
821 return_value = PyHKEY_FromHKEY(_return_value);
822
823 exit:
824 /* Cleanup for sub_key */
825 #if !USE_UNICODE_WCHAR_CACHE
826 PyMem_Free((void *)sub_key);
827 #endif /* USE_UNICODE_WCHAR_CACHE */
828
829 return return_value;
830 }
831
832 PyDoc_STRVAR(winreg_OpenKeyEx__doc__,
833 "OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
834 "--\n"
835 "\n"
836 "Opens the specified key.\n"
837 "\n"
838 " key\n"
839 " An already open key, or any one of the predefined HKEY_* constants.\n"
840 " sub_key\n"
841 " A string that identifies the sub_key to open.\n"
842 " reserved\n"
843 " A reserved integer that must be zero. Default is zero.\n"
844 " access\n"
845 " An integer that specifies an access mask that describes the desired\n"
846 " security access for the key. Default is KEY_READ.\n"
847 "\n"
848 "The result is a new handle to the specified key.\n"
849 "If the function fails, an OSError exception is raised.");
850
851 #define WINREG_OPENKEYEX_METHODDEF \
852 {"OpenKeyEx", _PyCFunction_CAST(winreg_OpenKeyEx), METH_FASTCALL|METH_KEYWORDS, winreg_OpenKeyEx__doc__},
853
854 static HKEY
855 winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
856 int reserved, REGSAM access);
857
858 static PyObject *
winreg_OpenKeyEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)859 winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
860 {
861 PyObject *return_value = NULL;
862 static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
863 static _PyArg_Parser _parser = {"O&O&|ii:OpenKeyEx", _keywords, 0};
864 HKEY key;
865 const Py_UNICODE *sub_key = NULL;
866 int reserved = 0;
867 REGSAM access = KEY_READ;
868 HKEY _return_value;
869
870 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
871 clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
872 goto exit;
873 }
874 _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
875 if (_return_value == NULL) {
876 goto exit;
877 }
878 return_value = PyHKEY_FromHKEY(_return_value);
879
880 exit:
881 /* Cleanup for sub_key */
882 #if !USE_UNICODE_WCHAR_CACHE
883 PyMem_Free((void *)sub_key);
884 #endif /* USE_UNICODE_WCHAR_CACHE */
885
886 return return_value;
887 }
888
889 PyDoc_STRVAR(winreg_QueryInfoKey__doc__,
890 "QueryInfoKey($module, key, /)\n"
891 "--\n"
892 "\n"
893 "Returns information about a key.\n"
894 "\n"
895 " key\n"
896 " An already open key, or any one of the predefined HKEY_* constants.\n"
897 "\n"
898 "The result is a tuple of 3 items:\n"
899 "An integer that identifies the number of sub keys this key has.\n"
900 "An integer that identifies the number of values this key has.\n"
901 "An integer that identifies when the key was last modified (if available)\n"
902 "as 100\'s of nanoseconds since Jan 1, 1600.");
903
904 #define WINREG_QUERYINFOKEY_METHODDEF \
905 {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__},
906
907 static PyObject *
908 winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
909
910 static PyObject *
winreg_QueryInfoKey(PyObject * module,PyObject * arg)911 winreg_QueryInfoKey(PyObject *module, PyObject *arg)
912 {
913 PyObject *return_value = NULL;
914 HKEY key;
915
916 if (!clinic_HKEY_converter(arg, &key)) {
917 goto exit;
918 }
919 return_value = winreg_QueryInfoKey_impl(module, key);
920
921 exit:
922 return return_value;
923 }
924
925 PyDoc_STRVAR(winreg_QueryValue__doc__,
926 "QueryValue($module, key, sub_key, /)\n"
927 "--\n"
928 "\n"
929 "Retrieves the unnamed value for a key.\n"
930 "\n"
931 " key\n"
932 " An already open key, or any one of the predefined HKEY_* constants.\n"
933 " sub_key\n"
934 " A string that holds the name of the subkey with which the value\n"
935 " is associated. If this parameter is None or empty, the function\n"
936 " retrieves the value set by the SetValue() method for the key\n"
937 " identified by key.\n"
938 "\n"
939 "Values in the registry have name, type, and data components. This method\n"
940 "retrieves the data for a key\'s first value that has a NULL name.\n"
941 "But since the underlying API call doesn\'t return the type, you\'ll\n"
942 "probably be happier using QueryValueEx; this function is just here for\n"
943 "completeness.");
944
945 #define WINREG_QUERYVALUE_METHODDEF \
946 {"QueryValue", _PyCFunction_CAST(winreg_QueryValue), METH_FASTCALL, winreg_QueryValue__doc__},
947
948 static PyObject *
949 winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
950
951 static PyObject *
winreg_QueryValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)952 winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
953 {
954 PyObject *return_value = NULL;
955 HKEY key;
956 const Py_UNICODE *sub_key = NULL;
957
958 if (!_PyArg_CheckPositional("QueryValue", nargs, 2, 2)) {
959 goto exit;
960 }
961 if (!clinic_HKEY_converter(args[0], &key)) {
962 goto exit;
963 }
964 if (args[1] == Py_None) {
965 sub_key = NULL;
966 }
967 else if (PyUnicode_Check(args[1])) {
968 #if USE_UNICODE_WCHAR_CACHE
969 sub_key = _PyUnicode_AsUnicode(args[1]);
970 #else /* USE_UNICODE_WCHAR_CACHE */
971 sub_key = PyUnicode_AsWideCharString(args[1], NULL);
972 #endif /* USE_UNICODE_WCHAR_CACHE */
973 if (sub_key == NULL) {
974 goto exit;
975 }
976 }
977 else {
978 _PyArg_BadArgument("QueryValue", "argument 2", "str or None", args[1]);
979 goto exit;
980 }
981 return_value = winreg_QueryValue_impl(module, key, sub_key);
982
983 exit:
984 /* Cleanup for sub_key */
985 #if !USE_UNICODE_WCHAR_CACHE
986 PyMem_Free((void *)sub_key);
987 #endif /* USE_UNICODE_WCHAR_CACHE */
988
989 return return_value;
990 }
991
992 PyDoc_STRVAR(winreg_QueryValueEx__doc__,
993 "QueryValueEx($module, key, name, /)\n"
994 "--\n"
995 "\n"
996 "Retrieves the type and value of a specified sub-key.\n"
997 "\n"
998 " key\n"
999 " An already open key, or any one of the predefined HKEY_* constants.\n"
1000 " name\n"
1001 " A string indicating the value to query.\n"
1002 "\n"
1003 "Behaves mostly like QueryValue(), but also returns the type of the\n"
1004 "specified value name associated with the given open registry key.\n"
1005 "\n"
1006 "The return value is a tuple of the value and the type_id.");
1007
1008 #define WINREG_QUERYVALUEEX_METHODDEF \
1009 {"QueryValueEx", _PyCFunction_CAST(winreg_QueryValueEx), METH_FASTCALL, winreg_QueryValueEx__doc__},
1010
1011 static PyObject *
1012 winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name);
1013
1014 static PyObject *
winreg_QueryValueEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1015 winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1016 {
1017 PyObject *return_value = NULL;
1018 HKEY key;
1019 const Py_UNICODE *name = NULL;
1020
1021 if (!_PyArg_CheckPositional("QueryValueEx", nargs, 2, 2)) {
1022 goto exit;
1023 }
1024 if (!clinic_HKEY_converter(args[0], &key)) {
1025 goto exit;
1026 }
1027 if (args[1] == Py_None) {
1028 name = NULL;
1029 }
1030 else if (PyUnicode_Check(args[1])) {
1031 #if USE_UNICODE_WCHAR_CACHE
1032 name = _PyUnicode_AsUnicode(args[1]);
1033 #else /* USE_UNICODE_WCHAR_CACHE */
1034 name = PyUnicode_AsWideCharString(args[1], NULL);
1035 #endif /* USE_UNICODE_WCHAR_CACHE */
1036 if (name == NULL) {
1037 goto exit;
1038 }
1039 }
1040 else {
1041 _PyArg_BadArgument("QueryValueEx", "argument 2", "str or None", args[1]);
1042 goto exit;
1043 }
1044 return_value = winreg_QueryValueEx_impl(module, key, name);
1045
1046 exit:
1047 /* Cleanup for name */
1048 #if !USE_UNICODE_WCHAR_CACHE
1049 PyMem_Free((void *)name);
1050 #endif /* USE_UNICODE_WCHAR_CACHE */
1051
1052 return return_value;
1053 }
1054
1055 PyDoc_STRVAR(winreg_SaveKey__doc__,
1056 "SaveKey($module, key, file_name, /)\n"
1057 "--\n"
1058 "\n"
1059 "Saves the specified key, and all its subkeys to the specified file.\n"
1060 "\n"
1061 " key\n"
1062 " An already open key, or any one of the predefined HKEY_* constants.\n"
1063 " file_name\n"
1064 " The name of the file to save registry data to. This file cannot\n"
1065 " already exist. If this filename includes an extension, it cannot be\n"
1066 " used on file allocation table (FAT) file systems by the LoadKey(),\n"
1067 " ReplaceKey() or RestoreKey() methods.\n"
1068 "\n"
1069 "If key represents a key on a remote computer, the path described by\n"
1070 "file_name is relative to the remote computer.\n"
1071 "\n"
1072 "The caller of this method must possess the SeBackupPrivilege\n"
1073 "security privilege. This function passes NULL for security_attributes\n"
1074 "to the API.");
1075
1076 #define WINREG_SAVEKEY_METHODDEF \
1077 {"SaveKey", _PyCFunction_CAST(winreg_SaveKey), METH_FASTCALL, winreg_SaveKey__doc__},
1078
1079 static PyObject *
1080 winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name);
1081
1082 static PyObject *
winreg_SaveKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1083 winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1084 {
1085 PyObject *return_value = NULL;
1086 HKEY key;
1087 const Py_UNICODE *file_name = NULL;
1088
1089 if (!_PyArg_CheckPositional("SaveKey", nargs, 2, 2)) {
1090 goto exit;
1091 }
1092 if (!clinic_HKEY_converter(args[0], &key)) {
1093 goto exit;
1094 }
1095 if (!PyUnicode_Check(args[1])) {
1096 _PyArg_BadArgument("SaveKey", "argument 2", "str", args[1]);
1097 goto exit;
1098 }
1099 #if USE_UNICODE_WCHAR_CACHE
1100 file_name = _PyUnicode_AsUnicode(args[1]);
1101 #else /* USE_UNICODE_WCHAR_CACHE */
1102 file_name = PyUnicode_AsWideCharString(args[1], NULL);
1103 #endif /* USE_UNICODE_WCHAR_CACHE */
1104 if (file_name == NULL) {
1105 goto exit;
1106 }
1107 return_value = winreg_SaveKey_impl(module, key, file_name);
1108
1109 exit:
1110 /* Cleanup for file_name */
1111 #if !USE_UNICODE_WCHAR_CACHE
1112 PyMem_Free((void *)file_name);
1113 #endif /* USE_UNICODE_WCHAR_CACHE */
1114
1115 return return_value;
1116 }
1117
1118 PyDoc_STRVAR(winreg_SetValue__doc__,
1119 "SetValue($module, key, sub_key, type, value, /)\n"
1120 "--\n"
1121 "\n"
1122 "Associates a value with a specified key.\n"
1123 "\n"
1124 " key\n"
1125 " An already open key, or any one of the predefined HKEY_* constants.\n"
1126 " sub_key\n"
1127 " A string that names the subkey with which the value is associated.\n"
1128 " type\n"
1129 " An integer that specifies the type of the data. Currently this must\n"
1130 " be REG_SZ, meaning only strings are supported.\n"
1131 " value\n"
1132 " A string that specifies the new value.\n"
1133 "\n"
1134 "If the key specified by the sub_key parameter does not exist, the\n"
1135 "SetValue function creates it.\n"
1136 "\n"
1137 "Value lengths are limited by available memory. Long values (more than\n"
1138 "2048 bytes) should be stored as files with the filenames stored in\n"
1139 "the configuration registry to help the registry perform efficiently.\n"
1140 "\n"
1141 "The key identified by the key parameter must have been opened with\n"
1142 "KEY_SET_VALUE access.");
1143
1144 #define WINREG_SETVALUE_METHODDEF \
1145 {"SetValue", _PyCFunction_CAST(winreg_SetValue), METH_FASTCALL, winreg_SetValue__doc__},
1146
1147 static PyObject *
1148 winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
1149 DWORD type, PyObject *value_obj);
1150
1151 static PyObject *
winreg_SetValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1152 winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1153 {
1154 PyObject *return_value = NULL;
1155 HKEY key;
1156 const Py_UNICODE *sub_key = NULL;
1157 DWORD type;
1158 PyObject *value_obj;
1159
1160 if (!_PyArg_ParseStack(args, nargs, "O&O&kU:SetValue",
1161 clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &type, &value_obj)) {
1162 goto exit;
1163 }
1164 return_value = winreg_SetValue_impl(module, key, sub_key, type, value_obj);
1165
1166 exit:
1167 /* Cleanup for sub_key */
1168 #if !USE_UNICODE_WCHAR_CACHE
1169 PyMem_Free((void *)sub_key);
1170 #endif /* USE_UNICODE_WCHAR_CACHE */
1171
1172 return return_value;
1173 }
1174
1175 PyDoc_STRVAR(winreg_SetValueEx__doc__,
1176 "SetValueEx($module, key, value_name, reserved, type, value, /)\n"
1177 "--\n"
1178 "\n"
1179 "Stores data in the value field of an open registry key.\n"
1180 "\n"
1181 " key\n"
1182 " An already open key, or any one of the predefined HKEY_* constants.\n"
1183 " value_name\n"
1184 " A string containing the name of the value to set, or None.\n"
1185 " reserved\n"
1186 " Can be anything - zero is always passed to the API.\n"
1187 " type\n"
1188 " An integer that specifies the type of the data, one of:\n"
1189 " REG_BINARY -- Binary data in any form.\n"
1190 " REG_DWORD -- A 32-bit number.\n"
1191 " REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
1192 " REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
1193 " REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n"
1194 " references to environment variables (for example,\n"
1195 " %PATH%).\n"
1196 " REG_LINK -- A Unicode symbolic link.\n"
1197 " REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
1198 " by two null characters. Note that Python handles\n"
1199 " this termination automatically.\n"
1200 " REG_NONE -- No defined value type.\n"
1201 " REG_QWORD -- A 64-bit number.\n"
1202 " REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n"
1203 " REG_RESOURCE_LIST -- A device-driver resource list.\n"
1204 " REG_SZ -- A null-terminated string.\n"
1205 " value\n"
1206 " A string that specifies the new value.\n"
1207 "\n"
1208 "This method can also set additional value and type information for the\n"
1209 "specified key. The key identified by the key parameter must have been\n"
1210 "opened with KEY_SET_VALUE access.\n"
1211 "\n"
1212 "To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
1213 "\n"
1214 "Value lengths are limited by available memory. Long values (more than\n"
1215 "2048 bytes) should be stored as files with the filenames stored in\n"
1216 "the configuration registry to help the registry perform efficiently.");
1217
1218 #define WINREG_SETVALUEEX_METHODDEF \
1219 {"SetValueEx", _PyCFunction_CAST(winreg_SetValueEx), METH_FASTCALL, winreg_SetValueEx__doc__},
1220
1221 static PyObject *
1222 winreg_SetValueEx_impl(PyObject *module, HKEY key,
1223 const Py_UNICODE *value_name, PyObject *reserved,
1224 DWORD type, PyObject *value);
1225
1226 static PyObject *
winreg_SetValueEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1227 winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1228 {
1229 PyObject *return_value = NULL;
1230 HKEY key;
1231 const Py_UNICODE *value_name = NULL;
1232 PyObject *reserved;
1233 DWORD type;
1234 PyObject *value;
1235
1236 if (!_PyArg_ParseStack(args, nargs, "O&O&OkO:SetValueEx",
1237 clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &value_name, &reserved, &type, &value)) {
1238 goto exit;
1239 }
1240 return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
1241
1242 exit:
1243 /* Cleanup for value_name */
1244 #if !USE_UNICODE_WCHAR_CACHE
1245 PyMem_Free((void *)value_name);
1246 #endif /* USE_UNICODE_WCHAR_CACHE */
1247
1248 return return_value;
1249 }
1250
1251 PyDoc_STRVAR(winreg_DisableReflectionKey__doc__,
1252 "DisableReflectionKey($module, key, /)\n"
1253 "--\n"
1254 "\n"
1255 "Disables registry reflection for 32bit processes running on a 64bit OS.\n"
1256 "\n"
1257 " key\n"
1258 " An already open key, or any one of the predefined HKEY_* constants.\n"
1259 "\n"
1260 "Will generally raise NotImplementedError if executed on a 32bit OS.\n"
1261 "\n"
1262 "If the key is not on the reflection list, the function succeeds but has\n"
1263 "no effect. Disabling reflection for a key does not affect reflection\n"
1264 "of any subkeys.");
1265
1266 #define WINREG_DISABLEREFLECTIONKEY_METHODDEF \
1267 {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__},
1268
1269 static PyObject *
1270 winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
1271
1272 static PyObject *
winreg_DisableReflectionKey(PyObject * module,PyObject * arg)1273 winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
1274 {
1275 PyObject *return_value = NULL;
1276 HKEY key;
1277
1278 if (!clinic_HKEY_converter(arg, &key)) {
1279 goto exit;
1280 }
1281 return_value = winreg_DisableReflectionKey_impl(module, key);
1282
1283 exit:
1284 return return_value;
1285 }
1286
1287 PyDoc_STRVAR(winreg_EnableReflectionKey__doc__,
1288 "EnableReflectionKey($module, key, /)\n"
1289 "--\n"
1290 "\n"
1291 "Restores registry reflection for the specified disabled key.\n"
1292 "\n"
1293 " key\n"
1294 " An already open key, or any one of the predefined HKEY_* constants.\n"
1295 "\n"
1296 "Will generally raise NotImplementedError if executed on a 32bit OS.\n"
1297 "Restoring reflection for a key does not affect reflection of any\n"
1298 "subkeys.");
1299
1300 #define WINREG_ENABLEREFLECTIONKEY_METHODDEF \
1301 {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__},
1302
1303 static PyObject *
1304 winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
1305
1306 static PyObject *
winreg_EnableReflectionKey(PyObject * module,PyObject * arg)1307 winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
1308 {
1309 PyObject *return_value = NULL;
1310 HKEY key;
1311
1312 if (!clinic_HKEY_converter(arg, &key)) {
1313 goto exit;
1314 }
1315 return_value = winreg_EnableReflectionKey_impl(module, key);
1316
1317 exit:
1318 return return_value;
1319 }
1320
1321 PyDoc_STRVAR(winreg_QueryReflectionKey__doc__,
1322 "QueryReflectionKey($module, key, /)\n"
1323 "--\n"
1324 "\n"
1325 "Returns the reflection state for the specified key as a bool.\n"
1326 "\n"
1327 " key\n"
1328 " An already open key, or any one of the predefined HKEY_* constants.\n"
1329 "\n"
1330 "Will generally raise NotImplementedError if executed on a 32bit OS.");
1331
1332 #define WINREG_QUERYREFLECTIONKEY_METHODDEF \
1333 {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__},
1334
1335 static PyObject *
1336 winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
1337
1338 static PyObject *
winreg_QueryReflectionKey(PyObject * module,PyObject * arg)1339 winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
1340 {
1341 PyObject *return_value = NULL;
1342 HKEY key;
1343
1344 if (!clinic_HKEY_converter(arg, &key)) {
1345 goto exit;
1346 }
1347 return_value = winreg_QueryReflectionKey_impl(module, key);
1348
1349 exit:
1350 return return_value;
1351 }
1352 /*[clinic end generated code: output=e83bdaabb4fa2167 input=a9049054013a1b77]*/
1353