Author: guido.van.rossum
Date: Fri Apr 13 05:31:13 2007
New Revision: 54801

Modified:
   python/branches/p3yk/Lib/zipfile.py
   python/branches/p3yk/Python/bltinmodule.c
   python/branches/p3yk/Python/marshal.c
Log:
Support marshal.dump(x, f) where f is not a real file.
Support ord(b) where b is a 1-byte string.
In zipfile.py, work around bytes being ints instead of chars, sometimes.


Modified: python/branches/p3yk/Lib/zipfile.py
==============================================================================
--- python/branches/p3yk/Lib/zipfile.py (original)
+++ python/branches/p3yk/Lib/zipfile.py Fri Apr 13 05:31:13 2007
@@ -348,7 +348,13 @@
 
     def __call__(self, c):
         """Decrypt a single character."""
-        c = ord(c)
+        # XXX When this is called with a byte instead of a char, ord()
+        # isn't needed.  Don't die in that case.  In the future we should
+        # just leave this out, once we're always using bytes.
+        try:
+            c = ord(c)
+        except TypeError:
+            pass
         k = self.key2 | 2
         c = c ^ (((k * (k^1)) >> 8) & 255)
         c = chr(c)

Modified: python/branches/p3yk/Python/bltinmodule.c
==============================================================================
--- python/branches/p3yk/Python/bltinmodule.c   (original)
+++ python/branches/p3yk/Python/bltinmodule.c   Fri Apr 13 05:31:13 2007
@@ -1451,14 +1451,24 @@
                        return PyInt_FromLong(ord);
                }
 #ifdef Py_USING_UNICODE
-       } else if (PyUnicode_Check(obj)) {
+       }
+       else if (PyUnicode_Check(obj)) {
                size = PyUnicode_GET_SIZE(obj);
                if (size == 1) {
                        ord = (long)*PyUnicode_AS_UNICODE(obj);
                        return PyInt_FromLong(ord);
                }
 #endif
-       } else {
+       } 
+       else if (PyBytes_Check(obj)) {
+               /* XXX Hopefully this is temporary */
+               size = PyBytes_GET_SIZE(obj);
+               if (size == 1) {
+                       ord = (long)*PyBytes_AS_STRING(obj);
+                       return PyInt_FromLong(ord);
+               }
+       }
+       else {
                PyErr_Format(PyExc_TypeError,
                             "ord() expected string of length 1, but " \
                             "%.200s found", obj->ob_type->tp_name);

Modified: python/branches/p3yk/Python/marshal.c
==============================================================================
--- python/branches/p3yk/Python/marshal.c       (original)
+++ python/branches/p3yk/Python/marshal.c       Fri Apr 13 05:31:13 2007
@@ -1062,9 +1062,14 @@
        if (!PyArg_ParseTuple(args, "OO|i:dump", &x, &f, &version))
                return NULL;
        if (!PyFile_Check(f)) {
-               PyErr_SetString(PyExc_TypeError,
-                               "marshal.dump() 2nd arg must be file");
-               return NULL;
+               /* XXX Quick hack -- need to do this differently */
+               PyObject *s = PyMarshal_WriteObjectToString(x, version);
+               PyObject *res = NULL;
+               if (s != NULL) {
+                       res = PyObject_CallMethod(f, "write", "O", s);
+                       Py_DECREF(s);
+               }
+               return res;
        }
        wf.fp = PyFile_AsFile(f);
        wf.str = NULL;
_______________________________________________
Python-3000-checkins mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to