[Python-modules-commits] [python-pyld] 43/276: Remove dependent dangling embeds.

Wolfgang Borgert debacle at moszumanska.debian.org
Wed Oct 8 23:47:52 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 93af469665b661230e22d1edec88f9817715d2c3
Author: Dave Longley <dlongley at digitalbazaar.com>
Date:   Mon Nov 28 22:55:20 2011 -0500

    Remove dependent dangling embeds.
---
 lib/pyld/jsonld.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index c263c47..c549c52 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -1533,6 +1533,20 @@ def _isDuckType(src, frame):
 
     return rval
 
+def _removeDependentEmbeds(iri, embeds):
+    """
+    Recursively removes dependent dangling embeds.
+    
+    :param iri: the iri of the parent to remove the embeds for.
+    :param embeds: the embed map.
+    """
+    iris = embeds.keys()
+    for i in iris:
+        if (i in embeds and embeds[i]['parent'] is not None and
+            embeds[i]['parent']['@subject']['@iri'] == iri):
+            del embeds[i]
+            _removeDependentEmbeds(i, embeds)
+
 def _subframe(
    subjects, value, frame, embeds, autoembed, parent, parentKey, options):
     """
@@ -1577,6 +1591,7 @@ def _subframe(
         elif embed['parent'] is not None:
             objs = embed['parent'][embed['key']]
             if isinstance(objs, list):
+                # find and replace embed in array
                 for i in range(0, len(objs)):
                     if (isinstance(objs[i], dict) and '@subject' in objs[i] and
                         objs[i]['@subject']['@iri'] == iri):
@@ -1585,6 +1600,9 @@ def _subframe(
             else:
                 embed['parent'][embed['key']] = value['@subject']
 
+            # recursively remove any dependent dangling embeds
+            _removeDependentEmbeds(iri, embeds)
+
         # update embed entry
         embed['autoembed'] = autoembed
         embed['parent'] = parent

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