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.3
to
3.4
+31
-0
decouple.py

@@ -235,1 +235,32 @@ # coding: utf-8

return self.post_process(transform(s) for s in splitter)
class Choices(object):
"""
Allows for cast and validation based on a list of choices.
"""
def __init__(self, flat=None, cast=text_type, choices=None):
"""
Parameters:
flat -- a flat list of valid choices.
cast -- callable that transforms value before validation.
choices -- tuple of Django-like choices.
"""
self.flat = flat or []
self.cast = cast
self.choices = choices or []
self._valid_values = []
self._valid_values.extend(self.flat)
self._valid_values.extend([value for value, _ in self.choices])
def __call__(self, value):
transform = self.cast(value)
if transform not in self._valid_values:
raise ValueError((
'Value not in list: {!r}; valid values are {!r}'
).format(value, self._valid_values))
else:
return transform
+44
-6
Metadata-Version: 1.1
Name: python-decouple
Version: 3.3
Version: 3.4
Summary: Strict separation of settings from code.

@@ -29,6 +29,2 @@ Home-page: http://github.com/henriquebastos/python-decouple/

.. image:: https://landscape.io/github/henriquebastos/python-decouple/master/landscape.png
:target: https://landscape.io/github/henriquebastos/python-decouple/master
:alt: Code Health
.. image:: https://img.shields.io/pypi/v/python-decouple.svg

@@ -215,3 +211,3 @@ :target: https://pypi.python.org/pypi/python-decouple/

This *fail fast* policy helps you avoid chasing misbehaviors when you eventually forget a parameter.
This *fail fast* policy helps you avoid chasing misbehaviours when you eventually forget a parameter.

@@ -357,3 +353,45 @@ Overriding config files with environment variables

Built in Choices helper
~~~~~~~~~~~~~~~~~~~~~~~
Allows for cast and validation based on a list of choices. For example:
.. code-block:: python
>>> from decouple import config, Choices
>>> os.environ['CONNECTION_TYPE'] = 'usb'
>>> config('CONNECTION_TYPE', cast=Choices(['eth', 'usb', 'bluetooth']))
'usb'
>>> os.environ['CONNECTION_TYPE'] = 'serial'
>>> config('CONNECTION_TYPE', cast=Choices(['eth', 'usb', 'bluetooth']))
Traceback (most recent call last):
...
ValueError: Value not in list: 'serial'; valid values are ['eth', 'usb', 'bluetooth']
You can also parametrize *Choices helper* to cast to another type:
.. code-block:: python
>>> os.environ['SOME_NUMBER'] = '42'
>>> config('SOME_NUMBER', cast=Choices([7, 14, 42], cast=int))
42
You can also use a Django-like choices tuple:
.. code-block:: python
>>> USB = 'usb'
>>> ETH = 'eth'
>>> BLUETOOTH = 'bluetooth'
>>>
>>> CONNECTION_OPTIONS = (
... (USB, 'USB'),
... (ETH, 'Ethernet'),
... (BLUETOOTH, 'Bluetooth'),)
...
>>> os.environ['CONNECTION_TYPE'] = BLUETOOTH
>>> config('CONNECTION_TYPE', cast=Choices(choices=CONNECTION_OPTIONS))
'bluetooth'
Contribute

@@ -360,0 +398,0 @@ ==========

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

@@ -29,6 +29,2 @@ Home-page: http://github.com/henriquebastos/python-decouple/

.. image:: https://landscape.io/github/henriquebastos/python-decouple/master/landscape.png
:target: https://landscape.io/github/henriquebastos/python-decouple/master
:alt: Code Health
.. image:: https://img.shields.io/pypi/v/python-decouple.svg

@@ -215,3 +211,3 @@ :target: https://pypi.python.org/pypi/python-decouple/

This *fail fast* policy helps you avoid chasing misbehaviors when you eventually forget a parameter.
This *fail fast* policy helps you avoid chasing misbehaviours when you eventually forget a parameter.

