Mercurial > cpython-lru_cache-weakref
diff Python/getargs.c @ 17657:085f460b0e3b legacy-trunk
Added new parser markers 'et' and 'et#' which do not recode string
objects but instead assume that they use the requested encoding.
This is needed on Windows to enable opening files by passing in
Unicode file names.
| author | Marc-André Lemburg <mal@egenix.com> |
|---|---|
| date | Wed, 02 May 2001 17:16:16 +0000 |
| parents | 9a8e961b505f |
| children | f7c385226f65 |
line wrap: on
line diff
--- a/Python/getargs.c Wed May 02 15:13:44 2001 +0000 +++ b/Python/getargs.c Wed May 02 17:16:16 2001 +0000 @@ -687,25 +687,39 @@ char **buffer; const char *encoding; PyObject *u, *s; - int size; + int size, recode_strings; /* Get 'e' parameter: the encoding name */ encoding = (const char *)va_arg(*p_va, const char *); if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); - /* Get 's' parameter: the output buffer to use */ + /* Get output buffer parameter: + 's' (recode all objects via Unicode) or + 't' (only recode non-string objects) + */ if (*format != 's') + recode_strings = 1; + else if (*format == 't') + recode_strings = 0; + else return "(unknown parser marker combination)"; buffer = (char **)va_arg(*p_va, char **); format++; if (buffer == NULL) return "(buffer is NULL)"; + /* Encode object */ + if (!recode_strings && PyString_Check(arg)) { + s = arg; + Py_INCREF(s); + } + else { /* Convert object to Unicode */ u = PyUnicode_FromObject(arg); if (u == NULL) - return "string or unicode or text buffer"; + return \ + "string or unicode or text buffer"; /* Encode object; use default error handling */ s = PyUnicode_AsEncodedString(u, @@ -716,7 +730,9 @@ return "(encoding failed)"; if (!PyString_Check(s)) { Py_DECREF(s); - return "(encoder failed to return a string)"; + return \ + "(encoder failed to return a string)"; + } } size = PyString_GET_SIZE(s);
