3 This file holds decorator functions that can rearrange data returned from data sources. 4 They should be used to decorate the method that holds the script that is being passed to the framework. 6 Note: may also contain a decorator that can wrap a class around a function that contains a script (future development). 10 from data_sources
import json_data_node, json_list, json_dict, json_basic
18 def new_script(self, connection):
20 data = script(self, connection)
22 return json_data_node.make(array_of_dicts)
23 except (KeyError, TypeError)
as e:
24 raise Exception(
"The data you gave wasn't in the correct format: %s" %
str(e))
29 def new_script(self, connection):
31 data = script(self, connection)
32 if(isinstance(data, list)):
33 data = _json_data_node.make(data)
35 except (KeyError, TypeError)
as e:
36 raise Exception(
"The data you gave wasn't in the correct format: %s" %
str(e))
40 def new_script(self, connection):
42 data = script(self, connection)
43 return _to_sql_query(data)
44 except (KeyError, TypeError)
as e:
45 raise Exception(
"The data you gave wasn't in the correct format: %s" %
str(e))
49 def new_script(self, connection):
51 data = script(self, connection)
53 except (KeyError, TypeError)
as e:
54 raise Exception(
"The data you gave wasn't in the correct format: %s" %
str(e))
61 if not(data.__class__.__name__
in [
"json_list",
"json_dict",
"json_basic"]):
62 data = json_data_node.make(data)
63 headers = data.get(
"headers").
data()
64 data_list = data.get(
"data").
data()
65 def unicode_to_str(string):
66 return str(string)
if isinstance(string, unicode)
else string
67 headers =
map(unicode_to_str, headers)
69 row =
map(unicode_to_str, row)
71 array_of_dicts =
map(row_to_dict, data_list)
72 return json_data_node.make(array_of_dicts)
77 for n
in range(0, len(data.data())):
78 new_data.append(
map(
lambda entry :
str(entry)
if isinstance(entry, unicode)
else entry, data.get(n).
data().
values()))
79 return json_data_node.make({
90 def apply_function_to_key(row):
93 new_data = [apply_function_to_key(data[n])
for n
in range(0, len(data))]
97 if data.__class__.__name__
in [
"json_list",
"json_dict",
"json_basic"]:
99 new_data = [data[n].as_dicts()
for n
in range(0, len(data))]
100 return json_data_node.make(new_data)
103 if data.__class__.__name__
in [
"json_list",
"json_dict",
"json_basic"]:
105 new_data = [model(data[n])
for n
in range(0, len(data))]
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
char data[epos_bytes_allocation]