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