diff options
author | Guido van Rossum <guido@python.org> | 2007-07-10 08:30:03 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-07-10 08:30:03 (GMT) |
commit | a0982944464b94c2965e4776f376b66903f82764 (patch) | |
tree | da605f1e21057be547c9e75b73261ae815f38b34 /Python/mactoolboxglue.c | |
parent | 6718062538e642d62c626fd033f2c3a2356c5505 (diff) | |
download | cpython-a0982944464b94c2965e4776f376b66903f82764.zip cpython-a0982944464b94c2965e4776f376b66903f82764.tar.gz cpython-a0982944464b94c2965e4776f376b66903f82764.tar.bz2 |
Make test_urllib.py pass. Mostly str/bytes issues.
Also fix mac toolbox glue to accept str, str8, bytes for
255-byte strings.
Diffstat (limited to 'Python/mactoolboxglue.c')
-rw-r--r-- | Python/mactoolboxglue.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Python/mactoolboxglue.c b/Python/mactoolboxglue.c index 9a8d30b..85acb51 100644 --- a/Python/mactoolboxglue.c +++ b/Python/mactoolboxglue.c @@ -209,14 +209,29 @@ PyMac_BuildNumVersion(NumVersion t) int PyMac_GetStr255(PyObject *v, Str255 pbuf) { - int len; - if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) { + char *ptr; + Py_ssize_t len = 1000; + + if (PyUnicode_Check(v)) { + v = _PyUnicode_AsDefaultEncodedString(v, NULL); + if (v == NULL) + return NULL; + } + if (PyString_Check(v)) { + ptr = PyString_AS_STRING(v); + len = PyString_GET_SIZE(v); + } + else if (PyBytes_Check(v)) { + ptr = PyBytes_AS_STRING(v); + len = PyBytes_GET_SIZE(v); + } + if (len > 255) { PyErr_SetString(PyExc_TypeError, - "Str255 arg must be string of at most 255 chars"); + "Str255 arg must be string/bytes of at most 255 chars"); return 0; } pbuf[0] = len; - memcpy((char *)(pbuf+1), PyString_AsString(v), len); + memcpy((char *)(pbuf+1), ptr, len); return 1; } |