[Python-modules-commits] [python-pyld] 09/276: Simplified framing default option handling.

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 217d851058210466e19c34b580bd2e6161ddd607
Author: Dave Longley <dlongley at digitalbazaar.com>
Date:   Fri Jul 29 15:34:39 2011 -0400

    Simplified framing default option handling.
---
 lib/pyld/jsonld.py | 32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index fb63703..52ca4a8 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -1522,9 +1522,7 @@ def _frame(subjects, input, frame, embeds, options):
                 explicitOn = (frame['@explicit'] if '@explicit' in frame
                     else options['defaults']['explicitOn'])
                 if explicitOn:
-                    # FIXME: check this
-                    # python - iterate over copy of list to remove key
-                    for key in list(value):
+                    for key in value.keys():
                         # do not remove subject or any key in the frame
                         if key != _s and key not in frame:
                             del value[key]
@@ -1556,11 +1554,11 @@ def _frame(subjects, input, frame, embeds, options):
                                     value[key] = (f['@default'] if
                                         '@default' in f else None)
                         else:
-                            # add None property to value
-                            value[key] = None
+                            # add empty array/null property to value
+                            value[key] = [] if isinstance(f, list) else None
                         
-                        # handle setting default value(s)
-                        if key in value:
+                        # handle setting default value
+                        if value[key] is None:
                             # use first subframe if frame is an array
                             if isinstance(f, list):
                                 f = f[0] if len(f) > 0 else {}
@@ -1569,22 +1567,10 @@ def _frame(subjects, input, frame, embeds, options):
                             omitOn = (f['@omitDefault'] if
                                 '@omitDefault' in f
                                 else options['defaults']['omitDefaultOn']);
-                            
-                            if value[key] is None:
-                                if omitOn:
-                                    del value[key]
-                                elif '@default' in f:
-                                    value[key] = f['@default']
-                            elif isinstance(value[key], list):
-                                tmp = []
-                                for v in value[key]:
-                                    if v is None:
-                                        # do not auto-include null in arrays
-                                        if not omitOn and '@default' in f:
-                                            tmp.append(f['@default'])
-                                    else:
-                                        tmp.append(v)
-                                value[key] = tmp
+                            if omitOn:
+                                del value[key]
+                            elif '@default' in f:
+                                value[key] = f['@default']
 
             # add value to output
             if rval is None:

-- 
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