Use list to store new handles · pandas-dev/pandas@4774b75 (original) (raw)

`@@ -297,12 +297,11 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,

`

297

297

` -------

`

298

298

` f : file-like

`

299

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.

`

``

300

`+

handles : list of file-like objects

`

``

301

`+

A list of file-like object that were openned in this function.

`

303

302

` """

`

304

303

``

305

``

`-

new_handle = None

`

``

304

`+

handles = list()

`

306

305

`f = path_or_buf

`

307

306

`is_path = isinstance(path_or_buf, compat.string_types)

`

308

307

``

`@@ -358,13 +357,15 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,

`

358

357

`msg = 'Unrecognized compression type: {}'.format(compression)

`

359

358

`raise ValueError(msg)

`

360

359

``

``

360

`+

handles.append(f)

`

``

361

+

361

362

`# In Python 3

`

362

363

`if compat.PY3:

`

363

364

`from io import TextIOWrapper

`

364

365

`f = TextIOWrapper(f, encoding=encoding)

`

``

366

`+

handles.append(f)

`

365

367

``

366

``

`-

new_handle = f

`

367

``

`-

return f, new_handle

`

``

368

`+

return f, handles

`

368

369

``

369

370

`elif is_path:

`

370

371

`if compat.PY2:

`

`@@ -376,13 +377,13 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,

`

376

377

`else:

`

377

378

`# Python 3 and no explicit encoding

`

378

379

`f = open(path_or_buf, mode, errors='replace')

`

379

``

`-

new_handle = f

`

``

380

`+

handles.append(f)

`

380

381

``

381

382

`# in Python 3, convert BytesIO or fileobjects passed with an encoding

`

382

383

`if compat.PY3 and isinstance(path_or_buf, compat.BytesIO):

`

383

384

`from io import TextIOWrapper

`

384

385

`f = TextIOWrapper(f, encoding=encoding)

`

385

``

`-

new_handle = f

`

``

386

`+

handles.append(f)

`

386

387

``

387

388

`if memory_map and hasattr(f, 'fileno'):

`

388

389

`try:

`

`@@ -396,7 +397,7 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,

`

396

397

`# leave the file handler as is then

`

397

398

`pass

`

398

399

``

399

``

`-

return f, new_handle

`

``

400

`+

return f, handles

`

400

401

``

401

402

``

402

403

`class MMapWrapper(BaseIterator):

`