Christian Heimes added the comment:

Guido van Rossum wrote:
> Don't call open() with keyword arg for newline="\r"; open() takes
> positional args too. This is done specifically to simplify life for C
> code calling it. :-) Perhaps one of the PyFunction_Call(..) variants
> makes it easier to call it without having to explicitly construct the
> tuple for the argument list. (All this because you're leaking the
> value of PyString_FromString("\n"). :-)

I need a way to open a file with a specific encoding for
imp.find_module(), too. I found PyFile_FromFile(). It uses io.open but
it doesn't accept the additional arguments. I like to add another
function PyFile_FromFileEx() to the API.

PyObject *
PyFile_FromFileEx(FILE *fp, char *name, char *mode, int (*close)(FILE
*), int buffering, char *encoding, char *newline)

Some people may also miss the PyFile_FromString() function but that's a
different story. With the my new function I can create sys.stdin with:

PyFile_FromFileEx(stdin, "<stdin>", "r", fclose, -1, NULL, "\n")

I kinda like it :)

> I would change the error handling to avoid the 'finally' label, like this:
> 
>         if (0) {
>   error:
>                 status = -1;
>                 Py_XDECREF(args);
>         }

Wow, that's tricky. :)

> I would add a comment "see initstdio() in pythonrun.c" to the
> OpenWrapper class, which otherwise looks a bit mysterious (as it's not
> used anywhere in the Python code).

That sounds like a good idea!

The code for const char *PyTokenizer_FindEncoding(FILE *fp) and
imp.find_module() is also finished and works.

Christian

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1267>
__________________________________
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to