• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)(void(*)(void))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)(void(*)(void))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;
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)(void(*)(void))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;
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)(void(*)(void))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;
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)(void(*)(void))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;
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 (64-bit OS only).\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 "This method can not delete keys with subkeys.\n"
408 "\n"
409 "If the function succeeds, the entire key, including all of its values,\n"
410 "is removed.  If the function fails, an OSError exception is raised.\n"
411 "On unsupported Windows versions, NotImplementedError is raised.");
412 
413 #define WINREG_DELETEKEYEX_METHODDEF    \
414     {"DeleteKeyEx", (PyCFunction)(void(*)(void))winreg_DeleteKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_DeleteKeyEx__doc__},
415 
416 static PyObject *
417 winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
418                         const Py_UNICODE *sub_key, REGSAM access,
419                         int reserved);
420 
421 static PyObject *
winreg_DeleteKeyEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)422 winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
423 {
424     PyObject *return_value = NULL;
425     static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL};
426     static _PyArg_Parser _parser = {"O&O&|ii:DeleteKeyEx", _keywords, 0};
427     HKEY key;
428     const Py_UNICODE *sub_key;
429     REGSAM access = KEY_WOW64_64KEY;
430     int reserved = 0;
431 
432     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
433         clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Converter, &sub_key, &access, &reserved)) {
434         goto exit;
435     }
436     return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
437 
438 exit:
439     /* Cleanup for sub_key */
440     #if !USE_UNICODE_WCHAR_CACHE
441     PyMem_Free((void *)sub_key);
442     #endif /* USE_UNICODE_WCHAR_CACHE */
443 
444     return return_value;
445 }
446 
447 PyDoc_STRVAR(winreg_DeleteValue__doc__,
448 "DeleteValue($module, key, value, /)\n"
449 "--\n"
450 "\n"
451 "Removes a named value from a registry key.\n"
452 "\n"
453 "  key\n"
454 "    An already open key, or any one of the predefined HKEY_* constants.\n"
455 "  value\n"
456 "    A string that identifies the value to remove.");
457 
458 #define WINREG_DELETEVALUE_METHODDEF    \
459     {"DeleteValue", (PyCFunction)(void(*)(void))winreg_DeleteValue, METH_FASTCALL, winreg_DeleteValue__doc__},
460 
461 static PyObject *
462 winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value);
463 
464 static PyObject *
winreg_DeleteValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)465 winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
466 {
467     PyObject *return_value = NULL;
468     HKEY key;
469     const Py_UNICODE *value;
470 
471     if (!_PyArg_CheckPositional("DeleteValue", nargs, 2, 2)) {
472         goto exit;
473     }
474     if (!clinic_HKEY_converter(args[0], &key)) {
475         goto exit;
476     }
477     if (args[1] == Py_None) {
478         value = NULL;
479     }
480     else if (PyUnicode_Check(args[1])) {
481         #if USE_UNICODE_WCHAR_CACHE
482         value = _PyUnicode_AsUnicode(args[1]);
483         #else /* USE_UNICODE_WCHAR_CACHE */
484         value = PyUnicode_AsWideCharString(args[1], NULL);
485         #endif /* USE_UNICODE_WCHAR_CACHE */
486         if (value == NULL) {
487             goto exit;
488         }
489     }
490     else {
491         _PyArg_BadArgument("DeleteValue", "argument 2", "str or None", args[1]);
492         goto exit;
493     }
494     return_value = winreg_DeleteValue_impl(module, key, value);
495 
496 exit:
497     /* Cleanup for value */
498     #if !USE_UNICODE_WCHAR_CACHE
499     PyMem_Free((void *)value);
500     #endif /* USE_UNICODE_WCHAR_CACHE */
501 
502     return return_value;
503 }
504 
505 PyDoc_STRVAR(winreg_EnumKey__doc__,
506 "EnumKey($module, key, index, /)\n"
507 "--\n"
508 "\n"
509 "Enumerates subkeys of an open registry key.\n"
510 "\n"
511 "  key\n"
512 "    An already open key, or any one of the predefined HKEY_* constants.\n"
513 "  index\n"
514 "    An integer that identifies the index of the key to retrieve.\n"
515 "\n"
516 "The function retrieves the name of one subkey each time it is called.\n"
517 "It is typically called repeatedly until an OSError exception is\n"
518 "raised, indicating no more values are available.");
519 
520 #define WINREG_ENUMKEY_METHODDEF    \
521     {"EnumKey", (PyCFunction)(void(*)(void))winreg_EnumKey, METH_FASTCALL, winreg_EnumKey__doc__},
522 
523 static PyObject *
524 winreg_EnumKey_impl(PyObject *module, HKEY key, int index);
525 
526 static PyObject *
winreg_EnumKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)527 winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
528 {
529     PyObject *return_value = NULL;
530     HKEY key;
531     int index;
532 
533     if (!_PyArg_CheckPositional("EnumKey", nargs, 2, 2)) {
534         goto exit;
535     }
536     if (!clinic_HKEY_converter(args[0], &key)) {
537         goto exit;
538     }
539     index = _PyLong_AsInt(args[1]);
540     if (index == -1 && PyErr_Occurred()) {
541         goto exit;
542     }
543     return_value = winreg_EnumKey_impl(module, key, index);
544 
545 exit:
546     return return_value;
547 }
548 
549 PyDoc_STRVAR(winreg_EnumValue__doc__,
550 "EnumValue($module, key, index, /)\n"
551 "--\n"
552 "\n"
553 "Enumerates values of an open registry key.\n"
554 "\n"
555 "  key\n"
556 "    An already open key, or any one of the predefined HKEY_* constants.\n"
557 "  index\n"
558 "    An integer that identifies the index of the value to retrieve.\n"
559 "\n"
560 "The function retrieves the name of one subkey each time it is called.\n"
561 "It is typically called repeatedly, until an OSError exception\n"
562 "is raised, indicating no more values.\n"
563 "\n"
564 "The result is a tuple of 3 items:\n"
565 "  value_name\n"
566 "    A string that identifies the value.\n"
567 "  value_data\n"
568 "    An object that holds the value data, and whose type depends\n"
569 "    on the underlying registry type.\n"
570 "  data_type\n"
571 "    An integer that identifies the type of the value data.");
572 
573 #define WINREG_ENUMVALUE_METHODDEF    \
574     {"EnumValue", (PyCFunction)(void(*)(void))winreg_EnumValue, METH_FASTCALL, winreg_EnumValue__doc__},
575 
576 static PyObject *
577 winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
578 
579 static PyObject *
winreg_EnumValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)580 winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
581 {
582     PyObject *return_value = NULL;
583     HKEY key;
584     int index;
585 
586     if (!_PyArg_CheckPositional("EnumValue", nargs, 2, 2)) {
587         goto exit;
588     }
589     if (!clinic_HKEY_converter(args[0], &key)) {
590         goto exit;
591     }
592     index = _PyLong_AsInt(args[1]);
593     if (index == -1 && PyErr_Occurred()) {
594         goto exit;
595     }
596     return_value = winreg_EnumValue_impl(module, key, index);
597 
598 exit:
599     return return_value;
600 }
601 
602 PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__,
603 "ExpandEnvironmentStrings($module, string, /)\n"
604 "--\n"
605 "\n"
606 "Expand environment vars.");
607 
608 #define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF    \
609     {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__},
610 
611 static PyObject *
612 winreg_ExpandEnvironmentStrings_impl(PyObject *module,
613                                      const Py_UNICODE *string);
614 
615 static PyObject *
winreg_ExpandEnvironmentStrings(PyObject * module,PyObject * arg)616 winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
617 {
618     PyObject *return_value = NULL;
619     const Py_UNICODE *string;
620 
621     if (!PyUnicode_Check(arg)) {
622         _PyArg_BadArgument("ExpandEnvironmentStrings", "argument", "str", arg);
623         goto exit;
624     }
625     #if USE_UNICODE_WCHAR_CACHE
626     string = _PyUnicode_AsUnicode(arg);
627     #else /* USE_UNICODE_WCHAR_CACHE */
628     string = PyUnicode_AsWideCharString(arg, NULL);
629     #endif /* USE_UNICODE_WCHAR_CACHE */
630     if (string == NULL) {
631         goto exit;
632     }
633     return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
634 
635 exit:
636     /* Cleanup for string */
637     #if !USE_UNICODE_WCHAR_CACHE
638     PyMem_Free((void *)string);
639     #endif /* USE_UNICODE_WCHAR_CACHE */
640 
641     return return_value;
642 }
643 
644 PyDoc_STRVAR(winreg_FlushKey__doc__,
645 "FlushKey($module, key, /)\n"
646 "--\n"
647 "\n"
648 "Writes all the attributes of a key to the registry.\n"
649 "\n"
650 "  key\n"
651 "    An already open key, or any one of the predefined HKEY_* constants.\n"
652 "\n"
653 "It is not necessary to call FlushKey to change a key.  Registry changes\n"
654 "are flushed to disk by the registry using its lazy flusher.  Registry\n"
655 "changes are also flushed to disk at system shutdown.  Unlike\n"
656 "CloseKey(), the FlushKey() method returns only when all the data has\n"
657 "been written to the registry.\n"
658 "\n"
659 "An application should only call FlushKey() if it requires absolute\n"
660 "certainty that registry changes are on disk.  If you don\'t know whether\n"
661 "a FlushKey() call is required, it probably isn\'t.");
662 
663 #define WINREG_FLUSHKEY_METHODDEF    \
664     {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__},
665 
666 static PyObject *
667 winreg_FlushKey_impl(PyObject *module, HKEY key);
668 
669 static PyObject *
winreg_FlushKey(PyObject * module,PyObject * arg)670 winreg_FlushKey(PyObject *module, PyObject *arg)
671 {
672     PyObject *return_value = NULL;
673     HKEY key;
674 
675     if (!clinic_HKEY_converter(arg, &key)) {
676         goto exit;
677     }
678     return_value = winreg_FlushKey_impl(module, key);
679 
680 exit:
681     return return_value;
682 }
683 
684 PyDoc_STRVAR(winreg_LoadKey__doc__,
685 "LoadKey($module, key, sub_key, file_name, /)\n"
686 "--\n"
687 "\n"
688 "Insert data into the registry from a file.\n"
689 "\n"
690 "  key\n"
691 "    An already open key, or any one of the predefined HKEY_* constants.\n"
692 "  sub_key\n"
693 "    A string that identifies the sub-key to load.\n"
694 "  file_name\n"
695 "    The name of the file to load registry data from.  This file must\n"
696 "    have been created with the SaveKey() function.  Under the file\n"
697 "    allocation table (FAT) file system, the filename may not have an\n"
698 "    extension.\n"
699 "\n"
700 "Creates a subkey under the specified key and stores registration\n"
701 "information from a specified file into that subkey.\n"
702 "\n"
703 "A call to LoadKey() fails if the calling process does not have the\n"
704 "SE_RESTORE_PRIVILEGE privilege.\n"
705 "\n"
706 "If key is a handle returned by ConnectRegistry(), then the path\n"
707 "specified in fileName is relative to the remote computer.\n"
708 "\n"
709 "The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n"
710 "tree.");
711 
712 #define WINREG_LOADKEY_METHODDEF    \
713     {"LoadKey", (PyCFunction)(void(*)(void))winreg_LoadKey, METH_FASTCALL, winreg_LoadKey__doc__},
714 
715 static PyObject *
716 winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
717                     const Py_UNICODE *file_name);
718 
719 static PyObject *
winreg_LoadKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)720 winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
721 {
722     PyObject *return_value = NULL;
723     HKEY key;
724     const Py_UNICODE *sub_key;
725     const Py_UNICODE *file_name;
726 
727     if (!_PyArg_CheckPositional("LoadKey", nargs, 3, 3)) {
728         goto exit;
729     }
730     if (!clinic_HKEY_converter(args[0], &key)) {
731         goto exit;
732     }
733     if (!PyUnicode_Check(args[1])) {
734         _PyArg_BadArgument("LoadKey", "argument 2", "str", args[1]);
735         goto exit;
736     }
737     #if USE_UNICODE_WCHAR_CACHE
738     sub_key = _PyUnicode_AsUnicode(args[1]);
739     #else /* USE_UNICODE_WCHAR_CACHE */
740     sub_key = PyUnicode_AsWideCharString(args[1], NULL);
741     #endif /* USE_UNICODE_WCHAR_CACHE */
742     if (sub_key == NULL) {
743         goto exit;
744     }
745     if (!PyUnicode_Check(args[2])) {
746         _PyArg_BadArgument("LoadKey", "argument 3", "str", args[2]);
747         goto exit;
748     }
749     #if USE_UNICODE_WCHAR_CACHE
750     file_name = _PyUnicode_AsUnicode(args[2]);
751     #else /* USE_UNICODE_WCHAR_CACHE */
752     file_name = PyUnicode_AsWideCharString(args[2], NULL);
753     #endif /* USE_UNICODE_WCHAR_CACHE */
754     if (file_name == NULL) {
755         goto exit;
756     }
757     return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
758 
759 exit:
760     /* Cleanup for sub_key */
761     #if !USE_UNICODE_WCHAR_CACHE
762     PyMem_Free((void *)sub_key);
763     #endif /* USE_UNICODE_WCHAR_CACHE */
764     /* Cleanup for file_name */
765     #if !USE_UNICODE_WCHAR_CACHE
766     PyMem_Free((void *)file_name);
767     #endif /* USE_UNICODE_WCHAR_CACHE */
768 
769     return return_value;
770 }
771 
772 PyDoc_STRVAR(winreg_OpenKey__doc__,
773 "OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
774 "--\n"
775 "\n"
776 "Opens the specified key.\n"
777 "\n"
778 "  key\n"
779 "    An already open key, or any one of the predefined HKEY_* constants.\n"
780 "  sub_key\n"
781 "    A string that identifies the sub_key to open.\n"
782 "  reserved\n"
783 "    A reserved integer that must be zero.  Default is zero.\n"
784 "  access\n"
785 "    An integer that specifies an access mask that describes the desired\n"
786 "    security access for the key.  Default is KEY_READ.\n"
787 "\n"
788 "The result is a new handle to the specified key.\n"
789 "If the function fails, an OSError exception is raised.");
790 
791 #define WINREG_OPENKEY_METHODDEF    \
792     {"OpenKey", (PyCFunction)(void(*)(void))winreg_OpenKey, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKey__doc__},
793 
794 static HKEY
795 winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
796                     int reserved, REGSAM access);
797 
798 static PyObject *
winreg_OpenKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)799 winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
800 {
801     PyObject *return_value = NULL;
802     static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
803     static _PyArg_Parser _parser = {"O&O&|ii:OpenKey", _keywords, 0};
804     HKEY key;
805     const Py_UNICODE *sub_key;
806     int reserved = 0;
807     REGSAM access = KEY_READ;
808     HKEY _return_value;
809 
810     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
811         clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
812         goto exit;
813     }
814     _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
815     if (_return_value == NULL) {
816         goto exit;
817     }
818     return_value = PyHKEY_FromHKEY(_return_value);
819 
820 exit:
821     /* Cleanup for sub_key */
822     #if !USE_UNICODE_WCHAR_CACHE
823     PyMem_Free((void *)sub_key);
824     #endif /* USE_UNICODE_WCHAR_CACHE */
825 
826     return return_value;
827 }
828 
829 PyDoc_STRVAR(winreg_OpenKeyEx__doc__,
830 "OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
831 "--\n"
832 "\n"
833 "Opens the specified key.\n"
834 "\n"
835 "  key\n"
836 "    An already open key, or any one of the predefined HKEY_* constants.\n"
837 "  sub_key\n"
838 "    A string that identifies the sub_key to open.\n"
839 "  reserved\n"
840 "    A reserved integer that must be zero.  Default is zero.\n"
841 "  access\n"
842 "    An integer that specifies an access mask that describes the desired\n"
843 "    security access for the key.  Default is KEY_READ.\n"
844 "\n"
845 "The result is a new handle to the specified key.\n"
846 "If the function fails, an OSError exception is raised.");
847 
848 #define WINREG_OPENKEYEX_METHODDEF    \
849     {"OpenKeyEx", (PyCFunction)(void(*)(void))winreg_OpenKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKeyEx__doc__},
850 
851 static HKEY
852 winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
853                       int reserved, REGSAM access);
854 
855 static PyObject *
winreg_OpenKeyEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)856 winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
857 {
858     PyObject *return_value = NULL;
859     static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
860     static _PyArg_Parser _parser = {"O&O&|ii:OpenKeyEx", _keywords, 0};
861     HKEY key;
862     const Py_UNICODE *sub_key;
863     int reserved = 0;
864     REGSAM access = KEY_READ;
865     HKEY _return_value;
866 
867     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
868         clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
869         goto exit;
870     }
871     _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
872     if (_return_value == NULL) {
873         goto exit;
874     }
875     return_value = PyHKEY_FromHKEY(_return_value);
876 
877 exit:
878     /* Cleanup for sub_key */
879     #if !USE_UNICODE_WCHAR_CACHE
880     PyMem_Free((void *)sub_key);
881     #endif /* USE_UNICODE_WCHAR_CACHE */
882 
883     return return_value;
884 }
885 
886 PyDoc_STRVAR(winreg_QueryInfoKey__doc__,
887 "QueryInfoKey($module, key, /)\n"
888 "--\n"
889 "\n"
890 "Returns information about a key.\n"
891 "\n"
892 "  key\n"
893 "    An already open key, or any one of the predefined HKEY_* constants.\n"
894 "\n"
895 "The result is a tuple of 3 items:\n"
896 "An integer that identifies the number of sub keys this key has.\n"
897 "An integer that identifies the number of values this key has.\n"
898 "An integer that identifies when the key was last modified (if available)\n"
899 "as 100\'s of nanoseconds since Jan 1, 1600.");
900 
901 #define WINREG_QUERYINFOKEY_METHODDEF    \
902     {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__},
903 
904 static PyObject *
905 winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
906 
907 static PyObject *
winreg_QueryInfoKey(PyObject * module,PyObject * arg)908 winreg_QueryInfoKey(PyObject *module, PyObject *arg)
909 {
910     PyObject *return_value = NULL;
911     HKEY key;
912 
913     if (!clinic_HKEY_converter(arg, &key)) {
914         goto exit;
915     }
916     return_value = winreg_QueryInfoKey_impl(module, key);
917 
918 exit:
919     return return_value;
920 }
921 
922 PyDoc_STRVAR(winreg_QueryValue__doc__,
923 "QueryValue($module, key, sub_key, /)\n"
924 "--\n"
925 "\n"
926 "Retrieves the unnamed value for a key.\n"
927 "\n"
928 "  key\n"
929 "    An already open key, or any one of the predefined HKEY_* constants.\n"
930 "  sub_key\n"
931 "    A string that holds the name of the subkey with which the value\n"
932 "    is associated.  If this parameter is None or empty, the function\n"
933 "    retrieves the value set by the SetValue() method for the key\n"
934 "    identified by key.\n"
935 "\n"
936 "Values in the registry have name, type, and data components. This method\n"
937 "retrieves the data for a key\'s first value that has a NULL name.\n"
938 "But since the underlying API call doesn\'t return the type, you\'ll\n"
939 "probably be happier using QueryValueEx; this function is just here for\n"
940 "completeness.");
941 
942 #define WINREG_QUERYVALUE_METHODDEF    \
943     {"QueryValue", (PyCFunction)(void(*)(void))winreg_QueryValue, METH_FASTCALL, winreg_QueryValue__doc__},
944 
945 static PyObject *
946 winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
947 
948 static PyObject *
winreg_QueryValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)949 winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
950 {
951     PyObject *return_value = NULL;
952     HKEY key;
953     const Py_UNICODE *sub_key;
954 
955     if (!_PyArg_CheckPositional("QueryValue", nargs, 2, 2)) {
956         goto exit;
957     }
958     if (!clinic_HKEY_converter(args[0], &key)) {
959         goto exit;
960     }
961     if (args[1] == Py_None) {
962         sub_key = NULL;
963     }
964     else if (PyUnicode_Check(args[1])) {
965         #if USE_UNICODE_WCHAR_CACHE
966         sub_key = _PyUnicode_AsUnicode(args[1]);
967         #else /* USE_UNICODE_WCHAR_CACHE */
968         sub_key = PyUnicode_AsWideCharString(args[1], NULL);
969         #endif /* USE_UNICODE_WCHAR_CACHE */
970         if (sub_key == NULL) {
971             goto exit;
972         }
973     }
974     else {
975         _PyArg_BadArgument("QueryValue", "argument 2", "str or None", args[1]);
976         goto exit;
977     }
978     return_value = winreg_QueryValue_impl(module, key, sub_key);
979 
980 exit:
981     /* Cleanup for sub_key */
982     #if !USE_UNICODE_WCHAR_CACHE
983     PyMem_Free((void *)sub_key);
984     #endif /* USE_UNICODE_WCHAR_CACHE */
985 
986     return return_value;
987 }
988 
989 PyDoc_STRVAR(winreg_QueryValueEx__doc__,
990 "QueryValueEx($module, key, name, /)\n"
991 "--\n"
992 "\n"
993 "Retrieves the type and value of a specified sub-key.\n"
994 "\n"
995 "  key\n"
996 "    An already open key, or any one of the predefined HKEY_* constants.\n"
997 "  name\n"
998 "    A string indicating the value to query.\n"
999 "\n"
1000 "Behaves mostly like QueryValue(), but also returns the type of the\n"
1001 "specified value name associated with the given open registry key.\n"
1002 "\n"
1003 "The return value is a tuple of the value and the type_id.");
1004 
1005 #define WINREG_QUERYVALUEEX_METHODDEF    \
1006     {"QueryValueEx", (PyCFunction)(void(*)(void))winreg_QueryValueEx, METH_FASTCALL, winreg_QueryValueEx__doc__},
1007 
1008 static PyObject *
1009 winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name);
1010 
1011 static PyObject *
winreg_QueryValueEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1012 winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1013 {
1014     PyObject *return_value = NULL;
1015     HKEY key;
1016     const Py_UNICODE *name;
1017 
1018     if (!_PyArg_CheckPositional("QueryValueEx", nargs, 2, 2)) {
1019         goto exit;
1020     }
1021     if (!clinic_HKEY_converter(args[0], &key)) {
1022         goto exit;
1023     }
1024     if (args[1] == Py_None) {
1025         name = NULL;
1026     }
1027     else if (PyUnicode_Check(args[1])) {
1028         #if USE_UNICODE_WCHAR_CACHE
1029         name = _PyUnicode_AsUnicode(args[1]);
1030         #else /* USE_UNICODE_WCHAR_CACHE */
1031         name = PyUnicode_AsWideCharString(args[1], NULL);
1032         #endif /* USE_UNICODE_WCHAR_CACHE */
1033         if (name == NULL) {
1034             goto exit;
1035         }
1036     }
1037     else {
1038         _PyArg_BadArgument("QueryValueEx", "argument 2", "str or None", args[1]);
1039         goto exit;
1040     }
1041     return_value = winreg_QueryValueEx_impl(module, key, name);
1042 
1043 exit:
1044     /* Cleanup for name */
1045     #if !USE_UNICODE_WCHAR_CACHE
1046     PyMem_Free((void *)name);
1047     #endif /* USE_UNICODE_WCHAR_CACHE */
1048 
1049     return return_value;
1050 }
1051 
1052 PyDoc_STRVAR(winreg_SaveKey__doc__,
1053 "SaveKey($module, key, file_name, /)\n"
1054 "--\n"
1055 "\n"
1056 "Saves the specified key, and all its subkeys to the specified file.\n"
1057 "\n"
1058 "  key\n"
1059 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1060 "  file_name\n"
1061 "    The name of the file to save registry data to.  This file cannot\n"
1062 "    already exist. If this filename includes an extension, it cannot be\n"
1063 "    used on file allocation table (FAT) file systems by the LoadKey(),\n"
1064 "    ReplaceKey() or RestoreKey() methods.\n"
1065 "\n"
1066 "If key represents a key on a remote computer, the path described by\n"
1067 "file_name is relative to the remote computer.\n"
1068 "\n"
1069 "The caller of this method must possess the SeBackupPrivilege\n"
1070 "security privilege.  This function passes NULL for security_attributes\n"
1071 "to the API.");
1072 
1073 #define WINREG_SAVEKEY_METHODDEF    \
1074     {"SaveKey", (PyCFunction)(void(*)(void))winreg_SaveKey, METH_FASTCALL, winreg_SaveKey__doc__},
1075 
1076 static PyObject *
1077 winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name);
1078 
1079 static PyObject *
winreg_SaveKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1080 winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1081 {
1082     PyObject *return_value = NULL;
1083     HKEY key;
1084     const Py_UNICODE *file_name;
1085 
1086     if (!_PyArg_CheckPositional("SaveKey", nargs, 2, 2)) {
1087         goto exit;
1088     }
1089     if (!clinic_HKEY_converter(args[0], &key)) {
1090         goto exit;
1091     }
1092     if (!PyUnicode_Check(args[1])) {
1093         _PyArg_BadArgument("SaveKey", "argument 2", "str", args[1]);
1094         goto exit;
1095     }
1096     #if USE_UNICODE_WCHAR_CACHE
1097     file_name = _PyUnicode_AsUnicode(args[1]);
1098     #else /* USE_UNICODE_WCHAR_CACHE */
1099     file_name = PyUnicode_AsWideCharString(args[1], NULL);
1100     #endif /* USE_UNICODE_WCHAR_CACHE */
1101     if (file_name == NULL) {
1102         goto exit;
1103     }
1104     return_value = winreg_SaveKey_impl(module, key, file_name);
1105 
1106 exit:
1107     /* Cleanup for file_name */
1108     #if !USE_UNICODE_WCHAR_CACHE
1109     PyMem_Free((void *)file_name);
1110     #endif /* USE_UNICODE_WCHAR_CACHE */
1111 
1112     return return_value;
1113 }
1114 
1115 PyDoc_STRVAR(winreg_SetValue__doc__,
1116 "SetValue($module, key, sub_key, type, value, /)\n"
1117 "--\n"
1118 "\n"
1119 "Associates a value with a specified key.\n"
1120 "\n"
1121 "  key\n"
1122 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1123 "  sub_key\n"
1124 "    A string that names the subkey with which the value is associated.\n"
1125 "  type\n"
1126 "    An integer that specifies the type of the data.  Currently this must\n"
1127 "    be REG_SZ, meaning only strings are supported.\n"
1128 "  value\n"
1129 "    A string that specifies the new value.\n"
1130 "\n"
1131 "If the key specified by the sub_key parameter does not exist, the\n"
1132 "SetValue function creates it.\n"
1133 "\n"
1134 "Value lengths are limited by available memory. Long values (more than\n"
1135 "2048 bytes) should be stored as files with the filenames stored in\n"
1136 "the configuration registry to help the registry perform efficiently.\n"
1137 "\n"
1138 "The key identified by the key parameter must have been opened with\n"
1139 "KEY_SET_VALUE access.");
1140 
1141 #define WINREG_SETVALUE_METHODDEF    \
1142     {"SetValue", (PyCFunction)(void(*)(void))winreg_SetValue, METH_FASTCALL, winreg_SetValue__doc__},
1143 
1144 static PyObject *
1145 winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
1146                      DWORD type, PyObject *value_obj);
1147 
1148 static PyObject *
winreg_SetValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1149 winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1150 {
1151     PyObject *return_value = NULL;
1152     HKEY key;
1153     const Py_UNICODE *sub_key;
1154     DWORD type;
1155     PyObject *value_obj;
1156 
1157     if (!_PyArg_ParseStack(args, nargs, "O&O&kU:SetValue",
1158         clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &type, &value_obj)) {
1159         goto exit;
1160     }
1161     return_value = winreg_SetValue_impl(module, key, sub_key, type, value_obj);
1162 
1163 exit:
1164     /* Cleanup for sub_key */
1165     #if !USE_UNICODE_WCHAR_CACHE
1166     PyMem_Free((void *)sub_key);
1167     #endif /* USE_UNICODE_WCHAR_CACHE */
1168 
1169     return return_value;
1170 }
1171 
1172 PyDoc_STRVAR(winreg_SetValueEx__doc__,
1173 "SetValueEx($module, key, value_name, reserved, type, value, /)\n"
1174 "--\n"
1175 "\n"
1176 "Stores data in the value field of an open registry key.\n"
1177 "\n"
1178 "  key\n"
1179 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1180 "  value_name\n"
1181 "    A string containing the name of the value to set, or None.\n"
1182 "  reserved\n"
1183 "    Can be anything - zero is always passed to the API.\n"
1184 "  type\n"
1185 "    An integer that specifies the type of the data, one of:\n"
1186 "    REG_BINARY -- Binary data in any form.\n"
1187 "    REG_DWORD -- A 32-bit number.\n"
1188 "    REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
1189 "    REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
1190 "    REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n"
1191 "                     references to environment variables (for example,\n"
1192 "                     %PATH%).\n"
1193 "    REG_LINK -- A Unicode symbolic link.\n"
1194 "    REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
1195 "                    by two null characters.  Note that Python handles\n"
1196 "                    this termination automatically.\n"
1197 "    REG_NONE -- No defined value type.\n"
1198 "    REG_QWORD -- A 64-bit number.\n"
1199 "    REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n"
1200 "    REG_RESOURCE_LIST -- A device-driver resource list.\n"
1201 "    REG_SZ -- A null-terminated string.\n"
1202 "  value\n"
1203 "    A string that specifies the new value.\n"
1204 "\n"
1205 "This method can also set additional value and type information for the\n"
1206 "specified key.  The key identified by the key parameter must have been\n"
1207 "opened with KEY_SET_VALUE access.\n"
1208 "\n"
1209 "To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
1210 "\n"
1211 "Value lengths are limited by available memory. Long values (more than\n"
1212 "2048 bytes) should be stored as files with the filenames stored in\n"
1213 "the configuration registry to help the registry perform efficiently.");
1214 
1215 #define WINREG_SETVALUEEX_METHODDEF    \
1216     {"SetValueEx", (PyCFunction)(void(*)(void))winreg_SetValueEx, METH_FASTCALL, winreg_SetValueEx__doc__},
1217 
1218 static PyObject *
1219 winreg_SetValueEx_impl(PyObject *module, HKEY key,
1220                        const Py_UNICODE *value_name, PyObject *reserved,
1221                        DWORD type, PyObject *value);
1222 
1223 static PyObject *
winreg_SetValueEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1224 winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1225 {
1226     PyObject *return_value = NULL;
1227     HKEY key;
1228     const Py_UNICODE *value_name;
1229     PyObject *reserved;
1230     DWORD type;
1231     PyObject *value;
1232 
1233     if (!_PyArg_ParseStack(args, nargs, "O&O&OkO:SetValueEx",
1234         clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &value_name, &reserved, &type, &value)) {
1235         goto exit;
1236     }
1237     return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
1238 
1239 exit:
1240     /* Cleanup for value_name */
1241     #if !USE_UNICODE_WCHAR_CACHE
1242     PyMem_Free((void *)value_name);
1243     #endif /* USE_UNICODE_WCHAR_CACHE */
1244 
1245     return return_value;
1246 }
1247 
1248 PyDoc_STRVAR(winreg_DisableReflectionKey__doc__,
1249 "DisableReflectionKey($module, key, /)\n"
1250 "--\n"
1251 "\n"
1252 "Disables registry reflection for 32bit processes running on a 64bit OS.\n"
1253 "\n"
1254 "  key\n"
1255 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1256 "\n"
1257 "Will generally raise NotImplementedError if executed on a 32bit OS.\n"
1258 "\n"
1259 "If the key is not on the reflection list, the function succeeds but has\n"
1260 "no effect.  Disabling reflection for a key does not affect reflection\n"
1261 "of any subkeys.");
1262 
1263 #define WINREG_DISABLEREFLECTIONKEY_METHODDEF    \
1264     {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__},
1265 
1266 static PyObject *
1267 winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
1268 
1269 static PyObject *
winreg_DisableReflectionKey(PyObject * module,PyObject * arg)1270 winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
1271 {
1272     PyObject *return_value = NULL;
1273     HKEY key;
1274 
1275     if (!clinic_HKEY_converter(arg, &key)) {
1276         goto exit;
1277     }
1278     return_value = winreg_DisableReflectionKey_impl(module, key);
1279 
1280 exit:
1281     return return_value;
1282 }
1283 
1284 PyDoc_STRVAR(winreg_EnableReflectionKey__doc__,
1285 "EnableReflectionKey($module, key, /)\n"
1286 "--\n"
1287 "\n"
1288 "Restores registry reflection for the specified disabled key.\n"
1289 "\n"
1290 "  key\n"
1291 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1292 "\n"
1293 "Will generally raise NotImplementedError if executed on a 32bit OS.\n"
1294 "Restoring reflection for a key does not affect reflection of any\n"
1295 "subkeys.");
1296 
1297 #define WINREG_ENABLEREFLECTIONKEY_METHODDEF    \
1298     {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__},
1299 
1300 static PyObject *
1301 winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
1302 
1303 static PyObject *
winreg_EnableReflectionKey(PyObject * module,PyObject * arg)1304 winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
1305 {
1306     PyObject *return_value = NULL;
1307     HKEY key;
1308 
1309     if (!clinic_HKEY_converter(arg, &key)) {
1310         goto exit;
1311     }
1312     return_value = winreg_EnableReflectionKey_impl(module, key);
1313 
1314 exit:
1315     return return_value;
1316 }
1317 
1318 PyDoc_STRVAR(winreg_QueryReflectionKey__doc__,
1319 "QueryReflectionKey($module, key, /)\n"
1320 "--\n"
1321 "\n"
1322 "Returns the reflection state for the specified key as a bool.\n"
1323 "\n"
1324 "  key\n"
1325 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1326 "\n"
1327 "Will generally raise NotImplementedError if executed on a 32bit OS.");
1328 
1329 #define WINREG_QUERYREFLECTIONKEY_METHODDEF    \
1330     {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__},
1331 
1332 static PyObject *
1333 winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
1334 
1335 static PyObject *
winreg_QueryReflectionKey(PyObject * module,PyObject * arg)1336 winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
1337 {
1338     PyObject *return_value = NULL;
1339     HKEY key;
1340 
1341     if (!clinic_HKEY_converter(arg, &key)) {
1342         goto exit;
1343     }
1344     return_value = winreg_QueryReflectionKey_impl(module, key);
1345 
1346 exit:
1347     return return_value;
1348 }
1349 /*[clinic end generated code: output=497a2e804821d5c9 input=a9049054013a1b77]*/
1350