Track new handles in _get_handle · pandas-dev/pandas@94aa0cb (original) (raw)
`@@ -295,9 +295,14 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
`
295
295
``
296
296
` Returns
`
297
297
` -------
`
298
``
`-
A file like object.
`
``
298
`+
f : file-like
`
``
299
`+
A file-like object
`
``
300
`+
new_handle : file-like or None
`
``
301
`+
A file-like object that was openned in this function. Or None if none
`
``
302
`+
were openned.
`
299
303
` """
`
300
304
``
``
305
`+
new_handle = None
`
301
306
`f = path_or_buf
`
302
307
`is_path = isinstance(path_or_buf, compat.string_types)
`
303
308
``
`@@ -358,7 +363,8 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
`
358
363
`from io import TextIOWrapper
`
359
364
`f = TextIOWrapper(f, encoding=encoding)
`
360
365
``
361
``
`-
return f
`
``
366
`+
new_handle = f
`
``
367
`+
return f, new_handle
`
362
368
``
363
369
`elif is_path:
`
364
370
`if compat.PY2:
`
`@@ -370,11 +376,13 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
`
370
376
`else:
`
371
377
`# Python 3 and no explicit encoding
`
372
378
`f = open(path_or_buf, mode, errors='replace')
`
``
379
`+
new_handle = f
`
373
380
``
374
381
`# in Python 3, convert BytesIO or fileobjects passed with an encoding
`
375
382
`if compat.PY3 and isinstance(path_or_buf, compat.BytesIO):
`
376
383
`from io import TextIOWrapper
`
377
384
`f = TextIOWrapper(f, encoding=encoding)
`
``
385
`+
new_handle = f
`
378
386
``
379
387
`if memory_map and hasattr(f, 'fileno'):
`
380
388
`try:
`
`@@ -388,7 +396,7 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
`
388
396
`# leave the file handler as is then
`
389
397
`pass
`
390
398
``
391
``
`-
return f
`
``
399
`+
return f, new_handle
`
392
400
``
393
401
``
394
402
`class MMapWrapper(BaseIterator):
`