[api] Make autocast API constistant, closes #248554
authorVincent Michel <vincent.michel@logilab.fr>
Wed, 21 May 2014 22:12:01 +0000
changeset 431 a458f2793377
parent 430 e8f0139b1984
child 438 5689a4cc4915
[api] Make autocast API constistant, closes #248554
test/test_dataio.py
utils/dataio.py
--- a/test/test_dataio.py	Thu Apr 24 16:58:32 2014 +0000
+++ b/test/test_dataio.py	Wed May 21 22:12:01 2014 +0000
@@ -109,7 +109,7 @@
                           [3, ('23', 2.17), u'cherry', u'flower']], data)
 
         data = parsefile(path.join(TESTDIR, 'data', 'file2parse'),
-                         [0, (2, 3), 4, 1], delimiter=',', use_autocast=False)
+                         [0, (2, 3), 4, 1], delimiter=',', autocast_data=False)
         self.assertEqual([['1', ('12', '19'), 'apple', 'house'],
                           ['2', ('21.9', '19'), 'stramberry', 'horse'],
                           ['3', ('23', '2.17'), 'cherry', 'flower']], data)
@@ -226,7 +226,7 @@
                                  ' ?ville db-prop:longitude ?long .'
                                  ' ?ville db-prop:latitude ?lat .'
                                  ' FILTER (?population > 1000)'
-                                 '} LIMIT 100', indexes=[0, 1, (2, 3)], autocaste_data=False)
+                                 '} LIMIT 100', indexes=[0, 1, (2, 3)], autocast_data=False)
         self.assertEqual(len(alignset), 100)
         self.assertFalse(isinstance(alignset[0][2][0], float))
 
--- a/utils/dataio.py	Thu Apr 24 16:58:32 2014 +0000
+++ b/utils/dataio.py	Wed May 21 22:12:01 2014 +0000
@@ -68,7 +68,7 @@
     req = cnx.request()
     return req
 
-def rqlquery(host, rql, indexes=None, formatopt=None, _cache_cnx={}, **kwargs):
+def rqlquery(host, rql, indexes=None, formatopt=None, autocast_data=True, _cache_cnx={}, **kwargs):
     """ Run the rql query on the given cubicweb host
     Additional arguments can be passed to be properly substitued
     in the execute() function for appid accces.
@@ -83,7 +83,7 @@
                                     % {'rql': rql, 'host': host})
         filehandle.readline()#Skip the first line
         return parsefile(filehandle, delimiter=';', indexes=indexes,
-                         formatopt=formatopt);
+                         formatopt=formatopt, autocast_data=autocast_data);
     else:
         # By appid
         if host in _cache_cnx:
@@ -120,7 +120,7 @@
         else:
             return []
 
-def sparqlquery(endpoint, query, indexes=None, autocaste_data=True, raise_on_error=False):
+def sparqlquery(endpoint, query, indexes=None, autocast_data=True, raise_on_error=False):
     """ Run the sparql query on the given endpoint, and wrap the items in the
     indexes form. If indexes is empty, keep raw output"""
     results = []
@@ -129,10 +129,10 @@
         return results
     labels = rawresults['head']['vars']
     indexes = indexes or []
-    if autocaste_data:
+    if autocast_data:
         transform = autocast
     else:
-        def transform(*args): return args
+        def transform(x): return x
     for raw in rawresults["results"]["bindings"]:
         data = []
         if not indexes:
@@ -177,7 +177,7 @@
 ###############################################################################
 def parsefile(filename, indexes=None, nbmax=None, delimiter='\t',
               encoding='utf-8', field_size_limit=None,
-              use_autocast=True, formatopt=None):
+              autocast_data=True, formatopt=None):
     """ Parse the file (read ``nbmax`` line at maximum if given). Each
         line is splitted according ``delimiter`` and only ``indexes`` are kept
 
@@ -218,7 +218,7 @@
 
 
     # Autocast if asked
-    if use_autocast:
+    if autocast_data:
         deffunc = lambda x: autocast(x, encoding)
     else:
         deffunc = lambda x: x