@@ -138,39 +138,6 @@ def _is_s3_url(url):
138
138
return False
139
139
140
140
141
- def maybe_read_encoded_stream (reader , encoding = None , compression = None ):
142
- """
143
- Read an encoded stream from the reader and transform the bytes to unicode if
144
- required based on the encoding.
145
-
146
- Parameters
147
- ----------
148
- reader : a streamable file-like object
149
- encoding : optional, the encoding to attempt to read
150
-
151
- Returns
152
- -------
153
- a tuple of (a stream of decoded bytes, the encoding which was used)
154
- """
155
-
156
- if compat .PY3 or encoding is not None : # pragma: no cover
157
- if encoding :
158
- errors = 'strict'
159
- else :
160
- errors = 'replace'
161
- encoding = 'utf-8'
162
-
163
- if compression == 'gzip' :
164
- reader = BytesIO (reader .read ())
165
- else :
166
- reader = StringIO (reader .read ().decode (encoding , errors ))
167
- else :
168
- if compression == 'gzip' :
169
- reader = BytesIO (reader .read ())
170
- encoding = None
171
- return reader , encoding
172
-
173
-
174
141
def _expand_user (filepath_or_buffer ):
175
142
"""Return the argument with an initial component of ~ or ~user
176
143
replaced by that user's home directory.
@@ -240,7 +207,7 @@ def get_filepath_or_buffer(filepath_or_buffer, encoding=None,
240
207
if content_encoding == 'gzip' :
241
208
# Override compression based on Content-Encoding header
242
209
compression = 'gzip'
243
- reader , encoding = maybe_read_encoded_stream (req , encoding , compression )
210
+ reader = BytesIO (req . read () )
244
211
return reader , encoding , compression
245
212
246
213
if _is_s3_url (filepath_or_buffer ):
@@ -294,12 +261,7 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
294
261
f = path_or_buf
295
262
is_path = isinstance (path_or_buf , compat .string_types )
296
263
297
- # in Python 3, convert BytesIO or fileobjects passed with an encoding
298
- if compat .PY3 and isinstance (path_or_buf , compat .BytesIO ):
299
- from io import TextIOWrapper
300
- return TextIOWrapper (path_or_buf , encoding = encoding )
301
-
302
- elif compression :
264
+ if compression :
303
265
compression = compression .lower ()
304
266
305
267
if compat .PY2 and not is_path and encoding :
@@ -369,6 +331,11 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
369
331
# Python 3 and no explicit encoding
370
332
f = open (path_or_buf , mode , errors = 'replace' )
371
333
334
+ # in Python 3, convert BytesIO or fileobjects passed with an encoding
335
+ if compat .PY3 and isinstance (path_or_buf , compat .BytesIO ):
336
+ from io import TextIOWrapper
337
+ f = TextIOWrapper (f , encoding = encoding )
338
+
372
339
if memory_map and hasattr (f , 'fileno' ):
373
340
try :
374
341
g = MMapWrapper (f )
0 commit comments