

from __future__ import absolute_import

import errno
import io
from vdsm.common import password


def read_int(path, default=None):
    value = read(path, default)
    return int(value)


def read_password(path, default=None):
    value = read(path, default)
    return password.ProtectedPassword(value)


def read(path, default=None):
    try:
        with io.open(path, "r") as f:
            value = f.read()
    except EnvironmentError as e:
        if e.errno != errno.ENOENT or default is None:
            raise
        return default
    else:
        return value.strip()
