[sparql] improve error reporting and fix one bug stable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Tue, 01 Jun 2010 15:19:06 +0200
branchstable
changeset 5621 6f32f08d91f3
parent 5620 8bff6aae4623
child 5622 aa93a64c53d7
[sparql] improve error reporting and fix one bug
spa2rql.py
web/views/sparql.py
--- a/spa2rql.py	Tue Jun 01 14:26:50 2010 +0200
+++ b/spa2rql.py	Tue Jun 01 15:19:06 2010 +0200
@@ -75,7 +75,7 @@
             nbctypes = len(ctypes)
             ctypes &= varpossibletypes
             if not ctypes:
-                raise TypeResolverException()
+                raise TypeResolverException('No possible type')
             return len(ctypes) != nbctypes
         except KeyError:
             self.possible_types[var] = varpossibletypes
@@ -114,7 +114,7 @@
                                               if o == '*' or o in self.possible_types[objvar]]
                 # ensure this still make sense
                 if not yams_predicates:
-                    raise TypeResolverException()
+                    raise TypeResolverException('No yams predicate')
                 if len(yams_predicates) != nbchoices:
                     modified = True
 
--- a/web/views/sparql.py	Tue Jun 01 14:26:50 2010 +0200
+++ b/web/views/sparql.py	Tue Jun 01 15:19:06 2010 +0200
@@ -20,8 +20,8 @@
 """
 __docformat__ = "restructuredtext en"
 
-import rql
 from yams import xy
+from rql import TypeResolverException
 
 from lxml import etree
 from lxml.builder import E
@@ -51,25 +51,25 @@
 class SparqlFormView(form.FormViewMixIn, StartupView):
     __regid__ = 'sparql'
     def call(self):
-        form = self._cw.vreg.select('forms', 'sparql', self._cw)
+        form = self._cw.vreg['forms'].select('sparql', self._cw)
         self.w(form.render())
         sparql = self._cw.form.get('sparql')
         vid = self._cw.form.get('resultvid', 'table')
         if sparql:
             try:
                 qinfo = Sparql2rqlTranslator(self._cw.vreg.schema).translate(sparql)
-            except rql.TypeResolverException:
-                self.w(self._cw._('can not resolve entity types:') + u' ' + unicode('ex'))
+            except TypeResolverException, exc:
+                self.w(self._cw._('can not resolve entity types:') + u' ' + unicode(exc))
             except UnsupportedQuery:
                 self.w(self._cw._('we are not yet ready to handle this query'))
-            except xy.UnsupportedVocabulary, ex:
-                self.w(self._cw._('unknown vocabulary:') + u' ' + unicode('ex'))
+            except xy.UnsupportedVocabulary, exc:
+                self.w(self._cw._('unknown vocabulary:') + u' ' + unicode(exc))
             else:
+                rql, args = qinfo.finalize()
                 if vid == 'sparqlxml':
-                    url = self._cw.build_url('view', rql=qinfo.finalize(), vid=vid)
+                    url = self._cw.build_url('view', rql=(rql,args), vid=vid)
                     raise Redirect(url)
-                print qinfo.finalize()
-                rset = self._cw.execute(*qinfo.finalize())
+                rset = self._cw.execute(rql, args)
                 self.wview(vid, rset, 'null')