def _fileobj_to_fd(fileobj):
 if isinstance(fileobj, int):
  fd = fileobj
 else:
  try:
   fd = int(fileobj.fileno())
  except (AttributeError, TypeError, ValueError):
   raise ValueError('Invalid file object: {0!r}'.format(fileobj))
 if (fd < 0):
  raise ValueError('Invalid file descriptor: {0}'.format(fd))
 return fd

def _fileobj_to_fd ( fileobj ) : if isinstance ( fileobj , int ) : fd = fileobj else : try : fd = int ( fileobj . fileno ( ) ) except ( AttributeError , TypeError , ValueError ) : raise ValueError ( 'Invalid file object: {0!r}' . format ( fileobj ) ) if ( fd < 0 ) : raise ValueError ( 'Invalid file descriptor: {0}' . format ( fd ) ) return fd
return a file descriptor from a file object .