@@ -140,39 +140,6 @@ def _is_s3_url(url):
140140 return False
141141
142142
143- def maybe_read_encoded_stream (reader , encoding = None , compression = None ):
144- """
145- Read an encoded stream from the reader and transform the bytes to unicode if
146- required based on the encoding.
147-
148- Parameters
149- ----------
150- reader : a streamable file-like object
151- encoding : optional, the encoding to attempt to read
152-
153- Returns
154- -------
155- a tuple of (a stream of decoded bytes, the encoding which was used)
156- """
157-
158- if compat .PY3 or encoding is not None : # pragma: no cover
159- if encoding :
160- errors = 'strict'
161- else :
162- errors = 'replace'
163- encoding = 'utf-8'
164-
165- if compression == 'gzip' :
166- reader = BytesIO (reader .read ())
167- else :
168- reader = StringIO (reader .read ().decode (encoding , errors ))
169- else :
170- if compression == 'gzip' :
171- reader = BytesIO (reader .read ())
172- encoding = None
173- return reader , encoding
174-
175-
176143def _expand_user (filepath_or_buffer ):
177144 """Return the argument with an initial component of ~ or ~user
178145 replaced by that user's home directory.
@@ -242,7 +209,7 @@ def get_filepath_or_buffer(filepath_or_buffer, encoding=None,
242209 if content_encoding == 'gzip' :
243210 # Override compression based on Content-Encoding header
244211 compression = 'gzip'
245- reader , encoding = maybe_read_encoded_stream (req , encoding , compression )
212+ reader = BytesIO (req . read () )
246213 return reader , encoding , compression
247214
248215 if _is_s3_url (filepath_or_buffer ):
@@ -296,12 +263,7 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
296263 f = path_or_buf
297264 is_path = isinstance (path_or_buf , compat .string_types )
298265
299- # in Python 3, convert BytesIO or fileobjects passed with an encoding
300- if compat .PY3 and isinstance (path_or_buf , compat .BytesIO ):
301- from io import TextIOWrapper
302- return TextIOWrapper (path_or_buf , encoding = encoding )
303-
304- elif compression :
266+ if compression :
305267 compression = compression .lower ()
306268
307269 if compat .PY2 and not is_path and encoding :
@@ -371,6 +333,11 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
371333 # Python 3 and no explicit encoding
372334 f = open (path_or_buf , mode , errors = 'replace' )
373335
336+ # in Python 3, convert BytesIO or fileobjects passed with an encoding
337+ if compat .PY3 and isinstance (path_or_buf , compat .BytesIO ):
338+ from io import TextIOWrapper
339+ f = TextIOWrapper (f , encoding = encoding )
340+
374341 if memory_map and hasattr (f , 'fileno' ):
375342 try :
376343 g = MMapWrapper (f )
0 commit comments