Skip to content

Commit

Permalink
RF: builtins does not exist in python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldmccarthy committed Jan 2, 2021
1 parent aa94f24 commit 108c88f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions indexed_gzip/indexed_gzip.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@ cimport indexed_gzip.zran as zran
import io
import os
import pickle
import builtins
import logging
import tempfile
import warnings
import threading
import contextlib


builtin_open = open
"""Reference to the built-in open function, which is otherwise masked by
our open function below.
When support for Python 2.7 is dropped, the ``builtins`` module can be used
instead.
"""


log = logging.getLogger(__name__)


Expand Down Expand Up @@ -178,7 +186,7 @@ class IndexedGzipFile(io.BufferedReader):
tmpfile = tempfile.NamedTemporaryFile(delete=False)
tmpfile.close()
self.export_index(tmpfile.name)
with builtins.open(tmpfile.name, 'rb') as f:
with builtin_open(tmpfile.name, 'rb') as f:
index = f.read()
finally:
if tmpfile is not None:
Expand Down Expand Up @@ -349,7 +357,7 @@ cdef class _IndexedGzipFile:
# the lifetime of this object.
if not drop_handles:
if fileobj is None:
fileobj = builtins.open(filename, mode)
fileobj = builtin_open(filename, mode)
fd = fdopen(fileobj.fileno(), 'rb')


Expand Down Expand Up @@ -863,7 +871,7 @@ cdef class _IndexedGzipFile:
'Only one of filename or fileobj must be specified')

if filename is not None:
fileobj = builtins.open(filename, 'wb')
fileobj = builtin_open(filename, 'wb')
close_file = True

else:
Expand Down Expand Up @@ -905,7 +913,7 @@ cdef class _IndexedGzipFile:
'Only one of filename or fileobj must be specified')

if filename is not None:
fileobj = builtins.open(filename, 'rb')
fileobj = builtin_open(filename, 'rb')
close_file = True

else:
Expand Down

0 comments on commit 108c88f

Please sign in to comment.