New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

python-decouple

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

python-decouple - pypi Package Compare versions

Comparing version
3.1
to
3.2
+21
LICENSE
The MIT License
Copyright (c) 2013 Henrique Bastos
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
include LICENSE
+15
-9

@@ -6,2 +6,3 @@ # coding: utf-8

from shlex import shlex
from io import open

@@ -19,2 +20,3 @@

DEFAULT_ENCODING = 'UTF-8'

@@ -91,3 +93,3 @@ class UndefinedValueError(Exception):

class RepositoryEmpty(object):
def __init__(self, source=''):
def __init__(self, source='', encoding=DEFAULT_ENCODING):
pass

@@ -108,5 +110,5 @@

def __init__(self, source):
def __init__(self, source, encoding=DEFAULT_ENCODING):
self.parser = ConfigParser()
with open(source) as file_:
with open(source, encoding=encoding) as file_:
self.parser.readfp(file_)

@@ -126,6 +128,6 @@

"""
def __init__(self, source):
def __init__(self, source, encoding=DEFAULT_ENCODING):
self.data = {}
with open(source) as file_:
with open(source, encoding=encoding) as file_:
for line in file_:

@@ -137,3 +139,5 @@ line = line.strip()

k = k.strip()
v = v.strip().strip('\'"')
v = v.strip()
if len(v) >= 2 and ((v[0] == "'" and v[-1] == "'") or (v[0] == '"' and v[-1] == '"')):
v = v.strip('\'"')
self.data[k] = v

@@ -164,2 +168,4 @@

encoding = DEFAULT_ENCODING
def __init__(self, search_path=None):

@@ -178,3 +184,3 @@ self.search_path = search_path

parent = os.path.dirname(path)
if parent and parent != os.path.sep:
if parent and parent != os.path.abspath(os.sep):
return self._find_file(parent)

@@ -193,3 +199,3 @@

self.config = Config(Repository(filename))
self.config = Config(Repository(filename, encoding=self.encoding))

@@ -227,3 +233,3 @@ def _caller_path(self):

strip -- string of non-relevant characters to be passed to str.strip after the split.
tuple_ -- boolean to check if it is to return in tuple format.
post_process -- callable to post process all casted values. Default is `list`.
"""

@@ -230,0 +236,0 @@ self.cast = cast

+54
-22
Metadata-Version: 1.1
Name: python-decouple
Version: 3.1
Version: 3.2
Summary: Strict separation of settings from code.

@@ -15,5 +15,5 @@ Home-page: http://github.com/henriquebastos/python-decouple/

It also makes easy for you to:
It also makes it easy for you to:
#. store parameters on *ini* or *.env* files;
#. store parameters in *ini* or *.env* files;
#. define comprehensive default values;

@@ -104,2 +104,26 @@ #. properly convert values to the correct data type;

Encodings
---------
Decouple's default encoding is `UTF-8`.
But you can specify your preferred encoding.
Since `config` is lazy and only opens the configuration file when it's first needed, you have the chance to change
it's encoding right after import.
.. code-block:: python
from decouple import config
config.encoding = 'cp1251'
SECRET_KEY = config('SECRET_KEY')
If you wish to fallback to your system's default encoding do:
.. code-block:: python
import locale
from decouple import config
config.encoding = locale.getpreferredencoding(False)
SECRET_KEY = config('SECRET_KEY')
Where the settings data are stored?

@@ -190,3 +214,3 @@ -----------------------------------

If ``SECRET_KEY`` is not present on the ``.env``, *decouple* will raise an ``UndefinedValueError``.
If ``SECRET_KEY`` is not present in the ``.env``, *decouple* will raise an ``UndefinedValueError``.

@@ -198,5 +222,5 @@ This *fail fast* policy helps you avoid chasing misbehaviors when you eventually forget a parameter.

Some times you may want to change a parameter value without having to edit the ``.ini`` or ``.env`` files.
Sometimes you may want to change a parameter value without having to edit the ``.ini`` or ``.env`` files.
Since version 3.0, *decouple* respect the *unix way*.
Since version 3.0, *decouple* respects the *unix way*.
Therefore environment variables have precedence over config files.

@@ -256,13 +280,13 @@

