Mercurial > cpython-lru_cache-weakref
diff Python/marshal.c @ 41452:3c339de80010
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.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 13 Apr 2007 03:31:13 +0000 |
| parents | 4aee3f672f77 |
| children | 15b810e21fe9 |
line wrap: on
line diff
--- a/Python/marshal.c Fri Apr 13 02:23:57 2007 +0000 +++ b/Python/marshal.c Fri Apr 13 03:31:13 2007 +0000 @@ -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;
