def get_fileno(file):
    """Get the os-level fileno of a file-like object.

    This function decodes several common file wrapper structures in an attempt
    to determine the underlying OS-level fileno for an object.
    """
    while not hasattr(file,"fileno"):
        if hasattr(file,"file"):
            file = file.file
        elif hasattr(file,"_file"):
            file = file._file
        elif hasattr(file,"_fileobj"):
            file = file._fileobj
        else:
           raise AttributeError
    return file.fileno()