By default, all values returned by `decouple` are `strings`, after all they are
read from `text files` or the `envvars`.
By default, all values returned by ``decouple`` are ``strings``, after all they are
read from ``text files`` or the ``envvars``.
However, your Python code may expect some other value type, for example:
* Django's DEBUG expects a boolean True or False.
* Django's EMAIL_PORT expects an integer.
* Django's ALLOWED_HOSTS expects a list of hostnames.
* Django's SECURE_PROXY_SSL_HEADER expects a `tuple` with two elements, the name of the header to look for and the required value.
* Django's ``DEBUG`` expects a boolean ``True`` or ``False``.
* Django's ``EMAIL_PORT`` expects an ``integer``.
* Django's ``ALLOWED_HOSTS`` expects a ``list`` of hostnames.
* Django's ``SECURE_PROXY_SSL_HEADER`` expects a ``tuple`` with two elements, the name of the header to look for and the required value.
To meet this need, the `config` function accepts a `cast` argument which
To meet this need, the ``config`` function accepts a ``cast`` argument which
receives any *callable*, that will be used to *transform* the string value

@@ -273,3 +297,3 @@ into something else.

.. code-block:: pycon
.. code-block:: python

@@ -289,6 +313,6 @@ >>> os.environ['DEBUG'] = 'False'

>>> os.environ['SECURE_PROXY_SSL_HEADER'] = 'HTTP_X_FORWARDED_PROTO, https'
>>> config('SECURE_PROXY_SSL_HEADER', cast=Csv(tuple_=True))
>>> config('SECURE_PROXY_SSL_HEADER', cast=Csv(post_process=tuple))
('HTTP_X_FORWARDED_PROTO', 'https')
As you can see, `cast` is very flexible. But the last example got a bit complex.
As you can see, ``cast`` is very flexible. But the last example got a bit complex.

@@ -302,3 +326,3 @@ Built in Csv Helper

.. code-block:: pycon
.. code-block:: python

@@ -310,5 +334,13 @@ >>> from decouple import Csv

You can also have a `default` value that must be a string to be processed by `Csv`.
.. code-block:: python
>>> from decouple import Csv
>>> config('ALLOWED_HOSTS', default='127.0.0.1', cast=Csv())
['127.0.0.1']
You can also parametrize the *Csv Helper* to return other types of data.
.. code-block:: pycon
.. code-block:: python

@@ -324,5 +356,5 @@ >>> os.environ['LIST_OF_INTEGERS'] = '1,2,3,4,5'

By default *Csv* returns a `list`, but you can get a `tuple` or whatever you want using the `post_process` argument:
By default *Csv* returns a ``list``, but you can get a ``tuple`` or whatever you want using the ``post_process`` argument:
.. code-block:: pycon
.. code-block:: python

@@ -339,3 +371,3 @@ >>> os.environ['SECURE_PROXY_SSL_HEADER'] = 'HTTP_X_FORWARDED_PROTO, https'

Setup you development environment:
Setup your development environment:

@@ -359,3 +391,3 @@ .. code-block:: console

You can submit pull requests and issues for discussion. However I only
consider merge tested code.
consider merging tested code.

@@ -362,0 +394,0 @@

Metadata-Version: 1.1
Name: python-decouple
Version: 3.1
Version: 3.2
Summary: Strict separation of settings from code.

@@ -15,5 +15,5 @@ Home-page: http://github.com/henriquebastos/python-decouple/

It also makes easy for you to:
It also makes it easy for you to:
#. store parameters on *ini* or *.env* files;
#. store parameters in *ini* or *.env* files;
#. define comprehensive default values;

@@ -104,2 +104,26 @@ #. properly convert values to the correct data type;

Encodings
---------
Decouple's default encoding is `UTF-8`.
But you can specify your preferred encoding.
Since `config` is lazy and only opens the configuration file when it's first needed, you have the chance to change
it's encoding right after import.
.. code-block:: python
from decouple import config
config.encoding = 'cp1251'
SECRET_KEY = config('SECRET_KEY')
If you wish to fallback to your system's default encoding do:
.. code-block:: python
import locale
from decouple import config
config.encoding = locale.getpreferredencoding(False)
SECRET_KEY = config('SECRET_KEY')
Where the settings data are stored?

@@ -190,3 +214,3 @@ -----------------------------------

If ``SECRET_KEY`` is not present on the ``.env``, *decouple* will raise an ``UndefinedValueError``.
If ``SECRET_KEY`` is not present in the ``.env``, *decouple* will raise an ``UndefinedValueError``.

@@ -198,5 +222,5 @@ This *fail fast* policy helps you avoid chasing misbehaviors when you eventually forget a parameter.

