-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #366 from oddstr13/pr-json-filter-1
Filter keys containing None values from dictionaries returned from the server
- Loading branch information
Showing
20 changed files
with
214 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,72 @@ | ||
*.pyo | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
|
||
|
||
__local__/ | ||
machine_guid | ||
/resources/media/Thumbs.db | ||
Thumbs.db | ||
|
||
.idea/ | ||
.DS_Store | ||
.vscode/ | ||
pyinstrument/ | ||
pyinstrument_cext.so | ||
|
||
# Now managed by templates | ||
addon.xml | ||
|
||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from six import string_types | ||
from six.moves import collections_abc | ||
|
||
|
||
def clean_none_dict_values(obj): | ||
""" | ||
Recursively remove keys with a value of None | ||
""" | ||
if not isinstance(obj, collections_abc.Iterable) or isinstance(obj, string_types): | ||
return obj | ||
|
||
queue = [obj] | ||
|
||
while queue: | ||
item = queue.pop() | ||
|
||
if isinstance(item, collections_abc.Mapping): | ||
mutable = isinstance(item, collections_abc.MutableMapping) | ||
remove = [] | ||
|
||
for key, value in item.items(): | ||
if value is None and mutable: | ||
remove.append(key) | ||
|
||
elif isinstance(value, string_types): | ||
continue | ||
|
||
elif isinstance(value, collections_abc.Iterable): | ||
queue.append(value) | ||
|
||
if mutable: | ||
# Remove keys with None value | ||
for key in remove: | ||
item.pop(key) | ||
|
||
elif isinstance(item, collections_abc.Iterable): | ||
for value in item: | ||
if value is None or isinstance(value, string_types): | ||
continue | ||
elif isinstance(value, collections_abc.Iterable): | ||
queue.append(value) | ||
|
||
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
setuptools >= 44.1.1 # Old setuptools causes script.module.addon.signals to fail installing | ||
six >= 1.13 | ||
python-dateutil >= 2.8.1 | ||
requests >= 2.22 | ||
futures >= 2.2; python_version < '3.0' | ||
git+https://github.com/oddstr13/Kodistubs@python3 # Kodistubs >= 18 | ||
git+https://github.com/romanvm/kodi.six | ||
git+https://github.com/ruuk/script.module.addon.signals | ||
|
||
pytest >= 4.6.11 | ||
coverage >= 5.2 | ||
flake8 >= 3.8 | ||
flake8-import-order >= 0.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import sys | ||
|
||
import pytest | ||
|
||
sys.path.insert(0, 'jellyfin_kodi') | ||
|
||
from jellyfin.utils import clean_none_dict_values # noqa: E402 | ||
|
||
|
||
@pytest.mark.parametrize("obj,expected", [ | ||
(None, None), | ||
([None, 1, 2, 3, None, 4], [None, 1, 2, 3, None, 4]), | ||
({'foo': None, 'bar': 123}, {'bar': 123}), | ||
({ | ||
'dict': { | ||
'empty': None, | ||
'string': "Hello, Woorld!", | ||
}, | ||
'number': 123, | ||
'list': [ | ||
None, | ||
123, | ||
"foo", | ||
{ | ||
'empty': None, | ||
'number': 123, | ||
'string': "foo", | ||
'list': [], | ||
'dict': {}, | ||
} | ||
] | ||
}, { | ||
'dict': { | ||
'string': "Hello, Woorld!", | ||
}, | ||
'number': 123, | ||
'list': [ | ||
None, | ||
123, | ||
"foo", | ||
{ | ||
'number': 123, | ||
'string': "foo", | ||
'list': [], | ||
'dict': {}, | ||
} | ||
] | ||
}), | ||
]) | ||
def test_clean_none_dict_values(obj, expected): | ||
assert clean_none_dict_values(obj) == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters