]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.10/Modules/timemodule.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Modules / timemodule.c
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Modules/timemodule.c b/AppPkg/Applications/Python/Python-2.7.10/Modules/timemodule.c
deleted file mode 100644 (file)
index a4e64c2..0000000
+++ /dev/null
@@ -1,1064 +0,0 @@
-\r
-/* Time module */\r
-\r
-#include "Python.h"\r
-#include "structseq.h"\r
-#include "timefuncs.h"\r
-\r
-#ifdef __APPLE__\r
-#if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)\r
-  /*\r
-   * floattime falls back to ftime when getttimeofday fails because the latter\r
-   * might fail on some platforms. This fallback is unwanted on MacOSX because\r
-   * that makes it impossible to use a binary build on OSX 10.4 on earlier\r
-   * releases of the OS. Therefore claim we don't support ftime.\r
-   */\r
-# undef HAVE_FTIME\r
-#endif\r
-#endif\r
-\r
-#include <ctype.h>\r
-\r
-#ifdef HAVE_SYS_TYPES_H\r
-#include <sys/types.h>\r
-#endif /* HAVE_SYS_TYPES_H */\r
-\r
-#ifdef QUICKWIN\r
-#include <io.h>\r
-#endif\r
-\r
-#ifdef HAVE_FTIME\r
-#include <sys/timeb.h>\r
-#if !defined(MS_WINDOWS) && !defined(PYOS_OS2)\r
-extern int ftime(struct timeb *);\r
-#endif /* MS_WINDOWS */\r
-#endif /* HAVE_FTIME */\r
-\r
-#if defined(__WATCOMC__) && !defined(__QNX__)\r
-#include <i86.h>\r
-#else\r
-#ifdef MS_WINDOWS\r
-#define WIN32_LEAN_AND_MEAN\r
-#include <windows.h>\r
-#include "pythread.h"\r
-\r
-/* helper to allow us to interrupt sleep() on Windows*/\r
-static HANDLE hInterruptEvent = NULL;\r
-static BOOL WINAPI PyCtrlHandler(DWORD dwCtrlType)\r
-{\r
-    SetEvent(hInterruptEvent);\r
-    /* allow other default handlers to be called.\r
-       Default Python handler will setup the\r
-       KeyboardInterrupt exception.\r
-    */\r
-    return FALSE;\r
-}\r
-static long main_thread;\r
-\r
-\r
-#if defined(__BORLANDC__)\r
-/* These overrides not needed for Win32 */\r
-#define timezone _timezone\r
-#define tzname _tzname\r
-#define daylight _daylight\r
-#endif /* __BORLANDC__ */\r
-#endif /* MS_WINDOWS */\r
-#endif /* !__WATCOMC__ || __QNX__ */\r
-\r
-#if defined(MS_WINDOWS) && !defined(__BORLANDC__)\r
-/* Win32 has better clock replacement; we have our own version below. */\r
-#undef HAVE_CLOCK\r
-#endif /* MS_WINDOWS && !defined(__BORLANDC__) */\r
-\r
-#if defined(PYOS_OS2)\r
-#define INCL_DOS\r
-#define INCL_ERRORS\r
-#include <os2.h>\r
-#endif\r
-\r
-#if defined(PYCC_VACPP)\r
-#include <sys/time.h>\r
-#endif\r
-\r
-#ifdef __BEOS__\r
-#include <time.h>\r
-/* For bigtime_t, snooze(). - [cjh] */\r
-#include <support/SupportDefs.h>\r
-#include <kernel/OS.h>\r
-#endif\r
-\r
-#ifdef RISCOS\r
-extern int riscos_sleep(double);\r
-#endif\r
-\r
-/* Forward declarations */\r
-static int floatsleep(double);\r
-static double floattime(void);\r
-\r
-/* For Y2K check */\r
-static PyObject *moddict = NULL;\r
-\r
-/* Exposed in timefuncs.h. */\r
-time_t\r
-_PyTime_DoubleToTimet(double x)\r
-{\r
-    time_t result;\r
-    double diff;\r
-\r
-    result = (time_t)x;\r
-    /* How much info did we lose?  time_t may be an integral or\r
-     * floating type, and we don't know which.  If it's integral,\r
-     * we don't know whether C truncates, rounds, returns the floor,\r
-     * etc.  If we lost a second or more, the C rounding is\r
-     * unreasonable, or the input just doesn't fit in a time_t;\r
-     * call it an error regardless.  Note that the original cast to\r
-     * time_t can cause a C error too, but nothing we can do to\r
-     * worm around that.\r
-     */\r
-    diff = x - (double)result;\r
-    if (diff <= -1.0 || diff >= 1.0) {\r
-        PyErr_SetString(PyExc_ValueError,\r
-                        "timestamp out of range for platform time_t");\r
-        result = (time_t)-1;\r
-    }\r
-    return result;\r
-}\r
-\r
-static PyObject *\r
-time_time(PyObject *self, PyObject *unused)\r
-{\r
-    double secs;\r
-    secs = floattime();\r
-    if (secs == 0.0) {\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return NULL;\r
-    }\r
-    return PyFloat_FromDouble(secs);\r
-}\r
-\r
-PyDoc_STRVAR(time_doc,\r
-"time() -> floating point number\n\\r
-\n\\r
-Return the current time in seconds since the Epoch.\n\\r
-Fractions of a second may be present if the system clock provides them.");\r
-\r
-#ifdef HAVE_CLOCK\r
-\r
-#ifndef CLOCKS_PER_SEC\r
-#ifdef CLK_TCK\r
-#define CLOCKS_PER_SEC CLK_TCK\r
-#else\r
-#define CLOCKS_PER_SEC 1000000\r
-#endif\r
-#endif\r
-\r
-static PyObject *\r
-time_clock(PyObject *self, PyObject *unused)\r
-{\r
-    return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC);\r
-}\r
-#endif /* HAVE_CLOCK */\r
-\r
-#if defined(MS_WINDOWS) && !defined(__BORLANDC__)\r
-/* Due to Mark Hammond and Tim Peters */\r
-static PyObject *\r
-time_clock(PyObject *self, PyObject *unused)\r
-{\r
-    static LARGE_INTEGER ctrStart;\r
-    static double divisor = 0.0;\r
-    LARGE_INTEGER now;\r
-    double diff;\r
-\r
-    if (divisor == 0.0) {\r
-        LARGE_INTEGER freq;\r
-        QueryPerformanceCounter(&ctrStart);\r
-        if (!QueryPerformanceFrequency(&freq) || freq.QuadPart == 0) {\r
-            /* Unlikely to happen - this works on all intel\r
-               machines at least!  Revert to clock() */\r
-            return PyFloat_FromDouble(((double)clock()) /\r
-                                      CLOCKS_PER_SEC);\r
-        }\r
-        divisor = (double)freq.QuadPart;\r
-    }\r
-    QueryPerformanceCounter(&now);\r
-    diff = (double)(now.QuadPart - ctrStart.QuadPart);\r
-    return PyFloat_FromDouble(diff / divisor);\r
-}\r
-\r
-#define HAVE_CLOCK /* So it gets included in the methods */\r
-#endif /* MS_WINDOWS && !defined(__BORLANDC__) */\r
-\r
-#ifdef HAVE_CLOCK\r
-PyDoc_STRVAR(clock_doc,\r
-"clock() -> floating point number\n\\r
-\n\\r
-Return the CPU time or real time since the start of the process or since\n\\r
-the first call to clock().  This has as much precision as the system\n\\r
-records.");\r
-#endif\r
-\r
-static PyObject *\r
-time_sleep(PyObject *self, PyObject *args)\r
-{\r
-    double secs;\r
-    if (!PyArg_ParseTuple(args, "d:sleep", &secs))\r
-        return NULL;\r
-    if (floatsleep(secs) != 0)\r
-        return NULL;\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(sleep_doc,\r
-"sleep(seconds)\n\\r
-\n\\r
-Delay execution for a given number of seconds.  The argument may be\n\\r
-a floating point number for subsecond precision.");\r
-\r
-static PyStructSequence_Field struct_time_type_fields[] = {\r
-    {"tm_year", "year, for example, 1993"},\r
-    {"tm_mon", "month of year, range [1, 12]"},\r
-    {"tm_mday", "day of month, range [1, 31]"},\r
-    {"tm_hour", "hours, range [0, 23]"},\r
-    {"tm_min", "minutes, range [0, 59]"},\r
-    {"tm_sec", "seconds, range [0, 61])"},\r
-    {"tm_wday", "day of week, range [0, 6], Monday is 0"},\r
-    {"tm_yday", "day of year, range [1, 366]"},\r
-    {"tm_isdst", "1 if summer time is in effect, 0 if not, and -1 if unknown"},\r
-    {0}\r
-};\r
-\r
-static PyStructSequence_Desc struct_time_type_desc = {\r
-    "time.struct_time",\r
-    "The time value as returned by gmtime(), localtime(), and strptime(), and\n"\r
-    " accepted by asctime(), mktime() and strftime().  May be considered as a\n"\r
-    " sequence of 9 integers.\n\n"\r
-    " Note that several fields' values are not the same as those defined by\n"\r
-    " the C language standard for struct tm.  For example, the value of the\n"\r
-    " field tm_year is the actual year, not year - 1900.  See individual\n"\r
-    " fields' descriptions for details.",\r
-    struct_time_type_fields,\r
-    9,\r
-};\r
-\r
-static int initialized;\r
-static PyTypeObject StructTimeType;\r
-\r
-static PyObject *\r
-tmtotuple(struct tm *p)\r
-{\r
-    PyObject *v = PyStructSequence_New(&StructTimeType);\r
-    if (v == NULL)\r
-        return NULL;\r
-\r
-#define SET(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))\r
-\r
-    SET(0, p->tm_year + 1900);\r
-    SET(1, p->tm_mon + 1);         /* Want January == 1 */\r
-    SET(2, p->tm_mday);\r
-    SET(3, p->tm_hour);\r
-    SET(4, p->tm_min);\r
-    SET(5, p->tm_sec);\r
-    SET(6, (p->tm_wday + 6) % 7); /* Want Monday == 0 */\r
-    SET(7, p->tm_yday + 1);        /* Want January, 1 == 1 */\r
-    SET(8, p->tm_isdst);\r
-#undef SET\r
-    if (PyErr_Occurred()) {\r
-        Py_XDECREF(v);\r
-        return NULL;\r
-    }\r
-\r
-    return v;\r
-}\r
-\r
-static PyObject *\r
-time_convert(double when, struct tm * (*function)(const time_t *))\r
-{\r
-    struct tm *p;\r
-    time_t whent = _PyTime_DoubleToTimet(when);\r
-\r
-    if (whent == (time_t)-1 && PyErr_Occurred())\r
-        return NULL;\r
-    errno = 0;\r
-    p = function(&whent);\r
-    if (p == NULL) {\r
-#ifdef EINVAL\r
-        if (errno == 0)\r
-            errno = EINVAL;\r
-#endif\r
-        return PyErr_SetFromErrno(PyExc_ValueError);\r
-    }\r
-    return tmtotuple(p);\r
-}\r
-\r
-/* Parse arg tuple that can contain an optional float-or-None value;\r
-   format needs to be "|O:name".\r
-   Returns non-zero on success (parallels PyArg_ParseTuple).\r
-*/\r
-static int\r
-parse_time_double_args(PyObject *args, char *format, double *pwhen)\r
-{\r
-    PyObject *ot = NULL;\r
-\r
-    if (!PyArg_ParseTuple(args, format, &ot))\r
-        return 0;\r
-    if (ot == NULL || ot == Py_None)\r
-        *pwhen = floattime();\r
-    else {\r
-        double when = PyFloat_AsDouble(ot);\r
-        if (PyErr_Occurred())\r
-            return 0;\r
-        *pwhen = when;\r
-    }\r
-    return 1;\r
-}\r
-\r
-static PyObject *\r
-time_gmtime(PyObject *self, PyObject *args)\r
-{\r
-    double when;\r
-    if (!parse_time_double_args(args, "|O:gmtime", &when))\r
-        return NULL;\r
-    return time_convert(when, gmtime);\r
-}\r
-\r
-PyDoc_STRVAR(gmtime_doc,\r
-"gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,\n\\r
-                       tm_sec, tm_wday, tm_yday, tm_isdst)\n\\r
-\n\\r
-Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.\n\\r
-GMT).  When 'seconds' is not passed in, convert the current time instead.");\r
-\r
-static PyObject *\r
-time_localtime(PyObject *self, PyObject *args)\r
-{\r
-    double when;\r
-    if (!parse_time_double_args(args, "|O:localtime", &when))\r
-        return NULL;\r
-    return time_convert(when, localtime);\r
-}\r
-\r
-PyDoc_STRVAR(localtime_doc,\r
-"localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,\n\\r
-                          tm_sec,tm_wday,tm_yday,tm_isdst)\n\\r
-\n\\r
-Convert seconds since the Epoch to a time tuple expressing local time.\n\\r
-When 'seconds' is not passed in, convert the current time instead.");\r
-\r
-static int\r
-gettmarg(PyObject *args, struct tm *p)\r
-{\r
-    int y;\r
-    memset((void *) p, '\0', sizeof(struct tm));\r
-\r
-    if (!PyArg_Parse(args, "(iiiiiiiii)",\r
-                     &y,\r
-                     &p->tm_mon,\r
-                     &p->tm_mday,\r
-                     &p->tm_hour,\r
-                     &p->tm_min,\r
-                     &p->tm_sec,\r
-                     &p->tm_wday,\r
-                     &p->tm_yday,\r
-                     &p->tm_isdst))\r
-        return 0;\r
-    if (y < 1900) {\r
-        PyObject *accept = PyDict_GetItemString(moddict,\r
-                                                "accept2dyear");\r
-        if (accept == NULL || !PyInt_Check(accept) ||\r
-            PyInt_AsLong(accept) == 0) {\r
-            PyErr_SetString(PyExc_ValueError,\r
-                            "year >= 1900 required");\r
-            return 0;\r
-        }\r
-        if (69 <= y && y <= 99)\r
-            y += 1900;\r
-        else if (0 <= y && y <= 68)\r
-            y += 2000;\r
-        else {\r
-            PyErr_SetString(PyExc_ValueError,\r
-                            "year out of range");\r
-            return 0;\r
-        }\r
-    }\r
-    p->tm_year = y - 1900;\r
-    p->tm_mon--;\r
-    p->tm_wday = (p->tm_wday + 1) % 7;\r
-    p->tm_yday--;\r
-    return 1;\r
-}\r
-\r
-#ifdef HAVE_STRFTIME\r
-static PyObject *\r
-time_strftime(PyObject *self, PyObject *args)\r
-{\r
-    PyObject *tup = NULL;\r
-    struct tm buf;\r
-    const char *fmt;\r
-    size_t fmtlen, buflen;\r
-    char *outbuf = 0;\r
-    size_t i;\r
-\r
-    memset((void *) &buf, '\0', sizeof(buf));\r
-\r
-    if (!PyArg_ParseTuple(args, "s|O:strftime", &fmt, &tup))\r
-        return NULL;\r
-\r
-    if (tup == NULL) {\r
-        time_t tt = time(NULL);\r
-        buf = *localtime(&tt);\r
-    } else if (!gettmarg(tup, &buf))\r
-        return NULL;\r
-\r
-    /* Checks added to make sure strftime() does not crash Python by\r
-       indexing blindly into some array for a textual representation\r
-       by some bad index (fixes bug #897625).\r
-\r
-        Also support values of zero from Python code for arguments in which\r
-        that is out of range by forcing that value to the lowest value that\r
-        is valid (fixed bug #1520914).\r
-\r
-        Valid ranges based on what is allowed in struct tm:\r
-\r
-        - tm_year: [0, max(int)] (1)\r
-        - tm_mon: [0, 11] (2)\r
-        - tm_mday: [1, 31]\r
-        - tm_hour: [0, 23]\r
-        - tm_min: [0, 59]\r
-        - tm_sec: [0, 60]\r
-        - tm_wday: [0, 6] (1)\r
-        - tm_yday: [0, 365] (2)\r
-        - tm_isdst: [-max(int), max(int)]\r
-\r
-        (1) gettmarg() handles bounds-checking.\r
-        (2) Python's acceptable range is one greater than the range in C,\r
-        thus need to check against automatic decrement by gettmarg().\r
-    */\r
-    if (buf.tm_mon == -1)\r
-        buf.tm_mon = 0;\r
-    else if (buf.tm_mon < 0 || buf.tm_mon > 11) {\r
-        PyErr_SetString(PyExc_ValueError, "month out of range");\r
-            return NULL;\r
-    }\r
-    if (buf.tm_mday == 0)\r
-        buf.tm_mday = 1;\r
-    else if (buf.tm_mday < 0 || buf.tm_mday > 31) {\r
-        PyErr_SetString(PyExc_ValueError, "day of month out of range");\r
-            return NULL;\r
-    }\r
-    if (buf.tm_hour < 0 || buf.tm_hour > 23) {\r
-        PyErr_SetString(PyExc_ValueError, "hour out of range");\r
-        return NULL;\r
-    }\r
-    if (buf.tm_min < 0 || buf.tm_min > 59) {\r
-        PyErr_SetString(PyExc_ValueError, "minute out of range");\r
-        return NULL;\r
-    }\r
-    if (buf.tm_sec < 0 || buf.tm_sec > 61) {\r
-        PyErr_SetString(PyExc_ValueError, "seconds out of range");\r
-        return NULL;\r
-    }\r
-    /* tm_wday does not need checking of its upper-bound since taking\r
-    ``% 7`` in gettmarg() automatically restricts the range. */\r
-    if (buf.tm_wday < 0) {\r
-        PyErr_SetString(PyExc_ValueError, "day of week out of range");\r
-        return NULL;\r
-    }\r
-    if (buf.tm_yday == -1)\r
-        buf.tm_yday = 0;\r
-    else if (buf.tm_yday < 0 || buf.tm_yday > 365) {\r
-        PyErr_SetString(PyExc_ValueError, "day of year out of range");\r
-        return NULL;\r
-    }\r
-    /* Normalize tm_isdst just in case someone foolishly implements %Z\r
-       based on the assumption that tm_isdst falls within the range of\r
-       [-1, 1] */\r
-    if (buf.tm_isdst < -1)\r
-        buf.tm_isdst = -1;\r
-    else if (buf.tm_isdst > 1)\r
-        buf.tm_isdst = 1;\r
-\r
-#ifdef MS_WINDOWS\r
-    /* check that the format string contains only valid directives */\r
-    for(outbuf = strchr(fmt, '%');\r
-        outbuf != NULL;\r
-        outbuf = strchr(outbuf+2, '%'))\r
-    {\r
-        if (outbuf[1]=='#')\r
-            ++outbuf; /* not documented by python, */\r
-        if (outbuf[1]=='\0' ||\r
-            !strchr("aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))\r
-        {\r
-            PyErr_SetString(PyExc_ValueError, "Invalid format string");\r
-            return 0;\r
-        }\r
-    }\r
-#endif\r
-\r
-    fmtlen = strlen(fmt);\r
-\r
-    /* I hate these functions that presume you know how big the output\r
-     * will be ahead of time...\r
-     */\r
-    for (i = 1024; ; i += i) {\r
-        outbuf = (char *)malloc(i);\r
-        if (outbuf == NULL) {\r
-            return PyErr_NoMemory();\r
-        }\r
-        buflen = strftime(outbuf, i, fmt, &buf);\r
-        if (buflen > 0 || i >= 256 * fmtlen) {\r
-            /* If the buffer is 256 times as long as the format,\r
-               it's probably not failing for lack of room!\r
-               More likely, the format yields an empty result,\r
-               e.g. an empty format, or %Z when the timezone\r
-               is unknown. */\r
-            PyObject *ret;\r
-            ret = PyString_FromStringAndSize(outbuf, buflen);\r
-            free(outbuf);\r
-            return ret;\r
-        }\r
-        free(outbuf);\r
-#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)\r
-        /* VisualStudio .NET 2005 does this properly */\r
-        if (buflen == 0 && errno == EINVAL) {\r
-            PyErr_SetString(PyExc_ValueError, "Invalid format string");\r
-            return 0;\r
-        }\r
-#endif\r
-\r
-    }\r
-}\r
-\r
-PyDoc_STRVAR(strftime_doc,\r
-"strftime(format[, tuple]) -> string\n\\r
-\n\\r
-Convert a time tuple to a string according to a format specification.\n\\r
-See the library reference manual for formatting codes. When the time tuple\n\\r
-is not present, current time as returned by localtime() is used.");\r
-#endif /* HAVE_STRFTIME */\r
-\r
-static PyObject *\r
-time_strptime(PyObject *self, PyObject *args)\r
-{\r
-    PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime");\r
-    PyObject *strptime_result;\r
-\r
-    if (!strptime_module)\r
-        return NULL;\r
-    strptime_result = PyObject_CallMethod(strptime_module,\r
-                                            "_strptime_time", "O", args);\r
-    Py_DECREF(strptime_module);\r
-    return strptime_result;\r
-}\r
-\r
-PyDoc_STRVAR(strptime_doc,\r
-"strptime(string, format) -> struct_time\n\\r
-\n\\r
-Parse a string to a time tuple according to a format specification.\n\\r
-See the library reference manual for formatting codes (same as strftime()).");\r
-\r
-\r
-static PyObject *\r
-time_asctime(PyObject *self, PyObject *args)\r
-{\r
-    PyObject *tup = NULL;\r
-    struct tm buf;\r
-    char *p;\r
-    if (!PyArg_UnpackTuple(args, "asctime", 0, 1, &tup))\r
-        return NULL;\r
-    if (tup == NULL) {\r
-        time_t tt = time(NULL);\r
-        buf = *localtime(&tt);\r
-    } else if (!gettmarg(tup, &buf))\r
-        return NULL;\r
-    p = asctime(&buf);\r
-    if (p == NULL) {\r
-        PyErr_SetString(PyExc_ValueError, "invalid time");\r
-        return NULL;\r
-    }\r
-    if (p[24] == '\n')\r
-        p[24] = '\0';\r
-    return PyString_FromString(p);\r
-}\r
-\r
-PyDoc_STRVAR(asctime_doc,\r
-"asctime([tuple]) -> string\n\\r
-\n\\r
-Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.\n\\r
-When the time tuple is not present, current time as returned by localtime()\n\\r
-is used.");\r
-\r
-static PyObject *\r
-time_ctime(PyObject *self, PyObject *args)\r
-{\r
-    PyObject *ot = NULL;\r
-    time_t tt;\r
-    char *p;\r
-\r
-    if (!PyArg_UnpackTuple(args, "ctime", 0, 1, &ot))\r
-        return NULL;\r
-    if (ot == NULL || ot == Py_None)\r
-        tt = time(NULL);\r
-    else {\r
-        double dt = PyFloat_AsDouble(ot);\r
-        if (PyErr_Occurred())\r
-            return NULL;\r
-        tt = _PyTime_DoubleToTimet(dt);\r
-        if (tt == (time_t)-1 && PyErr_Occurred())\r
-            return NULL;\r
-    }\r
-    p = ctime(&tt);\r
-    if (p == NULL) {\r
-        PyErr_SetString(PyExc_ValueError, "unconvertible time");\r
-        return NULL;\r
-    }\r
-    if (p[24] == '\n')\r
-        p[24] = '\0';\r
-    return PyString_FromString(p);\r
-}\r
-\r
-PyDoc_STRVAR(ctime_doc,\r
-"ctime(seconds) -> string\n\\r
-\n\\r
-Convert a time in seconds since the Epoch to a string in local time.\n\\r
-This is equivalent to asctime(localtime(seconds)). When the time tuple is\n\\r
-not present, current time as returned by localtime() is used.");\r
-\r
-#ifdef HAVE_MKTIME\r
-static PyObject *\r
-time_mktime(PyObject *self, PyObject *tup)\r
-{\r
-    struct tm buf;\r
-    time_t tt;\r
-    if (!gettmarg(tup, &buf))\r
-        return NULL;\r
-    buf.tm_wday = -1;  /* sentinel; original value ignored */\r
-    tt = mktime(&buf);\r
-    /* Return value of -1 does not necessarily mean an error, but tm_wday\r
-     * cannot remain set to -1 if mktime succeeded. */\r
-    if (tt == (time_t)(-1) && buf.tm_wday == -1) {\r
-        PyErr_SetString(PyExc_OverflowError,\r
-                        "mktime argument out of range");\r
-        return NULL;\r
-    }\r
-    return PyFloat_FromDouble((double)tt);\r
-}\r
-\r
-PyDoc_STRVAR(mktime_doc,\r
-"mktime(tuple) -> floating point number\n\\r
-\n\\r
-Convert a time tuple in local time to seconds since the Epoch.");\r
-#endif /* HAVE_MKTIME */\r
-\r
-#ifdef HAVE_WORKING_TZSET\r
-static void inittimezone(PyObject *module);\r
-\r
-static PyObject *\r
-time_tzset(PyObject *self, PyObject *unused)\r
-{\r
-    PyObject* m;\r
-\r
-    m = PyImport_ImportModuleNoBlock("time");\r
-    if (m == NULL) {\r
-        return NULL;\r
-    }\r
-\r
-    tzset();\r
-\r
-    /* Reset timezone, altzone, daylight and tzname */\r
-    inittimezone(m);\r
-    Py_DECREF(m);\r
-\r
-    Py_INCREF(Py_None);\r
-    return Py_None;\r
-}\r
-\r
-PyDoc_STRVAR(tzset_doc,\r
-"tzset()\n\\r
-\n\\r
-Initialize, or reinitialize, the local timezone to the value stored in\n\\r
-os.environ['TZ']. The TZ environment variable should be specified in\n\\r
-standard Unix timezone format as documented in the tzset man page\n\\r
-(eg. 'US/Eastern', 'Europe/Amsterdam'). Unknown timezones will silently\n\\r
-fall back to UTC. If the TZ environment variable is not set, the local\n\\r
-timezone is set to the systems best guess of wallclock time.\n\\r
-Changing the TZ environment variable without calling tzset *may* change\n\\r
-the local timezone used by methods such as localtime, but this behaviour\n\\r
-should not be relied on.");\r
-#endif /* HAVE_WORKING_TZSET */\r
-\r
-static void\r
-inittimezone(PyObject *m) {\r
-    /* This code moved from inittime wholesale to allow calling it from\r
-    time_tzset. In the future, some parts of it can be moved back\r
-    (for platforms that don't HAVE_WORKING_TZSET, when we know what they\r
-    are), and the extraneous calls to tzset(3) should be removed.\r
-    I haven't done this yet, as I don't want to change this code as\r
-    little as possible when introducing the time.tzset and time.tzsetwall\r
-    methods. This should simply be a method of doing the following once,\r
-    at the top of this function and removing the call to tzset() from\r
-    time_tzset():\r
-\r
-        #ifdef HAVE_TZSET\r
-        tzset()\r
-        #endif\r
-\r
-    And I'm lazy and hate C so nyer.\r
-     */\r
-#if defined(HAVE_TZNAME) && !defined(__GLIBC__) && !defined(__CYGWIN__)\r
-    tzset();\r
-#ifdef PYOS_OS2\r
-    PyModule_AddIntConstant(m, "timezone", _timezone);\r
-#else /* !PYOS_OS2 */\r
-    PyModule_AddIntConstant(m, "timezone", timezone);\r
-#endif /* PYOS_OS2 */\r
-#ifdef HAVE_ALTZONE\r
-    PyModule_AddIntConstant(m, "altzone", altzone);\r
-#else\r
-#ifdef PYOS_OS2\r
-    PyModule_AddIntConstant(m, "altzone", _timezone-3600);\r
-#else /* !PYOS_OS2 */\r
-    PyModule_AddIntConstant(m, "altzone", timezone-3600);\r
-#endif /* PYOS_OS2 */\r
-#endif\r
-    PyModule_AddIntConstant(m, "daylight", daylight);\r
-    PyModule_AddObject(m, "tzname",\r
-                       Py_BuildValue("(zz)", tzname[0], tzname[1]));\r
-#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/\r
-#ifdef HAVE_STRUCT_TM_TM_ZONE\r
-    {\r
-#define YEAR ((time_t)((365 * 24 + 6) * 3600))\r
-        time_t t;\r
-        struct tm *p;\r
-        long janzone, julyzone;\r
-        char janname[10], julyname[10];\r
-        t = (time((time_t *)0) / YEAR) * YEAR;\r
-        p = localtime(&t);\r
-        janzone = -p->tm_gmtoff;\r
-        strncpy(janname, p->tm_zone ? p->tm_zone : "   ", 9);\r
-        janname[9] = '\0';\r
-        t += YEAR/2;\r
-        p = localtime(&t);\r
-        julyzone = -p->tm_gmtoff;\r
-        strncpy(julyname, p->tm_zone ? p->tm_zone : "   ", 9);\r
-        julyname[9] = '\0';\r
-\r
-        if( janzone < julyzone ) {\r
-            /* DST is reversed in the southern hemisphere */\r
-            PyModule_AddIntConstant(m, "timezone", julyzone);\r
-            PyModule_AddIntConstant(m, "altzone", janzone);\r
-            PyModule_AddIntConstant(m, "daylight",\r
-                                    janzone != julyzone);\r
-            PyModule_AddObject(m, "tzname",\r
-                               Py_BuildValue("(zz)",\r
-                                             julyname, janname));\r
-        } else {\r
-            PyModule_AddIntConstant(m, "timezone", janzone);\r
-            PyModule_AddIntConstant(m, "altzone", julyzone);\r
-            PyModule_AddIntConstant(m, "daylight",\r
-                                    janzone != julyzone);\r
-            PyModule_AddObject(m, "tzname",\r
-                               Py_BuildValue("(zz)",\r
-                                             janname, julyname));\r
-        }\r
-    }\r
-#else\r
-#endif /* HAVE_STRUCT_TM_TM_ZONE */\r
-#ifdef __CYGWIN__\r
-    tzset();\r
-    PyModule_AddIntConstant(m, "timezone", _timezone);\r
-    PyModule_AddIntConstant(m, "altzone", _timezone-3600);\r
-    PyModule_AddIntConstant(m, "daylight", _daylight);\r
-    PyModule_AddObject(m, "tzname",\r
-                       Py_BuildValue("(zz)", _tzname[0], _tzname[1]));\r
-#endif /* __CYGWIN__ */\r
-#endif /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/\r
-}\r
-\r
-\r
-static PyMethodDef time_methods[] = {\r
-    {"time",            time_time, METH_NOARGS, time_doc},\r
-#ifdef HAVE_CLOCK\r
-    {"clock",           time_clock, METH_NOARGS, clock_doc},\r
-#endif\r
-    {"sleep",           time_sleep, METH_VARARGS, sleep_doc},\r
-    {"gmtime",          time_gmtime, METH_VARARGS, gmtime_doc},\r
-    {"localtime",       time_localtime, METH_VARARGS, localtime_doc},\r
-    {"asctime",         time_asctime, METH_VARARGS, asctime_doc},\r
-    {"ctime",           time_ctime, METH_VARARGS, ctime_doc},\r
-#ifdef HAVE_MKTIME\r
-    {"mktime",          time_mktime, METH_O, mktime_doc},\r
-#endif\r
-#ifdef HAVE_STRFTIME\r
-    {"strftime",        time_strftime, METH_VARARGS, strftime_doc},\r
-#endif\r
-    {"strptime",        time_strptime, METH_VARARGS, strptime_doc},\r
-#ifdef HAVE_WORKING_TZSET\r
-    {"tzset",           time_tzset, METH_NOARGS, tzset_doc},\r
-#endif\r
-    {NULL,              NULL}           /* sentinel */\r
-};\r
-\r
-\r
-PyDoc_STRVAR(module_doc,\r
-"This module provides various functions to manipulate time values.\n\\r
-\n\\r
-There are two standard representations of time.  One is the number\n\\r
-of seconds since the Epoch, in UTC (a.k.a. GMT).  It may be an integer\n\\r
-or a floating point number (to represent fractions of seconds).\n\\r
-The Epoch is system-defined; on Unix, it is generally January 1st, 1970.\n\\r
-The actual value can be retrieved by calling gmtime(0).\n\\r
-\n\\r
-The other representation is a tuple of 9 integers giving local time.\n\\r
-The tuple items are:\n\\r
-  year (four digits, e.g. 1998)\n\\r
-  month (1-12)\n\\r
-  day (1-31)\n\\r
-  hours (0-23)\n\\r
-  minutes (0-59)\n\\r
-  seconds (0-59)\n\\r
-  weekday (0-6, Monday is 0)\n\\r
-  Julian day (day in the year, 1-366)\n\\r
-  DST (Daylight Savings Time) flag (-1, 0 or 1)\n\\r
-If the DST flag is 0, the time is given in the regular time zone;\n\\r
-if it is 1, the time is given in the DST time zone;\n\\r
-if it is -1, mktime() should guess based on the date and time.\n\\r
-\n\\r
-Variables:\n\\r
-\n\\r
-timezone -- difference in seconds between UTC and local standard time\n\\r
-altzone -- difference in  seconds between UTC and local DST time\n\\r
-daylight -- whether local time should reflect DST\n\\r
-tzname -- tuple of (standard time zone name, DST time zone name)\n\\r
-\n\\r
-Functions:\n\\r
-\n\\r
-time() -- return current time in seconds since the Epoch as a float\n\\r
-clock() -- return CPU time since process start as a float\n\\r
-sleep() -- delay for a number of seconds given as a float\n\\r
-gmtime() -- convert seconds since Epoch to UTC tuple\n\\r
-localtime() -- convert seconds since Epoch to local time tuple\n\\r
-asctime() -- convert time tuple to string\n\\r
-ctime() -- convert time in seconds to string\n\\r
-mktime() -- convert local time tuple to seconds since Epoch\n\\r
-strftime() -- convert time tuple to string according to format specification\n\\r
-strptime() -- parse string to time tuple according to format specification\n\\r
-tzset() -- change the local timezone");\r
-\r
-\r
-PyMODINIT_FUNC\r
-inittime(void)\r
-{\r
-    PyObject *m;\r
-    char *p;\r
-    m = Py_InitModule3("time", time_methods, module_doc);\r
-    if (m == NULL)\r
-        return;\r
-\r
-    /* Accept 2-digit dates unless PYTHONY2K is set and non-empty */\r
-    p = Py_GETENV("PYTHONY2K");\r
-    PyModule_AddIntConstant(m, "accept2dyear", (long) (!p || !*p));\r
-    /* If an embedded interpreter is shutdown and reinitialized the old\r
-       moddict was not decrefed on shutdown and the next import of this\r
-       module leads to a leak.  Conditionally decref here to prevent that.\r
-    */\r
-    Py_XDECREF(moddict);\r
-    /* Squirrel away the module's dictionary for the y2k check */\r
-    moddict = PyModule_GetDict(m);\r
-    Py_INCREF(moddict);\r
-\r
-    /* Set, or reset, module variables like time.timezone */\r
-    inittimezone(m);\r
-\r
-#ifdef MS_WINDOWS\r
-    /* Helper to allow interrupts for Windows.\r
-       If Ctrl+C event delivered while not sleeping\r
-       it will be ignored.\r
-    */\r
-    main_thread = PyThread_get_thread_ident();\r
-    hInterruptEvent = CreateEvent(NULL, TRUE, FALSE, NULL);\r
-    SetConsoleCtrlHandler( PyCtrlHandler, TRUE);\r
-#endif /* MS_WINDOWS */\r
-    if (!initialized) {\r
-        PyStructSequence_InitType(&StructTimeType,\r
-                                  &struct_time_type_desc);\r
-    }\r
-    Py_INCREF(&StructTimeType);\r
-    PyModule_AddObject(m, "struct_time", (PyObject*) &StructTimeType);\r
-    initialized = 1;\r
-}\r
-\r
-\r
-/* Implement floattime() for various platforms */\r
-\r
-static double\r
-floattime(void)\r
-{\r
-    /* There are three ways to get the time:\r
-      (1) gettimeofday() -- resolution in microseconds\r
-      (2) ftime() -- resolution in milliseconds\r
-      (3) time() -- resolution in seconds\r
-      In all cases the return value is a float in seconds.\r
-      Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may\r
-      fail, so we fall back on ftime() or time().\r
-      Note: clock resolution does not imply clock accuracy! */\r
-#ifdef HAVE_GETTIMEOFDAY\r
-    {\r
-        struct timeval t;\r
-#ifdef GETTIMEOFDAY_NO_TZ\r
-        if (gettimeofday(&t) == 0)\r
-            return (double)t.tv_sec + t.tv_usec*0.000001;\r
-#else /* !GETTIMEOFDAY_NO_TZ */\r
-        if (gettimeofday(&t, (struct timezone *)NULL) == 0)\r
-            return (double)t.tv_sec + t.tv_usec*0.000001;\r
-#endif /* !GETTIMEOFDAY_NO_TZ */\r
-    }\r
-\r
-#endif /* !HAVE_GETTIMEOFDAY */\r
-    {\r
-#if defined(HAVE_FTIME)\r
-        struct timeb t;\r
-        ftime(&t);\r
-        return (double)t.time + (double)t.millitm * (double)0.001;\r
-#else /* !HAVE_FTIME */\r
-        time_t secs;\r
-        time(&secs);\r
-        return (double)secs;\r
-#endif /* !HAVE_FTIME */\r
-    }\r
-}\r
-\r
-\r
-/* Implement floatsleep() for various platforms.\r
-   When interrupted (or when another error occurs), return -1 and\r
-   set an exception; else return 0. */\r
-\r
-static int\r
-floatsleep(double secs)\r
-{\r
-/* XXX Should test for MS_WINDOWS first! */\r
-#if defined(HAVE_SELECT) && !defined(__BEOS__) && !defined(__EMX__)\r
-    struct timeval t;\r
-    double frac;\r
-    frac = fmod(secs, 1.0);\r
-    secs = floor(secs);\r
-    t.tv_sec = (long)secs;\r
-    t.tv_usec = (long)(frac*1000000.0);\r
-    Py_BEGIN_ALLOW_THREADS\r
-    if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {\r
-#ifdef EINTR\r
-        if (errno != EINTR) {\r
-#else\r
-        if (1) {\r
-#endif\r
-            Py_BLOCK_THREADS\r
-            PyErr_SetFromErrno(PyExc_IOError);\r
-            return -1;\r
-        }\r
-    }\r
-    Py_END_ALLOW_THREADS\r
-#elif defined(__WATCOMC__) && !defined(__QNX__)\r
-    /* XXX Can't interrupt this sleep */\r
-    Py_BEGIN_ALLOW_THREADS\r
-    delay((int)(secs * 1000 + 0.5));  /* delay() uses milliseconds */\r
-    Py_END_ALLOW_THREADS\r
-#elif defined(MS_WINDOWS)\r
-    {\r
-        double millisecs = secs * 1000.0;\r
-        unsigned long ul_millis;\r
-\r
-        if (millisecs > (double)ULONG_MAX) {\r
-            PyErr_SetString(PyExc_OverflowError,\r
-                            "sleep length is too large");\r
-            return -1;\r
-        }\r
-        Py_BEGIN_ALLOW_THREADS\r
-        /* Allow sleep(0) to maintain win32 semantics, and as decreed\r
-         * by Guido, only the main thread can be interrupted.\r
-         */\r
-        ul_millis = (unsigned long)millisecs;\r
-        if (ul_millis == 0 ||\r
-            main_thread != PyThread_get_thread_ident())\r
-            Sleep(ul_millis);\r
-        else {\r
-            DWORD rc;\r
-            ResetEvent(hInterruptEvent);\r
-            rc = WaitForSingleObject(hInterruptEvent, ul_millis);\r
-            if (rc == WAIT_OBJECT_0) {\r
-                /* Yield to make sure real Python signal\r
-                 * handler called.\r
-                 */\r
-                Sleep(1);\r
-                Py_BLOCK_THREADS\r
-                errno = EINTR;\r
-                PyErr_SetFromErrno(PyExc_IOError);\r
-                return -1;\r
-            }\r
-        }\r
-        Py_END_ALLOW_THREADS\r
-    }\r
-#elif defined(PYOS_OS2)\r
-    /* This Sleep *IS* Interruptable by Exceptions */\r
-    Py_BEGIN_ALLOW_THREADS\r
-    if (DosSleep(secs * 1000) != NO_ERROR) {\r
-        Py_BLOCK_THREADS\r
-        PyErr_SetFromErrno(PyExc_IOError);\r
-        return -1;\r
-    }\r
-    Py_END_ALLOW_THREADS\r
-#elif defined(__BEOS__)\r
-    /* This sleep *CAN BE* interrupted. */\r
-    {\r
-        if( secs <= 0.0 ) {\r
-            return;\r
-        }\r
-\r
-        Py_BEGIN_ALLOW_THREADS\r
-        /* BeOS snooze() is in microseconds... */\r
-        if( snooze( (bigtime_t)( secs * 1000.0 * 1000.0 ) ) == B_INTERRUPTED ) {\r
-            Py_BLOCK_THREADS\r
-            PyErr_SetFromErrno( PyExc_IOError );\r
-            return -1;\r
-        }\r
-        Py_END_ALLOW_THREADS\r
-    }\r
-#elif defined(RISCOS)\r
-    if (secs <= 0.0)\r
-        return 0;\r
-    Py_BEGIN_ALLOW_THREADS\r
-    /* This sleep *CAN BE* interrupted. */\r
-    if ( riscos_sleep(secs) )\r
-        return -1;\r
-    Py_END_ALLOW_THREADS\r
-#elif defined(PLAN9)\r
-    {\r
-        double millisecs = secs * 1000.0;\r
-        if (millisecs > (double)LONG_MAX) {\r
-            PyErr_SetString(PyExc_OverflowError, "sleep length is too large");\r
-            return -1;\r
-        }\r
-        /* This sleep *CAN BE* interrupted. */\r
-        Py_BEGIN_ALLOW_THREADS\r
-        if(sleep((long)millisecs) < 0){\r
-            Py_BLOCK_THREADS\r
-            PyErr_SetFromErrno(PyExc_IOError);\r
-            return -1;\r
-        }\r
-        Py_END_ALLOW_THREADS\r
-    }\r
-#else\r
-    /* XXX Can't interrupt this sleep */\r
-    Py_BEGIN_ALLOW_THREADS\r
-    sleep((int)secs);\r
-    Py_END_ALLOW_THREADS\r
-#endif\r
-\r
-    return 0;\r
-}\r
-\r
-/* export floattime to socketmodule.c */\r
-PyAPI_FUNC(double)\r
-_PyTime_FloatTime(void)\r
-{\r
-    return floattime();\r
-}\r