Some times you may want to change a parameter value without having to edit the ``.ini`` or ``.env`` files.
Sometimes you may want to change a parameter value without having to edit the ``.ini`` or ``.env`` files.
Since version 3.0, *decouple* respect the *unix way*.
Since version 3.0, *decouple* respects the *unix way*.
Therefore environment variables have precedence over config files.

@@ -256,13 +280,13 @@

By default, all values returned by `decouple` are `strings`, after all they are
read from `text files` or the `envvars`.
By default, all values returned by ``decouple`` are ``strings``, after all they are
read from ``text files`` or the ``envvars``.
However, your Python code may expect some other value type, for example:
* Django's DEBUG expects a boolean True or False.
* Django's EMAIL_PORT expects an integer.
* Django's ALLOWED_HOSTS expects a list of hostnames.
* Django's SECURE_PROXY_SSL_HEADER expects a `tuple` with two elements, the name of the header to look for and the required value.
* Django's ``DEBUG`` expects a boolean ``True`` or ``False``.
* Django's ``EMAIL_PORT`` expects an ``integer``.
* Django's ``ALLOWED_HOSTS`` expects a ``list`` of hostnames.
* Django's ``SECURE_PROXY_SSL_HEADER`` expects a ``tuple`` with two elements, the name of the header to look for and the required value.
To meet this need, the `config` function accepts a `cast` argument which
To meet this need, the ``config`` function accepts a ``cast`` argument which
receives any *callable*, that will be used to *transform* the string value

@@ -273,3 +297,3 @@ into something else.

.. code-block:: pycon
.. code-block:: python

@@ -289,6 +313,6 @@ >>> os.environ['DEBUG'] = 'False'

>>> os.environ['SECURE_PROXY_SSL_HEADER'] = 'HTTP_X_FORWARDED_PROTO, https'
>>> config('SECURE_PROXY_SSL_HEADER', cast=Csv(tuple_=True))
>>> config('SECURE_PROXY_SSL_HEADER', cast=Csv(post_process=tuple))
('HTTP_X_FORWARDED_PROTO', 'https')
As you can see, `cast` is very flexible. But the last example got a bit complex.
As you can see, ``cast`` is very flexible. But the last example got a bit complex.

@@ -302,3 +326,3 @@ Built in Csv Helper

.. code-block:: pycon
.. code-block:: python

@@ -310,5 +334,13 @@ >>> from decouple import Csv

You can also have a `default` value that must be a string to be processed by `Csv`.
.. code-block:: python
>>> from decouple import Csv
>>> config('ALLOWED_HOSTS', default='127.0.0.1', cast=Csv())
['127.0.0.1']
You can also parametrize the *Csv Helper* to return other types of data.
.. code-block:: pycon
.. code-block:: python

@@ -324,5 +356,5 @@ >>> os.environ['LIST_OF_INTEGERS'] = '1,2,3,4,5'

By default *Csv* returns a `list`, but you can get a `tuple` or whatever you want using the `post_process` argument:
By default *Csv* returns a ``list``, but you can get a ``tuple`` or whatever you want using the ``post_process`` argument:
.. code-block:: pycon
.. code-block:: python

@@ -339,3 +371,3 @@ >>> os.environ['SECURE_PROXY_SSL_HEADER'] = 'HTTP_X_FORWARDED_PROTO, https'

Setup you development environment:
Setup your development environment:

@@ -359,3 +391,3 @@ .. code-block:: console

You can submit pull requests and issues for discussion. However I only
consider merge tested code.
consider merging tested code.

@@ -362,0 +394,0 @@

@@ -0,3 +1,6 @@

LICENSE
MANIFEST.in
README.rst
decouple.py
setup.cfg
setup.py

@@ -4,0 +7,0 @@ python_decouple.egg-info/PKG-INFO

@@ -7,5 +7,5 @@ Python Decouple: Strict separation of settings from code

It also makes easy for you to:
It also makes it easy for you to:
#. store parameters on *ini* or *.env* files;
#. store parameters in *ini* or *.env* files;
#. define comprehensive default values;

@@ -96,2 +96,26 @@ #. properly convert values to the correct data type;

Encodings
---------
Decouple's default encoding is `UTF-8`.
But you can specify your preferred encoding.
Since `config` is lazy and only opens the configuration file when it's first needed, you have the chance to change
it's encoding right after import.
.. code-block:: python
from decouple import config
config.encoding = 'cp1251'
SECRET_KEY = config('SECRET_KEY')
If you wish to fallback to your system's default encoding do:
.. code-block:: python
import locale
from decouple import config
config.encoding = locale.getpreferredencoding(False)
SECRET_KEY = config('SECRET_KEY')
Where the settings data are stored?

