def ioType(fileIshObject, default=unicode):
 if isinstance(fileIshObject, TextIOBase):
  return unicode
 if isinstance(fileIshObject, IOBase):
  return bytes
 encoding = getattr(fileIshObject, 'encoding', None)
 import codecs
 if isinstance(fileIshObject, (codecs.StreamReader, codecs.StreamWriter)):
  if encoding:
   return unicode
  else:
   return bytes
 if (not _PY3):
  if isinstance(fileIshObject, file):
   if (encoding is not None):
    return basestring
   else:
    return bytes
  from cStringIO import InputType, OutputType
  from StringIO import StringIO
  if isinstance(fileIshObject, (StringIO, InputType, OutputType)):
   return bytes
 return default

def ioType ( fileIshObject , default = unicode ) : if isinstance ( fileIshObject , TextIOBase ) : return unicode if isinstance ( fileIshObject , IOBase ) : return bytes encoding = getattr ( fileIshObject , 'encoding' , None ) import codecs if isinstance ( fileIshObject , ( codecs . StreamReader , codecs . StreamWriter ) ) : if encoding : return unicode else : return bytes if ( not _PY3 ) : if isinstance ( fileIshObject , file ) : if ( encoding is not None ) : return basestring else : return bytes from cStringIO import InputType , OutputType from StringIO import StringIO if isinstance ( fileIshObject , ( StringIO , InputType , OutputType ) ) : return bytes return default
determine the type which will be returned from the given file objects read() and accepted by its write() method as an argument .