zopefoundation / persistent

automatic persistence for Python objects
https://pypi.org/project/persistent/
Other
46 stars 28 forks source link

pyTimeStamp and TimeStamp __init__ accept different arguments #13

Closed do3cc closed 8 years ago

do3cc commented 9 years ago

This is on master:

>>> from persistent.TimeStamp import TimeStamp
>>> TimeStamp(2014, 2, 3)
'\x03\xa4\x8a\xa0\x00\x00\x00\x00'
>>> from persistent.TimeStamp import pyTimeStamp
>>> pyTimeStamp(2014, 2, 3)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/do3cc/dev/presistent/persistent/timestamp.py", line 86, in __init__
    raise TypeError('Pass either a single 8-octet arg '
TypeError: Pass either a single 8-octet arg or 5 integers and a float
tseaver commented 9 years ago

The following patch corrects this problem:

--- a/persistent/_timestamp.c
+++ b/persistent/_timestamp.c
@@ -478,7 +478,7 @@ TimeStamp_TimeStamp(PyObject *obj, PyObject *args)
    }
    PyErr_Clear();

-    if (!PyArg_ParseTuple(args, "iii|iid", &y, &mo, &d, &h, &m, &sec))
+    if (!PyArg_ParseTuple(args, "iiiiid", &y, &mo, &d, &h, &m, &sec))
        return NULL;
    return TimeStamp_FromDate(y, mo, d, h, m, sec);
}

@jimfulton, can you recall a reason why the h, m, and sec were optional? ZODB never constructs a TimeStamp instance with anything other than an 8-byte octet or 5 ints and a float.