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_ParseStack(args, nargs, "ZO&:ConnectRegistry",
156         &computer_name, clinic_HKEY_converter, &key)) {
157         goto exit;
158     }
159     _return_value = winreg_ConnectRegistry_impl(module, computer_name, key);
160     if (_return_value == NULL) {
161         goto exit;
162     }
163     return_value = PyHKEY_FromHKEY(_return_value);
164 
165 exit:
166     return return_value;
167 }
168 
169 PyDoc_STRVAR(winreg_CreateKey__doc__,
170 "CreateKey($module, key, sub_key, /)\n"
171 "--\n"
172 "\n"
173 "Creates or opens the specified key.\n"
174 "\n"
175 "  key\n"
176 "    An already open key, or one of the predefined HKEY_* constants.\n"
177 "  sub_key\n"
178 "    The name of the key this method opens or creates.\n"
179 "\n"
180 "If key is one of the predefined keys, sub_key may be None. In that case,\n"
181 "the handle returned is the same key handle passed in to the function.\n"
182 "\n"
183 "If the key already exists, this function opens the existing key.\n"
184 "\n"
185 "The return value is the handle of the opened key.\n"
186 "If the function fails, an OSError exception is raised.");
187 
188 #define WINREG_CREATEKEY_METHODDEF    \
189     {"CreateKey", (PyCFunction)(void(*)(void))winreg_CreateKey, METH_FASTCALL, winreg_CreateKey__doc__},
190 
191 static HKEY
192 winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
193 
194 static PyObject *
winreg_CreateKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)195 winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
196 {
197     PyObject *return_value = NULL;
198     HKEY key;
199     const Py_UNICODE *sub_key;
200     HKEY _return_value;
201 
202     if (!_PyArg_ParseStack(args, nargs, "O&Z:CreateKey",
203         clinic_HKEY_converter, &key, &sub_key)) {
204         goto exit;
205     }
206     _return_value = winreg_CreateKey_impl(module, key, sub_key);
207     if (_return_value == NULL) {
208         goto exit;
209     }
210     return_value = PyHKEY_FromHKEY(_return_value);
211 
212 exit:
213     return return_value;
214 }
215 
216 PyDoc_STRVAR(winreg_CreateKeyEx__doc__,
217 "CreateKeyEx($module, /, key, sub_key, reserved=0,\n"
218 "            access=winreg.KEY_WRITE)\n"
219 "--\n"
220 "\n"
221 "Creates or opens the specified key.\n"
222 "\n"
223 "  key\n"
224 "    An already open key, or one of the predefined HKEY_* constants.\n"
225 "  sub_key\n"
226 "    The name of the key this method opens or creates.\n"
227 "  reserved\n"
228 "    A reserved integer, and must be zero.  Default is zero.\n"
229 "  access\n"
230 "    An integer that specifies an access mask that describes the\n"
231 "    desired security access for the key. Default is KEY_WRITE.\n"
232 "\n"
233 "If key is one of the predefined keys, sub_key may be None. In that case,\n"
234 "the handle returned is the same key handle passed in to the function.\n"
235 "\n"
236 "If the key already exists, this function opens the existing key\n"
237 "\n"
238 "The return value is the handle of the opened key.\n"
239 "If the function fails, an OSError exception is raised.");
240 
241 #define WINREG_CREATEKEYEX_METHODDEF    \
242     {"CreateKeyEx", (PyCFunction)(void(*)(void))winreg_CreateKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_CreateKeyEx__doc__},
243 
244 static HKEY
245 winreg_CreateKeyEx_impl(PyObject *module, HKEY key,
246                         const Py_UNICODE *sub_key, int reserved,
247                         REGSAM access);
248 
249 static PyObject *
winreg_CreateKeyEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)250 winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
251 {
252     PyObject *return_value = NULL;
253     static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
254     static _PyArg_Parser _parser = {"O&Z|ii:CreateKeyEx", _keywords, 0};
255     HKEY key;
256     const Py_UNICODE *sub_key;
257     int reserved = 0;
258     REGSAM access = KEY_WRITE;
259     HKEY _return_value;
260 
261     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
262         clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
263         goto exit;
264     }
265     _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
266     if (_return_value == NULL) {
267         goto exit;
268     }
269     return_value = PyHKEY_FromHKEY(_return_value);
270 
271 exit:
272     return return_value;
273 }
274 
275 PyDoc_STRVAR(winreg_DeleteKey__doc__,
276 "DeleteKey($module, key, sub_key, /)\n"
277 "--\n"
278 "\n"
279 "Deletes the specified key.\n"
280 "\n"
281 "  key\n"
282 "    An already open key, or any one of the predefined HKEY_* constants.\n"
283 "  sub_key\n"
284 "    A string that must be the name of a subkey of the key identified by\n"
285 "    the key parameter. This value must not be None, and the key may not\n"
286 "    have subkeys.\n"
287 "\n"
288 "This method can not delete keys with subkeys.\n"
289 "\n"
290 "If the function succeeds, the entire key, including all of its values,\n"
291 "is removed.  If the function fails, an OSError exception is raised.");
292 
293 #define WINREG_DELETEKEY_METHODDEF    \
294     {"DeleteKey", (PyCFunction)(void(*)(void))winreg_DeleteKey, METH_FASTCALL, winreg_DeleteKey__doc__},
295 
296 static PyObject *
297 winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
298 
299 static PyObject *
winreg_DeleteKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)300 winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
301 {
302     PyObject *return_value = NULL;
303     HKEY key;
304     const Py_UNICODE *sub_key;
305 
306     if (!_PyArg_ParseStack(args, nargs, "O&u:DeleteKey",
307         clinic_HKEY_converter, &key, &sub_key)) {
308         goto exit;
309     }
310     return_value = winreg_DeleteKey_impl(module, key, sub_key);
311 
312 exit:
313     return return_value;
314 }
315 
316 PyDoc_STRVAR(winreg_DeleteKeyEx__doc__,
317 "DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n"
318 "            reserved=0)\n"
319 "--\n"
320 "\n"
321 "Deletes the specified key (64-bit OS only).\n"
322 "\n"
323 "  key\n"
324 "    An already open key, or any one of the predefined HKEY_* constants.\n"
325 "  sub_key\n"
326 "    A string that must be the name of a subkey of the key identified by\n"
327 "    the key parameter. This value must not be None, and the key may not\n"
328 "    have subkeys.\n"
329 "  access\n"
330 "    An integer that specifies an access mask that describes the\n"
331 "    desired security access for the key. Default is KEY_WOW64_64KEY.\n"
332 "  reserved\n"
333 "    A reserved integer, and must be zero.  Default is zero.\n"
334 "\n"
335 "This method can not delete keys with subkeys.\n"
336 "\n"
337 "If the function succeeds, the entire key, including all of its values,\n"
338 "is removed.  If the function fails, an OSError exception is raised.\n"
339 "On unsupported Windows versions, NotImplementedError is raised.");
340 
341 #define WINREG_DELETEKEYEX_METHODDEF    \
342     {"DeleteKeyEx", (PyCFunction)(void(*)(void))winreg_DeleteKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_DeleteKeyEx__doc__},
343 
344 static PyObject *
345 winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
346                         const Py_UNICODE *sub_key, REGSAM access,
347                         int reserved);
348 
349 static PyObject *
winreg_DeleteKeyEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)350 winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
351 {
352     PyObject *return_value = NULL;
353     static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL};
354     static _PyArg_Parser _parser = {"O&u|ii:DeleteKeyEx", _keywords, 0};
355     HKEY key;
356     const Py_UNICODE *sub_key;
357     REGSAM access = KEY_WOW64_64KEY;
358     int reserved = 0;
359 
360     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
361         clinic_HKEY_converter, &key, &sub_key, &access, &reserved)) {
362         goto exit;
363     }
364     return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
365 
366 exit:
367     return return_value;
368 }
369 
370 PyDoc_STRVAR(winreg_DeleteValue__doc__,
371 "DeleteValue($module, key, value, /)\n"
372 "--\n"
373 "\n"
374 "Removes a named value from a registry key.\n"
375 "\n"
376 "  key\n"
377 "    An already open key, or any one of the predefined HKEY_* constants.\n"
378 "  value\n"
379 "    A string that identifies the value to remove.");
380 
381 #define WINREG_DELETEVALUE_METHODDEF    \
382     {"DeleteValue", (PyCFunction)(void(*)(void))winreg_DeleteValue, METH_FASTCALL, winreg_DeleteValue__doc__},
383 
384 static PyObject *
385 winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value);
386 
387 static PyObject *
winreg_DeleteValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)388 winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
389 {
390     PyObject *return_value = NULL;
391     HKEY key;
392     const Py_UNICODE *value;
393 
394     if (!_PyArg_ParseStack(args, nargs, "O&Z:DeleteValue",
395         clinic_HKEY_converter, &key, &value)) {
396         goto exit;
397     }
398     return_value = winreg_DeleteValue_impl(module, key, value);
399 
400 exit:
401     return return_value;
402 }
403 
404 PyDoc_STRVAR(winreg_EnumKey__doc__,
405 "EnumKey($module, key, index, /)\n"
406 "--\n"
407 "\n"
408 "Enumerates subkeys of an open registry key.\n"
409 "\n"
410 "  key\n"
411 "    An already open key, or any one of the predefined HKEY_* constants.\n"
412 "  index\n"
413 "    An integer that identifies the index of the key to retrieve.\n"
414 "\n"
415 "The function retrieves the name of one subkey each time it is called.\n"
416 "It is typically called repeatedly until an OSError exception is\n"
417 "raised, indicating no more values are available.");
418 
419 #define WINREG_ENUMKEY_METHODDEF    \
420     {"EnumKey", (PyCFunction)(void(*)(void))winreg_EnumKey, METH_FASTCALL, winreg_EnumKey__doc__},
421 
422 static PyObject *
423 winreg_EnumKey_impl(PyObject *module, HKEY key, int index);
424 
425 static PyObject *
winreg_EnumKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)426 winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
427 {
428     PyObject *return_value = NULL;
429     HKEY key;
430     int index;
431 
432     if (!_PyArg_CheckPositional("EnumKey", nargs, 2, 2)) {
433         goto exit;
434     }
435     if (!clinic_HKEY_converter(args[0], &key)) {
436         goto exit;
437     }
438     if (PyFloat_Check(args[1])) {
439         PyErr_SetString(PyExc_TypeError,
440                         "integer argument expected, got float" );
441         goto exit;
442     }
443     index = _PyLong_AsInt(args[1]);
444     if (index == -1 && PyErr_Occurred()) {
445         goto exit;
446     }
447     return_value = winreg_EnumKey_impl(module, key, index);
448 
449 exit:
450     return return_value;
451 }
452 
453 PyDoc_STRVAR(winreg_EnumValue__doc__,
454 "EnumValue($module, key, index, /)\n"
455 "--\n"
456 "\n"
457 "Enumerates values of an open registry key.\n"
458 "\n"
459 "  key\n"
460 "    An already open key, or any one of the predefined HKEY_* constants.\n"
461 "  index\n"
462 "    An integer that identifies the index of the value to retrieve.\n"
463 "\n"
464 "The function retrieves the name of one subkey each time it is called.\n"
465 "It is typically called repeatedly, until an OSError exception\n"
466 "is raised, indicating no more values.\n"
467 "\n"
468 "The result is a tuple of 3 items:\n"
469 "  value_name\n"
470 "    A string that identifies the value.\n"
471 "  value_data\n"
472 "    An object that holds the value data, and whose type depends\n"
473 "    on the underlying registry type.\n"
474 "  data_type\n"
475 "    An integer that identifies the type of the value data.");
476 
477 #define WINREG_ENUMVALUE_METHODDEF    \
478     {"EnumValue", (PyCFunction)(void(*)(void))winreg_EnumValue, METH_FASTCALL, winreg_EnumValue__doc__},
479 
480 static PyObject *
481 winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
482 
483 static PyObject *
winreg_EnumValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)484 winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
485 {
486     PyObject *return_value = NULL;
487     HKEY key;
488     int index;
489 
490     if (!_PyArg_CheckPositional("EnumValue", nargs, 2, 2)) {
491         goto exit;
492     }
493     if (!clinic_HKEY_converter(args[0], &key)) {
494         goto exit;
495     }
496     if (PyFloat_Check(args[1])) {
497         PyErr_SetString(PyExc_TypeError,
498                         "integer argument expected, got float" );
499         goto exit;
500     }
501     index = _PyLong_AsInt(args[1]);
502     if (index == -1 && PyErr_Occurred()) {
503         goto exit;
504     }
505     return_value = winreg_EnumValue_impl(module, key, index);
506 
507 exit:
508     return return_value;
509 }
510 
511 PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__,
512 "ExpandEnvironmentStrings($module, string, /)\n"
513 "--\n"
514 "\n"
515 "Expand environment vars.");
516 
517 #define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF    \
518     {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__},
519 
520 static PyObject *
521 winreg_ExpandEnvironmentStrings_impl(PyObject *module,
522                                      const Py_UNICODE *string);
523 
524 static PyObject *
winreg_ExpandEnvironmentStrings(PyObject * module,PyObject * arg)525 winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
526 {
527     PyObject *return_value = NULL;
528     const Py_UNICODE *string;
529 
530     if (!PyArg_Parse(arg, "u:ExpandEnvironmentStrings", &string)) {
531         goto exit;
532     }
533     return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
534 
535 exit:
536     return return_value;
537 }
538 
539 PyDoc_STRVAR(winreg_FlushKey__doc__,
540 "FlushKey($module, key, /)\n"
541 "--\n"
542 "\n"
543 "Writes all the attributes of a key to the registry.\n"
544 "\n"
545 "  key\n"
546 "    An already open key, or any one of the predefined HKEY_* constants.\n"
547 "\n"
548 "It is not necessary to call FlushKey to change a key.  Registry changes\n"
549 "are flushed to disk by the registry using its lazy flusher.  Registry\n"
550 "changes are also flushed to disk at system shutdown.  Unlike\n"
551 "CloseKey(), the FlushKey() method returns only when all the data has\n"
552 "been written to the registry.\n"
553 "\n"
554 "An application should only call FlushKey() if it requires absolute\n"
555 "certainty that registry changes are on disk.  If you don\'t know whether\n"
556 "a FlushKey() call is required, it probably isn\'t.");
557 
558 #define WINREG_FLUSHKEY_METHODDEF    \
559     {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__},
560 
561 static PyObject *
562 winreg_FlushKey_impl(PyObject *module, HKEY key);
563 
564 static PyObject *
winreg_FlushKey(PyObject * module,PyObject * arg)565 winreg_FlushKey(PyObject *module, PyObject *arg)
566 {
567     PyObject *return_value = NULL;
568     HKEY key;
569 
570     if (!clinic_HKEY_converter(arg, &key)) {
571         goto exit;
572     }
573     return_value = winreg_FlushKey_impl(module, key);
574 
575 exit:
576     return return_value;
577 }
578 
579 PyDoc_STRVAR(winreg_LoadKey__doc__,
580 "LoadKey($module, key, sub_key, file_name, /)\n"
581 "--\n"
582 "\n"
583 "Insert data into the registry from a file.\n"
584 "\n"
585 "  key\n"
586 "    An already open key, or any one of the predefined HKEY_* constants.\n"
587 "  sub_key\n"
588 "    A string that identifies the sub-key to load.\n"
589 "  file_name\n"
590 "    The name of the file to load registry data from.  This file must\n"
591 "    have been created with the SaveKey() function.  Under the file\n"
592 "    allocation table (FAT) file system, the filename may not have an\n"
593 "    extension.\n"
594 "\n"
595 "Creates a subkey under the specified key and stores registration\n"
596 "information from a specified file into that subkey.\n"
597 "\n"
598 "A call to LoadKey() fails if the calling process does not have the\n"
599 "SE_RESTORE_PRIVILEGE privilege.\n"
600 "\n"
601 "If key is a handle returned by ConnectRegistry(), then the path\n"
602 "specified in fileName is relative to the remote computer.\n"
603 "\n"
604 "The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n"
605 "tree.");
606 
607 #define WINREG_LOADKEY_METHODDEF    \
608     {"LoadKey", (PyCFunction)(void(*)(void))winreg_LoadKey, METH_FASTCALL, winreg_LoadKey__doc__},
609 
610 static PyObject *
611 winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
612                     const Py_UNICODE *file_name);
613 
614 static PyObject *
winreg_LoadKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)615 winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
616 {
617     PyObject *return_value = NULL;
618     HKEY key;
619     const Py_UNICODE *sub_key;
620     const Py_UNICODE *file_name;
621 
622     if (!_PyArg_ParseStack(args, nargs, "O&uu:LoadKey",
623         clinic_HKEY_converter, &key, &sub_key, &file_name)) {
624         goto exit;
625     }
626     return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
627 
628 exit:
629     return return_value;
630 }
631 
632 PyDoc_STRVAR(winreg_OpenKey__doc__,
633 "OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
634 "--\n"
635 "\n"
636 "Opens the specified key.\n"
637 "\n"
638 "  key\n"
639 "    An already open key, or any one of the predefined HKEY_* constants.\n"
640 "  sub_key\n"
641 "    A string that identifies the sub_key to open.\n"
642 "  reserved\n"
643 "    A reserved integer that must be zero.  Default is zero.\n"
644 "  access\n"
645 "    An integer that specifies an access mask that describes the desired\n"
646 "    security access for the key.  Default is KEY_READ.\n"
647 "\n"
648 "The result is a new handle to the specified key.\n"
649 "If the function fails, an OSError exception is raised.");
650 
651 #define WINREG_OPENKEY_METHODDEF    \
652     {"OpenKey", (PyCFunction)(void(*)(void))winreg_OpenKey, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKey__doc__},
653 
654 static HKEY
655 winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
656                     int reserved, REGSAM access);
657 
658 static PyObject *
winreg_OpenKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)659 winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
660 {
661     PyObject *return_value = NULL;
662     static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
663     static _PyArg_Parser _parser = {"O&Z|ii:OpenKey", _keywords, 0};
664     HKEY key;
665     const Py_UNICODE *sub_key;
666     int reserved = 0;
667     REGSAM access = KEY_READ;
668     HKEY _return_value;
669 
670     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
671         clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
672         goto exit;
673     }
674     _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
675     if (_return_value == NULL) {
676         goto exit;
677     }
678     return_value = PyHKEY_FromHKEY(_return_value);
679 
680 exit:
681     return return_value;
682 }
683 
684 PyDoc_STRVAR(winreg_OpenKeyEx__doc__,
685 "OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
686 "--\n"
687 "\n"
688 "Opens the specified key.\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 open.\n"
694 "  reserved\n"
695 "    A reserved integer that must be zero.  Default is zero.\n"
696 "  access\n"
697 "    An integer that specifies an access mask that describes the desired\n"
698 "    security access for the key.  Default is KEY_READ.\n"
699 "\n"
700 "The result is a new handle to the specified key.\n"
701 "If the function fails, an OSError exception is raised.");
702 
703 #define WINREG_OPENKEYEX_METHODDEF    \
704     {"OpenKeyEx", (PyCFunction)(void(*)(void))winreg_OpenKeyEx, METH_FASTCALL|METH_KEYWORDS, winreg_OpenKeyEx__doc__},
705 
706 static HKEY
707 winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
708                       int reserved, REGSAM access);
709 
710 static PyObject *
winreg_OpenKeyEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)711 winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
712 {
713     PyObject *return_value = NULL;
714     static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
715     static _PyArg_Parser _parser = {"O&Z|ii:OpenKeyEx", _keywords, 0};
716     HKEY key;
717     const Py_UNICODE *sub_key;
718     int reserved = 0;
719     REGSAM access = KEY_READ;
720     HKEY _return_value;
721 
722     if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
723         clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) {
724         goto exit;
725     }
726     _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
727     if (_return_value == NULL) {
728         goto exit;
729     }
730     return_value = PyHKEY_FromHKEY(_return_value);
731 
732 exit:
733     return return_value;
734 }
735 
736 PyDoc_STRVAR(winreg_QueryInfoKey__doc__,
737 "QueryInfoKey($module, key, /)\n"
738 "--\n"
739 "\n"
740 "Returns information about a key.\n"
741 "\n"
742 "  key\n"
743 "    An already open key, or any one of the predefined HKEY_* constants.\n"
744 "\n"
745 "The result is a tuple of 3 items:\n"
746 "An integer that identifies the number of sub keys this key has.\n"
747 "An integer that identifies the number of values this key has.\n"
748 "An integer that identifies when the key was last modified (if available)\n"
749 "as 100\'s of nanoseconds since Jan 1, 1600.");
750 
751 #define WINREG_QUERYINFOKEY_METHODDEF    \
752     {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__},
753 
754 static PyObject *
755 winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
756 
757 static PyObject *
winreg_QueryInfoKey(PyObject * module,PyObject * arg)758 winreg_QueryInfoKey(PyObject *module, PyObject *arg)
759 {
760     PyObject *return_value = NULL;
761     HKEY key;
762 
763     if (!clinic_HKEY_converter(arg, &key)) {
764         goto exit;
765     }
766     return_value = winreg_QueryInfoKey_impl(module, key);
767 
768 exit:
769     return return_value;
770 }
771 
772 PyDoc_STRVAR(winreg_QueryValue__doc__,
773 "QueryValue($module, key, sub_key, /)\n"
774 "--\n"
775 "\n"
776 "Retrieves the unnamed value for a 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 holds the name of the subkey with which the value\n"
782 "    is associated.  If this parameter is None or empty, the function\n"
783 "    retrieves the value set by the SetValue() method for the key\n"
784 "    identified by key.\n"
785 "\n"
786 "Values in the registry have name, type, and data components. This method\n"
787 "retrieves the data for a key\'s first value that has a NULL name.\n"
788 "But since the underlying API call doesn\'t return the type, you\'ll\n"
789 "probably be happier using QueryValueEx; this function is just here for\n"
790 "completeness.");
791 
792 #define WINREG_QUERYVALUE_METHODDEF    \
793     {"QueryValue", (PyCFunction)(void(*)(void))winreg_QueryValue, METH_FASTCALL, winreg_QueryValue__doc__},
794 
795 static PyObject *
796 winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
797 
798 static PyObject *
winreg_QueryValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)799 winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
800 {
801     PyObject *return_value = NULL;
802     HKEY key;
803     const Py_UNICODE *sub_key;
804 
805     if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValue",
806         clinic_HKEY_converter, &key, &sub_key)) {
807         goto exit;
808     }
809     return_value = winreg_QueryValue_impl(module, key, sub_key);
810 
811 exit:
812     return return_value;
813 }
814 
815 PyDoc_STRVAR(winreg_QueryValueEx__doc__,
816 "QueryValueEx($module, key, name, /)\n"
817 "--\n"
818 "\n"
819 "Retrieves the type and value of a specified sub-key.\n"
820 "\n"
821 "  key\n"
822 "    An already open key, or any one of the predefined HKEY_* constants.\n"
823 "  name\n"
824 "    A string indicating the value to query.\n"
825 "\n"
826 "Behaves mostly like QueryValue(), but also returns the type of the\n"
827 "specified value name associated with the given open registry key.\n"
828 "\n"
829 "The return value is a tuple of the value and the type_id.");
830 
831 #define WINREG_QUERYVALUEEX_METHODDEF    \
832     {"QueryValueEx", (PyCFunction)(void(*)(void))winreg_QueryValueEx, METH_FASTCALL, winreg_QueryValueEx__doc__},
833 
834 static PyObject *
835 winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name);
836 
837 static PyObject *
winreg_QueryValueEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs)838 winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
839 {
840     PyObject *return_value = NULL;
841     HKEY key;
842     const Py_UNICODE *name;
843 
844     if (!_PyArg_ParseStack(args, nargs, "O&Z:QueryValueEx",
845         clinic_HKEY_converter, &key, &name)) {
846         goto exit;
847     }
848     return_value = winreg_QueryValueEx_impl(module, key, name);
849 
850 exit:
851     return return_value;
852 }
853 
854 PyDoc_STRVAR(winreg_SaveKey__doc__,
855 "SaveKey($module, key, file_name, /)\n"
856 "--\n"
857 "\n"
858 "Saves the specified key, and all its subkeys to the specified file.\n"
859 "\n"
860 "  key\n"
861 "    An already open key, or any one of the predefined HKEY_* constants.\n"
862 "  file_name\n"
863 "    The name of the file to save registry data to.  This file cannot\n"
864 "    already exist. If this filename includes an extension, it cannot be\n"
865 "    used on file allocation table (FAT) file systems by the LoadKey(),\n"
866 "    ReplaceKey() or RestoreKey() methods.\n"
867 "\n"
868 "If key represents a key on a remote computer, the path described by\n"
869 "file_name is relative to the remote computer.\n"
870 "\n"
871 "The caller of this method must possess the SeBackupPrivilege\n"
872 "security privilege.  This function passes NULL for security_attributes\n"
873 "to the API.");
874 
875 #define WINREG_SAVEKEY_METHODDEF    \
876     {"SaveKey", (PyCFunction)(void(*)(void))winreg_SaveKey, METH_FASTCALL, winreg_SaveKey__doc__},
877 
878 static PyObject *
879 winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name);
880 
881 static PyObject *
winreg_SaveKey(PyObject * module,PyObject * const * args,Py_ssize_t nargs)882 winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
883 {
884     PyObject *return_value = NULL;
885     HKEY key;
886     const Py_UNICODE *file_name;
887 
888     if (!_PyArg_ParseStack(args, nargs, "O&u:SaveKey",
889         clinic_HKEY_converter, &key, &file_name)) {
890         goto exit;
891     }
892     return_value = winreg_SaveKey_impl(module, key, file_name);
893 
894 exit:
895     return return_value;
896 }
897 
898 PyDoc_STRVAR(winreg_SetValue__doc__,
899 "SetValue($module, key, sub_key, type, value, /)\n"
900 "--\n"
901 "\n"
902 "Associates a value with a specified key.\n"
903 "\n"
904 "  key\n"
905 "    An already open key, or any one of the predefined HKEY_* constants.\n"
906 "  sub_key\n"
907 "    A string that names the subkey with which the value is associated.\n"
908 "  type\n"
909 "    An integer that specifies the type of the data.  Currently this must\n"
910 "    be REG_SZ, meaning only strings are supported.\n"
911 "  value\n"
912 "    A string that specifies the new value.\n"
913 "\n"
914 "If the key specified by the sub_key parameter does not exist, the\n"
915 "SetValue function creates it.\n"
916 "\n"
917 "Value lengths are limited by available memory. Long values (more than\n"
918 "2048 bytes) should be stored as files with the filenames stored in\n"
919 "the configuration registry to help the registry perform efficiently.\n"
920 "\n"
921 "The key identified by the key parameter must have been opened with\n"
922 "KEY_SET_VALUE access.");
923 
924 #define WINREG_SETVALUE_METHODDEF    \
925     {"SetValue", (PyCFunction)(void(*)(void))winreg_SetValue, METH_FASTCALL, winreg_SetValue__doc__},
926 
927 static PyObject *
928 winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
929                      DWORD type, const Py_UNICODE *value,
930                      Py_ssize_clean_t value_length);
931 
932 static PyObject *
winreg_SetValue(PyObject * module,PyObject * const * args,Py_ssize_t nargs)933 winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
934 {
935     PyObject *return_value = NULL;
936     HKEY key;
937     const Py_UNICODE *sub_key;
938     DWORD type;
939     const Py_UNICODE *value;
940     Py_ssize_clean_t value_length;
941 
942     if (!_PyArg_ParseStack(args, nargs, "O&Zku#:SetValue",
943         clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) {
944         goto exit;
945     }
946     return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length);
947 
948 exit:
949     return return_value;
950 }
951 
952 PyDoc_STRVAR(winreg_SetValueEx__doc__,
953 "SetValueEx($module, key, value_name, reserved, type, value, /)\n"
954 "--\n"
955 "\n"
956 "Stores data in the value field of an open registry key.\n"
957 "\n"
958 "  key\n"
959 "    An already open key, or any one of the predefined HKEY_* constants.\n"
960 "  value_name\n"
961 "    A string containing the name of the value to set, or None.\n"
962 "  reserved\n"
963 "    Can be anything - zero is always passed to the API.\n"
964 "  type\n"
965 "    An integer that specifies the type of the data, one of:\n"
966 "    REG_BINARY -- Binary data in any form.\n"
967 "    REG_DWORD -- A 32-bit number.\n"
968 "    REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
969 "    REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
970 "    REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n"
971 "                     references to environment variables (for example,\n"
972 "                     %PATH%).\n"
973 "    REG_LINK -- A Unicode symbolic link.\n"
974 "    REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
975 "                    by two null characters.  Note that Python handles\n"
976 "                    this termination automatically.\n"
977 "    REG_NONE -- No defined value type.\n"
978 "    REG_QWORD -- A 64-bit number.\n"
979 "    REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n"
980 "    REG_RESOURCE_LIST -- A device-driver resource list.\n"
981 "    REG_SZ -- A null-terminated string.\n"
982 "  value\n"
983 "    A string that specifies the new value.\n"
984 "\n"
985 "This method can also set additional value and type information for the\n"
986 "specified key.  The key identified by the key parameter must have been\n"
987 "opened with KEY_SET_VALUE access.\n"
988 "\n"
989 "To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
990 "\n"
991 "Value lengths are limited by available memory. Long values (more than\n"
992 "2048 bytes) should be stored as files with the filenames stored in\n"
993 "the configuration registry to help the registry perform efficiently.");
994 
995 #define WINREG_SETVALUEEX_METHODDEF    \
996     {"SetValueEx", (PyCFunction)(void(*)(void))winreg_SetValueEx, METH_FASTCALL, winreg_SetValueEx__doc__},
997 
998 static PyObject *
999 winreg_SetValueEx_impl(PyObject *module, HKEY key,
1000                        const Py_UNICODE *value_name, PyObject *reserved,
1001                        DWORD type, PyObject *value);
1002 
1003 static PyObject *
winreg_SetValueEx(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1004 winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1005 {
1006     PyObject *return_value = NULL;
1007     HKEY key;
1008     const Py_UNICODE *value_name;
1009     PyObject *reserved;
1010     DWORD type;
1011     PyObject *value;
1012 
1013     if (!_PyArg_ParseStack(args, nargs, "O&ZOkO:SetValueEx",
1014         clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) {
1015         goto exit;
1016     }
1017     return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
1018 
1019 exit:
1020     return return_value;
1021 }
1022 
1023 PyDoc_STRVAR(winreg_DisableReflectionKey__doc__,
1024 "DisableReflectionKey($module, key, /)\n"
1025 "--\n"
1026 "\n"
1027 "Disables registry reflection for 32bit processes running on a 64bit OS.\n"
1028 "\n"
1029 "  key\n"
1030 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1031 "\n"
1032 "Will generally raise NotImplementedError if executed on a 32bit OS.\n"
1033 "\n"
1034 "If the key is not on the reflection list, the function succeeds but has\n"
1035 "no effect.  Disabling reflection for a key does not affect reflection\n"
1036 "of any subkeys.");
1037 
1038 #define WINREG_DISABLEREFLECTIONKEY_METHODDEF    \
1039     {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__},
1040 
1041 static PyObject *
1042 winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
1043 
1044 static PyObject *
winreg_DisableReflectionKey(PyObject * module,PyObject * arg)1045 winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
1046 {
1047     PyObject *return_value = NULL;
1048     HKEY key;
1049 
1050     if (!clinic_HKEY_converter(arg, &key)) {
1051         goto exit;
1052     }
1053     return_value = winreg_DisableReflectionKey_impl(module, key);
1054 
1055 exit:
1056     return return_value;
1057 }
1058 
1059 PyDoc_STRVAR(winreg_EnableReflectionKey__doc__,
1060 "EnableReflectionKey($module, key, /)\n"
1061 "--\n"
1062 "\n"
1063 "Restores registry reflection for the specified disabled key.\n"
1064 "\n"
1065 "  key\n"
1066 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1067 "\n"
1068 "Will generally raise NotImplementedError if executed on a 32bit OS.\n"
1069 "Restoring reflection for a key does not affect reflection of any\n"
1070 "subkeys.");
1071 
1072 #define WINREG_ENABLEREFLECTIONKEY_METHODDEF    \
1073     {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__},
1074 
1075 static PyObject *
1076 winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
1077 
1078 static PyObject *
winreg_EnableReflectionKey(PyObject * module,PyObject * arg)1079 winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
1080 {
1081     PyObject *return_value = NULL;
1082     HKEY key;
1083 
1084     if (!clinic_HKEY_converter(arg, &key)) {
1085         goto exit;
1086     }
1087     return_value = winreg_EnableReflectionKey_impl(module, key);
1088 
1089 exit:
1090     return return_value;
1091 }
1092 
1093 PyDoc_STRVAR(winreg_QueryReflectionKey__doc__,
1094 "QueryReflectionKey($module, key, /)\n"
1095 "--\n"
1096 "\n"
1097 "Returns the reflection state for the specified key as a bool.\n"
1098 "\n"
1099 "  key\n"
1100 "    An already open key, or any one of the predefined HKEY_* constants.\n"
1101 "\n"
1102 "Will generally raise NotImplementedError if executed on a 32bit OS.");
1103 
1104 #define WINREG_QUERYREFLECTIONKEY_METHODDEF    \
1105     {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__},
1106 
1107 static PyObject *
1108 winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
1109 
1110 static PyObject *
winreg_QueryReflectionKey(PyObject * module,PyObject * arg)1111 winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
1112 {
1113     PyObject *return_value = NULL;
1114     HKEY key;
1115 
1116     if (!clinic_HKEY_converter(arg, &key)) {
1117         goto exit;
1118     }
1119     return_value = winreg_QueryReflectionKey_impl(module, key);
1120 
1121 exit:
1122     return return_value;
1123 }
1124 /*[clinic end generated code: output=015afbbd690eb59d input=a9049054013a1b77]*/
1125