@@ -357,3 +353,45 @@ Overriding config files with environment variables

Built in Choices helper
~~~~~~~~~~~~~~~~~~~~~~~
Allows for cast and validation based on a list of choices. For example:
.. code-block:: python
>>> from decouple import config, Choices
>>> os.environ['CONNECTION_TYPE'] = 'usb'
>>> config('CONNECTION_TYPE', cast=Choices(['eth', 'usb', 'bluetooth']))
'usb'
>>> os.environ['CONNECTION_TYPE'] = 'serial'
>>> config('CONNECTION_TYPE', cast=Choices(['eth', 'usb', 'bluetooth']))
Traceback (most recent call last):
...
ValueError: Value not in list: 'serial'; valid values are ['eth', 'usb', 'bluetooth']
You can also parametrize *Choices helper* to cast to another type:
.. code-block:: python
>>> os.environ['SOME_NUMBER'] = '42'
>>> config('SOME_NUMBER', cast=Choices([7, 14, 42], cast=int))
42
You can also use a Django-like choices tuple:
.. code-block:: python
>>> USB = 'usb'
>>> ETH = 'eth'
>>> BLUETOOTH = 'bluetooth'
>>>
>>> CONNECTION_OPTIONS = (
... (USB, 'USB'),
... (ETH, 'Ethernet'),
... (BLUETOOTH, 'Bluetooth'),)
...
>>> os.environ['CONNECTION_TYPE'] = BLUETOOTH
>>> config('CONNECTION_TYPE', cast=Choices(choices=CONNECTION_OPTIONS))
'bluetooth'
Contribute

@@ -360,0 +398,0 @@ ==========

@@ -21,6 +21,2 @@ Python Decouple: Strict separation of settings from code

.. image:: https://landscape.io/github/henriquebastos/python-decouple/master/landscape.png
:target: https://landscape.io/github/henriquebastos/python-decouple/master
:alt: Code Health
.. image:: https://img.shields.io/pypi/v/python-decouple.svg

@@ -207,3 +203,3 @@ :target: https://pypi.python.org/pypi/python-decouple/

This *fail fast* policy helps you avoid chasing misbehaviors when you eventually forget a parameter.
This *fail fast* policy helps you avoid chasing misbehaviours when you eventually forget a parameter.

@@ -349,3 +345,45 @@ Overriding config files with environment variables

Built in Choices helper
~~~~~~~~~~~~~~~~~~~~~~~
Allows for cast and validation based on a list of choices. For example:
.. code-block:: python
>>> from decouple import config, Choices
>>> os.environ['CONNECTION_TYPE'] = 'usb'
>>> config('CONNECTION_TYPE', cast=Choices(['eth', 'usb', 'bluetooth']))
'usb'
>>> os.environ['CONNECTION_TYPE'] = 'serial'
>>> config('CONNECTION_TYPE', cast=Choices(['eth', 'usb', 'bluetooth']))
Traceback (most recent call last):
...
ValueError: Value not in list: 'serial'; valid values are ['eth', 'usb', 'bluetooth']
You can also parametrize *Choices helper* to cast to another type:
.. code-block:: python
>>> os.environ['SOME_NUMBER'] = '42'
>>> config('SOME_NUMBER', cast=Choices([7, 14, 42], cast=int))
42
You can also use a Django-like choices tuple:
.. code-block:: python
>>> USB = 'usb'
>>> ETH = 'eth'
>>> BLUETOOTH = 'bluetooth'
>>>
>>> CONNECTION_OPTIONS = (
... (USB, 'USB'),
... (ETH, 'Ethernet'),
... (BLUETOOTH, 'Bluetooth'),)
...
>>> os.environ['CONNECTION_TYPE'] = BLUETOOTH
>>> config('CONNECTION_TYPE', cast=Choices(choices=CONNECTION_OPTIONS))
'bluetooth'
Contribute

@@ -352,0 +390,0 @@ ==========

+1
-1

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

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

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