@@ -182,3 +206,3 @@ -----------------------------------

If ``SECRET_KEY`` is not present on the ``.env``, *decouple* will raise an ``UndefinedValueError``.
If ``SECRET_KEY`` is not present in the ``.env``, *decouple* will raise an ``UndefinedValueError``.

@@ -190,5 +214,5 @@ This *fail fast* policy helps you avoid chasing misbehaviors when you eventually forget a parameter.

Some times you may want to change a parameter value without having to edit the ``.ini`` or ``.env`` files.
Sometimes you may want to change a parameter value without having to edit the ``.ini`` or ``.env`` files.
Since version 3.0, *decouple* respect the *unix way*.
Since version 3.0, *decouple* respects the *unix way*.
Therefore environment variables have precedence over config files.

@@ -248,13 +272,13 @@

By default, all values returned by `decouple` are `strings`, after all they are
read from `text files` or the `envvars`.
By default, all values returned by ``decouple`` are ``strings``, after all they are
read from ``text files`` or the ``envvars``.
However, your Python code may expect some other value type, for example:
* Django's DEBUG expects a boolean True or False.
* Django's EMAIL_PORT expects an integer.
* Django's ALLOWED_HOSTS expects a list of hostnames.
* Django's SECURE_PROXY_SSL_HEADER expects a `tuple` with two elements, the name of the header to look for and the required value.
* Django's ``DEBUG`` expects a boolean ``True`` or ``False``.
* Django's ``EMAIL_PORT`` expects an ``integer``.
* Django's ``ALLOWED_HOSTS`` expects a ``list`` of hostnames.
* Django's ``SECURE_PROXY_SSL_HEADER`` expects a ``tuple`` with two elements, the name of the header to look for and the required value.
To meet this need, the `config` function accepts a `cast` argument which
To meet this need, the ``config`` function accepts a ``cast`` argument which
receives any *callable*, that will be used to *transform* the string value

@@ -265,3 +289,3 @@ into something else.

.. code-block:: pycon
.. code-block:: python

@@ -281,6 +305,6 @@ >>> os.environ['DEBUG'] = 'False'

>>> os.environ['SECURE_PROXY_SSL_HEADER'] = 'HTTP_X_FORWARDED_PROTO, https'
>>> config('SECURE_PROXY_SSL_HEADER', cast=Csv(tuple_=True))
>>> config('SECURE_PROXY_SSL_HEADER', cast=Csv(post_process=tuple))
('HTTP_X_FORWARDED_PROTO', 'https')
As you can see, `cast` is very flexible. But the last example got a bit complex.
As you can see, ``cast`` is very flexible. But the last example got a bit complex.

@@ -294,3 +318,3 @@ Built in Csv Helper

.. code-block:: pycon
.. code-block:: python

@@ -302,5 +326,13 @@ >>> from decouple import Csv

You can also have a `default` value that must be a string to be processed by `Csv`.
.. code-block:: python
>>> from decouple import Csv
>>> config('ALLOWED_HOSTS', default='127.0.0.1', cast=Csv())
['127.0.0.1']
You can also parametrize the *Csv Helper* to return other types of data.
.. code-block:: pycon
.. code-block:: python

@@ -316,5 +348,5 @@ >>> os.environ['LIST_OF_INTEGERS'] = '1,2,3,4,5'

By default *Csv* returns a `list`, but you can get a `tuple` or whatever you want using the `post_process` argument:
By default *Csv* returns a ``list``, but you can get a ``tuple`` or whatever you want using the ``post_process`` argument:
.. code-block:: pycon
.. code-block:: python

@@ -331,3 +363,3 @@ >>> os.environ['SECURE_PROXY_SSL_HEADER'] = 'HTTP_X_FORWARDED_PROTO, https'

Setup you development environment:
Setup your development environment:

@@ -351,3 +383,3 @@ .. code-block:: console

You can submit pull requests and issues for discussion. However I only
consider merge tested code.
consider merging tested code.

@@ -354,0 +386,0 @@

@@ -0,1 +1,4 @@

[metadata]
license-file = LICENSE
[egg_info]

@@ -2,0 +5,0 @@ tag_build =

@@ -9,3 +9,3 @@ # coding: utf-8

setup(name='python-decouple',
version='3.1',
version='3.2',
description='Strict separation of settings from code.',

@@ -12,0 +12,0 @@ long_description=open(README).read(),