[PATCH 1 of 1 skos V2] [rdf] Don't propagate exception if language isn't accepted by rdflib

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Feb 24 16:45:17 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1485776389 -3600
#      Mon Jan 30 12:39:49 2017 +0100
# Node ID 3f2be8f07627ccc45a4441d3e9ecaea79240bbc2
# Parent  bed11030cfaa202ce2d99f2af7f8ea7a2933e719
[rdf] Don't propagate exception if language isn't accepted by rdflib

diff --git a/rdfio.py b/rdfio.py
--- a/rdfio.py
+++ b/rdfio.py
@@ -256,11 +256,17 @@ class AbstractRDFGraph(object):
         """
         assert isinstance(subj, self.uri)
         assert isinstance(predicate, self.uri)
         if not isinstance(obj, self.uri):
             if isinstance(obj, unicode_with_language):
-                obj = self._literal(text_type(obj), lang=obj.lang)
+                try:
+                    obj = self._literal(text_type(obj), lang=obj.lang)
+                # an exception may be raised if the library doesn't like specified
+                # language (e.g. rdflib check them using a regexp), but we don't
+                # know at this point which kind of exception so catch Exception
+                except Exception:
+                    obj = self._literal(obj)
             else:
                 obj = self._literal(obj)
         self._add(subj, predicate, obj)
 
     def _add(self, subj, predicate, obj):


More information about the saem-devel mailing list