<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def opener(mode='r'):
 """Factory for creating file objects Keyword Arguments: - mode -- A string indicating how the file is to be opened. Accepts the same values as the builtin open() function. - bufsize -- The file's desired buffer size. Accepts the same values as the builtin open() function. """


    def open_file(f):
        if f is sys.stdout or f is sys.stdin:
            return f
        elif f == '-':
            return sys.stdin if 'r' in mode else sys.stdout
        elif f.endswith('.bz2'):
            return bz2.BZ2File(f, mode)
        elif f.endswith('.gz'):
            return gzip.open(f, mode)
        else:
            return open(f, mode)

    return open_file