Update of /cvsroot/pywin32/pywin32/win32/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv1486/win32/src
Modified Files:
PyTime.cpp PyWinTypes.h PyWinTypesmodule.cpp odbc.cpp
win32evtlog.i
Log Message:
Rationalize pywin32 time api and use of it, including removal of support
for MS_WINCE, on the road to optionally using timezone-aware datetime
objects.
Index: odbc.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/odbc.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** odbc.cpp 8 Dec 2008 13:16:37 -0000 1.29
--- odbc.cpp 8 Jan 2009 02:56:17 -0000 1.30
***************
*** 885,889 ****
ZeroMemory(dt, len);
// Accept either a PyTime or datetime object
! if (PyTime_Check(item)){
SYSTEMTIME st;
if (!((PyTime *)item)->GetTime(&st))
--- 885,890 ----
ZeroMemory(dt, len);
// Accept either a PyTime or datetime object
! #ifndef NO_PYWINTYPES_TIME
! if (PyWinTime_CHECK(item)){
SYSTEMTIME st;
if (!((PyTime *)item)->GetTime(&st))
***************
*** 899,902 ****
--- 900,904 ----
}
else{
+ #endif // NO_PYWINTYPES_TIME
// Python 2.3 doesn't have C Api for datetime
TmpPyObject timeseq = PyObject_CallMethod(item, "timetuple", NULL);
***************
*** 929,934 ****
// Convert to nanoseconds
dt->fraction *= 1000;
- }
}
if (unsuccessful(SQLBindParameter(
--- 931,938 ----
// Convert to nanoseconds
dt->fraction *= 1000;
}
+ #ifndef NO_PYWINTYPES_TIME
+ }
+ #endif // NO_PYWINTYPES_TIME
if (unsuccessful(SQLBindParameter(
***************
*** 1162,1166 ****
rv = ibindFloat(cur, iCol, item);
}
! else if (PyTime_Check(item) || PyObject_HasAttrString(item, "timetuple"))
{
rv = ibindDate(cur, iCol, item);
--- 1166,1170 ----
rv = ibindFloat(cur, iCol, item);
}
! else if (PyWinTime_Check(item))
{
rv = ibindDate(cur, iCol, item);
Index: win32evtlog.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32evtlog.i,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** win32evtlog.i 11 Dec 2008 00:25:40 -0000 1.8
--- win32evtlog.i 8 Jan 2009 02:56:18 -0000 1.9
***************
*** 141,146 ****
}
! TimeGenerated = PyWinTimeObject_FromLong(pEvt->TimeGenerated);
! TimeWritten = PyWinTimeObject_FromLong(pEvt->TimeWritten);
if (pEvt->UserSidLength==0) {
--- 141,146 ----
}
! TimeGenerated = PyWinTimeObject_Fromtime_t((time_t)pEvt->TimeGenerated);
! TimeWritten = PyWinTimeObject_Fromtime_t((time_t)pEvt->TimeWritten);
if (pEvt->UserSidLength==0) {
Index: PyWinTypesmodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** PyWinTypesmodule.cpp 8 Dec 2008 13:16:37 -0000 1.47
--- PyWinTypesmodule.cpp 8 Jan 2009 02:56:17 -0000 1.48
***************
*** 23,26 ****
--- 23,29 ----
extern PyObject *PyWinMethod_NewHKEY(PyObject *self, PyObject *args);
+ extern BOOL _PyWinDateTime_Init();
+ extern BOOL _PyWinDateTime_PrepareModuleDict(PyObject *dict);
+
#ifdef MS_WINCE
// Where is this supposed to come from on CE???
***************
*** 760,766 ****
{"IID", PyWinMethod_NewIID, 1 }, // @pymeth IID|Makes an <o PyIID> object from a string.
#endif
! #ifndef NO_PYWINTYPES_TIME
! {"Time", PyWinMethod_NewTime, 1 }, // @pymeth Time|Makes a <o PyTime> object from the argument. Argument can be an integer/float or a tuple (as returned by time module functions).
! #endif
#ifndef MS_WINCE
{"CreateGuid", PyWin_CreateGuid, 1 }, // @pymeth CreateGuid|Creates a new, unique GUIID.
--- 763,767 ----
{"IID", PyWinMethod_NewIID, 1 }, // @pymeth IID|Makes an <o PyIID> object from a string.
#endif
! {"Time", PyWinMethod_NewTime, 1 }, // @pymeth Time|Makes a <o PyTime> object from the argument.
#ifndef MS_WINCE
{"CreateGuid", PyWin_CreateGuid, 1 }, // @pymeth CreateGuid|Creates a new, unique GUIID.
***************
*** 941,947 ****
PYWIN_MODULE_INIT_RETURN_ERROR;
! #ifndef NO_PYWINTYPES_TIME
! ADD_TYPE(TimeType);
! #endif // NO_PYWINTYPES_TIME
#ifndef NO_PYWINTYPES_IID
ADD_TYPE(IIDType);
--- 942,947 ----
PYWIN_MODULE_INIT_RETURN_ERROR;
! if (!_PyWinDateTime_PrepareModuleDict(dict))
! PYWIN_MODULE_INIT_RETURN_ERROR;
#ifndef NO_PYWINTYPES_IID
ADD_TYPE(IIDType);
Index: PyWinTypes.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** PyWinTypes.h 3 Jan 2009 06:43:58 -0000 1.59
--- PyWinTypes.h 8 Jan 2009 02:56:17 -0000 1.60
***************
*** 470,473 ****
--- 470,476 ----
** TIME support
*/
+ // The NO_PYWINTYPES_TIME define was initially used for CE builds. We now
+ // use that symbol to mean "do we include our old, crap, custom time object?"
+ // This is currently always true on the trunk - but not for long :)
PYWINTYPES_EXPORT PyObject *PyWinObject_FromSYSTEMTIME(const SYSTEMTIME &t);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromFILETIME(const FILETIME &t);
***************
*** 478,501 ****
// LARGE_INTEGER prototype to avoid pulling in the windows security headers.
PYWINTYPES_EXPORT PyObject *PyWinObject_FromTimeStamp(const LARGE_INTEGER &t);
PYWINTYPES_EXPORT BOOL PyWinObject_AsDATE(PyObject *ob, DATE *pDate);
! PYWINTYPES_EXPORT BOOL PyWinObject_AsFILETIME(PyObject *ob, FILETIME *pDate);
PYWINTYPES_EXPORT BOOL PyWinObject_AsSYSTEMTIME(PyObject *ob, SYSTEMTIME *pDate);
! #ifndef NO_PYWINTYPES_TIME
! extern PYWINTYPES_EXPORT PyTypeObject PyTimeType; // the Type for PyTime
! #define PyTime_Check(ob) ((ob)->ob_type == &PyTimeType)
- PYWINTYPES_EXPORT PyObject *PyWinObject_FromDATE(DATE t);
- PYWINTYPES_EXPORT PyObject *PyWinTimeObject_FromLong(long t);
! // A global function that can work as a module method for making a time object.
! PYWINTYPES_EXPORT PyObject *PyWinMethod_NewTime( PyObject *self, PyObject *args);
! #endif // NO_PYWINTYPES_TIME
! // Convert a time object to a time_t value.
! PYWINTYPES_EXPORT BOOL PyWinObject_Astime_t(PyObject *ob, time_t *t);
// functions to return WIN32_FIND_DATA tuples, used in shell, win32api, and win32file
--- 481,503 ----
// LARGE_INTEGER prototype to avoid pulling in the windows security headers.
PYWINTYPES_EXPORT PyObject *PyWinObject_FromTimeStamp(const LARGE_INTEGER &t);
+ PYWINTYPES_EXPORT PyObject *PyWinTimeObject_Fromtime_t(time_t t);
+ PYWINTYPES_EXPORT PyObject *PyWinObject_FromDATE(DATE t);
PYWINTYPES_EXPORT BOOL PyWinObject_AsDATE(PyObject *ob, DATE *pDate);
! PYWINTYPES_EXPORT BOOL PyWinObject_AsFILETIME(PyObject *ob, FILETIME *pDate);
PYWINTYPES_EXPORT BOOL PyWinObject_AsSYSTEMTIME(PyObject *ob, SYSTEMTIME *pDate);
! // A global function that can work as a module method for making a time object.
! PYWINTYPES_EXPORT PyObject *PyWinMethod_NewTime( PyObject *self, PyObject *args);
! PYWINTYPES_EXPORT BOOL PyWinTime_Check(PyObject *ob);
! #ifndef NO_PYWINTYPES_TIME
! extern PYWINTYPES_EXPORT PyTypeObject PyTimeType; // the Type for PyTime
! #define PyWinTime_CHECK(ob) ((ob)->ob_type == &PyTimeType)
! #endif // NO_PYWINTYPES_TIME
// functions to return WIN32_FIND_DATA tuples, used in shell, win32api, and win32file
Index: PyTime.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyTime.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** PyTime.cpp 11 Dec 2008 00:25:40 -0000 1.22
--- PyTime.cpp 8 Jan 2009 02:56:17 -0000 1.23
***************
*** 5,31 ****
#include "PyWinTypes.h"
#include "PyWinObjects.h"
- #ifndef MS_WINCE
#include "time.h"
- #endif
#include "tchar.h"
- #ifndef NO_PYWINTYPES_TIME
-
- #ifdef MS_WINCE
- #include <oleauto.h> // Time conversion functions on CE.
- // The Python helpers.
- BOOL PyCE_UnixTimeToFileTime(time_t t, LPFILETIME pft);
- BOOL PyCE_UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst);
- BOOL PyCE_FileTimeToUnixTime(FILETIME *pft, time_t *pt);
- BOOL PyCE_SystemTimeToUnixTime(SYSTEMTIME *pst, time_t *pt);
- void PyCE_TimeStructToSystemTime(struct tm *ptm, SYSTEMTIME *pst);
- #endif
-
- #if _MSC_VER < 1100
- // MSVC < 5.0 headers dont have these
- WINOLEAUTAPI_(INT) SystemTimeToVariantTime(LPSYSTEMTIME lpSystemTime, DOUBLE* pvtime);
- WINOLEAUTAPI_(INT) VariantTimeToSystemTime(DOUBLE vtime, LPSYSTEMTIME lpSystemTime);
- #endif
-
static WORD SequenceIndexAsWORD(PyObject *seq, int index)
{
--- 5,11 ----
***************
*** 36,41 ****
--- 16,36 ----
}
+ BOOL PyWinTime_Check(PyObject *ob)
+ {
+ return 0 ||
+ #ifndef NO_PYWINTYPES_TIME
+ PyWinTime_CHECK(ob) ||
+ #endif
+ PyObject_HasAttrString(ob, "timetuple");
+ }
+
PyObject *PyWin_NewTime(PyObject *timeOb)
{
+ // If it already a datetime object, just return it as-is.
+ if (PyWinTime_CHECK(timeOb)) {
+ Py_INCREF(timeOb);
+ return timeOb;
+ }
+
PyObject *result = NULL;
/***** Commented out temporarily
***************
*** 129,135 ****
return new PyTime(t);
}
! PyObject *PyWinTimeObject_FromLong(long t)
{
! return new PyTime((time_t)t);
}
--- 124,130 ----
return new PyTime(t);
}
! PyObject *PyWinTimeObject_Fromtime_t(time_t t)
{
! return new PyTime(t);
}
***************
*** 148,152 ****
PyObject *newref = NULL;
BOOL rc;
! if (!PyTime_Check(ob)) {
if (!(ob = PyWin_NewTime(ob)))
return FALSE;
--- 143,147 ----
PyObject *newref = NULL;
BOOL rc;
! if (!PyWinTime_Check(ob)) {
if (!(ob = PyWin_NewTime(ob)))
return FALSE;
***************
*** 162,166 ****
PyObject *newref = NULL;
BOOL rc;
! if (!PyTime_Check(ob)) {
if (!(ob = PyWin_NewTime(ob)))
return FALSE;
--- 157,161 ----
PyObject *newref = NULL;
BOOL rc;
! if (!PyWinTime_Check(ob)) {
if (!(ob = PyWin_NewTime(ob)))
return FALSE;
***************
*** 175,179 ****
PyObject *newref = NULL;
BOOL rc;
! if (!PyTime_Check(ob)) {
if (!(ob = PyWin_NewTime(ob)))
return FALSE;
--- 170,174 ----
PyObject *newref = NULL;
BOOL rc;
! if (!PyWinTime_Check(ob)) {
if (!(ob = PyWin_NewTime(ob)))
return FALSE;
***************
*** 323,331 ****
// @xref <om pywintypes.Time>
- #endif /* MS_WINCE */
struct PyMethodDef PyTime::methods[] = {
- #ifndef MS_WINCE
{"Format", PyTime::Format, 1}, // @pymeth Format|Formats the time value
- #endif
{NULL}
};
--- 318,323 ----
***************
*** 424,441 ****
ob_type = &PyTimeType;
_Py_NewReference(this);
-
- #ifdef MS_WINCE
- /* WinCE makes life harder than it should be! */
- FILETIME ftLocal, ftUTC;
- PyCE_UnixTimeToFileTime( (time_t)t, &ftUTC);
- FileTimeToLocalFileTime(&ftUTC, &ftLocal);
-
- time_t temp_t;
-
- PyCE_FileTimeToUnixTime(&ftLocal, &temp_t);
- m_time = (double)temp_t;
-
- #else
- /* "Normal" Win32 handling */
m_time = 0;
struct tm *ptm = localtime(&t);
--- 416,419 ----
***************
*** 454,458 ****
(void)SystemTimeToVariantTime(&st, &m_time);
}
- #endif /* MS_WINCE */
}
--- 432,435 ----
***************
*** 530,534 ****
PyObject *PyTime::richcompare(PyObject *other, int op)
{
! if (!PyTime_Check(other)){
PyErr_SetString(PyExc_TypeError, "PyTime cannot be compared to other types");
return NULL;
--- 507,511 ----
PyObject *PyTime::richcompare(PyObject *other, int op)
{
! if (!PyWinTime_Check(other)){
PyErr_SetString(PyExc_TypeError, "PyTime cannot be compared to other types");
return NULL;
***************
*** 588,603 ****
tm.tm_year = st.wYear - 1900;
tm.tm_isdst = -1; /* have the library figure it out */
-
- #ifdef MS_WINCE
- /* Windows CE hacks! */
- FILETIME ft;
- long t;
- PyCE_TimeStructToSystemTime(&tm, &st);
- SystemTimeToFileTime(&st, &ft);
- PyCE_FileTimeToUnixTime(&ft, &t);
-
- return t;
- #else
- /* Normal win32 code */
long result = (long)mktime(&tm);
if ( result == -1 )
--- 565,568 ----
***************
*** 607,611 ****
}
return result;
- #endif
}
--- 572,575 ----
***************
*** 782,878 ****
}
! #else // NO_PYWINTYPES_TIME
! // We dont have a decent time implementation, but
! // we need _some_ implementation of these functions!
!
! double PyCE_SystemTimeToCTime(SYSTEMTIME* pstTime)
! {
! SYSTEMTIME stBase;
! FILETIME ftTime;
! FILETIME ftBase;
! __int64 iTime;
! __int64 iBase;
!
! SystemTimeToFileTime(pstTime, &ftTime);
!
! stBase.wYear = 1970;
! stBase.wMonth = 1;
! stBase.wDayOfWeek = 1;
! stBase.wDay = 1;
! stBase.wHour = 0;
! stBase.wMinute = 0;
! stBase.wSecond = 0;
! stBase.wMilliseconds = 0;
! SystemTimeToFileTime(&stBase, &ftBase);
!
! iTime=ftTime.dwHighDateTime;
! iTime=iTime << 32;
! iTime |= ftTime.dwLowDateTime;
!
! iBase=ftBase.dwHighDateTime;
! iBase=iBase << 32;
! iBase |= ftBase.dwLowDateTime;
!
! return (double)((iTime - iBase) / 10000000L);
! }
!
! BOOL PyCE_UnixTimeToFileTime(time_t t, LPFILETIME pft)
! {
! // Note that LONGLONG is a 64-bit value
! LONGLONG ll;
! ll = ((__int64)t * 10000000) + 116444736000000000;
! // ll = Int32x32To64(t, 10000000) + 116444736000000000;
! pft->dwLowDateTime = (DWORD)ll;
! pft->dwHighDateTime = (DWORD)(ll >> 32);
! return TRUE;
! }
!
! // We expose some time functions, but just return
! // standard Python floats. We need a better solution!
!
! PYWINTYPES_EXPORT PyObject *PyWinObject_FromSYSTEMTIME(const SYSTEMTIME &st)
! {
! return PyFloat_FromDouble(PyCE_SystemTimeToCTime((SYSTEMTIME *)&st));
! }
! PYWINTYPES_EXPORT PyObject *PyWinObject_FromFILETIME(const FILETIME &t)
! {
! SYSTEMTIME st;
! if (!FileTimeToSystemTime(&t, &st))
! return PyInt_FromLong(-1);
! return PyFloat_FromDouble(PyCE_SystemTimeToCTime(&st));
! }
! //PYWINTYPES_EXPORT BOOL PyWinObject_AsDATE(PyObject *ob, DATE *pDate)
! //{
! //}
! PYWINTYPES_EXPORT BOOL PyWinObject_AsFILETIME(PyObject *ob, FILETIME *ft)
! {
! PyObject *intOb = PyNumber_Int(ob);
! if (intOb==NULL) return FALSE;
! time_t t = (time_t)PyInt_AsLong(intOb);
! BOOL rc = PyCE_UnixTimeToFileTime(t, ft);
! Py_DECREF(intOb);
! return rc;
! }
! PYWINTYPES_EXPORT BOOL PyWinObject_AsSYSTEMTIME(PyObject *ob, SYSTEMTIME *st)
{
- FILETIME ft;
- if (!PyWinObject_AsFILETIME(ob, &ft))
- return FALSE;
- if (!FileTimeToSystemTime(&ft, st)) {
- PyErr_SetString(PyExc_TypeError, "The value is out of range for a SYSTEMTIME");
- return FALSE;
- }
return TRUE;
}
! #endif // NO_PYWINTYPES_TIME
!
! PYWINTYPES_EXPORT BOOL PyWinObject_Astime_t(PyObject *ob, time_t *t)
{
! // We need to get smarter about 64bit time_t values...
! *t = (time_t)PyInt_AsLong(ob);
! if (*t == -1 && PyErr_Occurred())
return FALSE;
return TRUE;
}
--- 746,764 ----
}
! #endif // NO_PYWINTYPES_TIME
! // A couple of public functions used by the module init
! BOOL _PyWinDateTime_Init()
{
return TRUE;
}
! BOOL _PyWinDateTime_PrepareModuleDict(PyObject *dict)
{
! #ifndef NO_PYWINTYPES_TIME
! if (PyType_Ready(&PyTimeType)==-1
! || PyDict_SetItemString(dict, "TimeType", (PyObject *)&PyTimeType) == -1)
return FALSE;
+ #endif
return TRUE;
}
|