FileObject open mode

25 views
Skip to first unread message

Danil "Eleneldil G. Arilou" Lavrentyuk

unread,
May 15, 2013, 2:58:32 AM5/15/13
to gevent
Hi!

I've found it's a bit strange that a FileObject, created over opened file, doesn't use that file's mode, but defaults it to 'rb'.

Here is the patch to the gevent/fileobject.py that changes this behaviour to copy opened file's mode by default. It falls back to the default 'rb' if the fobj hasn't got the `mode` attribute.

153c153
<         def __init__(self, fobj, mode='rb', bufsize=-1, close=True):
---
>         def __init__(self, fobj, mode=None, bufsize=-1, close=True):
158a159,163
>             if mode is None:
>                 try:
>                     mode = fobj.mode
>                 except AttributeError:
>                     mode = 'rb'

With best regards,
Eleneldil ( Danil )
Reply all
Reply to author
Forward
0 new messages