[Python-modules-commits] [python-pyld] 06/276: Removed nulls in flatten.
Wolfgang Borgert
debacle at moszumanska.debian.org
Wed Oct 8 23:47:48 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to branch master
in repository python-pyld.
commit 0b8d65f29b92f025be7b5257fc18c0ca1cdc1dbf
Author: Dave Longley <dlongley at digitalbazaar.com>
Date: Fri Jul 29 11:46:12 2011 -0400
Removed nulls in flatten.
---
lib/pyld/jsonld.py | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index 8f17a2c..0d886b5 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -342,9 +342,12 @@ def _expand(ctx, property, value, expandSubjects):
# TODO: add data format error detection?
+ # value is null, nothing to expand
+ if value is None:
+ rval = None
# if no property is specified and the value is a string (this means the
# value is a property itself), expand to an IRI
- if property is None and isinstance(value, (str, unicode)):
+ elif property is None and isinstance(value, (str, unicode)):
rval = _expandTerm(ctx, value, None)
elif isinstance(value, list):
# recursively add expanded values to array
@@ -589,7 +592,10 @@ class NameGenerator:
# @param subjects the subjects map to populate.
# @param bnodes the bnodes array to populate.
def _collectSubjects(input, subjects, bnodes):
- if isinstance(input, list):
+ if input is None:
+ # nothing to collect
+ pass
+ elif isinstance(input, list):
for i in input:
_collectSubjects(i, subjects, bnodes)
elif isinstance(input, dict):
@@ -653,16 +659,17 @@ def _flatten(parent, parentProperty, value, subjects):
flattened = subject
# flatten embeds
- for key in value:
- if isinstance(value[key], list):
- subject[key] = []
- _flatten(subject[key], None, value[key], subjects)
- if len(subject[key]) == 1:
- # convert subject[key] to object if only 1 value was
- # added
- subject[key] = subject[key][0]
- else:
- _flatten(subject, key, value[key], subjects)
+ for key,v in value.items():
+ # drop null values
+ if v is not None:
+ if isinstance(v, list):
+ subject[key] = []
+ _flatten(subject[key], None, v, subjects)
+ if len(subject[key]) == 1:
+ # convert subject[key] to object if it has only 1
+ subject[key] = subject[key][0]
+ else:
+ _flatten(subject, key, v, subjects)
# string value
else:
flattened = value
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pyld.git
More information about the Python-modules-commits
mailing list