<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def freader(filename, gz=False, bz=False):
 """ Returns a filereader object that can handle gzipped input """


    filecheck(filename)
    if filename.endswith('.gz'):
        gz = True
    elif filename.endswith('.bz2'):
        bz = True

    if gz:
        return gzip.open(filename, 'rb')
    elif bz:
        return bz2.BZ2File(filename, 'rb')
    else:
        return io.open(filename, 'rb')