import codecs


def read_from(filename, encoding='utf-8'):
    """Read data from a filename, optionally with an encoding."""

    if encoding is None:
        fp = open(filename)
    else:
        fp = codecs.open(filename, encoding=encoding)

    try:
        return fp.read()
    finally:
        fp.close()