from typing import Dict
import re


def _load_env(file_handler) -> Dict:
    """Deserializes an environment file like .env-devel and
    returns a key-value map of the environment

    Analogous to json.load
    """
    PATTERN_ENVIRON_EQUAL = re.compile(r"^(\w+)=(.*)$")
    # Works even for `POSTGRES_EXPORTER_DATA_SOURCE_NAME=postgresql://simcore:simcore@postgres:5432/simcoredb?sslmode=disable`

    environ = {}
    for line in file_handler:
        m = PATTERN_ENVIRON_EQUAL.match(line)
        if m:
            key, value = m.groups()
            environ[key] = str(value)
    return environ