Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 58505:bc2b88beae45 legacy-trunk
Issue #7766: Change sys.getwindowsversion() return value to a named tuple and add the additional members returned in an OSVERSIONINFOEX structure. The new members are service_pack_major, service_pack_minor, suite_mask, and product_type.
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Wed, 27 Jan 2010 00:28:29 +0000 |
| parents | aacee9749d15 |
| children | 24665a9d881a |
comparison
equal
deleted
inserted
replaced
| 58503:f9fd1795fcf7 | 58505:bc2b88beae45 |
|---|---|
| 555 | 555 |
| 556 #ifdef MS_WINDOWS | 556 #ifdef MS_WINDOWS |
| 557 PyDoc_STRVAR(getwindowsversion_doc, | 557 PyDoc_STRVAR(getwindowsversion_doc, |
| 558 "getwindowsversion()\n\ | 558 "getwindowsversion()\n\ |
| 559 \n\ | 559 \n\ |
| 560 Return information about the running version of Windows.\n\ | 560 Return information about the running version of Windows as a named tuple.\n\ |
| 561 The result is a tuple of (major, minor, build, platform, text)\n\ | 561 The members are named: major, minor, build, platform, service_pack,\n\ |
| 562 All elements are numbers, except text which is a string.\n\ | 562 service_pack_major, service_pack_minor, suite_mask, and product_type. For\n\ |
| 563 Platform may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP\n\ | 563 backward compatibiliy, only the first 5 items are available by indexing.\n\ |
| 564 " | 564 All elements are numbers, except service_pack which is a string. Platform\n\ |
| 565 ); | 565 may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP/Vista/7,\n\ |
| 566 3 for Windows CE. Product_type may be 1 for a workstation, 2 for a domain\n\ | |
| 567 controller, 3 for a server." | |
| 568 ); | |
| 569 | |
| 570 static PyTypeObject WindowsVersionType = {0, 0, 0, 0, 0, 0}; | |
| 571 | |
| 572 static PyStructSequence_Field windows_version_fields[] = { | |
| 573 {"major", "Major version number"}, | |
| 574 {"minor", "Minor version number"}, | |
| 575 {"build", "Build number"}, | |
| 576 {"platform", "Operating system platform"}, | |
| 577 {"service_pack", "Latest Service Pack installed on the system"}, | |
| 578 {"service_pack_major", "Service Pack major version number"}, | |
| 579 {"service_pack_minor", "Service Pack minor version number"}, | |
| 580 {"suite_mask", "Bit mask identifying available product suites"}, | |
| 581 {"product_type", "System product type"}, | |
| 582 {0} | |
| 583 }; | |
| 584 | |
| 585 static PyStructSequence_Desc windows_version_desc = { | |
| 586 "sys.getwindowsversion", /* name */ | |
| 587 getwindowsversion_doc, /* doc */ | |
| 588 windows_version_fields, /* fields */ | |
| 589 5 /* For backward compatibility, | |
| 590 only the first 5 items are accessible | |
| 591 via indexing, the rest are name only */ | |
| 592 }; | |
| 566 | 593 |
| 567 static PyObject * | 594 static PyObject * |
| 568 sys_getwindowsversion(PyObject *self) | 595 sys_getwindowsversion(PyObject *self) |
| 569 { | 596 { |
| 570 OSVERSIONINFO ver; | 597 PyObject *version; |
| 598 int pos = 0; | |
| 599 OSVERSIONINFOEX ver; | |
| 571 ver.dwOSVersionInfoSize = sizeof(ver); | 600 ver.dwOSVersionInfoSize = sizeof(ver); |
| 572 if (!GetVersionEx(&ver)) | 601 if (!GetVersionEx((OSVERSIONINFO*) &ver)) |
| 573 return PyErr_SetFromWindowsErr(0); | 602 return PyErr_SetFromWindowsErr(0); |
| 574 return Py_BuildValue("HHHHs", | 603 |
| 575 ver.dwMajorVersion, | 604 version = PyStructSequence_New(&WindowsVersionType); |
| 576 ver.dwMinorVersion, | 605 if (version == NULL) |
| 577 ver.dwBuildNumber, | 606 return NULL; |
| 578 ver.dwPlatformId, | 607 |
| 579 ver.szCSDVersion); | 608 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwMajorVersion)); |
| 609 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwMinorVersion)); | |
| 610 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwBuildNumber)); | |
| 611 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.dwPlatformId)); | |
| 612 PyStructSequence_SET_ITEM(version, pos++, PyString_FromString(ver.szCSDVersion)); | |
| 613 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wServicePackMajor)); | |
| 614 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wServicePackMinor)); | |
| 615 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wSuiteMask)); | |
| 616 PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wProductType)); | |
| 617 | |
| 618 return version; | |
| 580 } | 619 } |
| 581 | 620 |
| 582 #endif /* MS_WINDOWS */ | 621 #endif /* MS_WINDOWS */ |
| 583 | 622 |
| 584 #ifdef HAVE_DLOPEN | 623 #ifdef HAVE_DLOPEN |
| 1496 PyStructSequence_InitType(&FlagsType, &flags_desc); | 1535 PyStructSequence_InitType(&FlagsType, &flags_desc); |
| 1497 SET_SYS_FROM_STRING("flags", make_flags()); | 1536 SET_SYS_FROM_STRING("flags", make_flags()); |
| 1498 /* prevent user from creating new instances */ | 1537 /* prevent user from creating new instances */ |
| 1499 FlagsType.tp_init = NULL; | 1538 FlagsType.tp_init = NULL; |
| 1500 FlagsType.tp_new = NULL; | 1539 FlagsType.tp_new = NULL; |
| 1540 | |
| 1541 | |
| 1542 #if defined(MS_WINDOWS) | |
| 1543 /* getwindowsversion */ | |
| 1544 if (WindowsVersionType.tp_name == 0) | |
| 1545 PyStructSequence_InitType(&WindowsVersionType, &windows_version_desc); | |
| 1546 /* prevent user from creating new instances */ | |
| 1547 WindowsVersionType.tp_init = NULL; | |
| 1548 WindowsVersionType.tp_new = NULL; | |
| 1549 #endif | |
| 1501 | 1550 |
| 1502 /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */ | 1551 /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */ |
| 1503 #ifndef PY_NO_SHORT_FLOAT_REPR | 1552 #ifndef PY_NO_SHORT_FLOAT_REPR |
| 1504 SET_SYS_FROM_STRING("float_repr_style", | 1553 SET_SYS_FROM_STRING("float_repr_style", |
| 1505 PyString_FromString("short")); | 1554 PyString_FromString("short")); |
