def _fileobj_to_fd(fileobj):
if isinstance(fileobj, int):<EOL><INDENT>fd = fileobj<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>fd = int(fileobj.fileno())<EOL><DEDENT>except (AttributeError, TypeError, ValueError) as ex:<EOL><INDENT>raise ValueError("<STR_LIT>".format(fileobj)) from ex<EOL><DEDENT><DEDENT>if fd < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>".format(fd))<EOL><DEDENT>return fd<EOL>
Return a file descriptor from a file object.

Parameters:
fileobj -- file object or file descriptor

Returns:
corresponding file descriptor

Raises:
ValueError if the object is invalid