@@ -57,7 +57,6 @@ import collections
5757import re
5858import warnings
5959import array
60- import StringIO
6160
6261from cpython cimport array as c_array
6362from cpython.version cimport PY_MAJOR_VERSION
@@ -67,6 +66,11 @@ from pysam.cutils cimport encode_filename, from_string_and_size
6766from pysam.calignedsegment cimport makeAlignedSegment, makePileupColumn
6867from pysam.chtslib cimport hisremote
6968
69+ if PY_MAJOR_VERSION >= 3 :
70+ from io import StringIO
71+ else :
72+ from StringIO import StringIO
73+
7074cimport cython
7175
7276# #######################################################
@@ -408,17 +412,18 @@ cdef class AlignmentFile:
408412 if self .htsfile != NULL :
409413 self .close()
410414
411- # check if we are working with a File object
412- if hasattr (filepath_or_object, " fileno" ):
413- filename = filepath_or_object.name
414- if filepath_or_object.closed:
415- raise ValueError (' I/O operation on closed file' )
416- elif isinstance (filepath_or_object, StringIO.StringIO):
415+ # StringIO not supported
416+ if isinstance (filepath_or_object, StringIO):
417417 filename = " stringio"
418418 raise NotImplementedError (
419419 " access from StringIO objects not supported" )
420420 if filepath_or_object.closed:
421421 raise ValueError (' I/O operation on closed StringIO object' )
422+ # check if we are working with a File object
423+ elif hasattr (filepath_or_object, " fileno" ):
424+ filename = filepath_or_object.name
425+ if filepath_or_object.closed:
426+ raise ValueError (' I/O operation on closed file' )
422427 else :
423428 filename = filepath_or_object
424429
0 commit comments