def nopen(f, mode="<STR_LIT:r>"):
if isinstance(f, int_types):<EOL><INDENT>return nopen(sys.argv[f], mode)<EOL><DEDENT>if not isinstance(f, basestring):<EOL><INDENT>return f<EOL><DEDENT>if f.startswith("<STR_LIT:|>"):<EOL><INDENT>p = Popen(f[<NUM_LIT:1>:], stdout=PIPE, stdin=PIPE,<EOL>stderr=sys.stderr if mode == "<STR_LIT:r>" else PIPE,<EOL>shell=True, bufsize=-<NUM_LIT:1>, <EOL>preexec_fn=prefunc,<EOL>close_fds=False, executable=os.environ.get('<STR_LIT>'))<EOL>if sys.version_info[<NUM_LIT:0>] > <NUM_LIT:2>:<EOL><INDENT>import io<EOL>p.stdout = io.TextIOWrapper(p.stdout)<EOL>p.stdin = io.TextIOWrapper(p.stdin)<EOL>if mode != "<STR_LIT:r>":<EOL><INDENT>p.stderr = io.TextIOWrapper(p.stderr)<EOL><DEDENT><DEDENT>if mode and mode[<NUM_LIT:0>] == "<STR_LIT:r>":<EOL><INDENT>return process_iter(p, f[<NUM_LIT:1>:])<EOL><DEDENT>return p<EOL><DEDENT>if f.startswith(("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")):<EOL><INDENT>fh = urlopen(f)<EOL>if f.endswith("<STR_LIT>"):<EOL><INDENT>return ungzipper(fh)<EOL><DEDENT>if sys.version_info[<NUM_LIT:0>] < <NUM_LIT:3>:<EOL><INDENT>return fh<EOL><DEDENT>import io<EOL>return io.TextIOWrapper(fh)<EOL><DEDENT>f = op.expanduser(op.expandvars(f))<EOL>if f.endswith(("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")):<EOL><INDENT>fh = gzip.open(f, mode)<EOL>if sys.version_info[<NUM_LIT:0>] < <NUM_LIT:3>:<EOL><INDENT>return fh<EOL><DEDENT>import io<EOL>return io.TextIOWrapper(fh)<EOL><DEDENT>elif f.endswith(("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")):<EOL><INDENT>fh = bz2.BZ2File(f, mode)<EOL>if sys.version_info[<NUM_LIT:0>] < <NUM_LIT:3>:<EOL><INDENT>return fh<EOL><DEDENT>import io<EOL>return io.TextIOWrapper(fh)<EOL><DEDENT>return {"<STR_LIT:r>": sys.stdin, "<STR_LIT:w>": sys.stdout}[mode[<NUM_LIT:0>]] if f == "<STR_LIT:->"else open(f, mode)<EOL>
r"""
    open a file that's gzipped or return stdin for '-'
    if f is a number, the result of nopen(sys.argv[f]) is returned.

    >>> nopen('-') == sys.stdin, nopen('-', 'w') == sys.stdout
    (True, True)

    >>> nopen(sys.argv[0])
    <...file...>

    # expands user and vars ($HOME)
    >>> nopen("~/.bashrc").name == nopen("$HOME/.bashrc").name
    True

    # an already open file.
    >>> nopen(open(sys.argv[0]))
    <...file...>

    >>> nopen(0)
    <...file...>

    Or provide nicer access to Popen.stdout
    >>> files = list(nopen("|ls"))
    >>> assert 'setup.py\n' in files or b'setup.py\n' in files, files