import gzip


def smart_ropen(path):
    """Open file in reading mode directly or through gzip depending on extension."""
    if path.endswith('.gz'):
        #return TextIOWrapper(gzip.open(path, 'rb'))  # python3
        return gzip.open(path, 'rb')
    else:
        return open(path, 'r')