@@ -210,8 +210,8 @@ def vfsopen(obj, mode='r', buffering=-1, encoding=None, errors=None,
210210 Open the file pointed to by this path and return a file object, as
211211 the built-in open() function does.
212212
213- Unlike the built-in open() function, this function accepts 'openable'
214- objects, which are objects with any of these special methods:
213+ Unlike the built-in open() function, this function additionally accepts
214+ 'openable' objects, which are objects with any of these special methods:
215215
216216 __open_reader__()
217217 __open_writer__(mode)
@@ -222,18 +222,23 @@ def vfsopen(obj, mode='r', buffering=-1, encoding=None, errors=None,
222222 mode is requested, the result is wrapped in an io.TextIOWrapper object.
223223 """
224224 text = 'b' not in mode
225- if buffering != - 1 :
226- raise ValueError ("buffer size can't be customized" )
227- elif text :
225+ if text :
228226 # Call io.text_encoding() here to ensure any warning is raised at an
229227 # appropriate stack level.
230228 encoding = text_encoding (encoding )
231- elif encoding is not None :
232- raise ValueError ("binary mode doesn't take an encoding argument" )
233- elif errors is not None :
234- raise ValueError ("binary mode doesn't take an errors argument" )
235- elif newline is not None :
236- raise ValueError ("binary mode doesn't take a newline argument" )
229+ try :
230+ return open (obj , mode , buffering , encoding , errors , newline )
231+ except TypeError :
232+ pass
233+ if buffering != - 1 :
234+ raise ValueError ("buffer size can't be customized" )
235+ if not text :
236+ if encoding is not None :
237+ raise ValueError ("binary mode doesn't take an encoding argument" )
238+ if errors is not None :
239+ raise ValueError ("binary mode doesn't take an errors argument" )
240+ if newline is not None :
241+ raise ValueError ("binary mode doesn't take a newline argument" )
237242 mode = '' .join (sorted (c for c in mode if c not in 'bt' ))
238243 if mode == 'r' :
239244 stream = _open_reader (obj )
0 commit comments