Parses the dotenv file, comments (#) are ignored.
    A key must have a '=' to mark it as a key. Strings without a '='
    are ignored.

    :param dotenv_path:
    :return: generator yielding (key,value)
12632
def parse_dotenv(dotenv_path):
    
    with open(dotenv_path) as f:
        for line in f:
            line = line.strip()
            if not line or line.startswith('#') or '=' not in line:
                continue
            k, v = line.split('=', 1)

            # Remove any leading and trailing spaces in key, value
            k, v = k.strip(), v.strip()

            if len(v) > 0:
                quoted = v[0] == v[len(v) - 1] in ['"', "'"]

                if quoted:
                    v = decode_escaped(v[1:-1])

            yield k, v
170594
def _import_yaml(config_file_path):
    
    try:
        logger.info('Importing config %s...', config_file_path)
        with open(config_file_path) as config_file:
            return yaml.safe_load(config_file.read())
    except IOError as ex:
        raise RepexError('{0}: {1} ({2})'.format(
            ERRORS['config_file_not_found'], config_file_path, ex))
    except (yaml.parser.ParserError, yaml.scanner.ScannerError) as ex:
        raise RepexError('{0} ({1})'.format(ERRORS['invalid_yaml'], ex))
1221494
def html_for_env_var(key):
    
    value = os.getenv(key)
    return KEY_VALUE_TEMPLATE.format(key, value)
12663
def parse_hash_comment(file_path):
    
    with open(file_path) as fp:
        for line in fp:
            if line.startswith("# SHA1:"):
                return line
    return None
75792
def get_token(filename=TOKEN_PATH, envvar=TOKEN_ENVVAR):
    
    if os.path.isfile(filename):
        with open(filename) as token_file:
            token = token_file.readline().strip()

    else:
        token = os.environ.get(envvar)

        if not token:
            raise ValueError("No token found.\n"
                             "{} file doesn't exist.\n{} environment variable is not set.".format(filename, envvar))

    return token
163066
def getenv_escaped(key: str, default: str = None) -> Optional[str]:
    
    value = os.getenv(key, default)
    # noinspection PyDeprecation
    return cgi.escape(value) if value is not None else None
848541
def get_env(env_file='.env'):
    
    try:
        with open(env_file) as f:
            for line in f.readlines():
                try:
                    key, val = line.split('=', maxsplit=1)
                    os.environ.setdefault(key.strip(), val.strip())
                except ValueError:
                    pass
    except FileNotFoundError:
        pass
901537
def assertpath(path_, msg='', **kwargs):
    
    if NO_ASSERTS:
        return
    if path_ is None:
        raise AssertionError('path is None! %s' % (path_, msg))
    if path_ == '':
        raise AssertionError('path=%r is the empty string! %s' % (path_, msg))
    if not checkpath(path_, **kwargs):
        raise AssertionError('path=%r does not exist! %s' % (path_, msg))
1276889
def read(self, path, environ):
        
        try:
            inp = open(path, 'rb')
        except FileNotFoundError as error:
            if error.errno != 2:
                raise
            return None
        parsing = parse_vexrc(inp, environ)
        for heading, key, value in parsing:
            heading = self.default_heading if heading is None else heading
            if heading not in self.headings:
                self.headings[heading] = OrderedDict()
            self.headings[heading][key] = value
        parsing.close()
835493
def gen_from_yaml_config(self, config_path: str) -> Iterator:
        
        if not config_path:
            return {}

        with open(config_path, 'r') as f:
            yaml_config = yaml.load(f)

        gen = map(lambda x: (x[0].upper(), x[1]), yaml_config.items())

        return gen
915553
def parse_vmware_file(path):
        

        pairs = OrderedDict()
        encoding = "utf-8"
        # get the first line to read the .encoding value
        with open(path, "rb") as f:
            line = f.readline().decode(encoding, errors="ignore")
            if line.startswith("#!"):
                # skip the shebang
                line = f.readline().decode(encoding, errors="ignore")
            try:
                key, value = line.split('=', 1)
                if key.strip().lower() == ".encoding":
                    file_encoding = value.strip('" ')
                    try:
                        codecs.lookup(file_encoding)
                        encoding = file_encoding
                    except LookupError:
                        log.warning("Invalid file encoding detected in '{}': {}".format(path, file_encoding))
            except ValueError:
                log.warning("Couldn't find file encoding in {}, using {}...".format(path, encoding))

        # read the file with the correct encoding
        with open(path, encoding=encoding, errors="ignore") as f:
            for line in f.read().splitlines():
                try:
                    key, value = line.split('=', 1)
                    pairs[key.strip().lower()] = value.strip('" ')
                except ValueError:
                    continue
        return pairs
1050368
def set_key(dotenv_path, key_to_set, value_to_set, quote_mode="always"):
    
    value_to_set = value_to_set.strip("'").strip('"')
    if not os.path.exists(dotenv_path):
        warnings.warn("can't write to %s - it doesn't exist." % dotenv_path)
        return None, key_to_set, value_to_set

    if " " in value_to_set:
        quote_mode = "always"

    line_template = '{}="{}"\n' if quote_mode == "always" else '{}={}\n'
    line_out = line_template.format(key_to_set, value_to_set)

    with rewrite(dotenv_path) as (source, dest):
        replaced = False
        for mapping in parse_stream(source):
            if mapping.key == key_to_set:
                dest.write(line_out)
                replaced = True
            else:
                dest.write(mapping.original)
        if not replaced:
            dest.write(line_out)

    return True, key_to_set, value_to_set
960805
def parse(file_path):
    ''''''

    _, ext = path.splitext(file_path)

    if ext in ('.yaml', '.yml'):
        func = yaml.load

    elif ext == '.json':
        func = json.load

    else:
        raise ValueError("Unrecognized config file type %s" % ext)

    with open(file_path, 'r') as f:
        return func(f)
154167
public static function parse($dotenv, $data = [], $flags = self::FLAG_STRICT)
    {
        if (!is_array($dotenv)) {
            $dotenv = explode("\n", $dotenv);
        }
        $result = (!empty($data)) ? $data : [];

        // nothing to do with empty dotenv
        if (empty($dotenv)) {
            return $result;
        }

        // FLAG_REPLACE_DUPLICATES and FLAG_STRICT are mutually exclusive
        if (($flags & static::FLAG_REPLACE_DUPLICATES) &&  ($flags & static::FLAG_STRICT)) {
            throw new InvalidArgumentException("Can't use FLAG_REPLACE_DUPLICATES and FLAG_STRICT together");
        }

        foreach ($dotenv as $line) {
            $line = trim($line);

            // Disregard comments
            if (strpos($line, '#') === 0) {
                continue;
            }

            // Only use nont-empty lines that look like setters
            if (!preg_match('#^\s*(.+?)=(.*)?$#', $line, $matches)) {
                continue;
            }

            $name = static::normalizeName($matches[1]);

            $value = static::normalizeValue(trim($matches[2]));
            $value = static::resolveNested($value, $result);

            if ($value === "" && ($flags & static::FLAG_SKIP_EMPTY)) {
                continue;
            }

            if (!isset($result[$name]) || ($flags & static::FLAG_REPLACE_DUPLICATES)) {
                $result[$name] = $value;
                continue;
            }

            if ($flags & static::FLAG_STRICT) {
                throw new RuntimeException("Duplicate value found for variable '$name'");
            }
        }

        return $result;
    }
56193
def parse_model_file(path):
    

    context = FilePathContext(path)

    format = resolve_format(None, context.filepath)
    if format == 'tsv':
        logger.debug('Parsing model file {} as TSV'.format(context.filepath))
        with context.open('r') as f:
            for reaction_id in parse_model_table_file(context, f):
                yield reaction_id
    elif format == 'yaml':
        logger.debug('Parsing model file {} as YAML'.format(context.filepath))
        with context.open('r') as f:
            for reaction_id in parse_model_yaml_file(context, f):
                yield reaction_id
699031
def addEnvPath(env, name, value):
    
    try:
        oldval = env[name]
        if not oldval.endswith(';'):
            oldval = oldval + ';'
    except KeyError:
        oldval = ""
    if not value.endswith(';'):
        value = value + ';'
    env[name] = oldval + value
1358722
def load_dotenvs():
    
    if not os.getenv('DOTENVS_LOADED'):
        envs = ['.env', '.flaskenv']
        for env in envs:
            path = os.path.join(os.getcwd(), env)
            if os.path.isfile(path):
                dotenvs(path)
        os.environ['DOTENVS_LOADED'] = 'yes'