Skip to content
Myr

Merge pull request #3932 from greyli/set-encoding

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Set default encoding to UTF-8 for load_dotenv

authored by David Lord · committed by GitHub · parents 6d9d79c, 33145c3 · Browse files · 3 files+9 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+9 added−4 removed

  • tests:+4 added−2 removed
  • other:+5 added−2 removed

3 files+9 added−4 removed

modified:src/flask/cli.py+5 added-2 removed
617 unmodified lines
618 .. versionchanged:: 1.1.0619 Returns ``False`` when python-dotenv is not installed, or when620 the given path isn't a file.621622 .. versionchanged:: 2.0623 When loading the env files, set the default encoding to UTF-8.624625 .. versionadded:: 1.0626 """627 if dotenv is None:628 if path or os.path.isfile(".env") or os.path.isfile(".flaskenv"):
9 unmodified lines
638 # if the given path specifies the actual file then return True,639 # else False640 if path is not None:641 if os.path.isfile(path):639 return dotenv.load_dotenv(path)642 return dotenv.load_dotenv(path, encoding="utf-8")643644 return False645646 new_dir = None
6 unmodified lines
653654 if new_dir is None:655 new_dir = os.path.dirname(path)656654 dotenv.load_dotenv(path)657 dotenv.load_dotenv(path, encoding="utf-8")658659 return new_dir is not None # at least one file was located and loaded660661
304 unmodified lines
modified:tests/test_apps/.env+1 added
1FOO=env2SPAM=13EGGS=24HAM=火腿
modified:tests/test_cli.py+3 added-2 removed
503 unmodified lines
504505@need_dotenv506def test_load_dotenv(monkeypatch):507 # can't use monkeypatch.delitem since the keys don't exist yet508 for item in ("FOO", "BAR", "SPAM"):508 for item in ("FOO", "BAR", "SPAM", "HAM"):509 monkeypatch._setitem.append((os.environ, item, notset))510511 monkeypatch.setenv("EGGS", "3")512 monkeypatch.chdir(test_path)
6 unmodified lines
519 # set only in .env520 assert os.environ["SPAM"] == "1"521 # set manually, files don't overwrite522 assert os.environ["EGGS"] == "3"523523 # test env file encoding524 assert os.environ["HAM"] == "火腿"525 # Non existent file should not load526 assert not load_dotenv("non-existent-file")527528
134 unmodified lines