[dataimport] Handle various data formats when creating buffers from data.
authorVladimir Popescu <vladimir.popescu@logilab.fr>
Tue, 02 Apr 2013 12:04:22 +0200
changeset 8834 6947201033be
parent 8833 39f81e2db2fc
child 8835 3612b760488b
[dataimport] Handle various data formats when creating buffers from data. :note: On the long run, this should be addressed before, when these data are created.
dataimport.py
--- a/dataimport.py	Tue Apr 02 12:12:41 2013 +0200
+++ b/dataimport.py	Tue Apr 02 12:04:22 2013 +0200
@@ -431,7 +431,14 @@
         # If an error is raised, do not continue.
         formatted_row = []
         for col in columns:
-            value = row[col]
+            if isinstance(row, dict):
+                value = row.get(col)
+            elif isinstance(row, (tuple, list)):
+                value = row[col]
+            else:
+                raise ValueError("Input data of improper type: %s; "
+                                 "expected tuple, list or dict." 
+                                 % type(row).__name__)
             if value is None:
                 value = 'NULL'
             elif isinstance(value, (long, int, float)):