[Jython-checkins] jython: Fix time.asctime so it checks its time sequence param

jim.baker jython-checkins at python.org
Sat Dec 13 05:20:09 CET 2014


https://hg.python.org/jython/rev/f55d51fa7843
changeset:   7449:f55d51fa7843
user:        Jim Baker <jim.baker at rackspace.com>
date:        Fri Dec 12 21:20:04 2014 -0700
summary:
  Fix time.asctime so it checks its time sequence param

files:
  Lib/test/test_time.py                 |   1 -
  src/org/python/modules/time/Time.java |  15 ++++++++++++++-
  2 files changed, 14 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -125,7 +125,6 @@
         except ValueError:
             self.fail('strptime failed on empty args.')
 
-    @unittest.skip("FIXME: broken")
     def test_asctime(self):
         time.asctime(time.gmtime(self.t))
         self.assertRaises(TypeError, time.asctime, 0)
diff --git a/src/org/python/modules/time/Time.java b/src/org/python/modules/time/Time.java
--- a/src/org/python/modules/time/Time.java
+++ b/src/org/python/modules/time/Time.java
@@ -31,6 +31,7 @@
 import org.python.core.PyException;
 import org.python.core.PyInteger;
 import org.python.core.PyObject;
+import org.python.core.PySequence;
 import org.python.core.PyString;
 import org.python.core.PyTuple;
 import org.python.core.__builtin__;
@@ -412,7 +413,19 @@
         return asctime(localtime());
     }
 
-    public static PyString asctime(PyTuple tup) {
+    public static PyString asctime(PyObject obj) {
+        PyTuple tup;
+        if (obj instanceof PyTuple) {
+            tup = (PyTuple)obj;
+        } else {
+            tup = PyTuple.fromIterable(obj);
+        }
+        int len = tup.__len__();
+        if (len != 9) {
+            throw Py.TypeError(
+                String.format("argument must be sequence of length 9, not %d", len));
+        }
+
         StringBuilder buf = new StringBuilder(25);
         buf.append(enshortdays[item(tup, 6)]).append(' ');
         buf.append(enshortmonths[item(tup, 1)]).append(' ');

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list