Repository: theskumar/python-dotenv
Pull request #57 (2017-05-26 15:33:20)

Disable ".env not found" warning by default
Because this warning _scares_ me and our team more often than _helps_ us.

Probably, similar changes should be applied to other functions.

### Added

`verbose` option for `load_dotenv`, which will log any error messages

### Changed

Warning `File .env not found` disabled by default.

Several investigations are here: motdotla/dotenv#154 (be careful, NodeJS thread)

coveralls: 
[![Coverage Status](https://coveralls.io/builds/11706070/badge)](https://coveralls.io/builds/11706070)

Coverage increased (+0.1%) to 82.514% when pulling **311f56cf524a9e2b38a65f210170e4e631778b35 on maxkoryukov:fix/disable-warn-on-not-exist** into **e5d68ff94f223b0a1fbee15dfdb6a6b6ff3f809f on theskumar:master**.

maxkoryukov: ping @theskumar 

Patch:
diff --git a/.bumpversion.cfg b/.bumpversion.cfg
index 4f5aee6..2be387d 100644
--- a/.bumpversion.cfg
+++ b/.bumpversion.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 0.6.4
+current_version = 0.6.5
 commit = True
 tag = True
 
diff --git a/README.rst b/README.rst
index 370828d..7059b4f 100644
--- a/README.rst
+++ b/README.rst
@@ -49,6 +49,9 @@ Add the following code to your ``settings.py``
     dotenv_path = join(dirname(__file__), '.env')
     load_dotenv(dotenv_path)
 
+    # OR, the same with increased verbosity:
+    load_dotenv(dotenv_path, verbose=True)
+
 Alternatively, you can use ``find_dotenv()`` method that will try to find a
 ``.env`` file by (a) guessing where to start using ``__file__`` or the working
 directory -- allowing this to work in non-file contexts such as IPython notebooks
@@ -246,6 +249,10 @@ Executing the tests:
 Changelog
 =========
 
+0.6.5
+----
+- Add support for special characters `\` (`@pjona`) (`#60 <https://github.com/theskumar/python-dotenv/issues/60>`__)
+
 0.6.4
 ----
 - Fix issue with single quotes (`@Flimm`) (`#52 <https://github.com/theskumar/python-dotenv/issues/52>`__)
@@ -279,6 +286,7 @@ Changelog
 - cli: Added ``-q/--quote`` option to control the behaviour of quotes around values in ``.env``. (Thanks `@hugochinchilla`_).
 - Improved test coverage.
 
+.. _@pjona: https://github.com/pjona
 .. _@Flimm: https://github.com/Flimm
 .. _@ticosax: https://github.com/ticosax
 .. _@tillahoffmann: https://github.com/tillahoffmann
diff --git a/dotenv/cli.py b/dotenv/cli.py
index 125a0a8..bd9bd7a 100644
--- a/dotenv/cli.py
+++ b/dotenv/cli.py
@@ -49,7 +49,7 @@ def set(ctx, key, value):
 @click.pass_context
 @click.argument('key', required=True)
 def get(ctx, key):
-    '''Retrive the value for the given key.'''
+    '''Retrieve the value for the given key.'''
     file = ctx.obj['FILE']
     stored_value = get_key(file, key)
     if stored_value:
diff --git a/dotenv/main.py b/dotenv/main.py
index ceac3fa..45f9905 100644
--- a/dotenv/main.py
+++ b/dotenv/main.py
@@ -16,12 +16,13 @@ def decode_escaped(escaped):
     return __escape_decoder(escaped)[0]
 
 
-def load_dotenv(dotenv_path):
+def load_dotenv(dotenv_path, verbose=False):
     """
     Read a .env file and load into os.environ.
     """
     if not os.path.exists(dotenv_path):
-        warnings.warn("Not loading %s - it doesn't exist." % dotenv_path)
+        if verbose:
+            warnings.warn("Not loading %s - it doesn't exist." % dotenv_path)
         return None
     for k, v in dotenv_values(dotenv_path).items():
         os.environ.setdefault(k, v)
@@ -100,7 +101,7 @@ def parse_dotenv(dotenv_path):
             k, v = line.split('=', 1)
 
             # Remove any leading and trailing spaces in key, value
-            k, v = k.strip(), v.strip()
+            k, v = k.strip(), v.strip().encode('unicode-escape').decode('ascii')
 
             if len(v) > 0:
                 quoted = v[0] == v[len(v) - 1] in ['"', "'"]
@@ -114,7 +115,7 @@ def parse_dotenv(dotenv_path):
 def resolve_nested_variables(values):
     def _replacement(name):
         """
-        get appropiate value for a variable name.
+        get appropriate value for a variable name.
         first search in environ, if not found,
         then look into the dotenv variables
         """
diff --git a/requirements.txt b/requirements.txt
index 3ecdc97..55a766b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,3 +5,4 @@ bumpversion
 wheel
 pytest-cov
 pytest-flake8
+click
diff --git a/setup.py b/setup.py
index 2c8dce7..84271fc 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ setup(
     name="python-dotenv",
     description="Add .env support to your django/flask apps in development and deployments",
     long_description=readme,
-    version="0.6.4",
+    version="0.6.5",
     author="Saurabh Kumar",
     author_email="me+github@saurabh-kumar.com",
     url="http://github.com/theskumar/python-dotenv",


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 449b54a..60c4ebf 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -58,6 +58,18 @@ def test_value_with_quotes():
     sh.rm(dotenv_path)
 
 
+def test_value_with_special_characters():
+    with open(dotenv_path, 'w') as f:
+        f.write(r'TEST="}=&~{,(\5%{&;"')
+    assert dotenv.get_key(dotenv_path, 'TEST') == r'}=&~{,(\5%{&;'
+    sh.rm(dotenv_path)
+
+    with open(dotenv_path, 'w') as f:
+        f.write(r"TEST='}=&~{,(\5%{&;'")
+    assert dotenv.get_key(dotenv_path, 'TEST') == r'}=&~{,(\5%{&;'
+    sh.rm(dotenv_path)
+
+
 def test_unset():
     sh.touch(dotenv_path)
     success, key_to_set, value_to_set = dotenv.set_key(dotenv_path, 'HELLO', 'WORLD')
diff --git a/tests/test_core.py b/tests/test_core.py
index 29f0f9a..8e9d3f0 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -10,7 +10,7 @@ from dotenv import load_dotenv, find_dotenv, set_key
 
 def test_warns_if_file_does_not_exist():
     with warnings.catch_warnings(record=True) as w:
-        load_dotenv('.does_not_exist')
+        load_dotenv('.does_not_exist', verbose=True)
 
         assert len(w) == 1
         assert w[0].category is UserWarning