annotate scripts/safety.py @ 0:1b0f96ed73f2 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
author iuc
date Sat, 17 Aug 2019 16:25:37 -0400
parents
children dddadbbac949
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
1 import re
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
2
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
3
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
4 class Safety():
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
5 """
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
6 Class to safely evaluate mathematical expression on single
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
7 or table data
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
8 """
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
9
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
10 __allowed_tokens = (
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
11 '(', ')', 'if', 'else', 'or', 'and', 'not', 'in',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
12 '+', '-', '*', '/', '%', ',', '!=', '==', '>', '>=', '<', '<=',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
13 'min', 'max', 'sum',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
14 )
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
15 __allowed_ref_types = {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
16 'pd.DataFrame': {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
17 'abs', 'add', 'agg', 'aggregate', 'align', 'all', 'any', 'append',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
18 'apply', 'applymap', 'as_matrix', 'asfreq', 'at', 'axes', 'bool',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
19 'clip', 'clip_lower', 'clip_upper', 'columns', 'combine',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
20 'compound', 'corr', 'count', 'cov', 'cummax', 'cummin', 'cumprod',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
21 'cumsum', 'describe', 'div', 'divide', 'dot', 'drop',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
22 'drop_duplicates', 'droplevel', 'dropna', 'duplicated', 'empty',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
23 'eq', 'equals', 'expanding', 'ffill', 'fillna', 'filter', 'first',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
24 'first_valid_index', 'floordiv', 'ge', 'groupby', 'gt', 'head',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
25 'iat', 'iloc', 'index', 'insert', 'interpolate', 'isin', 'isna',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
26 'isnull', 'items', 'iteritems', 'iterrows', 'itertuples', 'ix',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
27 'join', 'keys', 'kurt', 'kurtosis', 'last', 'last_valid_index',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
28 'le', 'loc', 'lookup', 'lt', 'mad', 'mask', 'max', 'mean',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
29 'median', 'melt', 'merge', 'min', 'mod', 'mode', 'mul', 'multiply',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
30 'ndim', 'ne', 'nlargest', 'notna', 'notnull', 'nsmallest',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
31 'nunique', 'pct_change', 'pivot', 'pivot_table', 'pop', 'pow',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
32 'prod', 'product', 'quantile', 'radd', 'rank', 'rdiv', 'replace',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
33 'resample', 'rfloordiv', 'rmod', 'rmul', 'rolling', 'round',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
34 'rpow', 'rsub', 'rtruediv', 'sample', 'select',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
35 'sem', 'shape', 'shift', 'size', 'skew', 'slice_shift',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
36 'squeeze', 'stack', 'std', 'sub', 'subtract', 'sum', 'swapaxes',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
37 'swaplevel', 'T', 'tail', 'take', 'transform', 'transpose',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
38 'truediv', 'truncate', 'tshift', 'unstack', 'var', 'where',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
39 },
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
40 'pd.Series': {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
41 'abs', 'add', 'agg', 'aggregate', 'align', 'all', 'any', 'append',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
42 'apply', 'argsort', 'as_matrix', 'asfreq', 'asof', 'astype', 'at',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
43 'at_time', 'autocorr', 'axes', 'between', 'between_time', 'bfill',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
44 'bool', 'cat', 'clip', 'clip_lower', 'clip_upper', 'combine',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
45 'combine_first', 'compound', 'corr', 'count', 'cov', 'cummax',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
46 'cummin', 'cumprod', 'cumsum', 'describe', 'diff', 'div', 'divide',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
47 'divmod', 'dot', 'drop', 'drop_duplicates', 'droplevel', 'dropna',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
48 'dt', 'dtype', 'dtypes', 'duplicated', 'empty', 'eq', 'equals',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
49 'ewm', 'expanding', 'factorize', 'ffill', 'fillna', 'filter',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
50 'first', 'first_valid_index', 'flags', 'floordiv', 'ge', 'groupby',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
51 'gt', 'hasnans', 'head', 'iat', 'idxmax', 'idxmin', 'iloc', 'imag',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
52 'index', 'interpolate', 'is_monotonic', 'is_monotonic_decreasing',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
53 'is_monotonic_increasing', 'is_unique', 'isin', 'isna', 'isnull',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
54 'item', 'items', 'iteritems', 'ix', 'keys', 'kurt', 'kurtosis',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
55 'last', 'last_valid_index', 'le', 'loc', 'lt', 'mad', 'map',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
56 'mask', 'max', 'mean', 'median', 'min', 'mod', 'mode', 'mul',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
57 'multiply', 'name', 'ndim', 'ne', 'nlargest', 'nonzero', 'notna',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
58 'notnull', 'nsmallest', 'nunique', 'pct_change', 'pop', 'pow',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
59 'prod', 'product', 'ptp', 'quantile', 'radd', 'rank', 'rdiv',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
60 'rdivmod', 'real', 'repeat', 'replace', 'resample', 'rfloordiv',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
61 'rmod', 'rmul', 'rolling', 'round', 'rpow', 'rsub', 'rtruediv',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
62 'sample', 'searchsorted', 'select', 'sem', 'shape', 'shift',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
63 'size', 'skew', 'slice_shift', 'sort_index', 'sort_values',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
64 'squeeze', 'std', 'sub', 'subtract', 'sum', 'swapaxes',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
65 'swaplevel', 'T', 'tail', 'take', 'transform', 'transpose',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
66 'truediv', 'truncate', 'tshift', 'unique', 'unstack',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
67 'value_counts', 'var', 'where', 'xs',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
68 },
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
69 }
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
70
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
71 __allowed_qualified = {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
72 # allowed numpy functionality
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
73 'np': {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
74 'abs', 'add', 'all', 'any', 'append', 'array', 'bool', 'ceil',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
75 'complex', 'cos', 'cosh', 'cov', 'cumprod', 'cumsum', 'degrees',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
76 'divide', 'divmod', 'dot', 'e', 'empty', 'exp', 'float', 'floor',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
77 'hypot', 'inf', 'int', 'isfinite', 'isin', 'isinf', 'isnan', 'log',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
78 'log10', 'log2', 'max', 'mean', 'median', 'min', 'mod', 'multiply',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
79 'nan', 'ndim', 'pi', 'product', 'quantile', 'radians', 'rank',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
80 'remainder', 'round', 'sin', 'sinh', 'size', 'sqrt', 'squeeze',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
81 'stack', 'std', 'str', 'subtract', 'sum', 'swapaxes', 'take',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
82 'tan', 'tanh', 'transpose', 'unique', 'var', 'where',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
83 },
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
84 # allowed math functionality
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
85 'math': {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
86 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
87 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
88 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
89 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
90 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
91 'modf', 'nan', 'pi', 'pow', 'radians', 'remainder', 'sin', 'sinh',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
92 'sqrt', 'tan', 'tanh', 'tau', 'trunc',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
93 },
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
94 # allowed pd functionality
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
95 'pd': {
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
96 'DataFrame', 'array', 'concat', 'cut', 'date_range', 'factorize',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
97 'interval_range', 'isna', 'isnull', 'melt', 'merge', 'notna',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
98 'notnull', 'period_range', 'pivot', 'pivot_table', 'unique',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
99 'value_counts', 'wide_to_long',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
100 },
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
101 }
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
102
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
103 def __init__(self, expression,
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
104 ref_whitelist=None, ref_type=None,
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
105 custom_qualified=None):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
106 self.allowed_qualified = self.__allowed_qualified.copy()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
107 if ref_whitelist is None:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
108 self.these = []
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
109 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
110 self.these = ref_whitelist
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
111 if ref_type is None or ref_type not in self.__allowed_ref_types:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
112 self.allowed_qualified['_this'] = set()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
113 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
114 self.allowed_qualified[
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
115 '_this'
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
116 ] = self.__allowed_ref_types[ref_type]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
117 if custom_qualified is not None:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
118 self.allowed_qualified.update(custom_qualified)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
119 self.expr = expression
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
120 self.__assertSafe()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
121
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
122 def generateFunction(self):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
123 "Generates a function to be evaluated outside the class"
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
124 cust_fun = "def fun(%s):\n\treturn(%s)" % (self.these[0], self.expr)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
125 return cust_fun
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
126
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
127 def __assertSafe(self):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
128 indeed, problematic_token = self.__isSafeStatement()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
129 if not indeed:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
130 self.detailedExcuse(problematic_token)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
131 raise ValueError("Custom Expression is not safe.")
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
132
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
133 @staticmethod
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
134 def detailedExcuse(word):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
135 "Gives a verbose statement for why users should not use some specific operators."
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
136 mess = None
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
137 if word == "for":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
138 mess = "for loops and comprehensions are not allowed. Use numpy or pandas table operations instead."
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
139 elif word == ":":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
140 mess = "Colons are not allowed. Use inline Python if/else statements."
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
141 elif word == "=":
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
142 mess = "Variable assignment is not allowed. Use object methods to substitute values."
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
143 elif word in ("[", "]"):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
144 mess = "Direct indexing of arrays is not allowed. Use numpy or pandas functions/methods to address specific parts of tables."
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
145 else:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
146 mess = "Not an allowed token in this operation"
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
147 print("( '%s' ) %s" % (word, mess))
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
148
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
149 def __isSafeStatement(self):
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
150 """
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
151 Determines if a user-expression is safe to evaluate.
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
152
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
153 To be considered safe an expression may contain only:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
154 - standard Python operators and numbers
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
155 - inline conditional expressions
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
156 - select functions and objects
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
157 by default, these come from the math, numpy and pandas
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
158 libraries, and must be qualified with the modules' conventional
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
159 names math, np, pd; can be overridden at the instance level
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
160 - references to a whitelist of objects (pd.DataFrames by default)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
161 and their methods
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
162 """
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
163
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
164 safe = True
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
165 # examples of user-expressions
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
166 # '-math.log(1 - elem/4096) * 4096 if elem != bn else elem - 0.5'
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
167 # 'vec.median() + vec.sum()'
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
168
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
169 # 1. Break expressions into tokens
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
170 # e.g.,
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
171 # [
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
172 # '-', 'math.log', '(', '1', '-', 'elem', '/', '4096', ')', '*',
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
173 # '4096', 'if', 'elem', '!=', 'bn', 'else', 'elem', '-', '0.5'
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
174 # ]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
175 # or
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
176 # ['vec.median', '(', ')', '+', 'vec.sum', '(', ')']
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
177 tokens = [
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
178 e for e in re.split(
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
179 r'([a-zA-Z0-9_.]+|[^a-zA-Z0-9_.() ]+|[()])', self.expr
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
180 ) if e.strip()
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
181 ]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
182
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
183 # 2. Subtract allowed standard tokens
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
184 rem = [e for e in tokens if e not in self.__allowed_tokens]
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
185
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
186 # 3. Subtract allowed qualified objects from allowed modules
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
187 # and whitelisted references and their attributes
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
188 rem2 = []
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
189 for e in rem:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
190 parts = e.split('.')
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
191 if len(parts) == 1:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
192 if parts[0] in self.these:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
193 continue
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
194 if len(parts) == 2:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
195 if parts[0] in self.these:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
196 parts[0] = '_this'
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
197 if parts[0] in self.allowed_qualified:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
198 if parts[1] in self.allowed_qualified[parts[0]]:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
199 continue
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
200 rem2.append(e)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
201
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
202 # 4. Assert that rest are real numbers
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
203 e = ''
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
204 for e in rem2:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
205 try:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
206 _ = float(e)
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
207 except ValueError:
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
208 safe = False
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
209 break
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
210
1b0f96ed73f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/table_compute commit 1ee75135483d5db22c540bc043746cd986f85762"
iuc
parents:
diff changeset
211 return safe, e