@@ -1074,9 +1074,6 @@ def close(self):
1074
1074
1075
1075
def _open (self , file , mode_int , closefd ):
1076
1076
"""Call the appropriate sf_open*() function from libsndfile."""
1077
- readable = hasattr (file , 'read' ) or hasattr (file , 'readinto' )
1078
- writeable = hasattr (file , 'write' )
1079
- seekable = hasattr (file , 'seek' ) and hasattr (file , 'tell' )
1080
1077
if isinstance (file , (_unicode , bytes )):
1081
1078
if _os .path .isfile (file ):
1082
1079
if 'x' in self .mode :
@@ -1093,9 +1090,7 @@ def _open(self, file, mode_int, closefd):
1093
1090
file_ptr = openfunction (file , mode_int , self ._info )
1094
1091
elif isinstance (file , int ):
1095
1092
file_ptr = _snd .sf_open_fd (file , mode_int , self ._info , closefd )
1096
- elif (seekable and
1097
- (readable or mode_int == _snd .SFM_WRITE ) and
1098
- (writeable or mode_int == _snd .SFM_READ )):
1093
+ elif _has_virtual_io_attrs (file , mode_int ):
1099
1094
file_ptr = _snd .sf_open_virtual (self ._init_virtual_io (file ),
1100
1095
mode_int , self ._info , _ffi .NULL )
1101
1096
else :
@@ -1411,3 +1406,15 @@ def _check_format(format_str):
1411
1406
except KeyError :
1412
1407
raise ValueError ("Unknown format: {0!r}" .format (format_str ))
1413
1408
return format_int
1409
+
1410
+
1411
+ def _has_virtual_io_attrs (file , mode_int ):
1412
+ """Check if file has all the necessary attributes for virtual IO."""
1413
+ readonly = mode_int == _snd .SFM_READ
1414
+ writeonly = mode_int == _snd .SFM_WRITE
1415
+ return all ([
1416
+ hasattr (file , 'seek' ),
1417
+ hasattr (file , 'tell' ),
1418
+ hasattr (file , 'write' ) or readonly ,
1419
+ hasattr (file , 'read' ) or hasattr (file , 'readinto' ) or writeonly ,
1420
+ ])
0 commit comments