def _fileobj_normalize_mode(f):
 mode = f.mode
 if isinstance(f, gzip.GzipFile):
  if (mode == gzip.READ):
   return 'rb'
  elif (mode == gzip.WRITE):
   return 'wb'
  else:
   return None
 if ('+' in mode):
  mode = mode.replace('+', '')
  mode += '+'
 return mode

def _fileobj_normalize_mode ( f ) : mode = f . mode if isinstance ( f , gzip . GzipFile ) : if ( mode == gzip . READ ) : return 'rb' elif ( mode == gzip . WRITE ) : return 'wb' else : return None if ( '+' in mode ) : mode = mode . replace ( '+' , '' ) mode += '+' return mode
takes care of some corner cases in python where the mode string is either oddly formatted or does not truly represent the file mode .