@@ -205,8 +205,8 @@ def vfsopen(obj, mode='r', buffering=-1, encoding=None, errors=None,
205205 Open the file pointed to by this path and return a file object, as
206206 the built-in open() function does.
207207
208- Unlike the built-in open() function, this function accepts 'openable'
209- objects, which are objects with any of these special methods:
208+ Unlike the built-in open() function, this function additionally accepts
209+ 'openable' objects, which are objects with any of these special methods:
210210
211211 __open_reader__()
212212 __open_writer__(mode)
@@ -216,19 +216,24 @@ def vfsopen(obj, mode='r', buffering=-1, encoding=None, errors=None,
216216 and 'x' modes; and '__open_updater__' for 'r+' and 'w+' modes. If text
217217 mode is requested, the result is wrapped in an io.TextIOWrapper object.
218218 """
219- text = 'b' not in mode
220219 if buffering != - 1 :
221220 raise ValueError ("buffer size can't be customized" )
221+ text = 'b' not in mode
222222 if text :
223223 # Call io.text_encoding() here to ensure any warning is raised at an
224224 # appropriate stack level.
225225 encoding = text_encoding (encoding )
226- elif encoding is not None :
227- raise ValueError ("binary mode doesn't take an encoding argument" )
228- elif errors is not None :
229- raise ValueError ("binary mode doesn't take an errors argument" )
230- elif newline is not None :
231- raise ValueError ("binary mode doesn't take a newline argument" )
226+ try :
227+ return open (obj , mode , buffering , encoding , errors , newline )
228+ except TypeError :
229+ pass
230+ if not text :
231+ if encoding is not None :
232+ raise ValueError ("binary mode doesn't take an encoding argument" )
233+ if errors is not None :
234+ raise ValueError ("binary mode doesn't take an errors argument" )
235+ if newline is not None :
236+ raise ValueError ("binary mode doesn't take a newline argument" )
232237 mode = '' .join (sorted (c for c in mode if c not in 'bt' ))
233238 if mode == 'r' :
234239 stream = _open_reader (obj )
0 commit comments