[pywin32-checkins] pywin32/win32/src win32apimodule.cpp,1.94,1.95
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2009-01-25 03:18:06
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31572/win32/src Modified Files: win32apimodule.cpp Log Message: * Allow GetTimeZoneInformation to return the SYSTEMTIME elements as tuples. * Add SetTimeZoneInformation. * Modernize how we check for exception objects in the 'console control handler' to allow things to work with py3k Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** win32apimodule.cpp 11 Dec 2008 05:09:00 -0000 1.94 --- win32apimodule.cpp 25 Jan 2009 03:17:58 -0000 1.95 *************** *** 104,107 **** --- 104,134 ---- return PyWin_SetAPIError(fnName, err); } + + PyObject *PyTuple_FromSYSTEMTIME(SYSTEMTIME &st) + { + return Py_BuildValue("iiiiiiii", + st.wYear, + st.wMonth, + st.wDayOfWeek, + st.wDay, + st.wHour, + st.wMinute, + st.wSecond, + st.wMilliseconds); + } + + BOOL PyTuple_AsSYSTEMTIME(PyObject *ob, SYSTEMTIME &st) + { + return PyArg_ParseTuple(ob, "iiiiiiii", + &st.wYear, + &st.wMonth, + &st.wDayOfWeek, + &st.wDay, + &st.wHour, + &st.wMinute, + &st.wSecond, + &st.wMilliseconds); + } + // @pymethod |win32api|Beep|Generates simple tones on the speaker. static PyObject * *************** *** 2344,2348 **** PyGetTimeZoneInformation(PyObject * self, PyObject * args) { ! if (!PyArg_ParseTuple (args, ":GetTimeZoneInformation")) return NULL; TIME_ZONE_INFORMATION tzinfo; --- 2371,2377 ---- PyGetTimeZoneInformation(PyObject * self, PyObject * args) { ! int bTimesAsTuples = 0; ! // @pyparm bool|times_as_tuples|False|If true, the SYSTEMTIME elements are returned as tuples instead of a time object. ! if (!PyArg_ParseTuple (args, "|i:GetTimeZoneInformation", &bTimesAsTuples)) return NULL; TIME_ZONE_INFORMATION tzinfo; *************** *** 2369,2376 **** tzinfo.Bias, PyWinObject_FromWCHAR(tzinfo.StandardName), ! PyWinObject_FromSYSTEMTIME(tzinfo.StandardDate), tzinfo.StandardBias, PyWinObject_FromWCHAR(tzinfo.DaylightName), ! PyWinObject_FromSYSTEMTIME(tzinfo.DaylightDate), tzinfo.DaylightBias ); --- 2398,2409 ---- tzinfo.Bias, PyWinObject_FromWCHAR(tzinfo.StandardName), ! bTimesAsTuples ? ! PyTuple_FromSYSTEMTIME(tzinfo.StandardDate) : ! PyWinObject_FromSYSTEMTIME(tzinfo.StandardDate), tzinfo.StandardBias, PyWinObject_FromWCHAR(tzinfo.DaylightName), ! bTimesAsTuples ? ! PyTuple_FromSYSTEMTIME(tzinfo.DaylightDate) : ! PyWinObject_FromSYSTEMTIME(tzinfo.DaylightDate), tzinfo.DaylightBias ); *************** *** 2384,2392 **** // @tupleitem 0|int|bias|Specifies the current bias, in minutes, for local time translation on this computer. The bias is the difference, in minutes, between Coordinated Universal Time (UTC) and local time. All translations between UTC and local time are based on the following formula:<nl><nl>UTC = local time + bias <nl><nl> // @tupleitem 1|unicode|standardName|Specifies a string associated with standard time on this operating system. For example, this member could contain "EST" to indicate Eastern Standard Time. This string is not used by the operating system, so anything stored there using the SetTimeZoneInformation function is returned unchanged by the GetTimeZoneInformation function. This string can be empty. ! // @tupleitem 2|<o PyTime>|standardTime|Specifies a SYSTEMTIME object that contains a date and local time when the transition from daylight saving time to standard time occurs on this operating system. If this date is not specified, the wMonth member in the SYSTEMTIME structure must be zero. If this date is specified, the DaylightDate value in the TIME_ZONE_INFORMATION structure must also be specified. // <nl>To select the correct day in the month, set the wYear member to zero, the wDayOfWeek member to an appropriate weekday, and the wDay member to a value in the range 1 through 5. Using this notation, the first Sunday in April can be specified, as can the last Thursday in October (5 is equal to "the last"). // @tupleitem 3|int|standardBias|Specifies a bias value to be used during local time translations that occur during standard time. This member is ignored if a value for the StandardDate member is not supplied. <nl>This value is added to the value of the Bias member to form the bias used during standard time. In most time zones, the value of this member is zero. // @tupleitem 4|unicode|daylightName| ! // @tupleitem 5|<o PyTime>|daylightTime| // @tupleitem 6|int|daylightBias|Specifies a bias value to be used during local time translations that occur during daylight saving time. This member is ignored if a value for the DaylightDate member is not supplied. // <nl>This value is added to the value of the Bias member to form the bias used during daylight saving time. In most time zones, the value of this member is 60. --- 2417,2425 ---- // @tupleitem 0|int|bias|Specifies the current bias, in minutes, for local time translation on this computer. The bias is the difference, in minutes, between Coordinated Universal Time (UTC) and local time. All translations between UTC and local time are based on the following formula:<nl><nl>UTC = local time + bias <nl><nl> // @tupleitem 1|unicode|standardName|Specifies a string associated with standard time on this operating system. For example, this member could contain "EST" to indicate Eastern Standard Time. This string is not used by the operating system, so anything stored there using the SetTimeZoneInformation function is returned unchanged by the GetTimeZoneInformation function. This string can be empty. ! // @tupleitem 2|<o PyTime>/tuple|standardTime|Specifies a SYSTEMTIME object that contains a date and local time when the transition from daylight saving time to standard time occurs on this operating system. If this date is not specified, the wMonth member in the SYSTEMTIME structure must be zero. If this date is specified, the DaylightDate value in the TIME_ZONE_INFORMATION structure must also be specified. // <nl>To select the correct day in the month, set the wYear member to zero, the wDayOfWeek member to an appropriate weekday, and the wDay member to a value in the range 1 through 5. Using this notation, the first Sunday in April can be specified, as can the last Thursday in October (5 is equal to "the last"). // @tupleitem 3|int|standardBias|Specifies a bias value to be used during local time translations that occur during standard time. This member is ignored if a value for the StandardDate member is not supplied. <nl>This value is added to the value of the Bias member to form the bias used during standard time. In most time zones, the value of this member is zero. // @tupleitem 4|unicode|daylightName| ! // @tupleitem 5|<o PyTime>/tuple|daylightTime| // @tupleitem 6|int|daylightBias|Specifies a bias value to be used during local time translations that occur during daylight saving time. This member is ignored if a value for the DaylightDate member is not supplied. // <nl>This value is added to the value of the Bias member to form the bias used during daylight saving time. In most time zones, the value of this member is 60. *************** *** 2394,2397 **** --- 2427,2482 ---- } + // @pymethod tuple|win32api|SetTimeZoneInformation|Sets the system time-zone information. + static PyObject * + PySetTimeZoneInformation(PyObject * self, PyObject * args) + { + // @pyparm tuple|tzi||A tuple with the timezone info + // @desc The tuple is of form. + TIME_ZONE_INFORMATION tzi; + PyObject *obStdName, *obStdDate; + PyObject *obDaylightName, *obDaylightDate; + if (!PyArg_ParseTuple (args, "(iOOiOOi):SetTimeZoneInformation", + &tzi.Bias, // @tupleitem 0|int|Bias| + &obStdName, // @tupleitem 1|string|StandardName + &obStdDate, // @tupleitem 2|SYSTEMTIME tuple|StandardDate + &tzi.StandardBias, // @tupleitem 3|int|StandardBias + &obDaylightName, // @tupleitem 4|string|DaylightName + &obDaylightDate, // @tupleitem 5|SYSTEMTIME tuple|DaylightDate + &tzi.DaylightBias))// @tupleitem 6|int|DaylightBias + return NULL; + WCHAR *temp; + if (!PyWinObject_AsWCHAR(obStdName, &temp)) + return NULL; + if (wcslen(temp)>31) { + PyWinObject_FreeWCHAR(temp); + return PyErr_Format(PyExc_ValueError, "Time zone names must be < 32 chars long"); + } + wcscpy(tzi.StandardName, temp); + PyWinObject_FreeWCHAR(temp); + // second string... + if (!PyWinObject_AsWCHAR(obDaylightName, &temp)) + return NULL; + if (wcslen(temp)>31) { + PyWinObject_FreeWCHAR(temp); + return PyErr_Format(PyExc_ValueError, "Time zone names must be < 32 chars long"); + } + wcscpy(tzi.DaylightName, temp); + PyWinObject_FreeWCHAR(temp); + + // tuples with a SYSTEMTIME + if (!PyTuple_AsSYSTEMTIME(obStdDate, tzi.StandardDate)) + return NULL; + if (!PyTuple_AsSYSTEMTIME(obDaylightDate, tzi.DaylightDate)) + return NULL; + + BOOL rc; + PyW32_BEGIN_ALLOW_THREADS + rc = ::SetTimeZoneInformation(&tzi); + PyW32_END_ALLOW_THREADS + if(!rc) + return ReturnAPIError("SetTimeZoneInformation"); + Py_RETURN_NONE; + } + // @pymethod string|win32api|GetDateFormat|Formats a date as a date string for a specified locale. The function formats either a specified date or the local system date. static PyObject *PyGetDateFormat(PyObject *self, PyObject *args) *************** *** 5460,5464 **** ret = PyInt_AsLong(obRet); // Exception instance to be raised. ! } else if (PyInstance_Check(obRet)) { *ppExcType = obRet; Py_INCREF(obRet); --- 5545,5549 ---- ret = PyInt_AsLong(obRet); // Exception instance to be raised. ! } else if (PyObject_IsSubclass(obRet, PyExc_Exception)) { *ppExcType = obRet; Py_INCREF(obRet); *************** *** 5516,5520 **** if (stateCur == NULL) stateCur = stateSave; PyThreadState_Swap(stateCur); ! if (PyInstance_Check(exc_type)) { if (exc_value != NULL) PyErr_SetString(PyExc_TypeError, "instance exception returned from exception handler may not have a separate value"); --- 5601,5605 ---- if (stateCur == NULL) stateCur = stateSave; PyThreadState_Swap(stateCur); ! if (PyObject_IsSubclass(exc_type, PyExc_Exception)) { if (exc_value != NULL) PyErr_SetString(PyExc_TypeError, "instance exception returned from exception handler may not have a separate value"); *************** *** 5522,5526 **** // Normalize to class, instance exc_value = exc_type; ! exc_type = (PyObject*) ((PyInstanceObject*)exc_type)->in_class; Py_INCREF(exc_type); PyErr_SetObject(exc_type, exc_value); --- 5607,5611 ---- // Normalize to class, instance exc_value = exc_type; ! exc_type = (PyObject *)exc_value->ob_type; Py_INCREF(exc_type); PyErr_SetObject(exc_type, exc_value); *************** *** 6182,6185 **** --- 6267,6271 ---- {"SetSystemPowerState", PySetSystemPowerState, 1}, // @pymeth SetSystemPowerState|Powers machine down to a suspended state {"SetThreadLocale", PySetThreadLocale, 1}, // @pymeth SetThreadLocale|Sets the current thread's locale. + {"SetTimeZoneInformation",PySetTimeZoneInformation,1}, // @pymeth SetTimeZoneInformation|Sets the system time-zone information. {"SetWindowLong", PySetWindowLong,1}, // @pymeth SetWindowLong|Places a long value at the specified offset into the extra window memory of the given window. {"ShellExecute", PyShellExecute, 1}, // @pymeth ShellExecute|Executes an application. |