mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
tokenizer.c: make coding markup work again.
io.open() now takes all positional parameters (so we can conveniently call it from C code). test_tarfile.py no longer uses u"..." literals, but is otherwise still badly broken. This is a checkpoint; some more stuff now breaks.
This commit is contained in:
parent
e7ba495627
commit
9cbfffd1a6
3 changed files with 35 additions and 32 deletions
|
@ -396,25 +396,29 @@ fp_readl(char *s, int size, struct tok_state *tok)
|
|||
static int
|
||||
fp_setreadl(struct tok_state *tok, const char* enc)
|
||||
{
|
||||
PyObject *reader, *stream, *readline;
|
||||
PyObject *readline = NULL, *stream = NULL, *io = NULL;
|
||||
int ok = 0;
|
||||
|
||||
/* XXX: constify filename argument. */
|
||||
stream = PyFile_FromFile(tok->fp, (char*)tok->filename, "rb", NULL);
|
||||
io = PyImport_ImportModule("io");
|
||||
if (io == NULL)
|
||||
goto cleanup;
|
||||
|
||||
stream = PyObject_CallMethod(io, "open", "ssis",
|
||||
tok->filename, "r", -1, enc);
|
||||
if (stream == NULL)
|
||||
return 0;
|
||||
goto cleanup;
|
||||
|
||||
reader = PyCodec_StreamReader(enc, stream, NULL);
|
||||
Py_DECREF(stream);
|
||||
if (reader == NULL)
|
||||
return 0;
|
||||
|
||||
readline = PyObject_GetAttrString(reader, "readline");
|
||||
Py_DECREF(reader);
|
||||
readline = PyObject_GetAttrString(stream, "readline");
|
||||
if (readline == NULL)
|
||||
return 0;
|
||||
goto cleanup;
|
||||
|
||||
tok->decoding_readline = readline;
|
||||
return 1;
|
||||
ok = 1;
|
||||
|
||||
cleanup:
|
||||
Py_XDECREF(stream);
|
||||
Py_XDECREF(io);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* Fetch the next byte from TOK. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue