static PyObject* mod_timefromticks(PyObject* self, PyObject* args) { UNUSED(self); time_t t = 0; struct tm* fields; // Sigh... If a float is passed but we ask for a long, we get a deprecation warning printed to the screen instead // of a failure. Not only is this not documented, it means we can't reliably use PyArg_ParseTuple('l') anywhere! // if (PyArg_ParseTuple(args, "l", &ticks)) PyObject* num; if (!PyArg_ParseTuple(args, "O", &num)) return 0; if (PyInt_Check(num)) t = PyInt_AS_LONG(num); else if (PyLong_Check(num)) t = PyLong_AsLong(num); else if (PyFloat_Check(num)) t = (long)PyFloat_AS_DOUBLE(num); else { PyErr_SetString(PyExc_TypeError, "TimeFromTicks requires a number."); return 0; } fields = localtime(&t); return PyTime_FromTime(fields->tm_hour, fields->tm_min, fields->tm_sec, 0); }
static PyObject* GetDataTimestamp(Cursor* cur, Py_ssize_t iCol) { TIMESTAMP_STRUCT value; SQLLEN cbFetched = 0; SQLRETURN ret; Py_BEGIN_ALLOW_THREADS ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_TYPE_TIMESTAMP, &value, sizeof(value), &cbFetched); Py_END_ALLOW_THREADS if (!SQL_SUCCEEDED(ret)) return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt); if (cbFetched == SQL_NULL_DATA) Py_RETURN_NONE; switch (cur->colinfos[iCol].sql_type) { case SQL_TYPE_TIME: { int micros = (int)(value.fraction / 1000); // nanos --> micros return PyTime_FromTime(value.hour, value.minute, value.second, micros); } case SQL_TYPE_DATE: return PyDate_FromDate(value.year, value.month, value.day); } int micros = (int)(value.fraction / 1000); // nanos --> micros return PyDateTime_FromDateAndTime(value.year, value.month, value.day, value.hour, value.minute, value.second, micros); }
static PyObject *meth_QTime_toPyTime(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { const QTime *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QTime, &sipCpp)) { PyObject * sipRes = 0; #line 357 "/home/vikky/Desktop/DVCS/stuff/scrapy/soft/PyQt-x11-gpl-4.11.4/sip/QtCore/qdatetime.sip" if (!PyDateTimeAPI) PyDateTime_IMPORT; // Convert to a Python time object. sipRes = PyTime_FromTime(sipCpp->hour(), sipCpp->minute(), sipCpp->second(), sipCpp->msec() * 1000); #line 67 "/home/vikky/Desktop/DVCS/stuff/scrapy/soft/PyQt-x11-gpl-4.11.4/QtCore/sipQtCoreQTime.cpp" return sipRes; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QTime, sipName_toPyTime, doc_QTime_toPyTime); return NULL; }
static PyObject *meth_QTime_toPyTime(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QTime *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QTime, &sipCpp)) { PyObject * sipRes = 0; #line 299 "/home/tsheasha/GUC/Bachelors/android-python27/python-build/PyQt-x11-gpl-4.8/sip/QtCore/qdatetime.sip" if (!PyDateTimeAPI) PyDateTime_IMPORT; // Convert to a Python time object. sipRes = PyTime_FromTime(sipCpp->hour(), sipCpp->minute(), sipCpp->second(), sipCpp->msec() * 1000); #line 74 "sipQtCoreQTime.cpp" return sipRes; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QTime, sipName_toPyTime, NULL); return NULL; }
static PyObject * str_to_time(PyObject *self, PyObject *arg) { const char *str; unsigned int hour, minute, second, microsecond = 0; if (arg == Py_None) Py_RETURN_NONE; str = PyString_AsString(arg); if (str == NULL) return NULL; /* microseconds are optional */ /* TODO: this is slightly less picky than the Python version which would not accept "00:00:00.". I don't know which is better, but they should be coherent. */ if (sscanf(str, "%2u:%2u:%2u.%6u", &hour, &minute, &second, µsecond) < 3) { PyErr_SetString(PyExc_ValueError, "Couldn't parse time string."); return NULL; } return PyTime_FromTime(hour, minute, second, microsecond); }
//----------------------------------------------------------------------------- // TimeVar_GetValue() // Returns the value stored at the given array position. //----------------------------------------------------------------------------- static PyObject *TimeVar_GetValue( udt_TimeVar *var, // variable to determine value for unsigned pos) // array position { TIME_STRUCT *sqlValue; sqlValue = &var->data[pos]; return PyTime_FromTime(sqlValue->hour, sqlValue->minute, sqlValue->second, 0); }
static PyObject* from_time_kobject(K x) { PyDateTime_IMPORT; PyObject* result; Py_ssize_t i, length ; length = (Py_ssize_t)(x->n); int h, m, s, ms; if(scalar(x)) { time_helper((int)(x->i), &h, &m, &s, &ms); result = PyTime_FromTime(h, m, s, ms); } else { result = PyList_New(length); for(i = 0; i != length; ++i) { time_helper((int)xI[i], &h, &m, &s, &ms); PyList_SetItem(result, i, PyTime_FromTime(h, m, s, ms)); } } return result; }
static PyObject* GetSqlServerTime(Cursor* cur, Py_ssize_t iCol) { SQL_SS_TIME2_STRUCT value; SQLLEN cbFetched = 0; SQLRETURN ret; Py_BEGIN_ALLOW_THREADS ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_BINARY, &value, sizeof(value), &cbFetched); Py_END_ALLOW_THREADS if (!SQL_SUCCEEDED(ret)) return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt); if (cbFetched == SQL_NULL_DATA) Py_RETURN_NONE; int micros = (int)(value.fraction / 1000); // nanos --> micros return PyTime_FromTime(value.hour, value.minute, value.second, micros); }
static PyObject* mod_timefromticks(PyObject* self, PyObject* args) { UNUSED(self); PyObject* num; if (!PyArg_ParseTuple(args, "O", &num)) return 0; if (!PyNumber_Check(num)) return PyErr_Format(PyExc_TypeError, "TimeFromTicks requires a number."); Object l(PyNumber_Long(num)); if (!l) return 0; time_t t = PyLong_AsLong(num); struct tm* fields = localtime(&t); return PyTime_FromTime(fields->tm_hour, fields->tm_min, fields->tm_sec, 0); }
static PyObject* decode_datetime(JSONData *jsondata) { PyObject *object; char c = 0; int n = 0; char *ptr = NULL, *tinfo_str = NULL; int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, usecond = 0; int is_tdelta = False, tinfo_len; // look for the closing quote ptr = jsondata->ptr + 2; // Skip the type hint and the opening quote while (True) { c = *ptr; if (c == 0) { PyErr_Format(JSON_DecodeError, "unterminated datetime string starting at position " SSIZE_T_F, (Py_ssize_t)(jsondata->ptr - jsondata->str)); goto failure; } if (c == '"') { break; } if (ptr - jsondata->ptr - 2 == 0 ) { // first character switch (c) { case '-': case '+': is_tdelta = True; } } ptr++; } // get only the actual datetime information skipSpaces(jsondata); tinfo_len = ptr - (jsondata->ptr + 2); if (tinfo_len) { tinfo_str = (char*) malloc(tinfo_len); strncpy(tinfo_str, jsondata->ptr + 2, tinfo_len); } if (is_tdelta) { n = sscanf(tinfo_str, "%d:%u:%u:%u.%u", &day, &hour, &minute, &second, &usecond); if (n != 3) { PyErr_Format(JSON_DecodeError, "bad timedelta format at position " SSIZE_T_F ": %s", (Py_ssize_t)(jsondata->ptr - jsondata->str), tinfo_str); goto failure; } else { second += minute * 60; second += hour * 60 * 60; object = PyDelta_FromDSU(day, second, usecond); } } else { char* is_datetime = strchr(tinfo_str, ' '); if (is_datetime == NULL) { switch (tinfo_len) { case 10: n = sscanf(tinfo_str, "%u-%u-%u", &year, &month, &day); object = PyDate_FromDate(year, month, day); break; case 8: n = sscanf(tinfo_str, "%u:%u:%u", &hour, &minute, &second); object = PyTime_FromTime(hour, minute, second, 0); break; case 15: n = sscanf(tinfo_str, "%u:%u:%u.%u", &hour, &minute, &second, &usecond); object = PyTime_FromTime(hour, minute, second, usecond); break; } } else { switch (tinfo_len) { case 19: n = sscanf(tinfo_str, "%u-%u-%u %u:%u:%u", &year, &month, &day, &hour, &minute, &second); object = PyDateTime_FromDateAndTime(year, month, day, hour, minute, second, 0); break; case 26: n = sscanf(tinfo_str, "%u-%u-%u %u:%u:%u.%u", &year, &month, &day, &hour, &minute, &second, &usecond); object = PyDateTime_FromDateAndTime(year, month, day, hour, minute, second, usecond); break; } } } if (object == NULL) { PyErr_Format(JSON_DecodeError, "bad format for time, date, or datetime at position " SSIZE_T_F ": %s", (Py_ssize_t)(jsondata->ptr - jsondata->str), tinfo_str); goto failure; } jsondata->ptr = jsondata->ptr + tinfo_len + 3; return object; failure: free(tinfo_str); Py_XDECREF(object); return NULL; }
static PyObject * str_to_time(PyObject *self, PyObject *arg) { #if PY_MAJOR_VERSION >= 3 PyObject *bytes; PyObject *err_bytes; #endif const char *str; int numparsed; unsigned int hour, minute, second, microsecond = 0; PyObject *err_repr; if (arg == Py_None) Py_RETURN_NONE; #if PY_MAJOR_VERSION >= 3 bytes = PyUnicode_AsASCIIString(arg); if (bytes == NULL) str = NULL; else str = PyBytes_AS_STRING(bytes); #else str = PyString_AsString(arg); #endif if (str == NULL) { err_repr = PyObject_Repr(arg); if (err_repr == NULL) return NULL; #if PY_MAJOR_VERSION >= 3 err_bytes = PyUnicode_AsASCIIString(err_repr); if (err_bytes == NULL) return NULL; PyErr_Format( PyExc_ValueError, "Couldn't parse time string '%.200s' - value is not a string.", PyBytes_AS_STRING(err_bytes)); Py_DECREF(err_bytes); #else PyErr_Format( PyExc_ValueError, "Couldn't parse time string '%.200s' - value is not a string.", PyString_AsString(err_repr)); #endif Py_DECREF(err_repr); return NULL; } /* microseconds are optional */ /* TODO: this is slightly less picky than the Python version which would not accept "00:00:00.". I don't know which is better, but they should be coherent. */ numparsed = sscanf(str, "%2u:%2u:%2u.%6u", &hour, &minute, &second, µsecond); #if PY_MAJOR_VERSION >= 3 Py_DECREF(bytes); #endif if (numparsed < 3) { err_repr = PyObject_Repr(arg); if (err_repr == NULL) return NULL; #if PY_MAJOR_VERSION >= 3 err_bytes = PyUnicode_AsASCIIString(err_repr); if (err_bytes == NULL) return NULL; PyErr_Format( PyExc_ValueError, "Couldn't parse time string: %.200s", PyBytes_AS_STRING(err_bytes)); Py_DECREF(err_bytes); #else PyErr_Format( PyExc_ValueError, "Couldn't parse time string: %.200s", PyString_AsString(err_repr)); #endif Py_DECREF(err_repr); return NULL; } return PyTime_FromTime(hour, minute, second, microsecond); }