@@ -275,23 +275,23 @@ def file_path_to_url(path):
275275 return urljoin ('file:' , pathname2url (path ))
276276
277277
278- def _get_handle (source , mode , encoding = None , compression = None ,
278+ def _get_handle (path_or_buf , mode , encoding = None , compression = None ,
279279 memory_map = False ):
280280 """
281281 Get file handle for given path/buffer and mode.
282282 """
283283
284- f = source
285- is_path = isinstance (source , compat .string_types )
284+ f = path_or_buf
285+ is_path = isinstance (path_or_buf , compat .string_types )
286286
287287 # in Python 3, convert BytesIO or fileobjects passed with an encoding
288- if compat .PY3 and isinstance (source , compat .BytesIO ):
288+ if compat .PY3 and isinstance (path_or_buf , compat .BytesIO ):
289289 from io import TextIOWrapper
290- return TextIOWrapper (source , encoding = encoding )
290+ return TextIOWrapper (path_or_buf , encoding = encoding )
291291
292292 elif compression :
293293 compression = compression .lower ()
294-
294+
295295 if compat .PY2 and not is_path and encoding :
296296 msg = 'compression with encoding is not yet supported in Python 2'
297297 raise ValueError (msg )
@@ -300,38 +300,38 @@ def _get_handle(source, mode, encoding=None, compression=None,
300300 if compression == 'gzip' :
301301 import gzip
302302 if is_path :
303- f = gzip .open (source , mode )
303+ f = gzip .open (path_or_buf , mode )
304304 else :
305- f = gzip .GzipFile (fileobj = source )
305+ f = gzip .GzipFile (fileobj = path_or_buf )
306306
307307 # BZ Compression
308308 elif compression == 'bz2' :
309309 import bz2
310310 if is_path :
311- f = bz2 .BZ2File (source , mode )
311+ f = bz2 .BZ2File (path_or_buf , mode )
312312 elif compat .PY2 :
313313 # Python 2's bz2 module can't take file objects, so have to
314314 # run through decompress manually
315- f = StringIO (bz2 .decompress (source .read ()))
315+ f = StringIO (bz2 .decompress (path_or_buf .read ()))
316316 else :
317- f = bz2 .BZ2File (source )
317+ f = bz2 .BZ2File (path_or_buf )
318318
319319 # ZIP Compression
320320 elif compression == 'zip' :
321321 import zipfile
322- zip_file = zipfile .ZipFile (source )
322+ zip_file = zipfile .ZipFile (path_or_buf )
323323 try :
324324 name , = zip_file .namelist ()
325325 except ValueError :
326- msg = 'Zip file must contain exactly one file {}' . format ( source )
327- raise ValueError ( msg )
328- f = zip_file .open (zip_names . pop () )
326+ raise ValueError ( 'Zip file must contain exactly one file {}'
327+ . format ( path_or_buf ) )
328+ f = zip_file .open (name )
329329
330330 # XZ Compression
331331 elif compression == 'xz' :
332332 lzma = compat .import_lzma ()
333- f = lzma .LZMAFile (source , mode )
334-
333+ f = lzma .LZMAFile (path_or_buf , mode )
334+
335335 # Unrecognized Compression
336336 else :
337337 msg = 'Unrecognized compression: {}' .format (compression )
@@ -347,13 +347,13 @@ def _get_handle(source, mode, encoding=None, compression=None,
347347 elif is_path :
348348 if compat .PY2 :
349349 # Python 2
350- f = open (source , mode )
350+ f = open (path_or_buf , mode )
351351 elif encoding :
352352 # Python 3 and encoding
353- f = open (source , mode , encoding = encoding )
353+ f = open (path_or_buf , mode , encoding = encoding )
354354 else :
355355 # Python 3 and no explicit encoding
356- f = open (source , mode , errors = 'replace' )
356+ f = open (path_or_buf , mode , errors = 'replace' )
357357
358358 if memory_map and hasattr (f , 'fileno' ):
359359 try :
0 commit comments