sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'toposort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'pick_first'},{'id': '7', 'type': 'string', 'children': [], 'value': "'head'"},{'id': '8', 'type': 'block', 'children': ['9', '13', '54', '59', '63', '69', '155', '173']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'in_deg'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'for_statement', 'children': ['14', '17', '23']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'next_nodes'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '33']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '26', 'type': 'list', 'children': ['27', '30'], 'value': '[next_nodes.head_node, next_nodes.update_node]'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'next_nodes'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'head_node'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'next_nodes'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'update_node'},{'id': '33', 'type': 'block', 'children': ['34', '40']},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'continue_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'in_deg'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '53'], 'value': '+'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'in_deg'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'integer', 'children': [], 'value': '1'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'stk'},{'id': '57', 'type': 'list', 'children': ['58'], 'value': '[FIRST]'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'FIRST'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '62', 'type': 'list', 'children': [], 'value': '[]'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'while_statement', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'stk'},{'id': '71', 'type': 'block', 'children': ['72', '80', '87', '99', '115']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'stk'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '87', 'type': 'if_statement', 'children': ['88', '91']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '!='},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'FIRST'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_get_traversal'},{'id': '104', 'type': 'argument_list', 'children': ['105', '114']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'BeforeNodes'},{'id': '113', 'type': 'argument_list', 'children': []},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'pick_first'},{'id': '115', 'type': 'for_statement', 'children': ['116', '117', '118']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'traversal'},{'id': '118', 'type': 'block', 'children': ['119', '125', '135', '141']},{'id': '119', 'type': 'if_statement', 'children': ['120', '123']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'is'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '122', 'type': 'None', 'children': []},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'continue_statement', 'children': []},{'id': '125', 'type': 'if_statement', 'children': ['126', '129']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'in'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'raise_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'string', 'children': [], 'value': "'Graph has a cycle'"},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'augmented_assignment', 'children': ['137', '140'], 'value': '-='},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'in_deg'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'if_statement', 'children': ['142', '147']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '146'], 'value': '=='},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'in_deg'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'stk'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'next_node'},{'id': '155', 'type': 'if_statement', 'children': ['156', '167']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '161'], 'value': '!='},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '161', 'type': 'binary_operator', 'children': ['162', '166'], 'value': '-'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'raise_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'string', 'children': [], 'value': "'Graph has a cycle'"},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ordered'}
def toposort(graph, pick_first='head'): in_deg = {} for node, next_nodes in six.iteritems(graph): for next_node in [next_nodes.head_node, next_nodes.update_node]: if next_node is None: continue in_deg[next_node] = in_deg.get(next_node, 0) + 1 stk = [FIRST] ordered = [] visited = set() while stk: node = stk.pop() visited.add(node) if node != FIRST: ordered.append(node) traversal = _get_traversal(graph.get(node, BeforeNodes()), pick_first) for next_node in traversal: if next_node is None: continue if next_node in visited: raise ValueError('Graph has a cycle') in_deg[next_node] -= 1 if in_deg[next_node] == 0: stk.append(next_node) if len(ordered) != len(graph) - 1: raise ValueError('Graph has a cycle') return ordered
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_cyclic_graph_best_effort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'pick_first'},{'id': '7', 'type': 'string', 'children': [], 'value': "'head'"},{'id': '8', 'type': 'block', 'children': ['9', '13', '19', '42', '46', '84', '88', '126']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'if_statement', 'children': ['20', '23', '32']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '=='},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'pick_first'},{'id': '22', 'type': 'string', 'children': [], 'value': "'head'"},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fst_attr'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'snd_attr'},{'id': '29', 'type': 'tuple', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'head_node'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'update_node'"},{'id': '32', 'type': 'else_clause', 'children': ['33']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fst_attr'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'snd_attr'},{'id': '39', 'type': 'tuple', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': "'update_node'"},{'id': '41', 'type': 'string', 'children': [], 'value': "'head_node'"},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'FIRST'},{'id': '46', 'type': 'while_statement', 'children': ['47', '50']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'block', 'children': ['51', '58', '68']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '63', 'type': 'argument_list', 'children': ['64', '67']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'fst_attr'},{'id': '68', 'type': 'if_statement', 'children': ['69', '76']},{'id': '69', 'type': 'boolean_operator', 'children': ['70', '73'], 'value': 'and'},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'not'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'FIRST'},{'id': '88', 'type': 'while_statement', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '91', 'type': 'None', 'children': []},{'id': '92', 'type': 'block', 'children': ['93', '100', '110']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '105', 'type': 'argument_list', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'snd_attr'},{'id': '110', 'type': 'if_statement', 'children': ['111', '118']},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '115'], 'value': 'and'},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'not'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'visited'},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ordered'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ordered'}
def sort_cyclic_graph_best_effort(graph, pick_first='head'): ordered = [] visited = set() if pick_first == 'head': fst_attr, snd_attr = ('head_node', 'update_node') else: fst_attr, snd_attr = ('update_node', 'head_node') current = FIRST while current is not None: visited.add(current) current = getattr(graph[current], fst_attr) if current not in visited and current is not None: ordered.append(current) current = FIRST while current is not None: visited.add(current) current = getattr(graph[current], snd_attr) if current not in visited and current is not None: ordered.append(current) return ordered
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'circlescan'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'r2'},{'id': '8', 'type': 'block', 'children': ['9', '19', '29', '33', '43']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '<'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '12', 'type': 'integer', 'children': [], 'value': '0'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'raise_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': '"Initial radius must be non-negative"'},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '<'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'r2'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'raise_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '"Final radius must be non-negative"'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '32', 'type': 'list', 'children': [], 'value': '[]'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'rstep'},{'id': '36', 'type': 'conditional_expression', 'children': ['37', '38', '41'], 'value': 'if'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '>='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'r2'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '41', 'type': 'unary_operator', 'children': ['42'], 'value': '-'},{'id': '42', 'type': 'integer', 'children': [], 'value': '1'},{'id': '43', 'type': 'for_statement', 'children': ['44', '45', '53']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49', '52']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'r2'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'rstep'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'rstep'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'if_statement', 'children': ['55', '58', '64']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'yield', 'children': ['61']},{'id': '61', 'type': 'expression_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '64', 'type': 'else_clause', 'children': ['65']},{'id': '65', 'type': 'block', 'children': ['66', '70', '158', '165', '169', '321']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '69', 'type': 'float', 'children': [], 'value': '0.707107'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'rotations'},{'id': '73', 'type': 'dictionary', 'children': ['74', '83', '93', '103', '115', '126', '138', '148']},{'id': '74', 'type': 'pair', 'children': ['75', '76']},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'list', 'children': ['77', '80'], 'value': '[[ 1, 0], [ 0, 1]]'},{'id': '77', 'type': 'list', 'children': ['78', '79'], 'value': '[ 1, 0]'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'list', 'children': ['81', '82'], 'value': '[ 0, 1]'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'list', 'children': ['86', '89'], 'value': '[[ a, a], [-a, a]]'},{'id': '86', 'type': 'list', 'children': ['87', '88'], 'value': '[ a, a]'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '89', 'type': 'list', 'children': ['90', '92'], 'value': '[-a, a]'},{'id': '90', 'type': 'unary_operator', 'children': ['91'], 'value': '-'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '93', 'type': 'pair', 'children': ['94', '95']},{'id': '94', 'type': 'integer', 'children': [], 'value': '2'},{'id': '95', 'type': 'list', 'children': ['96', '99'], 'value': '[[ 0, 1], [-1, 0]]'},{'id': '96', 'type': 'list', 'children': ['97', '98'], 'value': '[ 0, 1]'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'list', 'children': ['100', '102'], 'value': '[-1, 0]'},{'id': '100', 'type': 'unary_operator', 'children': ['101'], 'value': '-'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'pair', 'children': ['104', '105']},{'id': '104', 'type': 'integer', 'children': [], 'value': '3'},{'id': '105', 'type': 'list', 'children': ['106', '110'], 'value': '[[-a, a], [-a,-a]]'},{'id': '106', 'type': 'list', 'children': ['107', '109'], 'value': '[-a, a]'},{'id': '107', 'type': 'unary_operator', 'children': ['108'], 'value': '-'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '110', 'type': 'list', 'children': ['111', '113'], 'value': '[-a,-a]'},{'id': '111', 'type': 'unary_operator', 'children': ['112'], 'value': '-'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '113', 'type': 'unary_operator', 'children': ['114'], 'value': '-'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '115', 'type': 'pair', 'children': ['116', '117']},{'id': '116', 'type': 'integer', 'children': [], 'value': '4'},{'id': '117', 'type': 'list', 'children': ['118', '122'], 'value': '[[-1, 0], [ 0,-1]]'},{'id': '118', 'type': 'list', 'children': ['119', '121'], 'value': '[-1, 0]'},{'id': '119', 'type': 'unary_operator', 'children': ['120'], 'value': '-'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'list', 'children': ['123', '124'], 'value': '[ 0,-1]'},{'id': '123', 'type': 'integer', 'children': [], 'value': '0'},{'id': '124', 'type': 'unary_operator', 'children': ['125'], 'value': '-'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'pair', 'children': ['127', '128']},{'id': '127', 'type': 'integer', 'children': [], 'value': '5'},{'id': '128', 'type': 'list', 'children': ['129', '134'], 'value': '[[-a,-a], [ a,-a]]'},{'id': '129', 'type': 'list', 'children': ['130', '132'], 'value': '[-a,-a]'},{'id': '130', 'type': 'unary_operator', 'children': ['131'], 'value': '-'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '132', 'type': 'unary_operator', 'children': ['133'], 'value': '-'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '134', 'type': 'list', 'children': ['135', '136'], 'value': '[ a,-a]'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '136', 'type': 'unary_operator', 'children': ['137'], 'value': '-'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '138', 'type': 'pair', 'children': ['139', '140']},{'id': '139', 'type': 'integer', 'children': [], 'value': '6'},{'id': '140', 'type': 'list', 'children': ['141', '145'], 'value': '[[ 0,-1], [ 1, 0]]'},{'id': '141', 'type': 'list', 'children': ['142', '143'], 'value': '[ 0,-1]'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'id': '143', 'type': 'unary_operator', 'children': ['144'], 'value': '-'},{'id': '144', 'type': 'integer', 'children': [], 'value': '1'},{'id': '145', 'type': 'list', 'children': ['146', '147'], 'value': '[ 1, 0]'},{'id': '146', 'type': 'integer', 'children': [], 'value': '1'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'pair', 'children': ['149', '150']},{'id': '149', 'type': 'integer', 'children': [], 'value': '7'},{'id': '150', 'type': 'list', 'children': ['151', '155'], 'value': '[[ a,-a], [ a, a]]'},{'id': '151', 'type': 'list', 'children': ['152', '153'], 'value': '[ a,-a]'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '153', 'type': 'unary_operator', 'children': ['154'], 'value': '-'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '155', 'type': 'list', 'children': ['156', '157'], 'value': '[ a, a]'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'nangles'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'rotations'},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '168', 'type': 'list', 'children': [], 'value': '[]'},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '175']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'angle'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'nangles'},{'id': '175', 'type': 'block', 'children': ['176', '180', '184', '190']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '179', 'type': 'integer', 'children': [], 'value': '0'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '-'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '190', 'type': 'while_statement', 'children': ['191', '194']},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '<'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '194', 'type': 'block', 'children': ['195', '217', '239', '245', '251', '269', '286', '317']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'xr'},{'id': '198', 'type': 'binary_operator', 'children': ['199', '208'], 'value': '+'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '207'], 'value': '*'},{'id': '200', 'type': 'subscript', 'children': ['201', '206']},{'id': '201', 'type': 'subscript', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'rotations'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'angle'},{'id': '205', 'type': 'integer', 'children': [], 'value': '0'},{'id': '206', 'type': 'integer', 'children': [], 'value': '0'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '208', 'type': 'binary_operator', 'children': ['209', '216'], 'value': '*'},{'id': '209', 'type': 'subscript', 'children': ['210', '215']},{'id': '210', 'type': 'subscript', 'children': ['211', '214']},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'rotations'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'angle'},{'id': '214', 'type': 'integer', 'children': [], 'value': '0'},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'yr'},{'id': '220', 'type': 'binary_operator', 'children': ['221', '230'], 'value': '+'},{'id': '221', 'type': 'binary_operator', 'children': ['222', '229'], 'value': '*'},{'id': '222', 'type': 'subscript', 'children': ['223', '228']},{'id': '223', 'type': 'subscript', 'children': ['224', '227']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'rotations'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'angle'},{'id': '227', 'type': 'integer', 'children': [], 'value': '1'},{'id': '228', 'type': 'integer', 'children': [], 'value': '0'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '230', 'type': 'binary_operator', 'children': ['231', '238'], 'value': '*'},{'id': '231', 'type': 'subscript', 'children': ['232', '237']},{'id': '232', 'type': 'subscript', 'children': ['233', '236']},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'rotations'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'angle'},{'id': '236', 'type': 'integer', 'children': [], 'value': '1'},{'id': '237', 'type': 'integer', 'children': [], 'value': '1'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'xr'},{'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '+'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'xr'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'yr'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '+'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'yr'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '254', 'type': 'tuple', 'children': ['255', '262']},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'xr'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'yr'},{'id': '269', 'type': 'if_statement', 'children': ['270', '273']},{'id': '270', 'type': 'comparison_operator', 'children': ['271', '272'], 'value': 'not'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '273', 'type': 'block', 'children': ['274', '279']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'yield', 'children': ['276']},{'id': '276', 'type': 'expression_list', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'xr'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'yr'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'point'},{'id': '286', 'type': 'if_statement', 'children': ['287', '291', '300']},{'id': '287', 'type': '()', 'children': ['288']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': '<'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '290', 'type': 'integer', 'children': [], 'value': '0'},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'augmented_assignment', 'children': ['294', '295'], 'value': '+='},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '+'},{'id': '296', 'type': 'integer', 'children': [], 'value': '3'},{'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '*'},{'id': '298', 'type': 'integer', 'children': [], 'value': '2'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '300', 'type': 'else_clause', 'children': ['301']},{'id': '301', 'type': 'block', 'children': ['302', '313']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'augmented_assignment', 'children': ['304', '305'], 'value': '+='},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '305', 'type': 'binary_operator', 'children': ['306', '307'], 'value': '-'},{'id': '306', 'type': 'integer', 'children': [], 'value': '5'},{'id': '307', 'type': 'binary_operator', 'children': ['308', '309'], 'value': '*'},{'id': '308', 'type': 'integer', 'children': [], 'value': '2'},{'id': '309', 'type': '()', 'children': ['310']},{'id': '310', 'type': 'binary_operator', 'children': ['311', '312'], 'value': '-'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'augmented_assignment', 'children': ['315', '316'], 'value': '-='},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '316', 'type': 'integer', 'children': [], 'value': '1'},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'augmented_assignment', 'children': ['319', '320'], 'value': '+='},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '320', 'type': 'integer', 'children': [], 'value': '1'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'assignment', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'previous'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'current'}
def circlescan(x0, y0, r1, r2): if r1 < 0: raise ValueError("Initial radius must be non-negative") if r2 < 0: raise ValueError("Final radius must be non-negative") previous = [] rstep = 1 if r2 >= r1 else -1 for distance in range(r1, r2 + rstep, rstep): if distance == 0: yield x0, y0 else: a = 0.707107 rotations = {0: [[ 1, 0], [ 0, 1]], 1: [[ a, a], [-a, a]], 2: [[ 0, 1], [-1, 0]], 3: [[-a, a], [-a,-a]], 4: [[-1, 0], [ 0,-1]], 5: [[-a,-a], [ a,-a]], 6: [[ 0,-1], [ 1, 0]], 7: [[ a,-a], [ a, a]]} nangles = len(rotations) current = [] for angle in range(nangles): x = 0 y = distance d = 1 - distance while x < y: xr = rotations[angle][0][0]*x + rotations[angle][0][1]*y yr = rotations[angle][1][0]*x + rotations[angle][1][1]*y xr = x0 + xr yr = y0 + yr point = (int(round(xr)), int(round(yr))) if point not in previous: yield xr, yr current.append(point) if (d < 0): d += 3 + 2 * x else: d += 5 - 2 * (y-x) y -= 1 x += 1 previous = current
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ringscan'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'r2'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'chebyshev'},{'id': '11', 'type': 'block', 'children': ['12', '22', '32', '45', '49', '99', '106', '112', '122']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': '<'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': '"Initial radius must be non-negative"'},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '<'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'r2'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'raise_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': '"Final radius must be non-negative"'},{'id': '32', 'type': 'if_statement', 'children': ['33', '39']},{'id': '33', 'type': 'not_operator', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '38', 'type': 'string', 'children': [], 'value': '"__call__"'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'raise_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': '"Metric not callable"'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '52', 'type': 'dictionary', 'children': ['53', '58', '64', '70', '77', '83', '89', '94']},{'id': '53', 'type': 'pair', 'children': ['54', '55']},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'list', 'children': ['56', '57'], 'value': '[ 1, 0]'},{'id': '56', 'type': 'integer', 'children': [], 'value': '1'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'pair', 'children': ['59', '60']},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'list', 'children': ['61', '62'], 'value': '[ 1,-1]'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'unary_operator', 'children': ['63'], 'value': '-'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'pair', 'children': ['65', '66']},{'id': '65', 'type': 'integer', 'children': [], 'value': '2'},{'id': '66', 'type': 'list', 'children': ['67', '68'], 'value': '[ 0,-1]'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '-'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'pair', 'children': ['71', '72']},{'id': '71', 'type': 'integer', 'children': [], 'value': '3'},{'id': '72', 'type': 'list', 'children': ['73', '75'], 'value': '[-1,-1]'},{'id': '73', 'type': 'unary_operator', 'children': ['74'], 'value': '-'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'unary_operator', 'children': ['76'], 'value': '-'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'pair', 'children': ['78', '79']},{'id': '78', 'type': 'integer', 'children': [], 'value': '4'},{'id': '79', 'type': 'list', 'children': ['80', '82'], 'value': '[-1, 0]'},{'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'integer', 'children': [], 'value': '5'},{'id': '85', 'type': 'list', 'children': ['86', '88'], 'value': '[-1, 1]'},{'id': '86', 'type': 'unary_operator', 'children': ['87'], 'value': '-'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'integer', 'children': [], 'value': '6'},{'id': '91', 'type': 'list', 'children': ['92', '93'], 'value': '[ 0, 1]'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'pair', 'children': ['95', '96']},{'id': '95', 'type': 'integer', 'children': [], 'value': '7'},{'id': '96', 'type': 'list', 'children': ['97', '98'], 'value': '[ 1, 1]'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'nsteps'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '109', 'type': 'list', 'children': ['110', '111'], 'value': '[x0, y0]'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'rstep'},{'id': '115', 'type': 'conditional_expression', 'children': ['116', '117', '120'], 'value': 'if'},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': '>='},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'r2'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '120', 'type': 'unary_operator', 'children': ['121'], 'value': '-'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'for_statement', 'children': ['123', '124', '132']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128', '131']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '+'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'r2'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'rstep'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'rstep'},{'id': '132', 'type': 'block', 'children': ['133', '141', '145', '149', '238']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '136', 'type': 'list', 'children': ['137', '138'], 'value': '[x0, y0 + distance]'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'x0'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '+'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'y0'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ntrys'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'while_statement', 'children': ['150', '151']},{'id': '150', 'type': 'True', 'children': []},{'id': '151', 'type': 'block', 'children': ['152', '167', '186', '215', '219', '228', '232']},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': '=='},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'block', 'children': ['157', '166']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'yield', 'children': ['159']},{'id': '159', 'type': 'expression_list', 'children': ['160', '163']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '162', 'type': 'integer', 'children': [], 'value': '0'},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'break_statement', 'children': []},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'nextpoint'},{'id': '170', 'type': 'list_comprehension', 'children': ['171', '180']},{'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '+'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '175', 'type': 'subscript', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '180', 'type': 'for_in_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'integer', 'children': [], 'value': '2'},{'id': '186', 'type': 'if_statement', 'children': ['187', '194']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '193'], 'value': '!='},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'nextpoint'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'distance'},{'id': '194', 'type': 'block', 'children': ['195', '199', '205', '214']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'augmented_assignment', 'children': ['197', '198'], 'value': '+='},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ntrys'},{'id': '198', 'type': 'integer', 'children': [], 'value': '1'},{'id': '199', 'type': 'if_statement', 'children': ['200', '203']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': '=='},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'ntrys'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'nsteps'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'break_statement', 'children': []},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '208', 'type': 'binary_operator', 'children': ['209', '213'], 'value': '%'},{'id': '209', 'type': '()', 'children': ['210']},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '+'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'direction'},{'id': '212', 'type': 'integer', 'children': [], 'value': '1'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'nsteps'},{'id': '214', 'type': 'continue_statement', 'children': []},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'ntrys'},{'id': '218', 'type': 'integer', 'children': [], 'value': '0'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'yield', 'children': ['221']},{'id': '221', 'type': 'expression_list', 'children': ['222', '225']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '227', 'type': 'integer', 'children': [], 'value': '1'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'nextpoint'},{'id': '232', 'type': 'if_statement', 'children': ['233', '236']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '=='},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'break_statement', 'children': []},{'id': '238', 'type': 'if_statement', 'children': ['239', '242']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '=='},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'ntrys'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'nsteps'},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'break_statement', 'children': []}
def ringscan(x0, y0, r1, r2, metric=chebyshev): if r1 < 0: raise ValueError("Initial radius must be non-negative") if r2 < 0: raise ValueError("Final radius must be non-negative") if not hasattr(metric, "__call__"): raise TypeError("Metric not callable") direction = 0 steps = {0: [ 1, 0], 1: [ 1,-1], 2: [ 0,-1], 3: [-1,-1], 4: [-1, 0], 5: [-1, 1], 6: [ 0, 1], 7: [ 1, 1]} nsteps = len(steps) center = [x0, y0] rstep = 1 if r2 >= r1 else -1 for distance in range(r1, r2 + rstep, rstep): initial = [x0, y0 + distance] current = initial ntrys = 0 while True: if distance == 0: yield current[0], current[1] break nextpoint = [current[i] + steps[direction][i] for i in range(2)] if metric(center, nextpoint) != distance: ntrys += 1 if ntrys == nsteps: break direction = (direction + 1) % nsteps continue ntrys = 0 yield current[0], current[1] current = nextpoint if current == initial: break if ntrys == nsteps: break
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fetch'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '6', 'type': 'block', 'children': ['7', '22', '32']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '10', 'type': 'call', 'children': ['11', '18']},{'id': '11', 'type': 'attribute', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sync'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'device_uuid'},{'id': '22', 'type': 'if_statement', 'children': ['23', '30']},{'id': '23', 'type': 'boolean_operator', 'children': ['24', '27'], 'value': 'or'},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'not'},{'id': '28', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'return_statement', 'children': []},{'id': '32', 'type': 'while_statement', 'children': ['33', '34']},{'id': '33', 'type': 'True', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '53', '58', '62', '90']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'queue_items'},{'id': '38', 'type': 'call', 'children': ['39', '46']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sync'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'fetch'},{'id': '46', 'type': 'argument_list', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'device_uuid'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'session'},{'id': '52', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '53', 'type': 'if_statement', 'children': ['54', '56']},{'id': '54', 'type': 'not_operator', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'queue_items'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'break_statement', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ack_keys'},{'id': '61', 'type': 'list', 'children': [], 'value': '[]'},{'id': '62', 'type': 'for_statement', 'children': ['63', '64', '65']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'queue_items'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '76']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '69', 'type': 'argument_list', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '72', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '75', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ack_keys'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'subscript', 'children': ['84', '89']},{'id': '84', 'type': 'subscript', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '87', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'sync'"},{'id': '89', 'type': 'string', 'children': [], 'value': "'ack_key'"},{'id': '90', 'type': 'if_statement', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ack_keys'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '102']},{'id': '95', 'type': 'attribute', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sync'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ack'},{'id': '102', 'type': 'argument_list', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'device_uuid'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'ack_keys'}
def fetch(self, callback): session = self.client.sync.start(self.device_uuid) if session is None or 'id' not in session: return while True: queue_items = self.client.sync.fetch(self.device_uuid, session['id']) if not queue_items: break ack_keys = [] for item in queue_items: if callback(item['meta'], item['data']): ack_keys.append(item['meta']['sync']['ack_key']) if ack_keys: self.client.sync.ack(self.device_uuid, ack_keys)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'define_residues_for_plotting_traj'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'analysis_cutoff'},{'id': '6', 'type': 'block', 'children': ['7', '13', '55', '86', '128']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'residue_counts_fraction'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '18']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'residue_counts'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '26']},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'residue_counts_fraction'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '26', 'type': 'dictionary_comprehension', 'children': ['27', '42']},{'id': '27', 'type': 'pair', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '34'], 'value': '/'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'contacts_per_timeframe'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '46']},{'id': '43', 'type': 'pattern_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '46', 'type': 'call', 'children': ['47', '54']},{'id': '47', 'type': 'attribute', 'children': ['48', '53']},{'id': '48', 'type': 'subscript', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'residue_counts'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '60']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'residue_counts_fraction'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '68']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'residue_counts_fraction'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '78']},{'id': '71', 'type': 'attribute', 'children': ['72', '77']},{'id': '72', 'type': 'subscript', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'subscript', 'children': ['80', '85']},{'id': '80', 'type': 'subscript', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'residue_counts_fraction'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'residue'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'dict_of_plotted_res'},{'id': '93', 'type': 'dictionary_comprehension', 'children': ['94', '101', '106']},{'id': '94', 'type': 'pair', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '96', 'type': 'subscript', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '106', 'type': 'if_clause', 'children': ['107']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '116'], 'value': '>'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'subscript', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '116', 'type': '()', 'children': ['117']},{'id': '117', 'type': 'binary_operator', 'children': ['118', '127'], 'value': '*'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'trajectory'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'analysis_cutoff'},{'id': '128', 'type': 'assert_statement', 'children': ['129', '139']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '138'], 'value': '!='},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'dict_of_plotted_res'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '173'], 'value': '+'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '159'], 'value': '+'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '158'], 'value': '+'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '+'},{'id': '143', 'type': 'string', 'children': [], 'value': '"Nothing to draw for this ligand:(residue number: "'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'subscript', 'children': ['148', '157']},{'id': '148', 'type': 'attribute', 'children': ['149', '156']},{'id': '149', 'type': 'attribute', 'children': ['150', '155']},{'id': '150', 'type': 'attribute', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'universe'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ligand'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'resids'},{'id': '157', 'type': 'integer', 'children': [], 'value': '0'},{'id': '158', 'type': 'string', 'children': [], 'value': '" on the chain "'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'subscript', 'children': ['163', '172']},{'id': '163', 'type': 'attribute', 'children': ['164', '171']},{'id': '164', 'type': 'attribute', 'children': ['165', '170']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'universe'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ligand'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'segids'},{'id': '172', 'type': 'integer', 'children': [], 'value': '0'},{'id': '173', 'type': 'string', 'children': [], 'value': '") - try reducing the analysis cutoff."'}
def define_residues_for_plotting_traj(self, analysis_cutoff): self.residue_counts_fraction = {} for traj in self.residue_counts: self.residue_counts_fraction[traj] = {residue:float(values)/len(self.contacts_per_timeframe[traj]) for residue,values in self.residue_counts[traj].items()} for traj in self.residue_counts_fraction: for residue in self.residue_counts_fraction[traj]: self.frequency[residue].append(self.residue_counts_fraction[traj][residue]) self.topology_data.dict_of_plotted_res = {i:self.frequency[i] for i in self.frequency if sum(self.frequency[i])>(int(len(self.trajectory))*analysis_cutoff)} assert len(self.topology_data.dict_of_plotted_res)!=0,"Nothing to draw for this ligand:(residue number: "+ str(self.topology_data.universe.ligand.resids[0]) +" on the chain "+ str(self.topology_data.universe.ligand.segids[0]) +") - try reducing the analysis cutoff."
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_donors_and_acceptors_in_ligand'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '22']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'atom_names'},{'id': '9', 'type': 'list_comprehension', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '13', 'type': 'for_in_clause', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '15', 'type': 'attribute', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'universe'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ligand'},{'id': '22', 'type': 'try_statement', 'children': ['23', '86']},{'id': '23', 'type': 'block', 'children': ['24', '55']},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '41']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '26', 'type': 'call', 'children': ['27', '34']},{'id': '27', 'type': 'attribute', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'GetSubstructMatches'},{'id': '34', 'type': 'argument_list', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'HDonorSmarts'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'uniquify'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '49']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'donors'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'atom_names'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '72']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '57', 'type': 'call', 'children': ['58', '65']},{'id': '58', 'type': 'attribute', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'GetSubstructMatches'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'HAcceptorSmarts'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'uniquify'},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'acceptors'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'atom_names'},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'except_clause', 'children': ['87', '91']},{'id': '87', 'type': 'as_pattern', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '89', 'type': 'as_pattern_target', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '91', 'type': 'block', 'children': ['92', '101', '107', '113', '140', '144', '155']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'Chem'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'MolFromPDBFile'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'string', 'children': [], 'value': '"lig.pdb"'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'donors'},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'acceptors'},{'id': '112', 'type': 'list', 'children': [], 'value': '[]'},{'id': '113', 'type': 'for_statement', 'children': ['114', '115', '126']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'GetSubstructMatches'},{'id': '119', 'type': 'argument_list', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'HDonorSmarts'},{'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'uniquify'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'donors'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'atom_names'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'haccep'},{'id': '143', 'type': 'string', 'children': [], 'value': '"[$([O,S;H1;v2]-[!$(*=[O,N,P,S])]),$([O,S;H0;v2]),$([O,S;-]),$([N;v3;!$(N-*=!@[O,N,P,S])]),$([nH0,o,s;+0])]"'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'HAcceptorSmarts'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Chem'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'MolFromSmarts'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'haccep'},{'id': '155', 'type': 'for_statement', 'children': ['156', '157', '168']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'GetSubstructMatches'},{'id': '161', 'type': 'argument_list', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'HAcceptorSmarts'},{'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'uniquify'},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'acceptors'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'atom_names'},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'}
def find_donors_and_acceptors_in_ligand(self): atom_names=[x.name for x in self.topology_data.universe.ligand] try: for atom in self.topology_data.mol.GetSubstructMatches(self.HDonorSmarts, uniquify=1): self.donors.append(atom_names[atom[0]]) for atom in self.topology_data.mol.GetSubstructMatches(self.HAcceptorSmarts, uniquify=1): self.acceptors.append(atom_names[atom[0]]) except Exception as e: m = Chem.MolFromPDBFile("lig.pdb") self.donors = [] self.acceptors = [] for atom in m.GetSubstructMatches(self.HDonorSmarts, uniquify=1): self.donors.append(atom_names[atom[0]]) haccep = "[$([O,S;H1;v2]-[!$(*=[O,N,P,S])]),$([O,S;H0;v2]),$([O,S;-]),$([N;v3;!$(N-*=!@[O,N,P,S])]),$([nH0,o,s;+0])]" self.HAcceptorSmarts = Chem.MolFromSmarts(haccep) for atom in m.GetSubstructMatches(self.HAcceptorSmarts, uniquify=1): self.acceptors.append(atom_names[atom[0]])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'determine_hbonds_for_drawing'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'analysis_cutoff'},{'id': '6', 'type': 'block', 'children': ['7', '16', '83', '120', '126']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '21']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'hbonds_by_type'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '29']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '24', 'type': 'subscript', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'hbonds_by_type'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'traj'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'if_statement', 'children': ['31', '36', '59']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': '!='},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '34', 'type': 'string', 'children': [], 'value': '"donor_resnm"'},{'id': '35', 'type': 'string', 'children': [], 'value': '"LIG"'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'augmented_assignment', 'children': ['39', '56'], 'value': '+='},{'id': '39', 'type': 'subscript', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '43', 'type': 'tuple', 'children': ['44', '47', '50', '53']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '46', 'type': 'string', 'children': [], 'value': '"donor_idx"'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '49', 'type': 'string', 'children': [], 'value': '"acceptor_atom"'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '52', 'type': 'string', 'children': [], 'value': '"donor_atom"'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '55', 'type': 'string', 'children': [], 'value': '"acceptor_idx"'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '58', 'type': 'string', 'children': [], 'value': '"frequency"'},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'augmented_assignment', 'children': ['63', '80'], 'value': '+='},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '67', 'type': 'tuple', 'children': ['68', '71', '74', '77']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '70', 'type': 'string', 'children': [], 'value': '"acceptor_idx"'},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '73', 'type': 'string', 'children': [], 'value': '"donor_atom"'},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '76', 'type': 'string', 'children': [], 'value': '"acceptor_atom"'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '79', 'type': 'string', 'children': [], 'value': '"donor_idx"'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '82', 'type': 'string', 'children': [], 'value': '"frequency"'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '88', 'type': 'dictionary_comprehension', 'children': ['89', '96', '101']},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '96', 'type': 'for_in_clause', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '101', 'type': 'if_clause', 'children': ['102']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '108'], 'value': '>'},{'id': '103', 'type': 'subscript', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '108', 'type': '()', 'children': ['109']},{'id': '109', 'type': 'binary_operator', 'children': ['110', '119'], 'value': '*'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'trajectory'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'analysis_cutoff'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'hbonds_for_drawing'},{'id': '125', 'type': 'dictionary', 'children': []},{'id': '126', 'type': 'for_statement', 'children': ['127', '128', '131']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '131', 'type': 'block', 'children': ['132', '138', '248']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'atomname'},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'if_statement', 'children': ['139', '154', '159']},{'id': '139', 'type': 'boolean_operator', 'children': ['140', '147'], 'value': 'or'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'atomname'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': '"O"'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'atomname'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': '"N"'},{'id': '153', 'type': 'integer', 'children': [], 'value': '0'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'lig_atom'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'atomname'},{'id': '159', 'type': 'else_clause', 'children': ['160']},{'id': '160', 'type': 'block', 'children': ['161', '190', '203', '219']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'atomindex'},{'id': '164', 'type': 'subscript', 'children': ['165', '189']},{'id': '165', 'type': 'list_comprehension', 'children': ['166', '167', '183']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '167', 'type': 'for_in_clause', 'children': ['168', '171']},{'id': '168', 'type': 'pattern_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'attribute', 'children': ['175', '182']},{'id': '175', 'type': 'attribute', 'children': ['176', '181']},{'id': '176', 'type': 'attribute', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'universe'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ligand'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '183', 'type': 'if_clause', 'children': ['184']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '188'], 'value': '=='},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'atomname'},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'rdkit_atom'},{'id': '193', 'type': 'call', 'children': ['194', '201']},{'id': '194', 'type': 'attribute', 'children': ['195', '200']},{'id': '195', 'type': 'attribute', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'mol'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'GetAtomWithIdx'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'atomindex'},{'id': '203', 'type': 'for_statement', 'children': ['204', '205', '210']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'neigh'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'rdkit_atom'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'GetNeighbors'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'neigh_atom_id'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'neigh'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'GetIdx'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'lig_atom'},{'id': '222', 'type': 'subscript', 'children': ['223', '247']},{'id': '223', 'type': 'list_comprehension', 'children': ['224', '227', '243']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '227', 'type': 'for_in_clause', 'children': ['228', '231']},{'id': '228', 'type': 'pattern_list', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'atom'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'attribute', 'children': ['235', '242']},{'id': '235', 'type': 'attribute', 'children': ['236', '241']},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'topology_data'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'universe'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'ligand'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'atoms'},{'id': '243', 'type': 'if_clause', 'children': ['244']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '=='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'neigh_atom_id'},{'id': '247', 'type': 'integer', 'children': [], 'value': '0'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '265']},{'id': '250', 'type': 'subscript', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'hbonds_for_drawing'},{'id': '254', 'type': 'tuple', 'children': ['255', '258', '259', '262']},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '257', 'type': 'integer', 'children': [], 'value': '0'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'lig_atom'},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '261', 'type': 'integer', 'children': [], 'value': '2'},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'bond'},{'id': '264', 'type': 'integer', 'children': [], 'value': '3'},{'id': '265', 'type': 'subscript', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'bond'}
def determine_hbonds_for_drawing(self, analysis_cutoff): self.frequency = defaultdict(int) for traj in self.hbonds_by_type: for bond in self.hbonds_by_type[traj]: if bond["donor_resnm"]!="LIG": self.frequency[(bond["donor_idx"],bond["acceptor_atom"],bond["donor_atom"],bond["acceptor_idx"])] += bond["frequency"] else: self.frequency[(bond["acceptor_idx"],bond["donor_atom"],bond["acceptor_atom"],bond["donor_idx"])] += bond["frequency"] self.frequency = {i:self.frequency[i] for i in self.frequency if self.frequency[i]>(int(len(self.trajectory))*analysis_cutoff)} self.hbonds_for_drawing = {} for bond in self.frequency: atomname = bond[1] if atomname.startswith("O",0) or atomname.startswith("N",0): lig_atom=atomname else: atomindex = [index for index,atom in enumerate(self.topology_data.universe.ligand.atoms) if atom.name==atomname][0] rdkit_atom = self.topology_data.mol.GetAtomWithIdx(atomindex) for neigh in rdkit_atom.GetNeighbors(): neigh_atom_id = neigh.GetIdx() lig_atom = [atom.name for index,atom in enumerate(self.topology_data.universe.ligand.atoms) if index==neigh_atom_id][0] self.hbonds_for_drawing[(bond[0],lig_atom,bond[2],bond[3])]=self.frequency[bond]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'distance_function_match'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'thresh'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dist_fn'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'norm_funcs'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'block', 'children': ['12', '16', '26', '36', '92', '112', '118', '156', '230']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'norm_fn'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'norm_funcs'},{'id': '39', 'type': 'block', 'children': ['40', '74']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '46']},{'id': '42', 'type': 'pattern_list', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'new_common'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_match_by_norm_func'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51', '60', '73']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '51', 'type': 'lambda', 'children': ['52', '54']},{'id': '52', 'type': 'lambda_parameters', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'norm_fn'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'lambda', 'children': ['61', '64']},{'id': '61', 'type': 'lambda_parameters', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'dist_fn'},{'id': '66', 'type': 'argument_list', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'a1'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'a2'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'thresh'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '79', 'type': 'generator_expression', 'children': ['80', '87']},{'id': '80', 'type': 'tuple', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'c2'},{'id': '86', 'type': 'integer', 'children': [], 'value': '0'},{'id': '87', 'type': 'for_in_clause', 'children': ['88', '91']},{'id': '88', 'type': 'pattern_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'c2'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'new_common'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dist_matrix'},{'id': '95', 'type': 'list_comprehension', 'children': ['96', '107']},{'id': '96', 'type': 'list_comprehension', 'children': ['97', '102']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'dist_fn'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '102', 'type': 'for_in_clause', 'children': ['103', '106']},{'id': '103', 'type': 'pattern_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'i2'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '107', 'type': 'for_in_clause', 'children': ['108', '111']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'BipartiteConnectedComponents'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'for_statement', 'children': ['119', '120', '127']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'l1_i'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'for_statement', 'children': ['129', '130', '137']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'l2_i'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '137', 'type': 'block', 'children': ['138', '148']},{'id': '138', 'type': 'if_statement', 'children': ['139', '146']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '145'], 'value': '>'},{'id': '140', 'type': 'subscript', 'children': ['141', '144']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'dist_matrix'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'l1_i'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'l2_i'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'thresh'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'continue_statement', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'l1_i'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'l2_i'},{'id': '156', 'type': 'for_statement', 'children': ['157', '160', '165']},{'id': '157', 'type': 'pattern_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'l1_indices'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'l2_indices'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'components'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'get_connected_components'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'block', 'children': ['166', '176', '186', '202', '212']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'part_l1'},{'id': '169', 'type': 'list_comprehension', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '173', 'type': 'for_in_clause', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'l1_indices'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'part_l2'},{'id': '179', 'type': 'list_comprehension', 'children': ['180', '183']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '183', 'type': 'for_in_clause', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'l2_indices'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'part_dist_matrix'},{'id': '189', 'type': 'list_comprehension', 'children': ['190', '199']},{'id': '190', 'type': 'list_comprehension', 'children': ['191', '196']},{'id': '191', 'type': 'subscript', 'children': ['192', '195']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'dist_matrix'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'l1_i'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'l2_i'},{'id': '196', 'type': 'for_in_clause', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'l2_i'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'l2_indices'},{'id': '199', 'type': 'for_in_clause', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'l1_i'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'l1_indices'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'part_cmn'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': '_match_munkres'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209', '210', '211']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'part_l1'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'part_l2'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'part_dist_matrix'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'thresh'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '217', 'type': 'generator_expression', 'children': ['218', '225']},{'id': '218', 'type': 'tuple', 'children': ['219', '222']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '221', 'type': 'integer', 'children': [], 'value': '0'},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'c2'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'for_in_clause', 'children': ['226', '229']},{'id': '226', 'type': 'pattern_list', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'c1'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'c2'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'part_cmn'},{'id': '230', 'type': 'return_statement', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'common'}
def distance_function_match(l1, l2, thresh, dist_fn, norm_funcs=[]): common = [] l1 = list(enumerate(l1)) l2 = list(enumerate(l2)) for norm_fn in norm_funcs: new_common, l1, l2 = _match_by_norm_func( l1, l2, lambda a: norm_fn(a[1]), lambda a1, a2: dist_fn(a1[1], a2[1]), thresh) common.extend((c1[0], c2[0]) for c1, c2 in new_common) dist_matrix = [[dist_fn(e1, e2) for i2, e2 in l2] for i1, e1 in l1] components = BipartiteConnectedComponents() for l1_i in range(len(l1)): for l2_i in range(len(l2)): if dist_matrix[l1_i][l2_i] > thresh: continue components.add_edge(l1_i, l2_i) for l1_indices, l2_indices in components.get_connected_components(): part_l1 = [l1[i] for i in l1_indices] part_l2 = [l2[i] for i in l2_indices] part_dist_matrix = [[dist_matrix[l1_i][l2_i] for l2_i in l2_indices] for l1_i in l1_indices] part_cmn = _match_munkres(part_l1, part_l2, part_dist_matrix, thresh) common.extend((c1[0], c2[0]) for c1, c2 in part_cmn) return common
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_match_by_norm_func'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'norm_fn'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dist_fn'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'thresh'},{'id': '9', 'type': 'block', 'children': ['10', '14', '27', '40', '59', '78', '220', '230', '240']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'l1_only_idx'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'l2_only_idx'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'buckets_l1'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_group_by_fn'},{'id': '45', 'type': 'argument_list', 'children': ['46', '50']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '50', 'type': 'lambda', 'children': ['51', '53']},{'id': '51', 'type': 'lambda_parameters', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'norm_fn'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'buckets_l2'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_group_by_fn'},{'id': '64', 'type': 'argument_list', 'children': ['65', '69']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '69', 'type': 'lambda', 'children': ['70', '72']},{'id': '70', 'type': 'lambda_parameters', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'norm_fn'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'for_statement', 'children': ['79', '82', '87']},{'id': '79', 'type': 'pattern_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'normed'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'l1_elements'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'buckets_l1'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'block', 'children': ['88', '98', '106', '116', '126', '169', '173']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'l2_elements'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'buckets_l2'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'normed'},{'id': '97', 'type': 'list', 'children': [], 'value': '[]'},{'id': '98', 'type': 'if_statement', 'children': ['99', '104']},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '102'], 'value': 'or'},{'id': '100', 'type': 'not_operator', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'l1_elements'},{'id': '102', 'type': 'not_operator', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'l2_elements'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'continue_statement', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '113']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '110', 'type': 'tuple_pattern', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'e1_first'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'l1_elements'},{'id': '115', 'type': 'integer', 'children': [], 'value': '0'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '123']},{'id': '118', 'type': 'pattern_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '120', 'type': 'tuple_pattern', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'e2_first'},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'l2_elements'},{'id': '125', 'type': 'integer', 'children': [], 'value': '0'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'match_is_ambiguous'},{'id': '129', 'type': 'not_operator', 'children': ['130']},{'id': '130', 'type': '()', 'children': ['131']},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '141'], 'value': 'and'},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '137'], 'value': '=='},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'l1_elements'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'l2_elements'},{'id': '141', 'type': '()', 'children': ['142']},{'id': '142', 'type': 'boolean_operator', 'children': ['143', '156'], 'value': 'or'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '145', 'type': 'generator_expression', 'children': ['146', '149']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '=='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'e2_first'},{'id': '149', 'type': 'for_in_clause', 'children': ['150', '155']},{'id': '150', 'type': 'tuple_pattern', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '152', 'type': 'tuple_pattern', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'l2_elements'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '158', 'type': 'generator_expression', 'children': ['159', '162']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '=='},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'e1_first'},{'id': '162', 'type': 'for_in_clause', 'children': ['163', '168']},{'id': '163', 'type': 'tuple_pattern', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '165', 'type': 'tuple_pattern', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'l1_elements'},{'id': '169', 'type': 'if_statement', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'match_is_ambiguous'},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'continue_statement', 'children': []},{'id': '173', 'type': 'for_statement', 'children': ['174', '181', '186']},{'id': '174', 'type': 'pattern_list', 'children': ['175', '178']},{'id': '175', 'type': 'tuple_pattern', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'e1_idx'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '178', 'type': 'tuple_pattern', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'e2_idx'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'l1_elements'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'l2_elements'},{'id': '186', 'type': 'block', 'children': ['187', '197', '204', '211']},{'id': '187', 'type': 'if_statement', 'children': ['188', '195']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '194'], 'value': '>'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'dist_fn'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'thresh'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'continue_statement', 'children': []},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'l1_only_idx'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'e1_idx'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'l2_only_idx'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'e2_idx'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'tuple', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'l1_only'},{'id': '223', 'type': 'list_comprehension', 'children': ['224', '227']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'l1'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'l1_only_idx'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'l2_only'},{'id': '233', 'type': 'list_comprehension', 'children': ['234', '237']},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'l2'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '237', 'type': 'for_in_clause', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'l2_only_idx'},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'expression_list', 'children': ['242', '243', '244']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'l1_only'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'l2_only'}
def _match_by_norm_func(l1, l2, norm_fn, dist_fn, thresh): common = [] l1_only_idx = set(range(len(l1))) l2_only_idx = set(range(len(l2))) buckets_l1 = _group_by_fn(enumerate(l1), lambda x: norm_fn(x[1])) buckets_l2 = _group_by_fn(enumerate(l2), lambda x: norm_fn(x[1])) for normed, l1_elements in buckets_l1.items(): l2_elements = buckets_l2.get(normed, []) if not l1_elements or not l2_elements: continue _, (_, e1_first) = l1_elements[0] _, (_, e2_first) = l2_elements[0] match_is_ambiguous = not ( len(l1_elements) == len(l2_elements) and ( all(e2 == e2_first for (_, (_, e2)) in l2_elements) or all(e1 == e1_first for (_, (_, e1)) in l1_elements) ) ) if match_is_ambiguous: continue for (e1_idx, e1), (e2_idx, e2) in zip(l1_elements, l2_elements): if dist_fn(e1, e2) > thresh: continue l1_only_idx.remove(e1_idx) l2_only_idx.remove(e2_idx) common.append((e1, e2)) l1_only = [l1[i] for i in l1_only_idx] l2_only = [l2[i] for i in l2_only_idx] return common, l1_only, l2_only
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'props'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '8', 'type': 'string', 'children': [], 'value': "'='"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '35', '58']},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '27', 'type': 'argument_list', 'children': ['28', '32']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'to_comment'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '35', 'type': 'if_statement', 'children': ['36', '43']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '40'], 'value': 'and'},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '42', 'type': 'False', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '47', 'type': 'argument_list', 'children': ['48', '55']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'to_comment'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'java_timestamp'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '58', 'type': 'for_statement', 'children': ['59', '62', '69']},{'id': '59', 'type': 'pattern_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'itemize'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'props'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '73', 'type': 'argument_list', 'children': ['74', '80']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'join_key_value'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'fp'}
def dump(props, fp, separator='=', comments=None, timestamp=True, sort_keys=False): if comments is not None: print(to_comment(comments), file=fp) if timestamp is not None and timestamp is not False: print(to_comment(java_timestamp(timestamp)), file=fp) for k,v in itemize(props, sort_keys=sort_keys): print(join_key_value(k, v, separator), file=fp)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dumps'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'props'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '7', 'type': 'string', 'children': [], 'value': "'='"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '24', '42']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'StringIO'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30', '33', '36', '39']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'props'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'comments'},{'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort_keys'},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'getvalue'},{'id': '47', 'type': 'argument_list', 'children': []}
def dumps(props, separator='=', comments=None, timestamp=True, sort_keys=False): s = StringIO() dump(props, s, separator=separator, comments=comments, timestamp=timestamp, sort_keys=sort_keys) return s.getvalue()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'variants'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '11', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '22', '34', '40', '51', '55', '90', '123', '197', '263', '277', '314', '364', '395', '399', '428']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '21'], 'value': 'or'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '21', 'type': 'dictionary', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': '"Looking for variants in {0}"'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '+'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '43', 'type': 'boolean_operator', 'children': ['44', '50'], 'value': 'or'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'gemini_query'"},{'id': '50', 'type': 'string', 'children': [], 'value': '"SELECT * from variants v"'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'any_filter'},{'id': '54', 'type': 'False', 'children': []},{'id': '55', 'type': 'if_statement', 'children': ['56', '62']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': "'frequency'"},{'id': '62', 'type': 'block', 'children': ['63', '69', '80']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '68', 'type': 'string', 'children': [], 'value': "'frequency'"},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'extra_info'},{'id': '72', 'type': 'call', 'children': ['73', '78']},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'concatenated_string', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': '"(v.max_aaf_all < {0} or v.max_aaf_all is"'},{'id': '76', 'type': 'string', 'children': [], 'value': '" Null)"'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'build_gemini_query'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'extra_info'},{'id': '90', 'type': 'if_statement', 'children': ['91', '97']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': "'cadd'"},{'id': '97', 'type': 'block', 'children': ['98', '104', '113']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cadd_score'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '103', 'type': 'string', 'children': [], 'value': "'cadd'"},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'extra_info'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"(v.cadd_scaled > {0})"'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'cadd_score'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'build_gemini_query'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'extra_info'},{'id': '123', 'type': 'if_statement', 'children': ['124', '130']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'string', 'children': [], 'value': "'gene_ids'"},{'id': '130', 'type': 'block', 'children': ['131', '145', '149', '183', '187']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'gene_list'},{'id': '134', 'type': 'list_comprehension', 'children': ['135', '140']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '139', 'type': 'argument_list', 'children': []},{'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '144', 'type': 'string', 'children': [], 'value': "'gene_ids'"},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'gene_string'},{'id': '148', 'type': 'string', 'children': [], 'value': '"v.gene in ("'},{'id': '149', 'type': 'for_statement', 'children': ['150', '153', '157']},{'id': '150', 'type': 'pattern_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'gene_list'},{'id': '157', 'type': 'block', 'children': ['158']},{'id': '158', 'type': 'if_statement', 'children': ['159', '162', '172']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '=='},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '161', 'type': 'integer', 'children': [], 'value': '0'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'augmented_assignment', 'children': ['165', '166'], 'value': '+='},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'gene_string'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'string', 'children': [], 'value': '"\'{0}\'"'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '172', 'type': 'else_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '+='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'gene_string'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'string', 'children': [], 'value': '", \'{0}\'"'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'augmented_assignment', 'children': ['185', '186'], 'value': '+='},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'gene_string'},{'id': '186', 'type': 'string', 'children': [], 'value': '")"'},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'build_gemini_query'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'gene_string'},{'id': '197', 'type': 'if_statement', 'children': ['198', '204']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': "'range'"},{'id': '204', 'type': 'block', 'children': ['205', '213', '231', '253']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '208', 'type': 'subscript', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '211', 'type': 'string', 'children': [], 'value': "'range'"},{'id': '212', 'type': 'string', 'children': [], 'value': "'chromosome'"},{'id': '213', 'type': 'if_statement', 'children': ['214', '221']},{'id': '214', 'type': 'not_operator', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'string', 'children': [], 'value': "'chr'"},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'string', 'children': [], 'value': '"chr{0}"'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'range_string'},{'id': '234', 'type': 'call', 'children': ['235', '241']},{'id': '235', 'type': 'attribute', 'children': ['236', '240']},{'id': '236', 'type': 'concatenated_string', 'children': ['237', '238', '239']},{'id': '237', 'type': 'string', 'children': [], 'value': '"v.chrom = \'{0}\' AND "'},{'id': '238', 'type': 'string', 'children': [], 'value': '"((v.start BETWEEN {1} AND {2}) OR "'},{'id': '239', 'type': 'string', 'children': [], 'value': '"(v.end BETWEEN {1} AND {2}))"'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '241', 'type': 'argument_list', 'children': ['242', '243', '248']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '243', 'type': 'subscript', 'children': ['244', '247']},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '246', 'type': 'string', 'children': [], 'value': "'range'"},{'id': '247', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '248', 'type': 'subscript', 'children': ['249', '252']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '251', 'type': 'string', 'children': [], 'value': "'range'"},{'id': '252', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'build_gemini_query'},{'id': '260', 'type': 'argument_list', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'range_string'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'filtered_variants'},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '269', 'type': 'identifier', 'children': [], 'value': '_variants'},{'id': '270', 'type': 'argument_list', 'children': ['271', '274']},{'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'gemini_query'},{'id': '277', 'type': 'if_statement', 'children': ['278', '284']},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'string', 'children': [], 'value': "'consequence'"},{'id': '284', 'type': 'block', 'children': ['285', '294']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'consequences'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '293', 'type': 'string', 'children': [], 'value': "'consequence'"},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'assignment', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'filtered_variants'},{'id': '297', 'type': 'generator_expression', 'children': ['298', '299', '302']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '299', 'type': 'for_in_clause', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'filtered_variants'},{'id': '302', 'type': 'if_clause', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '312']},{'id': '304', 'type': 'attribute', 'children': ['305', '311']},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'consequences'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'consequences'},{'id': '314', 'type': 'if_statement', 'children': ['315', '321']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'string', 'children': [], 'value': "'impact_severities'"},{'id': '321', 'type': 'block', 'children': ['322', '339', '343']},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'severities'},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'list_comprehension', 'children': ['329', '334']},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'severity'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '333', 'type': 'argument_list', 'children': []},{'id': '334', 'type': 'for_in_clause', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'severity'},{'id': '336', 'type': 'subscript', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '338', 'type': 'string', 'children': [], 'value': "'impact_severities'"},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'assignment', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'new_filtered_variants'},{'id': '342', 'type': 'list', 'children': [], 'value': '[]'},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'assignment', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'filtered_variants'},{'id': '346', 'type': 'generator_expression', 'children': ['347', '348', '351']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '348', 'type': 'for_in_clause', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'filtered_variants'},{'id': '351', 'type': 'if_clause', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '362']},{'id': '353', 'type': 'attribute', 'children': ['354', '361']},{'id': '354', 'type': 'call', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': 'list', 'children': ['358'], 'value': '[variant.impact_severity]'},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'impact_severity'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'severities'},{'id': '364', 'type': 'if_statement', 'children': ['365', '371']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'string', 'children': [], 'value': "'sv_len'"},{'id': '371', 'type': 'block', 'children': ['372', '381']},{'id': '372', 'type': 'expression_statement', 'children': ['373']},{'id': '373', 'type': 'assignment', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'sv_len'},{'id': '375', 'type': 'call', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '377', 'type': 'argument_list', 'children': ['378']},{'id': '378', 'type': 'subscript', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '380', 'type': 'string', 'children': [], 'value': "'sv_len'"},{'id': '381', 'type': 'expression_statement', 'children': ['382']},{'id': '382', 'type': 'assignment', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'filtered_variants'},{'id': '384', 'type': 'generator_expression', 'children': ['385', '386', '389']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '386', 'type': 'for_in_clause', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'filtered_variants'},{'id': '389', 'type': 'if_clause', 'children': ['390']},{'id': '390', 'type': 'comparison_operator', 'children': ['391', '394'], 'value': '>='},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'sv_len'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'sv_len'},{'id': '395', 'type': 'expression_statement', 'children': ['396']},{'id': '396', 'type': 'assignment', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '398', 'type': 'list', 'children': [], 'value': '[]'},{'id': '399', 'type': 'for_statement', 'children': ['400', '403', '407']},{'id': '400', 'type': 'pattern_list', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '403', 'type': 'call', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'filtered_variants'},{'id': '407', 'type': 'block', 'children': ['408']},{'id': '408', 'type': 'if_statement', 'children': ['409', '412']},{'id': '409', 'type': 'comparison_operator', 'children': ['410', '411'], 'value': '>='},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '412', 'type': 'block', 'children': ['413']},{'id': '413', 'type': 'if_statement', 'children': ['414', '417', '425']},{'id': '414', 'type': 'comparison_operator', 'children': ['415', '416'], 'value': '<'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '417', 'type': 'block', 'children': ['418']},{'id': '418', 'type': 'expression_statement', 'children': ['419']},{'id': '419', 'type': 'call', 'children': ['420', '423']},{'id': '420', 'type': 'attribute', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '423', 'type': 'argument_list', 'children': ['424']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '425', 'type': 'else_clause', 'children': ['426']},{'id': '426', 'type': 'block', 'children': ['427']},{'id': '427', 'type': 'break_statement', 'children': []},{'id': '428', 'type': 'return_statement', 'children': ['429']},{'id': '429', 'type': 'call', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'Results'},{'id': '431', 'type': 'argument_list', 'children': ['432', '433']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '433', 'type': 'call', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '435', 'type': 'argument_list', 'children': ['436']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'variants'}
def variants(self, case_id, skip=0, count=1000, filters=None): filters = filters or {} logger.debug("Looking for variants in {0}".format(case_id)) limit = count + skip gemini_query = filters.get('gemini_query') or "SELECT * from variants v" any_filter = False if filters.get('frequency'): frequency = filters['frequency'] extra_info = "(v.max_aaf_all < {0} or v.max_aaf_all is"\ " Null)".format(frequency) gemini_query = self.build_gemini_query(gemini_query, extra_info) if filters.get('cadd'): cadd_score = filters['cadd'] extra_info = "(v.cadd_scaled > {0})".format(cadd_score) gemini_query = self.build_gemini_query(gemini_query, extra_info) if filters.get('gene_ids'): gene_list = [gene_id.strip() for gene_id in filters['gene_ids']] gene_string = "v.gene in (" for index, gene_id in enumerate(gene_list): if index == 0: gene_string += "'{0}'".format(gene_id) else: gene_string += ", '{0}'".format(gene_id) gene_string += ")" gemini_query = self.build_gemini_query(gemini_query, gene_string) if filters.get('range'): chrom = filters['range']['chromosome'] if not chrom.startswith('chr'): chrom = "chr{0}".format(chrom) range_string = "v.chrom = '{0}' AND "\ "((v.start BETWEEN {1} AND {2}) OR "\ "(v.end BETWEEN {1} AND {2}))".format( chrom, filters['range']['start'], filters['range']['end'] ) gemini_query = self.build_gemini_query(gemini_query, range_string) filtered_variants = self._variants( case_id=case_id, gemini_query=gemini_query, ) if filters.get('consequence'): consequences = set(filters['consequence']) filtered_variants = (variant for variant in filtered_variants if set(variant.consequences).intersection(consequences)) if filters.get('impact_severities'): severities = set([severity.strip() for severity in filters['impact_severities']]) new_filtered_variants = [] filtered_variants = (variant for variant in filtered_variants if set([variant.impact_severity]).intersection(severities)) if filters.get('sv_len'): sv_len = int(filters['sv_len']) filtered_variants = (variant for variant in filtered_variants if variant.sv_len >= sv_len) variants = [] for index, variant_obj in enumerate(filtered_variants): if index >= skip: if index < limit: variants.append(variant_obj) else: break return Results(variants, len(variants))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_format_variant'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'individual_objs'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'add_all_info'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '21', '44', '84', '92', '101', '115', '121', '129', '137', '148', '159', '273', '280', '294', '301', '328']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '20', 'type': 'string', 'children': [], 'value': "'chrom'"},{'id': '21', 'type': 'if_statement', 'children': ['22', '35']},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '29'], 'value': 'or'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "'chr'"},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'CHR'"},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '41', 'type': 'slice', 'children': ['42', '43']},{'id': '42', 'type': 'integer', 'children': [], 'value': '3'},{'id': '43', 'type': 'colon', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'variant_dict'},{'id': '47', 'type': 'dictionary', 'children': ['48', '51', '59', '64', '69', '74', '79']},{'id': '48', 'type': 'pair', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'CHROM'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'POS'"},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '58', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '59', 'type': 'pair', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'ID'"},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '63', 'type': 'string', 'children': [], 'value': "'rs_ids'"},{'id': '64', 'type': 'pair', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': "'REF'"},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '68', 'type': 'string', 'children': [], 'value': "'ref'"},{'id': '69', 'type': 'pair', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'ALT'"},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '73', 'type': 'string', 'children': [], 'value': "'alt'"},{'id': '74', 'type': 'pair', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': "'QUAL'"},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '78', 'type': 'string', 'children': [], 'value': "'qual'"},{'id': '79', 'type': 'pair', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': "'FILTER'"},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '83', 'type': 'string', 'children': [], 'value': "'filter'"},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'Variant'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'dictionary_splat', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'variant_dict'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'update_variant_id'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '100', 'type': 'string', 'children': [], 'value': "'variant_id'"},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '"Creating a variant object of variant {0}"'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'variant_id'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '120']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '119', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_add_most_severe_consequence'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_add_impact_severity'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '147', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '158', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '159', 'type': 'if_statement', 'children': ['160', '165', '192']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '164'], 'value': '=='},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '164', 'type': 'string', 'children': [], 'value': "'sv'"},{'id': '165', 'type': 'block', 'children': ['166', '174', '185']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sv_type'},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '173', 'type': 'string', 'children': [], 'value': "'sub_type'"},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '184', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': '_add_sv_coordinates'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'id': '193', 'type': 'block', 'children': ['194', '202', '210', '218', '226', '239', '245', '256', '262']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_add_transcripts'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': '_add_thousand_g'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': '_add_exac'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '222', 'type': 'identifier', 'children': [], 'value': '_add_gmaf'},{'id': '223', 'type': 'argument_list', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '226', 'type': 'if_statement', 'children': ['227', '230']},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '229', 'type': 'string', 'children': [], 'value': "'cadd_scaled'"},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'cadd_score'},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '238', 'type': 'string', 'children': [], 'value': "'cadd_scaled'"},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'polyphen'},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '244', 'type': 'string', 'children': [], 'value': "'polyphen_pred'"},{'id': '245', 'type': 'if_statement', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'polyphen'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'add_severity'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255']},{'id': '254', 'type': 'string', 'children': [], 'value': "'Polyphen'"},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'polyphen'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'sift'},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '261', 'type': 'string', 'children': [], 'value': "'sift_pred'"},{'id': '262', 'type': 'if_statement', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'sift'},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'add_severity'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272']},{'id': '271', 'type': 'string', 'children': [], 'value': "'SIFT'"},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'sift'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': '_add_hgnc_symbols'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '280', 'type': 'if_statement', 'children': ['281', '286']},{'id': '281', 'type': 'comparison_operator', 'children': ['282', '285'], 'value': '=='},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '285', 'type': 'string', 'children': [], 'value': "'snv'"},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '291', 'type': 'identifier', 'children': [], 'value': '_add_genes'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '298', 'type': 'identifier', 'children': [], 'value': '_add_consequences'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '301', 'type': 'if_statement', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'add_all_info'},{'id': '303', 'type': 'block', 'children': ['304', '314']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '308', 'type': 'identifier', 'children': [], 'value': '_add_genotypes'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311', '312', '313']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'gemini_variant'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'individual_objs'},{'id': '314', 'type': 'if_statement', 'children': ['315', '320']},{'id': '315', 'type': 'comparison_operator', 'children': ['316', '319'], 'value': '=='},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'variant_type'},{'id': '319', 'type': 'string', 'children': [], 'value': "'sv'"},{'id': '320', 'type': 'block', 'children': ['321']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '325', 'type': 'identifier', 'children': [], 'value': '_add_genes'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '328', 'type': 'return_statement', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'variant'}
def _format_variant(self, case_id, gemini_variant, individual_objs, index=0, add_all_info=False): chrom = gemini_variant['chrom'] if chrom.startswith('chr') or chrom.startswith('CHR'): chrom = chrom[3:] variant_dict = { 'CHROM':chrom, 'POS':str(gemini_variant['start']), 'ID':gemini_variant['rs_ids'], 'REF':gemini_variant['ref'], 'ALT':gemini_variant['alt'], 'QUAL':gemini_variant['qual'], 'FILTER':gemini_variant['filter'] } variant = Variant(**variant_dict) variant.update_variant_id(gemini_variant['variant_id']) logger.debug("Creating a variant object of variant {0}".format( variant.variant_id)) variant['index'] = index self._add_most_severe_consequence(variant, gemini_variant) self._add_impact_severity(variant, gemini_variant) variant.start = int(gemini_variant['start']) variant.stop = int(gemini_variant['end']) if self.variant_type == 'sv': variant.sv_type = gemini_variant['sub_type'] variant.stop = int(gemini_variant['end']) self._add_sv_coordinates(variant) else: self._add_transcripts(variant, gemini_variant) self._add_thousand_g(variant, gemini_variant) self._add_exac(variant, gemini_variant) self._add_gmaf(variant, gemini_variant) if gemini_variant['cadd_scaled']: variant.cadd_score = gemini_variant['cadd_scaled'] polyphen = gemini_variant['polyphen_pred'] if polyphen: variant.add_severity('Polyphen', polyphen) sift = gemini_variant['sift_pred'] if sift: variant.add_severity('SIFT', sift) self._add_hgnc_symbols(variant) if self.variant_type == 'snv': self._add_genes(variant) self._add_consequences(variant) if add_all_info: self._add_genotypes(variant, gemini_variant, case_id, individual_objs) if self.variant_type == 'sv': self._add_genes(variant) return variant
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'arg'},{'id': '3', 'type': 'parameters', 'children': ['4', '6']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '182']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'decorate'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '13', 'type': 'block', 'children': ['14', '33', '43', '62', '137', '180']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '18', 'type': 'identifier', 'children': [], 'value': '__cmd_name__'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'cmd_name'"},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '29', 'type': 'string', 'children': [], 'value': "'__cmd_name__'"},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '__cls__'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'check_class'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '50']},{'id': '44', 'type': 'not_operator', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '49', 'type': 'string', 'children': [], 'value': "'__arguments__'"},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '__arguments__'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_functarguments'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '62', 'type': 'if_statement', 'children': ['63', '72']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '68'], 'value': 'or'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '72', 'type': 'block', 'children': ['73', '97', '126']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'arg_name'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': "'dest'"},{'id': '82', 'type': 'call', 'children': ['83', '94']},{'id': '83', 'type': 'attribute', 'children': ['84', '93']},{'id': '84', 'type': 'call', 'children': ['85', '91']},{'id': '85', 'type': 'attribute', 'children': ['86', '90']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '88', 'type': 'unary_operator', 'children': ['89'], 'value': '-'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '96', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '97', 'type': 'try_statement', 'children': ['98', '122']},{'id': '98', 'type': 'block', 'children': ['99', '110', '116']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '106', 'type': 'identifier', 'children': [], 'value': '__named__'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'arg_name'},{'id': '110', 'type': 'delete_statement', 'children': ['111']},{'id': '111', 'type': 'subscript', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '114', 'type': 'identifier', 'children': [], 'value': '__named__'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '116', 'type': 'delete_statement', 'children': ['117']},{'id': '117', 'type': 'subscript', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '120', 'type': 'identifier', 'children': [], 'value': '__arguments__'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '122', 'type': 'except_clause', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'pass_statement', 'children': []},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '133']},{'id': '128', 'type': 'attribute', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '131', 'type': 'identifier', 'children': [], 'value': '__arguments__'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'tuple', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '137', 'type': 'if_statement', 'children': ['138', '151']},{'id': '138', 'type': 'boolean_operator', 'children': ['139', '144'], 'value': 'and'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '143'], 'value': 'is'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '142', 'type': 'identifier', 'children': [], 'value': '__cls__'},{'id': '143', 'type': 'None', 'children': []},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'FunctionType'},{'id': '151', 'type': 'block', 'children': ['152', '161']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'ArgParseInator'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'skip_init'},{'id': '160', 'type': 'True', 'children': []},{'id': '161', 'type': 'if_statement', 'children': ['162', '169']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '166'], 'value': 'not'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '165', 'type': 'identifier', 'children': [], 'value': '__cmd_name__'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '179']},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '178', 'type': 'identifier', 'children': [], 'value': '__cmd_name__'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '182', 'type': 'return_statement', 'children': ['183']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'decorate'}
def arg(*args, **kwargs): def decorate(func): func.__cmd_name__ = kwargs.pop( 'cmd_name', getattr(func, '__cmd_name__', func.__name__)) func.__cls__ = utils.check_class() if not hasattr(func, '__arguments__'): func.__arguments__ = utils.get_functarguments(func) if len(args) or len(kwargs): arg_name = kwargs.get( 'dest', args[-1].lstrip('-').replace('-', '_')) try: idx = func.__named__.index(arg_name) del func.__named__[idx] del func.__arguments__[idx] except ValueError: pass func.__arguments__.append((args, kwargs,)) if func.__cls__ is None and isinstance(func, types.FunctionType): ap_ = ArgParseInator(skip_init=True) if func.__cmd_name__ not in ap_.commands: ap_.commands[func.__cmd_name__] = func return func return decorate
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'class_args'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'block', 'children': ['6', '15', '23', '29', '33', '44', '92', '150']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ArgParseInator'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'keyword_argument', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'skip_init'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'collect_appendvars'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '__cls__'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'cmds'},{'id': '32', 'type': 'dictionary', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '__arguments__'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '42', 'type': 'string', 'children': [], 'value': "'__arguments__'"},{'id': '43', 'type': 'list', 'children': [], 'value': '[]'},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '71']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '46', 'type': 'list_comprehension', 'children': ['47', '48', '57']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '54', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'if_clause', 'children': ['58']},{'id': '58', 'type': 'boolean_operator', 'children': ['59', '64'], 'value': 'and'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '63', 'type': 'string', 'children': [], 'value': "'__cmd_name__'"},{'id': '64', 'type': 'not_operator', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '71', 'type': 'block', 'children': ['72', '78', '84']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '__subcommands__'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '__cls__'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '91']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'cmds'},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '90', 'type': 'identifier', 'children': [], 'value': '__cmd_name__'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '92', 'type': 'if_statement', 'children': ['93', '106', '123']},{'id': '93', 'type': 'boolean_operator', 'children': ['94', '99'], 'value': 'and'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '98', 'type': 'string', 'children': [], 'value': "'__cmd_name__'"},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': 'not'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '102', 'type': 'identifier', 'children': [], 'value': '__cmd_name__'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '106', 'type': 'block', 'children': ['107', '113']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '111', 'type': 'identifier', 'children': [], 'value': '__subcommands__'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'cmds'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '122']},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '__cmd_name__'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'for_statement', 'children': ['126', '129', '134']},{'id': '126', 'type': 'pattern_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'cmds'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '133', 'type': 'argument_list', 'children': []},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'if_statement', 'children': ['136', '141']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'not'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '149']},{'id': '144', 'type': 'subscript', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ap_'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'cls'}
def class_args(cls): ap_ = ArgParseInator(skip_init=True) utils.collect_appendvars(ap_, cls) cls.__cls__ = cls cmds = {} cls.__arguments__ = getattr(cls, '__arguments__', []) for func in [f for f in cls.__dict__.values() if hasattr(f, '__cmd_name__') and not inspect.isclass(f)]: func.__subcommands__ = None func.__cls__ = cls cmds[func.__cmd_name__] = func if hasattr(cls, '__cmd_name__') and cls.__cmd_name__ not in ap_.commands: cls.__subcommands__ = cmds ap_.commands[cls.__cmd_name__] = cls else: for name, func in cmds.items(): if name not in ap_.commands: ap_.commands[name] = func return cls
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_args'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '36', '58', '98', '110', '222']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_compile'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_self_event'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26', '34']},{'id': '24', 'type': 'string', 'children': [], 'value': "'before_parse'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'parse'"},{'id': '26', 'type': 'list_splat', 'children': ['27']},{'id': '27', 'type': 'subscript', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '31', 'type': 'slice', 'children': ['32', '33']},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'colon', 'children': []},{'id': '34', 'type': 'dictionary_splat', 'children': ['35']},{'id': '35', 'type': 'dictionary', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cmds'},{'id': '39', 'type': 'list_comprehension', 'children': ['40', '41', '50']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '47', 'type': 'slice', 'children': ['48', '49']},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'colon', 'children': []},{'id': '50', 'type': 'if_clause', 'children': ['51']},{'id': '51', 'type': 'not_operator', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '58', 'type': 'if_statement', 'children': ['59', '85']},{'id': '59', 'type': '()', 'children': ['60']},{'id': '60', 'type': 'boolean_operator', 'children': ['61', '78'], 'value': 'and'},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '75'], 'value': 'and'},{'id': '62', 'type': 'boolean_operator', 'children': ['63', '69'], 'value': 'and'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '68'], 'value': '>'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'cmds'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'not_operator', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'check_help'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'default_cmd'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': 'not'},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'cmds'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'default_cmd'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '114', 'type': 'block', 'children': ['115', '201', '216']},{'id': '115', 'type': 'if_statement', 'children': ['116', '127']},{'id': '116', 'type': 'boolean_operator', 'children': ['117', '120'], 'value': 'and'},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'add_output'},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '126'], 'value': 'is'},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'block', 'children': ['128', '138']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '138', 'type': 'if_statement', 'children': ['139', '150', '169']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '149'], 'value': '=='},{'id': '140', 'type': 'call', 'children': ['141', '148']},{'id': '141', 'type': 'attribute', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'string', 'children': [], 'value': "'raw'"},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': '_output'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '158', 'type': 'argument_list', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'write_mode'},{'id': '169', 'type': 'else_clause', 'children': ['170']},{'id': '170', 'type': 'block', 'children': ['171', '174']},{'id': '171', 'type': 'import_statement', 'children': ['172']},{'id': '172', 'type': 'dotted_name', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'codecs'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '178', 'type': 'identifier', 'children': [], 'value': '_output'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'codecs'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '183', 'type': 'argument_list', 'children': ['184', '189', '194']},{'id': '184', 'type': 'attribute', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'write_mode'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '196', 'type': 'attribute', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '201', 'type': 'if_statement', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': '_cfg_factory'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'cfg_file'},{'id': '211', 'type': 'attribute', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': '_is_parsed'},{'id': '221', 'type': 'True', 'children': []},{'id': '222', 'type': 'return_statement', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'}
def parse_args(self): self._compile() self.args = None self._self_event('before_parse', 'parse', *sys.argv[1:], **{}) cmds = [cmd for cmd in sys.argv[1:] if not cmd.startswith("-")] if (len(cmds) > 0 and not utils.check_help() and self.default_cmd and cmds[0] not in self.commands): sys.argv.insert(1, self.default_cmd) self.args = self.parser.parse_args() if self.args: if self.add_output and self.args.output is not None: self.encoding = self.args.encoding if self.args.encoding.lower() == 'raw': self._output = open(self.args.output, self.args.write_mode) else: import codecs self._output = codecs.open( self.args.output, self.args.write_mode, encoding=self.args.encoding) if self._cfg_factory: self.cfg_file = self.args.config self._is_parsed = True return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_command'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'new_attributes'},{'id': '7', 'type': 'block', 'children': ['8', '20', '72', '101', '109', '123']},{'id': '8', 'type': 'if_statement', 'children': ['9', '13']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_is_parsed'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'if_statement', 'children': ['21', '25', '30', '41']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'raise_statement', 'children': ['27']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ArgParseInatorNoCommandsFound'},{'id': '30', 'type': 'elif_clause', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_single'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_single'},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43', '60']},{'id': '43', 'type': 'if_statement', 'children': ['44', '50']},{'id': '44', 'type': 'not_operator', 'children': ['45']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': '"too few arguments"'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '72', 'type': 'if_statement', 'children': ['73', '82', '95']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '79'], 'value': 'and'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '78', 'type': 'string', 'children': [], 'value': "'__subcommands__'"},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '__subcommands__'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '86', 'type': 'subscript', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '__subcommands__'},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'subcommand'},{'id': '95', 'type': 'else_clause', 'children': ['96']},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'cmd_name'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '__cmd_name__'},{'id': '109', 'type': 'if_statement', 'children': ['110', '120']},{'id': '110', 'type': 'not_operator', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'check_auth'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_execute'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '131', 'type': 'dictionary_splat', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'new_attributes'}
def check_command(self, **new_attributes): if not self._is_parsed: self.parse_args() if not self.commands: raise exceptions.ArgParseInatorNoCommandsFound elif self._single: func = self._single else: if not self.args.command: self.parser.error("too few arguments") func = self.commands[self.args.command] if hasattr(func, '__subcommands__') and func.__subcommands__: command = func.__subcommands__[self.args.subcommand] else: command = func self.cmd_name = command.__cmd_name__ if not self.check_auth(id(command)): return 0 return self._execute(func, command, **new_attributes)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '25']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'merged_root'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_recursive_merge'},{'id': '15', 'type': 'argument_list', 'children': ['16', '19', '22']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'conflicts'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'MergeError'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'Conflicts Occurred in Merge Process'"},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'conflicts'}
def merge(self): self.merged_root = self._recursive_merge(self.root, self.head, self.update) if self.conflicts: raise MergeError('Conflicts Occurred in Merge Process', self.conflicts)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_zadd'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '21']},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'eval'},{'id': '21', 'type': 'argument_list', 'children': ['22', '25', '26', '27', '34']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'LUA_ZADD'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '29'], 'value': 'or'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_time'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pk'}
def _zadd(self, key, pk, ts=None, ttl=None): return self.r.eval(self.LUA_ZADD, 1, key, ts or self._time(), pk)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '24']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_keygen'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '24', 'type': 'try_statement', 'children': ['25', '38']},{'id': '25', 'type': 'block', 'children': ['26', '36']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_zadd'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34', '35']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ttl'},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'True', 'children': []},{'id': '38', 'type': 'except_clause', 'children': ['39', '45']},{'id': '39', 'type': 'as_pattern', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'redis'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '43', 'type': 'as_pattern_target', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '45', 'type': 'block', 'children': ['46', '57']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '%'},{'id': '55', 'type': 'string', 'children': [], 'value': '"redis event store failed with connection error %r"'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'False', 'children': []}
def add(self, event, pk, ts=None, ttl=None): key = self._keygen(event, ts) try: self._zadd(key, pk, ts, ttl) return True except redis.ConnectionError as e: self.logger.error( "redis event store failed with connection error %r" % e) return False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_parameter'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '10', '27', '38', '48', '57', '79', '87', '113', '126', '136', '152', '179', '216', '224', '252', '287', '303', '316']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''Add the parameter to ``Parameters``.\n **Arguments**\n The arguments are lumped into two groups:``Parameters.add_parameter``\n and ``argparse.ArgumentParser.add_argument``. Parameters that are only\n used by ``Parameters.add_parameter`` are removed before ``kwargs`` is\n passed directly to argparse.ArgumentParser.add_argument``.\n .. note::\n Once ``parse`` has been called ``Parameters.parsed`` will be True\n and it is inadvisable to add more parameters to the ``Parameters``.\n *``Parameters.add_parameter`` Arguments*\n :``environment_prefix``: Prefix to add when searching the environment\n for this parameter. Default:\n os.path.basename(sys.argv[0]).\n :``group``: Group (namespace or prefix) for parameter\n (corresponds to section name in configuration\n files). Default: 'default'.\n :``options``: REQUIRED. The list of options to match for\n this parameter in argv.\n :``only``: Iterable containing the components that this\n parameter applies to (i.e. 'environment',\n 'configuration', 'argument'). Default:\n ('environment', 'configuration', 'argument').\n *``argparse.ArgumentParser.add_argument`` Arguments*\n :``name or flags``: Positional argument filled in by options keyword\n argument.\n :``action``: The basic type of action to be taken when this\n argument is encountered at the command line.\n :``nargs``: The number of command-line arguments that should be\n consumed.\n :``const``: A constant value required by some action and nargs\n selections.\n :``default``: The value produced if the argument is absent from\n the command line.\n :``type``: The type to which the command-line argument should\n be converted.\n :``choices``: A container of the allowable values for the\n argument.\n :``required``: Whether or not the command-line option may be\n omitted (optionals only).\n :``help``: A brief description of what the argument does.\n :``metavar``: A name for the argument in usage messages.\n :``dest``: The name of the attribute to be added to the object\n returned by parse_args().\n '''"},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '13', 'type': 'call', 'children': ['14', '25']},{'id': '14', 'type': 'attribute', 'children': ['15', '24']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '17', 'type': 'argument_list', 'children': ['18', '21']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '20', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'in'},{'id': '29', 'type': 'string', 'children': [], 'value': "'dest'"},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '37', 'type': 'string', 'children': [], 'value': "'dest'"},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'group'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '55']},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '60', 'type': 'call', 'children': ['61', '76']},{'id': '61', 'type': 'attribute', 'children': ['62', '75']},{'id': '62', 'type': 'call', 'children': ['63', '73']},{'id': '63', 'type': 'attribute', 'children': ['64', '72']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'list', 'children': ['70', '71'], 'value': '[ group, parameter_name ]'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': "'adding parameter %s'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '87', 'type': 'if_statement', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '91', 'type': 'block', 'children': ['92', '100']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'adding parameter %s after parse'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '105', 'type': 'argument_list', 'children': ['106', '112']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'adding parameter {} after parse'"},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'RuntimeWarning'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '120']},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '135']},{'id': '128', 'type': 'subscript', 'children': ['129', '134']},{'id': '129', 'type': 'subscript', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '134', 'type': 'string', 'children': [], 'value': "'group'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '145']},{'id': '138', 'type': 'subscript', 'children': ['139', '144']},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '144', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '161']},{'id': '154', 'type': 'subscript', 'children': ['155', '160']},{'id': '155', 'type': 'subscript', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '160', 'type': 'string', 'children': [], 'value': "'environment_prefix'"},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': "'environment_prefix'"},{'id': '167', 'type': 'call', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'if_statement', 'children': ['180', '189']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '188'], 'value': 'is'},{'id': '181', 'type': 'subscript', 'children': ['182', '187']},{'id': '182', 'type': 'subscript', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '187', 'type': 'string', 'children': [], 'value': "'environment_prefix'"},{'id': '188', 'type': 'None', 'children': []},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '199']},{'id': '192', 'type': 'subscript', 'children': ['193', '198']},{'id': '193', 'type': 'subscript', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '198', 'type': 'string', 'children': [], 'value': "'environment_prefix'"},{'id': '199', 'type': 'call', 'children': ['200', '213']},{'id': '200', 'type': 'attribute', 'children': ['201', '212']},{'id': '201', 'type': 'call', 'children': ['202', '211']},{'id': '202', 'type': 'attribute', 'children': ['203', '210']},{'id': '203', 'type': 'subscript', 'children': ['204', '209']},{'id': '204', 'type': 'subscript', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '209', 'type': 'string', 'children': [], 'value': "'environment_prefix'"},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '215', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': "'group: %s'"},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '237']},{'id': '226', 'type': 'attribute', 'children': ['227', '236']},{'id': '227', 'type': 'call', 'children': ['228', '233']},{'id': '228', 'type': 'attribute', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'grouped_parameters'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '235', 'type': 'dictionary', 'children': []},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '237', 'type': 'argument_list', 'children': ['238', '247']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '242', 'type': 'argument_list', 'children': ['243', '246']},{'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '+'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '245', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '246', 'type': 'string', 'children': [], 'value': "''"},{'id': '247', 'type': 'subscript', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'action_defaults'},{'id': '255', 'type': 'dictionary', 'children': ['256', '264', '272', '275', '278', '281', '284']},{'id': '256', 'type': 'pair', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': "'store'"},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '264', 'type': 'pair', 'children': ['265', '266']},{'id': '265', 'type': 'string', 'children': [], 'value': "'store_const'"},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'string', 'children': [], 'value': "'const'"},{'id': '272', 'type': 'pair', 'children': ['273', '274']},{'id': '273', 'type': 'string', 'children': [], 'value': "'store_true'"},{'id': '274', 'type': 'False', 'children': []},{'id': '275', 'type': 'pair', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': "'store_false'"},{'id': '277', 'type': 'True', 'children': []},{'id': '278', 'type': 'pair', 'children': ['279', '280']},{'id': '279', 'type': 'string', 'children': [], 'value': "'append'"},{'id': '280', 'type': 'list', 'children': [], 'value': '[]'},{'id': '281', 'type': 'pair', 'children': ['282', '283']},{'id': '282', 'type': 'string', 'children': [], 'value': "'append_const'"},{'id': '283', 'type': 'list', 'children': [], 'value': '[]'},{'id': '284', 'type': 'pair', 'children': ['285', '286']},{'id': '285', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '286', 'type': 'integer', 'children': [], 'value': '0'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '294']},{'id': '289', 'type': 'subscript', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'parameter_name'},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'action_defaults'},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '300', 'type': 'argument_list', 'children': ['301', '302']},{'id': '301', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '302', 'type': 'string', 'children': [], 'value': "'store'"},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '308', 'type': 'argument_list', 'children': ['309', '310']},{'id': '309', 'type': 'string', 'children': [], 'value': "'default value: %s'"},{'id': '310', 'type': 'call', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '316', 'type': 'if_statement', 'children': ['317', '327']},{'id': '317', 'type': 'comparison_operator', 'children': ['318', '319'], 'value': 'in'},{'id': '318', 'type': 'string', 'children': [], 'value': "'argument'"},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325']},{'id': '324', 'type': 'string', 'children': [], 'value': "'only'"},{'id': '325', 'type': 'list', 'children': ['326'], 'value': "[ 'argument' ]"},{'id': '326', 'type': 'string', 'children': [], 'value': "'argument'"},{'id': '327', 'type': 'block', 'children': ['328', '352', '417']},{'id': '328', 'type': 'if_statement', 'children': ['329', '334']},{'id': '329', 'type': 'comparison_operator', 'children': ['330', '331'], 'value': 'not'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '333', 'type': 'identifier', 'children': [], 'value': '_group_parsers'},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'assignment', 'children': ['337', '342']},{'id': '337', 'type': 'subscript', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '340', 'type': 'identifier', 'children': [], 'value': '_group_parsers'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '342', 'type': 'call', 'children': ['343', '350']},{'id': '343', 'type': 'attribute', 'children': ['344', '349']},{'id': '344', 'type': 'subscript', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '347', 'type': 'identifier', 'children': [], 'value': '_group_parsers'},{'id': '348', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'add_argument_group'},{'id': '350', 'type': 'argument_list', 'children': ['351']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '352', 'type': 'if_statement', 'children': ['353', '360']},{'id': '353', 'type': 'boolean_operator', 'children': ['354', '357'], 'value': 'and'},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '356', 'type': 'identifier', 'children': [], 'value': '_group_prefix'},{'id': '357', 'type': 'comparison_operator', 'children': ['358', '359'], 'value': '!='},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '359', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '360', 'type': 'block', 'children': ['361', '373', '382', '407']},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'long_option'},{'id': '364', 'type': 'call', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '366', 'type': 'argument_list', 'children': ['367', '370']},{'id': '367', 'type': 'subscript', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '369', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '370', 'type': 'keyword_argument', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '380']},{'id': '375', 'type': 'attribute', 'children': ['376', '379']},{'id': '376', 'type': 'subscript', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '378', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'long_option'},{'id': '382', 'type': 'expression_statement', 'children': ['383']},{'id': '383', 'type': 'call', 'children': ['384', '389']},{'id': '384', 'type': 'attribute', 'children': ['385', '388']},{'id': '385', 'type': 'subscript', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '387', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'call', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'long_option'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '394', 'type': 'argument_list', 'children': ['395', '396']},{'id': '395', 'type': 'string', 'children': [], 'value': "'--'"},{'id': '396', 'type': 'binary_operator', 'children': ['397', '406'], 'value': '+'},{'id': '397', 'type': 'binary_operator', 'children': ['398', '399'], 'value': '+'},{'id': '398', 'type': 'string', 'children': [], 'value': "'--'"},{'id': '399', 'type': 'call', 'children': ['400', '403']},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '403', 'type': 'argument_list', 'children': ['404', '405']},{'id': '404', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '405', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '406', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '407', 'type': 'expression_statement', 'children': ['408']},{'id': '408', 'type': 'call', 'children': ['409', '412']},{'id': '409', 'type': 'attribute', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '412', 'type': 'argument_list', 'children': ['413', '414']},{'id': '413', 'type': 'string', 'children': [], 'value': "'options: %s'"},{'id': '414', 'type': 'subscript', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '416', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '417', 'type': 'expression_statement', 'children': ['418']},{'id': '418', 'type': 'call', 'children': ['419', '426']},{'id': '419', 'type': 'attribute', 'children': ['420', '425']},{'id': '420', 'type': 'subscript', 'children': ['421', '424']},{'id': '421', 'type': 'attribute', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '423', 'type': 'identifier', 'children': [], 'value': '_group_parsers'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '426', 'type': 'argument_list', 'children': ['427', '434']},{'id': '427', 'type': 'list_splat', 'children': ['428']},{'id': '428', 'type': 'call', 'children': ['429', '432']},{'id': '429', 'type': 'attribute', 'children': ['430', '431']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '432', 'type': 'argument_list', 'children': ['433']},{'id': '433', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '434', 'type': 'dictionary_splat', 'children': ['435']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def add_parameter(self, **kwargs): '''Add the parameter to ``Parameters``. **Arguments** The arguments are lumped into two groups:``Parameters.add_parameter`` and ``argparse.ArgumentParser.add_argument``. Parameters that are only used by ``Parameters.add_parameter`` are removed before ``kwargs`` is passed directly to argparse.ArgumentParser.add_argument``. .. note:: Once ``parse`` has been called ``Parameters.parsed`` will be True and it is inadvisable to add more parameters to the ``Parameters``. *``Parameters.add_parameter`` Arguments* :``environment_prefix``: Prefix to add when searching the environment for this parameter. Default: os.path.basename(sys.argv[0]). :``group``: Group (namespace or prefix) for parameter (corresponds to section name in configuration files). Default: 'default'. :``options``: REQUIRED. The list of options to match for this parameter in argv. :``only``: Iterable containing the components that this parameter applies to (i.e. 'environment', 'configuration', 'argument'). Default: ('environment', 'configuration', 'argument'). *``argparse.ArgumentParser.add_argument`` Arguments* :``name or flags``: Positional argument filled in by options keyword argument. :``action``: The basic type of action to be taken when this argument is encountered at the command line. :``nargs``: The number of command-line arguments that should be consumed. :``const``: A constant value required by some action and nargs selections. :``default``: The value produced if the argument is absent from the command line. :``type``: The type to which the command-line argument should be converted. :``choices``: A container of the allowable values for the argument. :``required``: Whether or not the command-line option may be omitted (optionals only). :``help``: A brief description of what the argument does. :``metavar``: A name for the argument in usage messages. :``dest``: The name of the attribute to be added to the object returned by parse_args(). ''' parameter_name = max(kwargs['options'], key = len).lstrip('-') if 'dest' in kwargs: parameter_name = kwargs['dest'] group = kwargs.pop('group', 'default') self.groups.add(group) parameter_name = '.'.join([ group, parameter_name ]).lstrip('.').replace('-', '_') logger.info('adding parameter %s', parameter_name) if self.parsed: logger.warn('adding parameter %s after parse', parameter_name) warnings.warn('adding parameter {} after parse'.format(parameter_name), RuntimeWarning) self.parameters[parameter_name] = copy.copy(kwargs) self.parameters[parameter_name]['group'] = group self.parameters[parameter_name]['type'] = kwargs.get('type', str) self.parameters[parameter_name]['environment_prefix'] = kwargs.pop('environment_prefix', os.path.basename(sys.argv[0])) if self.parameters[parameter_name]['environment_prefix'] is not None: self.parameters[parameter_name]['environment_prefix'] = self.parameters[parameter_name]['environment_prefix'].upper().replace('-', '_') logger.info('group: %s', group) self.grouped_parameters.setdefault(group, {}).setdefault(parameter_name.replace(group + '.', ''), self.parameters[parameter_name]) action_defaults = { 'store': kwargs.get('default'), 'store_const': kwargs.get('const'), 'store_true': False, 'store_false': True, 'append': [], 'append_const': [], 'count': 0, } self.defaults[parameter_name] = action_defaults[kwargs.get('action', 'store')] logger.info('default value: %s', kwargs.get('default')) if 'argument' in kwargs.pop('only', [ 'argument' ]): if group not in self._group_parsers: self._group_parsers[group] = self._group_parsers['default'].add_argument_group(group) if self._group_prefix and group != 'default': long_option = max(kwargs['options'], key = len) kwargs['options'].remove(long_option) kwargs['options'].append(long_option.replace('--', '--' + group.replace('_', '-') + '-')) logger.debug('options: %s', kwargs['options']) self._group_parsers[group].add_argument(*kwargs.pop('options'), **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mysql_pub'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mysql_dsn'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'blocking'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '13', 'type': 'block', 'children': ['14', '21', '47', '76', '108']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'mysql_dsn'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'mysql_settings'},{'id': '24', 'type': 'dictionary', 'children': ['25', '30', '37', '42']},{'id': '25', 'type': 'pair', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': '"host"'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'hostname'},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': '"port"'},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '36'], 'value': 'or'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '36', 'type': 'integer', 'children': [], 'value': '3306'},{'id': '37', 'type': 'pair', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '"user"'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '42', 'type': 'pair', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': '"passwd"'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'pymysqlreplication'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'BinLogStreamReader'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '65', '68', '74']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mysql_settings'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'server_id'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'integer', 'children': [], 'value': '1000000000'},{'id': '64', 'type': 'integer', 'children': [], 'value': '4294967295'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'blocking'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'blocking'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'only_events'},{'id': '70', 'type': 'list', 'children': ['71', '72', '73'], 'value': '[DeleteRowsEvent, UpdateRowsEvent, WriteRowsEvent]'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'DeleteRowsEvent'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'UpdateRowsEvent'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'WriteRowsEvent'},{'id': '74', 'type': 'dictionary_splat', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '76', 'type': 'function_definition', 'children': ['77', '78', '80']},{'id': '77', 'type': 'function_name', 'children': [], 'value': '_pk'},{'id': '78', 'type': 'parameters', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '80', 'type': 'block', 'children': ['81', '96']},{'id': '81', 'type': 'if_statement', 'children': ['82', '89']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '84', 'type': 'argument_list', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'primary_key'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'return_statement', 'children': ['91']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'primary_key'},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '99', 'type': 'generator_expression', 'children': ['100', '103']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '103', 'type': 'for_in_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'primary_key'},{'id': '108', 'type': 'for_statement', 'children': ['109', '110', '111']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '111', 'type': 'block', 'children': ['112', '119', '129', '153', '166', '376']},{'id': '112', 'type': 'if_statement', 'children': ['113', '117']},{'id': '113', 'type': 'not_operator', 'children': ['114']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'primary_key'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'continue_statement', 'children': []},{'id': '119', 'type': 'if_statement', 'children': ['120', '127']},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '122'], 'value': 'and'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': 'not'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'continue_statement', 'children': []},{'id': '129', 'type': 'try_statement', 'children': ['130', '137']},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '137', 'type': 'except_clause', 'children': ['138', '144']},{'id': '138', 'type': 'as_pattern', 'children': ['139', '142']},{'id': '139', 'type': 'tuple', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '142', 'type': 'as_pattern_target', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '144', 'type': 'block', 'children': ['145', '152']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '152', 'type': 'continue_statement', 'children': []},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '156', 'type': 'call', 'children': ['157', '162']},{'id': '157', 'type': 'attribute', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'fromtimestamp'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '166', 'type': 'if_statement', 'children': ['167', '172', '236', '306']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'WriteRowsEvent'},{'id': '172', 'type': 'block', 'children': ['173', '181', '188', '197']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '%'},{'id': '177', 'type': 'string', 'children': [], 'value': '"%s_write"'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'sg'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'sg_raw'},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '%'},{'id': '195', 'type': 'string', 'children': [], 'value': '"%s_raw"'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '197', 'type': 'for_statement', 'children': ['198', '199', '200']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '200', 'type': 'block', 'children': ['201', '210', '217', '224']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': '_pk'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '209', 'type': 'string', 'children': [], 'value': '"values"'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'sg'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'sg_raw'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '%'},{'id': '231', 'type': 'string', 'children': [], 'value': '"%s -> %s, %s"'},{'id': '232', 'type': 'tuple', 'children': ['233', '234', '235']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '236', 'type': 'elif_clause', 'children': ['237', '242']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'UpdateRowsEvent'},{'id': '242', 'type': 'block', 'children': ['243', '251', '258', '267']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '%'},{'id': '247', 'type': 'string', 'children': [], 'value': '"%s_update"'},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'sg'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'sg_raw'},{'id': '261', 'type': 'call', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'binary_operator', 'children': ['265', '266'], 'value': '%'},{'id': '265', 'type': 'string', 'children': [], 'value': '"%s_raw"'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '267', 'type': 'for_statement', 'children': ['268', '269', '270']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '270', 'type': 'block', 'children': ['271', '280', '287', '294']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': '_pk'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '279', 'type': 'string', 'children': [], 'value': '"after_values"'},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'sg'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'sg_raw'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'binary_operator', 'children': ['301', '302'], 'value': '%'},{'id': '301', 'type': 'string', 'children': [], 'value': '"%s -> %s, %s"'},{'id': '302', 'type': 'tuple', 'children': ['303', '304', '305']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '306', 'type': 'elif_clause', 'children': ['307', '312']},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'DeleteRowsEvent'},{'id': '312', 'type': 'block', 'children': ['313', '321', '328', '337']},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '316', 'type': 'binary_operator', 'children': ['317', '318'], 'value': '%'},{'id': '317', 'type': 'string', 'children': [], 'value': '"%s_delete"'},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'assignment', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'sg'},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'sg_raw'},{'id': '331', 'type': 'call', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '333', 'type': 'argument_list', 'children': ['334']},{'id': '334', 'type': 'binary_operator', 'children': ['335', '336'], 'value': '%'},{'id': '335', 'type': 'string', 'children': [], 'value': '"%s_raw"'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '337', 'type': 'for_statement', 'children': ['338', '339', '340']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '340', 'type': 'block', 'children': ['341', '350', '357', '364']},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'assignment', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': '_pk'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'subscript', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '349', 'type': 'string', 'children': [], 'value': '"values"'},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'sg'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'call', 'children': ['359', '362']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'sg_raw'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'binary_operator', 'children': ['371', '372'], 'value': '%'},{'id': '371', 'type': 'string', 'children': [], 'value': '"%s -> %s, %s"'},{'id': '372', 'type': 'tuple', 'children': ['373', '374', '375']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'sg_name'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'timestamp'},{'id': '376', 'type': 'expression_statement', 'children': ['377']},{'id': '377', 'type': 'call', 'children': ['378', '384']},{'id': '378', 'type': 'attribute', 'children': ['379', '383']},{'id': '379', 'type': 'call', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'signal'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'string', 'children': [], 'value': '"mysql_binlog_pos"'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'send'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'binary_operator', 'children': ['386', '387'], 'value': '%'},{'id': '386', 'type': 'string', 'children': [], 'value': '"%s:%s"'},{'id': '387', 'type': 'tuple', 'children': ['388', '391']},{'id': '388', 'type': 'attribute', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'log_file'},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'log_pos'}
def mysql_pub(mysql_dsn, tables=None, blocking=False, **kwargs): parsed = urlparse(mysql_dsn) mysql_settings = { "host": parsed.hostname, "port": parsed.port or 3306, "user": parsed.username, "passwd": parsed.password } stream = pymysqlreplication.BinLogStreamReader( mysql_settings, server_id=random.randint(1000000000, 4294967295), blocking=blocking, only_events=[DeleteRowsEvent, UpdateRowsEvent, WriteRowsEvent], **kwargs ) def _pk(values): if isinstance(event.primary_key, str): return values[event.primary_key] return tuple(values[k] for k in event.primary_key) for event in stream: if not event.primary_key: continue if tables and event.table not in tables: continue try: rows = event.rows except (UnicodeDecodeError, ValueError) as e: logger.exception(e) continue timestamp = datetime.datetime.fromtimestamp(event.timestamp) if isinstance(event, WriteRowsEvent): sg_name = "%s_write" % event.table sg = signal(sg_name) sg_raw = signal("%s_raw" % sg_name) for row in rows: pk = _pk(row["values"]) sg.send(pk) sg_raw.send(row) logger.debug("%s -> %s, %s" % (sg_name, pk, timestamp)) elif isinstance(event, UpdateRowsEvent): sg_name = "%s_update" % event.table sg = signal(sg_name) sg_raw = signal("%s_raw" % sg_name) for row in rows: pk = _pk(row["after_values"]) sg.send(pk) sg_raw.send(row) logger.debug("%s -> %s, %s" % (sg_name, pk, timestamp)) elif isinstance(event, DeleteRowsEvent): sg_name = "%s_delete" % event.table sg = signal(sg_name) sg_raw = signal("%s_raw" % sg_name) for row in rows: pk = _pk(row["values"]) sg.send(pk) sg_raw.send(row) logger.debug("%s -> %s, %s" % (sg_name, pk, timestamp)) signal("mysql_binlog_pos").send( "%s:%s" % (stream.log_file, stream.log_pos))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_step'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'xy_values'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'coeff'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '9', 'type': 'block', 'children': ['10', '25', '196', '215', '233']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '13', 'type': 'dictionary_comprehension', 'children': ['14', '17']},{'id': '14', 'type': 'pair', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'for_in_clause', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'xy_values'},{'id': '25', 'type': 'for_statement', 'children': ['26', '33', '41']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '30']},{'id': '27', 'type': 'tuple_pattern', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'index1'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'value1'},{'id': '30', 'type': 'tuple_pattern', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'index2'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'value2'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'combinations'},{'id': '35', 'type': 'argument_list', 'children': ['36', '40']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'xy_values'},{'id': '40', 'type': 'integer', 'children': [], 'value': '2'},{'id': '41', 'type': 'block', 'children': ['42', '63']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'calc_2d_forces'},{'id': '49', 'type': 'argument_list', 'children': ['50', '53', '56', '59', '62']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'value1'},{'id': '52', 'type': 'integer', 'children': [], 'value': '0'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'value1'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'value2'},{'id': '58', 'type': 'integer', 'children': [], 'value': '0'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'value2'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '63', 'type': 'if_statement', 'children': ['64', '71', '133']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '68'], 'value': '<'},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'coeff'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'index1'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'coeff'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'index2'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'if_statement', 'children': ['73', '86', '109']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '81'], 'value': '<'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '78'], 'value': '-'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'b_lenght'},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'coeff'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'index2'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '85'], 'value': '/'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'b_lenght'},{'id': '85', 'type': 'integer', 'children': [], 'value': '10'},{'id': '86', 'type': 'block', 'children': ['87', '98']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'index1'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'index2'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111', '122']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'index1'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '121', 'type': 'integer', 'children': [], 'value': '0'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'index2'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'if_statement', 'children': ['136', '149', '172']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '144'], 'value': '<'},{'id': '137', 'type': 'binary_operator', 'children': ['138', '141'], 'value': '-'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'b_lenght'},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'coeff'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'index1'},{'id': '144', 'type': 'binary_operator', 'children': ['145', '148'], 'value': '/'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'b_lenght'},{'id': '148', 'type': 'integer', 'children': [], 'value': '10'},{'id': '149', 'type': 'block', 'children': ['150', '161']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '157']},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'index1'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'index2'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '171', 'type': 'integer', 'children': [], 'value': '1'},{'id': '172', 'type': 'else_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174', '185']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '181']},{'id': '176', 'type': 'attribute', 'children': ['177', '180']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'index1'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '184', 'type': 'integer', 'children': [], 'value': '1'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'index2'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '199', 'type': 'dictionary_comprehension', 'children': ['200', '206']},{'id': '200', 'type': 'pair', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '206', 'type': 'for_in_clause', 'children': ['207', '210']},{'id': '207', 'type': 'pattern_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '214', 'type': 'argument_list', 'children': []},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'energy'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'list_comprehension', 'children': ['222', '226']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '226', 'type': 'for_in_clause', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '232', 'type': 'argument_list', 'children': []},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'expression_list', 'children': ['235', '252']},{'id': '235', 'type': 'list_comprehension', 'children': ['236', '244']},{'id': '236', 'type': '()', 'children': ['237']},{'id': '237', 'type': 'binary_operator', 'children': ['238', '243'], 'value': '+'},{'id': '238', 'type': 'binary_operator', 'children': ['239', '242'], 'value': '/'},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'forces'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '242', 'type': 'integer', 'children': [], 'value': '10'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '244', 'type': 'for_in_clause', 'children': ['245', '248']},{'id': '245', 'type': 'pattern_list', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'energy'}
def do_step(self, values, xy_values,coeff, width): forces = {k:[] for k,i in enumerate(xy_values)} for (index1, value1), (index2,value2) in combinations(enumerate(xy_values),2): f = self.calc_2d_forces(value1[0],value1[1],value2[0],value2[1],width) if coeff[index1] < coeff[index2]: if self.b_lenght-coeff[index2]<self.b_lenght/10: forces[index1].append(f[1]) forces[index2].append(f[0]) else: forces[index1].append(f[0]) forces[index2].append(f[1]) else: if self.b_lenght-coeff[index1]<self.b_lenght/10: forces[index1].append(f[0]) forces[index2].append(f[1]) else: forces[index1].append(f[1]) forces[index2].append(f[0]) forces = {k:sum(v) for k,v in forces.items()} energy = sum([abs(x) for x in forces.values()]) return [(forces[k]/10+v) for k, v in enumerate(values)], energy
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute_get'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '19', '31', '37', '43', '112', '152', '164', '191']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '12', 'type': 'binary_operator', 'children': ['13', '14'], 'value': '%'},{'id': '13', 'type': 'string', 'children': [], 'value': "'%s/%s'"},{'id': '14', 'type': 'tuple', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'base_url'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'resource'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': "'headers'"},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '35', 'type': 'string', 'children': [], 'value': "'Accept'"},{'id': '36', 'type': 'string', 'children': [], 'value': "'application/json'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '41', 'type': 'string', 'children': [], 'value': "'Content-Type'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'application/json'"},{'id': '43', 'type': 'if_statement', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '45', 'type': 'block', 'children': ['46', '55']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '49', 'type': 'conditional_expression', 'children': ['50', '51', '54'], 'value': 'if'},{'id': '50', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '54', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '55', 'type': 'for_statement', 'children': ['56', '59', '64']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'block', 'children': ['65', '108']},{'id': '65', 'type': 'if_statement', 'children': ['66', '80', '96']},{'id': '66', 'type': 'boolean_operator', 'children': ['67', '72'], 'value': 'and'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '71', 'type': 'string', 'children': [], 'value': "'__iter__'"},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '77'], 'value': 'not'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'},{'id': '85', 'type': 'string', 'children': [], 'value': "'%s%s%s=%s'"},{'id': '86', 'type': 'tuple', 'children': ['87', '88', '89', '90']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': "','"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '96', 'type': 'else_clause', 'children': ['97']},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '%'},{'id': '102', 'type': 'string', 'children': [], 'value': "'%s%s%s=%s'"},{'id': '103', 'type': 'tuple', 'children': ['104', '105', '106', '107']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '111', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '112', 'type': 'if_statement', 'children': ['113', '116', '127']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '115', 'type': 'identifier', 'children': [], 'value': '_access_token'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '122']},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '121', 'type': 'string', 'children': [], 'value': "'Authorization'"},{'id': '122', 'type': 'binary_operator', 'children': ['123', '124'], 'value': '%'},{'id': '123', 'type': 'string', 'children': [], 'value': "'Bearer %s'"},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '_access_token'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129', '138']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '132', 'type': 'conditional_expression', 'children': ['133', '134', '137'], 'value': 'if'},{'id': '133', 'type': 'string', 'children': [], 'value': "'&'"},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'in'},{'id': '135', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '137', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'},{'id': '142', 'type': 'string', 'children': [], 'value': "'%s%sclient_id=%s&client_secret=%s'"},{'id': '143', 'type': 'tuple', 'children': ['144', '145', '146', '149']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'separator'},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': '_client_id'},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_client_secret'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '164', 'type': 'if_statement', 'children': ['165', '172']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '171'], 'value': '!='},{'id': '166', 'type': 'binary_operator', 'children': ['167', '170'], 'value': '//'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '170', 'type': 'integer', 'children': [], 'value': '100'},{'id': '171', 'type': 'integer', 'children': [], 'value': '2'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'raise_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'GhostException'},{'id': '176', 'type': 'argument_list', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '180', 'type': 'call', 'children': ['181', '188']},{'id': '181', 'type': 'attribute', 'children': ['182', '187']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': "'errors'"},{'id': '190', 'type': 'list', 'children': [], 'value': '[]'},{'id': '191', 'type': 'return_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '196', 'type': 'argument_list', 'children': []}
def execute_get(self, resource, **kwargs): url = '%s/%s' % (self.base_url, resource) headers = kwargs.pop('headers', dict()) headers['Accept'] = 'application/json' headers['Content-Type'] = 'application/json' if kwargs: separator = '&' if '?' in url else '?' for key, value in kwargs.items(): if hasattr(value, '__iter__') and type(value) not in six.string_types: url = '%s%s%s=%s' % (url, separator, key, ','.join(value)) else: url = '%s%s%s=%s' % (url, separator, key, value) separator = '&' if self._access_token: headers['Authorization'] = 'Bearer %s' % self._access_token else: separator = '&' if '?' in url else '?' url = '%s%sclient_id=%s&client_secret=%s' % ( url, separator, self._client_id, self._client_secret ) response = requests.get(url, headers=headers) if response.status_code // 100 != 2: raise GhostException(response.status_code, response.json().get('errors', [])) return response.json()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'variants'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '11', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '22', '33', '39', '45', '70', '74', '91', '95', '112', '116', '133', '137', '154', '158', '175', '181', '190', '200', '210', '220', '224', '228', '406']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '21'], 'value': 'or'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '21', 'type': 'dictionary', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'case'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'case_id'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '+'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '52']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'string', 'children': [], 'value': "'gene_ids'"},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '65']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '69', 'type': 'string', 'children': [], 'value': "'gene_ids'"},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'if_statement', 'children': ['75', '81']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': "'frequency'"},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '90', 'type': 'string', 'children': [], 'value': "'frequency'"},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'cadd'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'if_statement', 'children': ['96', '102']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'string', 'children': [], 'value': "'cadd'"},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'cadd'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '111', 'type': 'string', 'children': [], 'value': "'cadd'"},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'genetic_models'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'if_statement', 'children': ['117', '123']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': "'genetic_models'"},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'genetic_models'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '132', 'type': 'string', 'children': [], 'value': "'genetic_models'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sv_len'},{'id': '136', 'type': 'None', 'children': []},{'id': '137', 'type': 'if_statement', 'children': ['138', '144']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'string', 'children': [], 'value': "'sv_len'"},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sv_len'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '153', 'type': 'string', 'children': [], 'value': "'sv_len'"},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'impact_severities'},{'id': '157', 'type': 'None', 'children': []},{'id': '158', 'type': 'if_statement', 'children': ['159', '165']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': "'impact_severities'"},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'impact_severities'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '174', 'type': 'string', 'children': [], 'value': "'impact_severities'"},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'vcf_file_path'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'variant_source'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'get_header'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'vcf_file_path'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'vep_header'},{'id': '195', 'type': 'attribute', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'vep_columns'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'snpeff_header'},{'id': '205', 'type': 'attribute', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'snpeff_columns'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': '_get_filtered_variants'},{'id': '217', 'type': 'argument_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'vcf_file_path'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '223', 'type': 'list', 'children': [], 'value': '[]'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'skip_index'},{'id': '227', 'type': 'integer', 'children': [], 'value': '0'},{'id': '228', 'type': 'for_statement', 'children': ['229', '232', '236']},{'id': '229', 'type': 'pattern_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'variants'},{'id': '236', 'type': 'block', 'children': ['237', '241']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'augmented_assignment', 'children': ['239', '240'], 'value': '+='},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '240', 'type': 'integer', 'children': [], 'value': '1'},{'id': '241', 'type': 'if_statement', 'children': ['242', '245', '400']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': '>='},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'skip_index'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '245', 'type': 'block', 'children': ['246', '263', '286', '303', '319', '335', '362', '378']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '252', 'type': 'identifier', 'children': [], 'value': '_format_variants'},{'id': '253', 'type': 'argument_list', 'children': ['254', '257', '260']},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'case_obj'},{'id': '263', 'type': 'if_statement', 'children': ['264', '267']},{'id': '264', 'type': 'boolean_operator', 'children': ['265', '266'], 'value': 'and'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'if_statement', 'children': ['269', '281']},{'id': '269', 'type': 'not_operator', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '279']},{'id': '271', 'type': 'attribute', 'children': ['272', '278']},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '277', 'type': 'string', 'children': [], 'value': "'gene_symbols'"},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '285', 'type': 'None', 'children': []},{'id': '286', 'type': 'if_statement', 'children': ['287', '290']},{'id': '287', 'type': 'boolean_operator', 'children': ['288', '289'], 'value': 'and'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'impact_severities'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'if_statement', 'children': ['292', '298']},{'id': '292', 'type': 'not_operator', 'children': ['293']},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '297'], 'value': 'in'},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '296', 'type': 'string', 'children': [], 'value': "'impact_severity'"},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'impact_severities'},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '302', 'type': 'None', 'children': []},{'id': '303', 'type': 'if_statement', 'children': ['304', '307']},{'id': '304', 'type': 'boolean_operator', 'children': ['305', '306'], 'value': 'and'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '307', 'type': 'block', 'children': ['308']},{'id': '308', 'type': 'if_statement', 'children': ['309', '314']},{'id': '309', 'type': 'comparison_operator', 'children': ['310', '313'], 'value': '>'},{'id': '310', 'type': 'attribute', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'max_freq'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'frequency'},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '318', 'type': 'None', 'children': []},{'id': '319', 'type': 'if_statement', 'children': ['320', '323']},{'id': '320', 'type': 'boolean_operator', 'children': ['321', '322'], 'value': 'and'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'cadd'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'if_statement', 'children': ['325', '330']},{'id': '325', 'type': 'comparison_operator', 'children': ['326', '329'], 'value': '<'},{'id': '326', 'type': 'subscript', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '328', 'type': 'string', 'children': [], 'value': "'cadd_score'"},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'cadd'},{'id': '330', 'type': 'block', 'children': ['331']},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '334', 'type': 'None', 'children': []},{'id': '335', 'type': 'if_statement', 'children': ['336', '339']},{'id': '336', 'type': 'boolean_operator', 'children': ['337', '338'], 'value': 'and'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'genetic_models'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '339', 'type': 'block', 'children': ['340', '349']},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '343', 'type': 'call', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '345', 'type': 'argument_list', 'children': ['346']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'genetic_models'},{'id': '349', 'type': 'if_statement', 'children': ['350', '357']},{'id': '350', 'type': 'not_operator', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'models'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'genetic_models'},{'id': '357', 'type': 'block', 'children': ['358']},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '361', 'type': 'None', 'children': []},{'id': '362', 'type': 'if_statement', 'children': ['363', '366']},{'id': '363', 'type': 'boolean_operator', 'children': ['364', '365'], 'value': 'and'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'sv_len'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '366', 'type': 'block', 'children': ['367']},{'id': '367', 'type': 'if_statement', 'children': ['368', '373']},{'id': '368', 'type': 'comparison_operator', 'children': ['369', '372'], 'value': '<'},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'sv_len'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'sv_len'},{'id': '373', 'type': 'block', 'children': ['374']},{'id': '374', 'type': 'expression_statement', 'children': ['375']},{'id': '375', 'type': 'assignment', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '377', 'type': 'None', 'children': []},{'id': '378', 'type': 'if_statement', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '380', 'type': 'block', 'children': ['381', '385']},{'id': '381', 'type': 'expression_statement', 'children': ['382']},{'id': '382', 'type': 'augmented_assignment', 'children': ['383', '384'], 'value': '+='},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'skip_index'},{'id': '384', 'type': 'integer', 'children': [], 'value': '1'},{'id': '385', 'type': 'if_statement', 'children': ['386', '389', '397']},{'id': '386', 'type': 'comparison_operator', 'children': ['387', '388'], 'value': '<='},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'skip_index'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '389', 'type': 'block', 'children': ['390']},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'call', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'variant_obj'},{'id': '397', 'type': 'else_clause', 'children': ['398']},{'id': '398', 'type': 'block', 'children': ['399']},{'id': '399', 'type': 'break_statement', 'children': []},{'id': '400', 'type': 'else_clause', 'children': ['401']},{'id': '401', 'type': 'block', 'children': ['402']},{'id': '402', 'type': 'expression_statement', 'children': ['403']},{'id': '403', 'type': 'augmented_assignment', 'children': ['404', '405'], 'value': '+='},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'skip_index'},{'id': '405', 'type': 'integer', 'children': [], 'value': '1'},{'id': '406', 'type': 'return_statement', 'children': ['407']},{'id': '407', 'type': 'call', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'Results'},{'id': '409', 'type': 'argument_list', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '411', 'type': 'call', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '413', 'type': 'argument_list', 'children': ['414']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'result'}
def variants(self, case_id, skip=0, count=1000, filters=None): filters = filters or {} case_obj = self.case(case_id=case_id) limit = count + skip genes = set() if filters.get('gene_ids'): genes = set([gene_id.strip() for gene_id in filters['gene_ids']]) frequency = None if filters.get('frequency'): frequency = float(filters['frequency']) cadd = None if filters.get('cadd'): cadd = float(filters['cadd']) genetic_models = None if filters.get('genetic_models'): genetic_models = set(filters['genetic_models']) sv_len = None if filters.get('sv_len'): sv_len = float(filters['sv_len']) impact_severities = None if filters.get('impact_severities'): impact_severities = set(filters['impact_severities']) vcf_file_path = case_obj.variant_source self.head = get_header(vcf_file_path) self.vep_header = self.head.vep_columns self.snpeff_header = self.head.snpeff_columns variants = self._get_filtered_variants(vcf_file_path, filters) result = [] skip_index = 0 for index, variant in enumerate(variants): index += 1 if skip_index >= skip: variant_obj = self._format_variants( variant=variant, index=index, case_obj=case_obj, ) if genes and variant_obj: if not set(variant_obj['gene_symbols']).intersection(genes): variant_obj = None if impact_severities and variant_obj: if not variant_obj['impact_severity'] in impact_severities: variant_obj = None if frequency and variant_obj: if variant_obj.max_freq > frequency: variant_obj = None if cadd and variant_obj: if variant_obj['cadd_score'] < cadd: variant_obj = None if genetic_models and variant_obj: models = set(variant_obj.genetic_models) if not models.intersection(genetic_models): variant_obj = None if sv_len and variant_obj: if variant_obj.sv_len < sv_len: variant_obj = None if variant_obj: skip_index += 1 if skip_index <= limit: result.append(variant_obj) else: break else: skip_index += 1 return Results(result, len(result))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_filtered_variants'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'vcf_file_path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '8', 'type': 'dictionary', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '16', '22', '28', '53', '70', '87', '99', '153']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'consequences'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sv_types'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '35']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'gene_ids'"},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'list_comprehension', 'children': ['43', '48']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'gene_id'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '52', 'type': 'string', 'children': [], 'value': "'gene_ids'"},{'id': '53', 'type': 'if_statement', 'children': ['54', '60']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'consequence'"},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'consequences'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '69', 'type': 'string', 'children': [], 'value': "'consequence'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '77']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': "'sv_types'"},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sv_types'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '86', 'type': 'string', 'children': [], 'value': "'sv_types'"},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': '"Get variants from {0}"'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'vcf_file_path'},{'id': '99', 'type': 'if_statement', 'children': ['100', '106', '144']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'string', 'children': [], 'value': "'range'"},{'id': '106', 'type': 'block', 'children': ['107', '130', '137']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'range_str'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': '"{0}:{1}-{2}"'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '114', 'type': 'argument_list', 'children': ['115', '120', '125']},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '118', 'type': 'string', 'children': [], 'value': "'range'"},{'id': '119', 'type': 'string', 'children': [], 'value': "'chromosome'"},{'id': '120', 'type': 'subscript', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '123', 'type': 'string', 'children': [], 'value': "'range'"},{'id': '124', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '125', 'type': 'subscript', 'children': ['126', '129']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '128', 'type': 'string', 'children': [], 'value': "'range'"},{'id': '129', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'vcf'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'VCF'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'vcf_file_path'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'vcf'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'range_str'},{'id': '144', 'type': 'else_clause', 'children': ['145']},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'VCF'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'vcf_file_path'},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '156', 'type': 'block', 'children': ['157', '164', '168', '196', '219', '242']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'variant_line'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'variant'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '167', 'type': 'True', 'children': []},{'id': '168', 'type': 'if_statement', 'children': ['169', '172']},{'id': '169', 'type': 'boolean_operator', 'children': ['170', '171'], 'value': 'and'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '172', 'type': 'block', 'children': ['173', '177']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '176', 'type': 'False', 'children': []},{'id': '177', 'type': 'for_statement', 'children': ['178', '179', '180']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'genes'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'if_statement', 'children': ['182', '190']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '189'], 'value': 'in'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'string', 'children': [], 'value': '"{0}"'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'variant_line'},{'id': '190', 'type': 'block', 'children': ['191', '195']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '194', 'type': 'True', 'children': []},{'id': '195', 'type': 'break_statement', 'children': []},{'id': '196', 'type': 'if_statement', 'children': ['197', '200']},{'id': '197', 'type': 'boolean_operator', 'children': ['198', '199'], 'value': 'and'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'consequences'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '200', 'type': 'block', 'children': ['201', '205']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '204', 'type': 'False', 'children': []},{'id': '205', 'type': 'for_statement', 'children': ['206', '207', '208']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'consequence'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'consequences'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'if_statement', 'children': ['210', '213']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'in'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'consequence'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'variant_line'},{'id': '213', 'type': 'block', 'children': ['214', '218']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '217', 'type': 'True', 'children': []},{'id': '218', 'type': 'break_statement', 'children': []},{'id': '219', 'type': 'if_statement', 'children': ['220', '223']},{'id': '220', 'type': 'boolean_operator', 'children': ['221', '222'], 'value': 'and'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'sv_types'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '223', 'type': 'block', 'children': ['224', '228']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '227', 'type': 'False', 'children': []},{'id': '228', 'type': 'for_statement', 'children': ['229', '230', '231']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sv_type'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'sv_types'},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'if_statement', 'children': ['233', '236']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': 'in'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'sv_type'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'variant_line'},{'id': '236', 'type': 'block', 'children': ['237', '241']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'assignment', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '240', 'type': 'True', 'children': []},{'id': '241', 'type': 'break_statement', 'children': []},{'id': '242', 'type': 'if_statement', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'keep_variant'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'yield', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'variant'}
def _get_filtered_variants(self, vcf_file_path, filters={}): genes = set() consequences = set() sv_types = set() if filters.get('gene_ids'): genes = set([gene_id.strip() for gene_id in filters['gene_ids']]) if filters.get('consequence'): consequences = set(filters['consequence']) if filters.get('sv_types'): sv_types = set(filters['sv_types']) logger.info("Get variants from {0}".format(vcf_file_path)) if filters.get('range'): range_str = "{0}:{1}-{2}".format( filters['range']['chromosome'], filters['range']['start'], filters['range']['end']) vcf = VCF(vcf_file_path) handle = vcf(range_str) else: handle = VCF(vcf_file_path) for variant in handle: variant_line = str(variant) keep_variant = True if genes and keep_variant: keep_variant = False for gene in genes: if "{0}".format(gene) in variant_line: keep_variant = True break if consequences and keep_variant: keep_variant = False for consequence in consequences: if consequence in variant_line: keep_variant = True break if sv_types and keep_variant: keep_variant = False for sv_type in sv_types: if sv_type in variant_line: keep_variant = True break if keep_variant: yield variant
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'for_statement', 'children': ['8', '11', '24']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'grouped'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '13', 'type': 'argument_list', 'children': ['14', '21']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'iterable'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'yield', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'grouped'}
def group(iterable, key): for _, grouped in groupby(sorted(iterable, key=key), key=key): yield list(grouped)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '14', '32', '43', '49', '55', '64', '80', '100', '123', '243', '303']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Run the LaTeX compilation.'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'old_dir'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'clean'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'old_dir'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '38']},{'id': '34', 'type': 'pattern_list', 'children': ['35', '36', '37']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'cite_counter'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'toc_file'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'gloss_files'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_read_latex_files'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'latex_run'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'read_glossaries'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'gloss_changed'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'makeindex_runs'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'gloss_files'},{'id': '64', 'type': 'if_statement', 'children': ['65', '73']},{'id': '65', 'type': 'boolean_operator', 'children': ['66', '67'], 'value': 'or'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'gloss_changed'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_is_toc_changed'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'toc_file'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'latex_run'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'if_statement', 'children': ['81', '87']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_need_bib_run'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cite_counter'},{'id': '87', 'type': 'block', 'children': ['88', '94']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'bibtex_run'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'latex_run'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'while_statement', 'children': ['101', '107']},{'id': '101', 'type': '()', 'children': ['102']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '106'], 'value': '<'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'latex_run_counter'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'MAX_RUNS'},{'id': '107', 'type': 'block', 'children': ['108', '117']},{'id': '108', 'type': 'if_statement', 'children': ['109', '115']},{'id': '109', 'type': 'not_operator', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'need_latex_rerun'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'break_statement', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'latex_run'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'if_statement', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'check_cite'},{'id': '129', 'type': 'block', 'children': ['130', '136', '159', '185', '208']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'cites'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'with_statement', 'children': ['137', '150']},{'id': '137', 'type': 'with_clause', 'children': ['138']},{'id': '138', 'type': 'with_item', 'children': ['139']},{'id': '139', 'type': 'as_pattern', 'children': ['140', '148']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '%'},{'id': '144', 'type': 'string', 'children': [], 'value': "'%s.aux'"},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'project_name'},{'id': '148', 'type': 'as_pattern_target', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'fobj'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'aux_content'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'fobj'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'for_statement', 'children': ['160', '161', '167']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'BIBCITE_PATTERN'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'finditer'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'aux_content'},{'id': '167', 'type': 'block', 'children': ['168', '178']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '171', 'type': 'subscript', 'children': ['172', '177']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'integer', 'children': [], 'value': '0'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'cites'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '185', 'type': 'with_statement', 'children': ['186', '199']},{'id': '186', 'type': 'with_clause', 'children': ['187']},{'id': '187', 'type': 'with_item', 'children': ['188']},{'id': '188', 'type': 'as_pattern', 'children': ['189', '197']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '%'},{'id': '193', 'type': 'string', 'children': [], 'value': "'%s.bib'"},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'bib_file'},{'id': '197', 'type': 'as_pattern_target', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'fobj'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'bib_content'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'fobj'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'for_statement', 'children': ['209', '210', '216']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'BIBENTRY_PATTERN'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'finditer'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'bib_content'},{'id': '216', 'type': 'block', 'children': ['217', '227']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '220', 'type': 'subscript', 'children': ['221', '226']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '225', 'type': 'argument_list', 'children': []},{'id': '226', 'type': 'integer', 'children': [], 'value': '0'},{'id': '227', 'type': 'if_statement', 'children': ['228', '231']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': 'not'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'cites'},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '239']},{'id': '234', 'type': 'attribute', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '%'},{'id': '241', 'type': 'string', 'children': [], 'value': '\'Bib entry not cited: "%s"\''},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '243', 'type': 'if_statement', 'children': ['244', '249']},{'id': '244', 'type': 'attribute', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'clean'},{'id': '249', 'type': 'block', 'children': ['250', '254', '265']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'ending'},{'id': '253', 'type': 'string', 'children': [], 'value': "'.dvi'"},{'id': '254', 'type': 'if_statement', 'children': ['255', '260']},{'id': '255', 'type': 'attribute', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'pdf'},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'ending'},{'id': '264', 'type': 'string', 'children': [], 'value': "'.pdf'"},{'id': '265', 'type': 'for_statement', 'children': ['266', '267', '273']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'if_statement', 'children': ['275', '289']},{'id': '275', 'type': 'not_operator', 'children': ['276']},{'id': '276', 'type': '()', 'children': ['277']},{'id': '277', 'type': 'boolean_operator', 'children': ['278', '283'], 'value': 'or'},{'id': '278', 'type': 'comparison_operator', 'children': ['279', '280'], 'value': 'in'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'old_dir'},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '287', 'type': 'argument_list', 'children': ['288']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'ending'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'try_statement', 'children': ['291', '299']},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '299', 'type': 'except_clause', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'IOError'},{'id': '301', 'type': 'block', 'children': ['302']},{'id': '302', 'type': 'pass_statement', 'children': []},{'id': '303', 'type': 'if_statement', 'children': ['304', '309']},{'id': '304', 'type': 'attribute', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'opt'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'preview'},{'id': '309', 'type': 'block', 'children': ['310']},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'open_preview'},{'id': '315', 'type': 'argument_list', 'children': []}
def run(self): '''Run the LaTeX compilation.''' self.old_dir = [] if self.opt.clean: self.old_dir = os.listdir('.') cite_counter, toc_file, gloss_files = self._read_latex_files() self.latex_run() self.read_glossaries() gloss_changed = self.makeindex_runs(gloss_files) if gloss_changed or self._is_toc_changed(toc_file): self.latex_run() if self._need_bib_run(cite_counter): self.bibtex_run() self.latex_run() while (self.latex_run_counter < MAX_RUNS): if not self.need_latex_rerun(): break self.latex_run() if self.opt.check_cite: cites = set() with open('%s.aux' % self.project_name) as fobj: aux_content = fobj.read() for match in BIBCITE_PATTERN.finditer(aux_content): name = match.groups()[0] cites.add(name) with open('%s.bib' % self.bib_file) as fobj: bib_content = fobj.read() for match in BIBENTRY_PATTERN.finditer(bib_content): name = match.groups()[0] if name not in cites: self.log.info('Bib entry not cited: "%s"' % name) if self.opt.clean: ending = '.dvi' if self.opt.pdf: ending = '.pdf' for fname in os.listdir('.'): if not (fname in self.old_dir or fname.endswith(ending)): try: os.remove(fname) except IOError: pass if self.opt.preview: self.open_preview()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'embed_ising'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'source_linear'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'source_quadratic'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'chain_strength'},{'id': '10', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '11', 'type': 'block', 'children': ['12', '34', '44', '130', '134', '300', '304', '323']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'unused'},{'id': '15', 'type': 'binary_operator', 'children': ['16', '21'], 'value': '-'},{'id': '16', 'type': 'set_comprehension', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '18', 'type': 'for_in_clause', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'},{'id': '21', 'type': 'call', 'children': ['22', '27']},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'list_splat', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'target_linear'},{'id': '37', 'type': 'dictionary_comprehension', 'children': ['38', '41']},{'id': '38', 'type': 'pair', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '40', 'type': 'float', 'children': [], 'value': '0.'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'},{'id': '44', 'type': 'for_statement', 'children': ['45', '48', '52']},{'id': '45', 'type': 'pattern_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'bias'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'source_linear'},{'id': '52', 'type': 'block', 'children': ['53', '96', '105']},{'id': '53', 'type': 'try_statement', 'children': ['54', '61']},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'chain_variables'},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '61', 'type': 'except_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '63', 'type': 'block', 'children': ['64', '90']},{'id': '64', 'type': 'try_statement', 'children': ['65', '77']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '71', 'type': 'set', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'unused'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'except_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': "'no embedding provided for source variable {}'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'chain_variables'},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '/'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'bias'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'chain_variables'},{'id': '105', 'type': 'for_statement', 'children': ['106', '107', '108']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'chain_variables'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'try_statement', 'children': ['110', '117']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'augmented_assignment', 'children': ['113', '116'], 'value': '+='},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'target_linear'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '117', 'type': 'except_clause', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'raise_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'chain variable {} not in target_adjacency'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'target_quadratic'},{'id': '133', 'type': 'dictionary', 'children': []},{'id': '134', 'type': 'for_statement', 'children': ['135', '140', '144']},{'id': '135', 'type': 'pattern_list', 'children': ['136', '139']},{'id': '136', 'type': 'tuple_pattern', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'bias'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'source_quadratic'},{'id': '144', 'type': 'block', 'children': ['145', '151', '166', '181', '230', '245', '254']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '150', 'type': 'argument_list', 'children': []},{'id': '151', 'type': 'if_statement', 'children': ['152', '155']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'not'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'raise_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'string', 'children': [], 'value': "'no embedding provided for source variable {}'"},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '166', 'type': 'if_statement', 'children': ['167', '170']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'not'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'raise_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'string', 'children': [], 'value': "'no embedding provided for source variable {}'"},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '181', 'type': 'for_statement', 'children': ['182', '183', '186']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'for_statement', 'children': ['188', '189', '192']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'try_statement', 'children': ['194', '217']},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'if_statement', 'children': ['196', '207']},{'id': '196', 'type': 'boolean_operator', 'children': ['197', '202'], 'value': 'and'},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'in'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '206'], 'value': 'not'},{'id': '203', 'type': 'tuple', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'tuple', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '217', 'type': 'except_clause', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'raise_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': "'chain variable {} not in target_adjacency'"},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '230', 'type': 'if_statement', 'children': ['231', '233']},{'id': '231', 'type': 'not_operator', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'raise_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'string', 'children': [], 'value': '"no edges in target graph between source variables {}, {}"'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '242', 'type': 'argument_list', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '/'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'bias'},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '254', 'type': 'for_statement', 'children': ['255', '258', '259']},{'id': '255', 'type': 'pattern_list', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'if_statement', 'children': ['261', '266', '275', '290']},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '265'], 'value': 'in'},{'id': '262', 'type': 'tuple', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'target_quadratic'},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'augmented_assignment', 'children': ['269', '274'], 'value': '+='},{'id': '269', 'type': 'subscript', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'target_quadratic'},{'id': '271', 'type': 'tuple', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '275', 'type': 'elif_clause', 'children': ['276', '281']},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '280'], 'value': 'in'},{'id': '277', 'type': 'tuple', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'target_quadratic'},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'augmented_assignment', 'children': ['284', '289'], 'value': '+='},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'target_quadratic'},{'id': '286', 'type': 'tuple', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '290', 'type': 'else_clause', 'children': ['291']},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '299']},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'target_quadratic'},{'id': '296', 'type': 'tuple', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'chain_quadratic'},{'id': '303', 'type': 'dictionary', 'children': []},{'id': '304', 'type': 'for_statement', 'children': ['305', '306', '310']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'itervalues'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'embedding'},{'id': '310', 'type': 'block', 'children': ['311']},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'chain_quadratic'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'chain_to_quadratic'},{'id': '319', 'type': 'argument_list', 'children': ['320', '321', '322']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'chain_strength'},{'id': '323', 'type': 'return_statement', 'children': ['324']},{'id': '324', 'type': 'expression_list', 'children': ['325', '326', '327']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'target_linear'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'target_quadratic'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'chain_quadratic'}
def embed_ising(source_linear, source_quadratic, embedding, target_adjacency, chain_strength=1.0): unused = {v for v in target_adjacency} - set().union(*embedding.values()) target_linear = {v: 0. for v in target_adjacency} for v, bias in iteritems(source_linear): try: chain_variables = embedding[v] except KeyError: try: embedding[v] = {unused.pop()} except KeyError: raise ValueError('no embedding provided for source variable {}'.format(v)) chain_variables = embedding[v] b = bias / len(chain_variables) for s in chain_variables: try: target_linear[s] += b except KeyError: raise ValueError('chain variable {} not in target_adjacency'.format(s)) target_quadratic = {} for (u, v), bias in iteritems(source_quadratic): edges = set() if u not in embedding: raise ValueError('no embedding provided for source variable {}'.format(u)) if v not in embedding: raise ValueError('no embedding provided for source variable {}'.format(v)) for s in embedding[u]: for t in embedding[v]: try: if s in target_adjacency[t] and (t, s) not in edges: edges.add((s, t)) except KeyError: raise ValueError('chain variable {} not in target_adjacency'.format(s)) if not edges: raise ValueError("no edges in target graph between source variables {}, {}".format(u, v)) b = bias / len(edges) for s, t in edges: if (s, t) in target_quadratic: target_quadratic[(s, t)] += b elif (t, s) in target_quadratic: target_quadratic[(t, s)] += b else: target_quadratic[(s, t)] = b chain_quadratic = {} for chain in itervalues(embedding): chain_quadratic.update(chain_to_quadratic(chain, target_adjacency, chain_strength)) return target_linear, target_quadratic, chain_quadratic
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit_richness'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'atol'},{'id': '7', 'type': 'float', 'children': [], 'value': '1.e-3'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'maxiter'},{'id': '10', 'type': 'integer', 'children': [], 'value': '50'},{'id': '11', 'type': 'block', 'children': ['12', '38', '61', '80', '100', '120', '124', '128', '240', '249']},{'id': '12', 'type': 'if_statement', 'children': ['13', '25']},{'id': '13', 'type': 'call', 'children': ['14', '24']},{'id': '14', 'type': 'attribute', 'children': ['15', '23']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '33']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': '"NaN signal probability found"'},{'id': '33', 'type': 'return_statement', 'children': ['34']},{'id': '34', 'type': 'expression_list', 'children': ['35', '36', '37']},{'id': '35', 'type': 'float', 'children': [], 'value': '0.'},{'id': '36', 'type': 'float', 'children': [], 'value': '0.'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'if_statement', 'children': ['39', '48']},{'id': '39', 'type': 'not_operator', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '48', 'type': 'block', 'children': ['49', '56']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': '"Signal probability is zero for all objects"'},{'id': '56', 'type': 'return_statement', 'children': ['57']},{'id': '57', 'type': 'expression_list', 'children': ['58', '59', '60']},{'id': '58', 'type': 'float', 'children': [], 'value': '0.'},{'id': '59', 'type': 'float', 'children': [], 'value': '0.'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'if_statement', 'children': ['62', '67']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '66'], 'value': '=='},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '66', 'type': 'integer', 'children': [], 'value': '0'},{'id': '67', 'type': 'block', 'children': ['68', '75']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': '"Observable fraction is zero"'},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'expression_list', 'children': ['77', '78', '79']},{'id': '77', 'type': 'float', 'children': [], 'value': '0.'},{'id': '78', 'type': 'float', 'children': [], 'value': '0.'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'list', 'children': ['89', '90', '95'], 'value': '[0., 1./self.f, 10./self.f]'},{'id': '89', 'type': 'float', 'children': [], 'value': '0.'},{'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '/'},{'id': '91', 'type': 'float', 'children': [], 'value': '1.'},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '/'},{'id': '96', 'type': 'float', 'children': [], 'value': '10.'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'loglike'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'list_comprehension', 'children': ['109', '117']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'found_maximum'},{'id': '123', 'type': 'False', 'children': []},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'while_statement', 'children': ['129', '131']},{'id': '129', 'type': 'not_operator', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'found_maximum'},{'id': '131', 'type': 'block', 'children': ['132', '148', '223', '227']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'parabola'},{'id': '135', 'type': 'call', 'children': ['136', '143']},{'id': '136', 'type': 'attribute', 'children': ['137', '142']},{'id': '137', 'type': 'attribute', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ugali'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'parabola'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'Parabola'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '*'},{'id': '146', 'type': 'float', 'children': [], 'value': '2.'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'loglike'},{'id': '148', 'type': 'if_statement', 'children': ['149', '154', '159']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': '<'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'parabola'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'vertex_x'},{'id': '153', 'type': 'float', 'children': [], 'value': '0.'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'found_maximum'},{'id': '158', 'type': 'True', 'children': []},{'id': '159', 'type': 'else_clause', 'children': ['160']},{'id': '160', 'type': 'block', 'children': ['161', '173', '193']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'parabola'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'vertex_x'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'loglike'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'loglike'},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '191', 'type': 'unary_operator', 'children': ['192'], 'value': '-'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'if_statement', 'children': ['194', '218']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '217'], 'value': '<'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'fabs'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '205'], 'value': '-'},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'loglike'},{'id': '203', 'type': 'unary_operator', 'children': ['204'], 'value': '-'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'loglike'},{'id': '212', 'type': 'slice', 'children': ['213', '214', '215']},{'id': '213', 'type': 'integer', 'children': [], 'value': '0'},{'id': '214', 'type': 'colon', 'children': []},{'id': '215', 'type': 'unary_operator', 'children': ['216'], 'value': '-'},{'id': '216', 'type': 'integer', 'children': [], 'value': '1'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'atol'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'found_maximum'},{'id': '222', 'type': 'True', 'children': []},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'augmented_assignment', 'children': ['225', '226'], 'value': '+='},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '226', 'type': 'integer', 'children': [], 'value': '1'},{'id': '227', 'type': 'if_statement', 'children': ['228', '231']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': '>'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'maxiter'},{'id': '231', 'type': 'block', 'children': ['232', '239']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'string', 'children': [], 'value': '"Maximum number of iterations reached"'},{'id': '239', 'type': 'break_statement', 'children': []},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'argmax'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'loglike'},{'id': '249', 'type': 'return_statement', 'children': ['250']},{'id': '250', 'type': 'expression_list', 'children': ['251', '254', '257']},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'loglike'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'richness'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'parabola'}
def fit_richness(self, atol=1.e-3, maxiter=50): if np.isnan(self.u).any(): logger.warning("NaN signal probability found") return 0., 0., None if not np.any(self.u): logger.warning("Signal probability is zero for all objects") return 0., 0., None if self.f == 0: logger.warning("Observable fraction is zero") return 0., 0., None richness = np.array([0., 1./self.f, 10./self.f]) loglike = np.array([self.value(richness=r) for r in richness]) found_maximum = False iteration = 0 while not found_maximum: parabola = ugali.utils.parabola.Parabola(richness, 2.*loglike) if parabola.vertex_x < 0.: found_maximum = True else: richness = np.append(richness, parabola.vertex_x) loglike = np.append(loglike, self.value(richness=richness[-1])) if np.fabs(loglike[-1] - np.max(loglike[0: -1])) < atol: found_maximum = True iteration+=1 if iteration > maxiter: logger.warning("Maximum number of iterations reached") break index = np.argmax(loglike) return loglike[index], richness[index], parabola
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_request'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '7', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '19', 'type': 'integer', 'children': [], 'value': '10'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'macaroons'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '31', '41', '70', '121', '132', '147', '159', '202', '263', '271']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '30', 'type': 'dictionary', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '34', 'type': 'dictionary', 'children': ['35', '38']},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'timeout'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '38', 'type': 'pair', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'headers'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '41', 'type': 'if_statement', 'children': ['42', '45']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46', '64']},{'id': '46', 'type': 'if_statement', 'children': ['47', '54']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '68', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '70', 'type': 'if_statement', 'children': ['71', '76', '94', '109']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'in'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '73', 'type': 'tuple', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '75', 'type': 'string', 'children': [], 'value': "'HEAD'"},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'string', 'children': [], 'value': "'{}?{}'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '93', 'type': 'True', 'children': []},{'id': '94', 'type': 'elif_clause', 'children': ['95', '102']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '97', 'type': 'tuple', 'children': ['98', '99', '100', '101']},{'id': '98', 'type': 'string', 'children': [], 'value': "'DELETE'"},{'id': '99', 'type': 'string', 'children': [], 'value': "'PATCH'"},{'id': '100', 'type': 'string', 'children': [], 'value': "'POST'"},{'id': '101', 'type': 'string', 'children': [], 'value': "'PUT'"},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '108']},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '107', 'type': 'string', 'children': [], 'value': "'Content-Type'"},{'id': '108', 'type': 'string', 'children': [], 'value': "'application/json'"},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'raise_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': "'invalid method {}'"},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'macaroons'},{'id': '124', 'type': 'None', 'children': []},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '131']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '130', 'type': 'string', 'children': [], 'value': "'Macaroons'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'macaroons'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '136', 'type': 'string', 'children': [], 'value': "'auth'"},{'id': '137', 'type': 'conditional_expression', 'children': ['138', '139', '142'], 'value': 'if'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': 'is'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '141', 'type': 'None', 'children': []},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'api_method'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'try_statement', 'children': ['160', '170', '183']},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'api_method'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '168', 'type': 'dictionary_splat', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '170', 'type': 'except_clause', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'Timeout'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'raise_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'timeout_error'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '183', 'type': 'except_clause', 'children': ['184', '188']},{'id': '184', 'type': 'as_pattern', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '186', 'type': 'as_pattern_target', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '188', 'type': 'block', 'children': ['189', '197']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': '_server_error_message'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '197', 'type': 'raise_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'ServerError'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '202', 'type': 'try_statement', 'children': ['203', '210', '238']},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'raise_for_status'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'except_clause', 'children': ['211', '215']},{'id': '211', 'type': 'as_pattern', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'HTTPError'},{'id': '213', 'type': 'as_pattern_target', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '215', 'type': 'block', 'children': ['216', '228']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': '_server_error_message'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '223', 'type': 'attribute', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '228', 'type': 'raise_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'ServerError'},{'id': '231', 'type': 'argument_list', 'children': ['232', '237']},{'id': '232', 'type': 'attribute', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '238', 'type': 'except_clause', 'children': ['239', '247']},{'id': '239', 'type': 'as_pattern', 'children': ['240', '245']},{'id': '240', 'type': 'attribute', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'RequestException'},{'id': '245', 'type': 'as_pattern_target', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '247', 'type': 'block', 'children': ['248', '258']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': '_server_error_message'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '258', 'type': 'raise_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'ServerError'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '263', 'type': 'if_statement', 'children': ['264', '268']},{'id': '264', 'type': 'not_operator', 'children': ['265']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'return_statement', 'children': ['270']},{'id': '270', 'type': 'dictionary', 'children': []},{'id': '271', 'type': 'try_statement', 'children': ['272', '279']},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'return_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '278', 'type': 'argument_list', 'children': []},{'id': '279', 'type': 'except_clause', 'children': ['280', '284']},{'id': '280', 'type': 'as_pattern', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '282', 'type': 'as_pattern_target', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '284', 'type': 'block', 'children': ['285', '295', '302']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '288', 'type': 'call', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'string', 'children': [], 'value': "'Error decoding JSON response: {} message: {}'"},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '302', 'type': 'raise_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'ServerError'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'msg'}
def make_request( url, method='GET', query=None, body=None, auth=None, timeout=10, client=None, macaroons=None): headers = {} kwargs = {'timeout': timeout, 'headers': headers} if body is not None: if isinstance(body, collections.Mapping): body = json.dumps(body) kwargs['data'] = body if method in ('GET', 'HEAD'): if query: url = '{}?{}'.format(url, urlencode(query, True)) elif method in ('DELETE', 'PATCH', 'POST', 'PUT'): headers['Content-Type'] = 'application/json' else: raise ValueError('invalid method {}'.format(method)) if macaroons is not None: headers['Macaroons'] = macaroons kwargs['auth'] = auth if client is None else client.auth() api_method = getattr(requests, method.lower()) try: response = api_method(url, **kwargs) except requests.exceptions.Timeout: raise timeout_error(url, timeout) except Exception as err: msg = _server_error_message(url, err) raise ServerError(msg) try: response.raise_for_status() except HTTPError as err: msg = _server_error_message(url, err.response.text) raise ServerError(err.response.status_code, msg) except requests.exceptions.RequestException as err: msg = _server_error_message(url, err.message) raise ServerError(msg) if not response.content: return {} try: return response.json() except Exception as err: msg = 'Error decoding JSON response: {} message: {}'.format(url, err) log.error(msg) raise ServerError(msg)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'time_stops'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14']},{'id': '6', 'type': 'if_statement', 'children': ['7', '11']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'supports_time'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'if_statement', 'children': ['15', '22', '325']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '21'], 'value': '=='},{'id': '16', 'type': 'attribute', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'calendar'},{'id': '21', 'type': 'string', 'children': [], 'value': "'standard'"},{'id': '22', 'type': 'block', 'children': ['23', '31', '39', '46', '288', '323']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'time_interval_units'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'time_interval'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '42', 'type': 'list', 'children': ['43'], 'value': '[self.time_start]'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'time_start'},{'id': '46', 'type': 'if_statement', 'children': ['47', '53', '100', '177']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'in'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '49', 'type': 'tuple', 'children': ['50', '51', '52']},{'id': '50', 'type': 'string', 'children': [], 'value': "'years'"},{'id': '51', 'type': 'string', 'children': [], 'value': "'decades'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'centuries'"},{'id': '53', 'type': 'block', 'children': ['54', '82']},{'id': '54', 'type': 'if_statement', 'children': ['55', '58', '63', '74']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '57', 'type': 'string', 'children': [], 'value': "'years'"},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'years'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '63', 'type': 'elif_clause', 'children': ['64', '67']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '=='},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '66', 'type': 'string', 'children': [], 'value': "'decades'"},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'years'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '*'},{'id': '72', 'type': 'integer', 'children': [], 'value': '10'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '74', 'type': 'else_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'years'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '*'},{'id': '80', 'type': 'integer', 'children': [], 'value': '100'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'next_value'},{'id': '85', 'type': 'lambda', 'children': ['86', '88']},{'id': '86', 'type': 'lambda_parameters', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '99'], 'value': '+'},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'years'},{'id': '100', 'type': 'elif_clause', 'children': ['101', '104']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '=='},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '103', 'type': 'string', 'children': [], 'value': "'months'"},{'id': '104', 'type': 'block', 'children': ['105', '173']},{'id': '105', 'type': 'function_definition', 'children': ['106', '107', '109']},{'id': '106', 'type': 'function_name', 'children': [], 'value': '_fn'},{'id': '107', 'type': 'parameters', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '109', 'type': 'block', 'children': ['110', '127', '140', '158']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '113', 'type': 'binary_operator', 'children': ['114', '117'], 'value': '+'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '126'], 'value': '//'},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '125'], 'value': '-'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '124'], 'value': '+'},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'integer', 'children': [], 'value': '12'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '130', 'type': 'boolean_operator', 'children': ['131', '139'], 'value': 'or'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '138'], 'value': '%'},{'id': '132', 'type': '()', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '137'], 'value': '+'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '138', 'type': 'integer', 'children': [], 'value': '12'},{'id': '139', 'type': 'integer', 'children': [], 'value': '12'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '145', 'type': 'argument_list', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '149', 'type': 'subscript', 'children': ['150', '157']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'calendar'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'monthrange'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'return_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '163', 'type': 'argument_list', 'children': ['164', '167', '170']},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'month'},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'day'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'next_value'},{'id': '176', 'type': 'identifier', 'children': [], 'value': '_fn'},{'id': '177', 'type': 'else_clause', 'children': ['178']},{'id': '178', 'type': 'block', 'children': ['179', '279']},{'id': '179', 'type': 'if_statement', 'children': ['180', '183', '193', '207', '221', '235', '249', '263']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '=='},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '182', 'type': 'string', 'children': [], 'value': "'milliseconds'"},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'milliseconds'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '193', 'type': 'elif_clause', 'children': ['194', '197']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': '=='},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '196', 'type': 'string', 'children': [], 'value': "'seconds'"},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '207', 'type': 'elif_clause', 'children': ['208', '211']},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': '=='},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '210', 'type': 'string', 'children': [], 'value': "'minutes'"},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'minutes'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '221', 'type': 'elif_clause', 'children': ['222', '225']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '=='},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '224', 'type': 'string', 'children': [], 'value': "'hours'"},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'keyword_argument', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'hours'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '235', 'type': 'elif_clause', 'children': ['236', '239']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '=='},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '238', 'type': 'string', 'children': [], 'value': "'days'"},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '249', 'type': 'elif_clause', 'children': ['250', '253']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '=='},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '252', 'type': 'string', 'children': [], 'value': "'weeks'"},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'weeks'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'interval'},{'id': '263', 'type': 'else_clause', 'children': ['264']},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'raise_statement', 'children': ['266']},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'ValidationError'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'string', 'children': [], 'value': '"Service has an invalid time_interval_units: {}"'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'attribute', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'service'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'time_interval_units'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'next_value'},{'id': '282', 'type': 'lambda', 'children': ['283', '285']},{'id': '283', 'type': 'lambda_parameters', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '285', 'type': 'binary_operator', 'children': ['286', '287'], 'value': '+'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '288', 'type': 'while_statement', 'children': ['289', '297']},{'id': '289', 'type': 'comparison_operator', 'children': ['290', '294'], 'value': '<'},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '292', 'type': 'unary_operator', 'children': ['293'], 'value': '-'},{'id': '293', 'type': 'integer', 'children': [], 'value': '1'},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'time_end'},{'id': '297', 'type': 'block', 'children': ['298', '308', '316']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '301', 'type': 'call', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'next_value'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'subscript', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '306', 'type': 'unary_operator', 'children': ['307'], 'value': '-'},{'id': '307', 'type': 'integer', 'children': [], 'value': '1'},{'id': '308', 'type': 'if_statement', 'children': ['309', '314']},{'id': '309', 'type': 'comparison_operator', 'children': ['310', '311'], 'value': '>'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'time_end'},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'break_statement', 'children': []},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '321']},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '323', 'type': 'return_statement', 'children': ['324']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '325', 'type': 'else_clause', 'children': ['326']},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'raise_statement', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}
def time_stops(self): if not self.supports_time: return [] if self.service.calendar == 'standard': units = self.service.time_interval_units interval = self.service.time_interval steps = [self.time_start] if units in ('years', 'decades', 'centuries'): if units == 'years': years = interval elif units == 'decades': years = 10 * interval else: years = 100 * interval next_value = lambda x: x.replace(year=x.year + years) elif units == 'months': def _fn(x): year = x.year + (x.month+interval-1) // 12 month = (x.month+interval) % 12 or 12 day = min(x.day, calendar.monthrange(year, month)[1]) return x.replace(year=year, month=month, day=day) next_value = _fn else: if units == 'milliseconds': delta = timedelta(milliseconds=interval) elif units == 'seconds': delta = timedelta(seconds=interval) elif units == 'minutes': delta = timedelta(minutes=interval) elif units == 'hours': delta = timedelta(hours=interval) elif units == 'days': delta = timedelta(days=interval) elif units == 'weeks': delta = timedelta(weeks=interval) else: raise ValidationError( "Service has an invalid time_interval_units: {}".format(self.service.time_interval_units) ) next_value = lambda x: x + delta while steps[-1] < self.time_end: value = next_value(steps[-1]) if value > self.time_end: break steps.append(value) return steps else: raise NotImplementedError
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_strings'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'strings'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort_order_first'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '50', '63', '200']},{'id': '18', 'type': 'if_statement', 'children': ['19', '21']},{'id': '19', 'type': 'not_operator', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '21', 'type': 'block', 'children': ['22', '36']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '27', 'type': 'generator_expression', 'children': ['28', '33']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'strings'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '41', 'type': 'generator_expression', 'children': ['42', '47']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'strings'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '55', 'type': 'generator_expression', 'children': ['56', '60']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '63', 'type': 'function_definition', 'children': ['64', '65', '71']},{'id': '64', 'type': 'function_name', 'children': [], 'value': 'compare'},{'id': '65', 'type': 'parameters', 'children': ['66', '67', '68']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '68', 'type': 'default_parameter', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '71', 'type': 'block', 'children': ['72', '176']},{'id': '72', 'type': 'if_statement', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'if_statement', 'children': ['76', '83', '158']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '82'], 'value': 'in'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '79', 'type': 'slice', 'children': ['80', '81']},{'id': '80', 'type': 'colon', 'children': []},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'if_statement', 'children': ['85', '92', '144']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '91'], 'value': 'in'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '88', 'type': 'slice', 'children': ['89', '90']},{'id': '89', 'type': 'colon', 'children': []},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '92', 'type': 'block', 'children': ['93', '117', '131']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'comparison'},{'id': '96', 'type': 'binary_operator', 'children': ['97', '107'], 'value': '-'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '104', 'type': 'slice', 'children': ['105', '106']},{'id': '105', 'type': 'colon', 'children': []},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '114', 'type': 'slice', 'children': ['115', '116']},{'id': '115', 'type': 'colon', 'children': []},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'comparison'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '/'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'comparison'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '130'], 'value': 'or'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'comparison'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'if_statement', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'comparison'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'return_statement', 'children': ['135']},{'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '*'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'comparison'},{'id': '137', 'type': '()', 'children': ['138']},{'id': '138', 'type': 'binary_operator', 'children': ['139', '143'], 'value': '+'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '142'], 'value': '*'},{'id': '140', 'type': 'unary_operator', 'children': ['141'], 'value': '-'},{'id': '141', 'type': 'integer', 'children': [], 'value': '2'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'elif_clause', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sort_order_first'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'binary_operator', 'children': ['149', '151'], 'value': '*'},{'id': '149', 'type': 'unary_operator', 'children': ['150'], 'value': '-'},{'id': '150', 'type': 'integer', 'children': [], 'value': '1'},{'id': '151', 'type': '()', 'children': ['152']},{'id': '152', 'type': 'binary_operator', 'children': ['153', '157'], 'value': '+'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '156'], 'value': '*'},{'id': '154', 'type': 'unary_operator', 'children': ['155'], 'value': '-'},{'id': '155', 'type': 'integer', 'children': [], 'value': '2'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'elif_clause', 'children': ['159', '168']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '161'], 'value': 'and'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sort_order_first'},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '167'], 'value': 'in'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '164', 'type': 'slice', 'children': ['165', '166']},{'id': '165', 'type': 'colon', 'children': []},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'prefix_len'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'binary_operator', 'children': ['171', '175'], 'value': '+'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '174'], 'value': '*'},{'id': '172', 'type': 'unary_operator', 'children': ['173'], 'value': '-'},{'id': '173', 'type': 'integer', 'children': [], 'value': '2'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'return_statement', 'children': ['177']},{'id': '177', 'type': 'binary_operator', 'children': ['178', '193'], 'value': '*'},{'id': '178', 'type': '()', 'children': ['179']},{'id': '179', 'type': 'binary_operator', 'children': ['180', '187'], 'value': '+'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '183'], 'value': '*'},{'id': '181', 'type': 'unary_operator', 'children': ['182'], 'value': '-'},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': '()', 'children': ['184']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': '<'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '*'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': '()', 'children': ['190']},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '>'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '193', 'type': '()', 'children': ['194']},{'id': '194', 'type': 'binary_operator', 'children': ['195', '199'], 'value': '+'},{'id': '195', 'type': 'binary_operator', 'children': ['196', '198'], 'value': '*'},{'id': '196', 'type': 'unary_operator', 'children': ['197'], 'value': '-'},{'id': '197', 'type': 'integer', 'children': [], 'value': '2'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '199', 'type': 'integer', 'children': [], 'value': '1'},{'id': '200', 'type': 'return_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'strings'},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'compare'}
def sort_strings(strings, sort_order=None, reverse=False, case_sensitive=False, sort_order_first=True): if not case_sensitive: sort_order = tuple(s.lower() for s in sort_order) strings = tuple(s.lower() for s in strings) prefix_len = max(len(s) for s in sort_order) def compare(a, b, prefix_len=prefix_len): if prefix_len: if a[:prefix_len] in sort_order: if b[:prefix_len] in sort_order: comparison = sort_order.index(a[:prefix_len]) - sort_order.index(b[:prefix_len]) comparison = int(comparison / abs(comparison or 1)) if comparison: return comparison * (-2 * reverse + 1) elif sort_order_first: return -1 * (-2 * reverse + 1) elif sort_order_first and b[:prefix_len] in sort_order: return -2 * reverse + 1 return (-1 * (a < b) + 1 * (a > b)) * (-2 * reverse + 1) return sorted(strings, key=functools.cmp_to_key(compare))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_field_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'field_dict'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'cleaner'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'time_zone'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '16', '20', '29', '95']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '19', 'type': 'dictionary', 'children': []},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'time_zone'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_TZ'},{'id': '29', 'type': 'for_statement', 'children': ['30', '33', '37']},{'id': '30', 'type': 'pattern_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'viewitems'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'field_dict'},{'id': '37', 'type': 'block', 'children': ['38', '44']},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '41', 'type': 'string', 'children': [], 'value': "'_state'"},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'continue_statement', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '50', '63', '87']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cleaner'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '63', 'type': 'elif_clause', 'children': ['64', '75']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '68', 'type': 'tuple', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'tz'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'localize'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'd'}
def clean_field_dict(field_dict, cleaner=str.strip, time_zone=None): r d = {} if time_zone is None: tz = DEFAULT_TZ for k, v in viewitems(field_dict): if k == '_state': continue if isinstance(v, basestring): d[k] = cleaner(str(v)) elif isinstance(v, (datetime.datetime, datetime.date)): d[k] = tz.localize(v) else: d[k] = v return d
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'hist_from_counts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'cumulative'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'to_str'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '16', 'type': 'string', 'children': [], 'value': "','"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'min_bin'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'max_bin'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '42', '75', '92', '96', '218', '229', '233', '264', '282']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'counters'},{'id': '27', 'type': 'list', 'children': ['28'], 'value': '[dict((i, c)for i, c in enumerate(counts))]'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '30', 'type': 'generator_expression', 'children': ['31', '34']},{'id': '31', 'type': 'tuple', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '34', 'type': 'for_in_clause', 'children': ['35', '38']},{'id': '35', 'type': 'pattern_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'intkeys_list'},{'id': '45', 'type': 'list_comprehension', 'children': ['46', '72']},{'id': '46', 'type': 'list_comprehension', 'children': ['47', '48', '51']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'counts_dict'},{'id': '51', 'type': 'if_clause', 'children': ['52']},{'id': '52', 'type': '()', 'children': ['53']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '59'], 'value': 'or'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '59', 'type': '()', 'children': ['60']},{'id': '60', 'type': 'boolean_operator', 'children': ['61', '66'], 'value': 'and'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '71'], 'value': '=='},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'counts_dict'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'counters'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '80']},{'id': '77', 'type': 'pattern_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'min_bin'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'max_bin'},{'id': '80', 'type': 'expression_list', 'children': ['81', '84']},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '83'], 'value': 'or'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'min_bin'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'or'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'max_bin'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '91'], 'value': '-'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'histograms'},{'id': '95', 'type': 'list', 'children': [], 'value': '[]'},{'id': '96', 'type': 'for_statement', 'children': ['97', '100', '105']},{'id': '97', 'type': 'pattern_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'intkeys'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'intkeys_list'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'counters'},{'id': '105', 'type': 'block', 'children': ['106', '113', '118', '150']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'augmented_assignment', 'children': ['108', '109'], 'value': '+='},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'histograms'},{'id': '109', 'type': 'list', 'children': ['110'], 'value': '[OrderedDict()]'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '116']},{'id': '114', 'type': 'not_operator', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'intkeys'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'continue_statement', 'children': []},{'id': '118', 'type': 'if_statement', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'normalize'},{'id': '120', 'type': 'block', 'children': ['121', '133']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '126', 'type': 'generator_expression', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '130', 'type': 'for_in_clause', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'intkeys'},{'id': '133', 'type': 'for_statement', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'intkeys'},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '149'], 'value': '/'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '150', 'type': 'if_statement', 'children': ['151', '152', '191']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'cumulative'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '162']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'min_bin'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'max_bin'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '171']},{'id': '165', 'type': 'subscript', 'children': ['166', '170']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'histograms'},{'id': '168', 'type': 'unary_operator', 'children': ['169'], 'value': '-'},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '179'], 'value': '+'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'call', 'children': ['180', '186']},{'id': '180', 'type': 'attribute', 'children': ['181', '185']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'histograms'},{'id': '183', 'type': 'unary_operator', 'children': ['184'], 'value': '-'},{'id': '184', 'type': 'integer', 'children': [], 'value': '1'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '186', 'type': 'argument_list', 'children': ['187', '190']},{'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '-'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '189', 'type': 'integer', 'children': [], 'value': '1'},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'},{'id': '191', 'type': 'else_clause', 'children': ['192']},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'for_statement', 'children': ['194', '195', '202']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'min_bin'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '+'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'max_bin'},{'id': '201', 'type': 'integer', 'children': [], 'value': '1'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '211']},{'id': '205', 'type': 'subscript', 'children': ['206', '210']},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'histograms'},{'id': '208', 'type': 'unary_operator', 'children': ['209'], 'value': '-'},{'id': '209', 'type': 'integer', 'children': [], 'value': '1'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '217', 'type': 'integer', 'children': [], 'value': '0'},{'id': '218', 'type': 'if_statement', 'children': ['219', '221']},{'id': '219', 'type': 'not_operator', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'histograms'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'histograms'},{'id': '225', 'type': 'list', 'children': ['226'], 'value': '[OrderedDict()]'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '228', 'type': 'argument_list', 'children': []},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'aligned_histograms'},{'id': '232', 'type': 'list', 'children': [], 'value': '[]'},{'id': '233', 'type': 'for_statement', 'children': ['234', '235', '242']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'min_bin'},{'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '+'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'max_bin'},{'id': '241', 'type': 'integer', 'children': [], 'value': '1'},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'augmented_assignment', 'children': ['245', '246'], 'value': '+='},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'aligned_histograms'},{'id': '246', 'type': 'list', 'children': ['247'], 'value': '[tuple([i] + [hist.get(i, 0) for hist in histograms])]'},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'binary_operator', 'children': ['251', '253'], 'value': '+'},{'id': '251', 'type': 'list', 'children': ['252'], 'value': '[i]'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '253', 'type': 'list_comprehension', 'children': ['254', '261']},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'hist'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '260', 'type': 'integer', 'children': [], 'value': '0'},{'id': '261', 'type': 'for_in_clause', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'hist'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'histograms'},{'id': '264', 'type': 'if_statement', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'to_str'},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'return_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'str_from_table'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272', '275']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'aligned_histograms'},{'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'max_rows'},{'id': '277', 'type': 'binary_operator', 'children': ['278', '281'], 'value': '+'},{'id': '278', 'type': 'binary_operator', 'children': ['279', '280'], 'value': '*'},{'id': '279', 'type': 'integer', 'children': [], 'value': '365'},{'id': '280', 'type': 'integer', 'children': [], 'value': '2'},{'id': '281', 'type': 'integer', 'children': [], 'value': '1'},{'id': '282', 'type': 'return_statement', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'aligned_histograms'}
def hist_from_counts(counts, normalize=False, cumulative=False, to_str=False, sep=',', min_bin=None, max_bin=None): counters = [dict((i, c)for i, c in enumerate(counts))] intkeys_list = [[c for c in counts_dict if (isinstance(c, int) or (isinstance(c, float) and int(c) == c))] for counts_dict in counters] min_bin, max_bin = min_bin or 0, max_bin or len(counts) - 1 histograms = [] for intkeys, counts in zip(intkeys_list, counters): histograms += [OrderedDict()] if not intkeys: continue if normalize: N = sum(counts[c] for c in intkeys) for c in intkeys: counts[c] = float(counts[c]) / N if cumulative: for i in range(min_bin, max_bin + 1): histograms[-1][i] = counts.get(i, 0) + histograms[-1].get(i - 1, 0) else: for i in range(min_bin, max_bin + 1): histograms[-1][i] = counts.get(i, 0) if not histograms: histograms = [OrderedDict()] aligned_histograms = [] for i in range(min_bin, max_bin + 1): aligned_histograms += [tuple([i] + [hist.get(i, 0) for hist in histograms])] if to_str: return str_from_table(aligned_histograms, sep=sep, max_rows=365 * 2 + 1) return aligned_histograms
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize_serial_number'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '16', '21', '24', '27', '30', '33']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '10', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'valid_chars'},{'id': '23', 'type': 'string', 'children': [], 'value': "' -0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'"},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'strip_whitespace'},{'id': '29', 'type': 'True', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '32', 'type': 'False', 'children': []},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'rex'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'nones'},{'id': '38', 'type': 'block', 'children': ['39', '41', '60', '79', '98', '117', '136', '155', '174', '193', '212', '231', '240', '252', '263', '304', '313', '324', '358', '370', '394', '416']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '41', 'type': 'if_statement', 'children': ['42', '45', '52']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '52', 'type': 'else_clause', 'children': ['53']},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '60', 'type': 'if_statement', 'children': ['61', '64', '71']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '63', 'type': 'None', 'children': []},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83', '90']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '98', 'type': 'if_statement', 'children': ['99', '102', '109']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '101', 'type': 'None', 'children': []},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '109', 'type': 'else_clause', 'children': ['110']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '117', 'type': 'if_statement', 'children': ['118', '121', '128']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'valid_chars'},{'id': '120', 'type': 'None', 'children': []},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'valid_chars'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'valid_chars'},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'valid_chars'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'valid_chars'},{'id': '136', 'type': 'if_statement', 'children': ['137', '140', '147']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'is'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '139', 'type': 'None', 'children': []},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '155', 'type': 'if_statement', 'children': ['156', '159', '166']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'is'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'strip_whitespace'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'strip_whitespace'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'strip_whitespace'},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'strip_whitespace'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'strip_whitespace'},{'id': '174', 'type': 'if_statement', 'children': ['175', '178', '185']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'is'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '177', 'type': 'None', 'children': []},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '185', 'type': 'else_clause', 'children': ['186']},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '193', 'type': 'if_statement', 'children': ['194', '197', '204']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': 'is'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '196', 'type': 'None', 'children': []},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '204', 'type': 'else_clause', 'children': ['205']},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'normalize_serial_number'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '212', 'type': 'if_statement', 'children': ['213', '216']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': 'is'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '215', 'type': 'None', 'children': []},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '220', 'type': 'generator_expression', 'children': ['221', '222', '227']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '222', 'type': 'for_in_clause', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'charlist'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'ascii_all'},{'id': '227', 'type': 'if_clause', 'children': ['228']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': 'not'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'valid_chars'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'string', 'children': [], 'value': "''"},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '243', 'type': 'call', 'children': ['244', '250']},{'id': '244', 'type': 'attribute', 'children': ['245', '249']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '252', 'type': 'if_statement', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'strip_whitespace'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '262', 'type': 'argument_list', 'children': []},{'id': '263', 'type': 'if_statement', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'if_statement', 'children': ['267', '268', '291']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'translate'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '284', 'type': 'binary_operator', 'children': ['285', '287'], 'value': '*'},{'id': '285', 'type': 'list', 'children': ['286'], 'value': "['']"},{'id': '286', 'type': 'string', 'children': [], 'value': "''"},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '291', 'type': 'else_clause', 'children': ['292']},{'id': '292', 'type': 'block', 'children': ['293']},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '296', 'type': 'subscript', 'children': ['297', '302']},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'multisplit'},{'id': '299', 'type': 'argument_list', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'invalid_chars'},{'id': '302', 'type': 'unary_operator', 'children': ['303'], 'value': '-'},{'id': '303', 'type': 'integer', 'children': [], 'value': '1'},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '307', 'type': 'subscript', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '309', 'type': 'slice', 'children': ['310', '312']},{'id': '310', 'type': 'unary_operator', 'children': ['311'], 'value': '-'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '312', 'type': 'colon', 'children': []},{'id': '313', 'type': 'if_statement', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'strip_whitespace'},{'id': '315', 'type': 'block', 'children': ['316']},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'assignment', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '323', 'type': 'argument_list', 'children': []},{'id': '324', 'type': 'if_statement', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'if_statement', 'children': ['328', '341', '346']},{'id': '328', 'type': 'boolean_operator', 'children': ['329', '338'], 'value': 'and'},{'id': '329', 'type': 'call', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '331', 'type': 'argument_list', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '333', 'type': 'tuple', 'children': ['334', '335', '336', '337']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '338', 'type': 'comparison_operator', 'children': ['339', '340'], 'value': 'in'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'assignment', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '345', 'type': 'string', 'children': [], 'value': "''"},{'id': '346', 'type': 'elif_clause', 'children': ['347', '353']},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '353', 'type': 'block', 'children': ['354']},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'assignment', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '357', 'type': 'string', 'children': [], 'value': "''"},{'id': '358', 'type': 'if_statement', 'children': ['359', '367']},{'id': '359', 'type': 'boolean_operator', 'children': ['360', '362'], 'value': 'and'},{'id': '360', 'type': 'not_operator', 'children': ['361']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '362', 'type': 'not_operator', 'children': ['363']},{'id': '363', 'type': '()', 'children': ['364']},{'id': '364', 'type': 'comparison_operator', 'children': ['365', '366'], 'value': 'is'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '366', 'type': 'False', 'children': []},{'id': '367', 'type': 'block', 'children': ['368']},{'id': '368', 'type': 'return_statement', 'children': ['369']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'blank'},{'id': '370', 'type': 'if_statement', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '372', 'type': 'block', 'children': ['373']},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'assignment', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '376', 'type': 'binary_operator', 'children': ['377', '393'], 'value': '+'},{'id': '377', 'type': 'binary_operator', 'children': ['378', '379'], 'value': '*'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '379', 'type': 'call', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'binary_operator', 'children': ['383', '384'], 'value': '-'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '384', 'type': 'binary_operator', 'children': ['385', '389'], 'value': '/'},{'id': '385', 'type': 'call', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '387', 'type': 'argument_list', 'children': ['388']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '389', 'type': 'call', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '391', 'type': 'argument_list', 'children': ['392']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'left_fill'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '394', 'type': 'if_statement', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '396', 'type': 'block', 'children': ['397']},{'id': '397', 'type': 'expression_statement', 'children': ['398']},{'id': '398', 'type': 'assignment', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '400', 'type': 'binary_operator', 'children': ['401', '402'], 'value': '+'},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '402', 'type': 'binary_operator', 'children': ['403', '404'], 'value': '*'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '404', 'type': '()', 'children': ['405']},{'id': '405', 'type': 'binary_operator', 'children': ['406', '407'], 'value': '-'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '407', 'type': 'binary_operator', 'children': ['408', '412'], 'value': '/'},{'id': '408', 'type': 'call', 'children': ['409', '410']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '410', 'type': 'argument_list', 'children': ['411']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'sn'},{'id': '412', 'type': 'call', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '414', 'type': 'argument_list', 'children': ['415']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'right_fill'},{'id': '416', 'type': 'return_statement', 'children': ['417']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'sn'}
def normalize_serial_number(sn, max_length=None, left_fill='0', right_fill=str(), blank=str(), valid_chars=' -0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', invalid_chars=None, strip_whitespace=True, join=False, na=rex.nones): r if max_length is None: max_length = normalize_serial_number.max_length else: normalize_serial_number.max_length = max_length if left_fill is None: left_fill = normalize_serial_number.left_fill else: normalize_serial_number.left_fill = left_fill if right_fill is None: right_fill = normalize_serial_number.right_fill else: normalize_serial_number.right_fill = right_fill if blank is None: blank = normalize_serial_number.blank else: normalize_serial_number.blank = blank if valid_chars is None: valid_chars = normalize_serial_number.valid_chars else: normalize_serial_number.valid_chars = valid_chars if invalid_chars is None: invalid_chars = normalize_serial_number.invalid_chars else: normalize_serial_number.invalid_chars = invalid_chars if strip_whitespace is None: strip_whitespace = normalize_serial_number.strip_whitespace else: normalize_serial_number.strip_whitespace = strip_whitespace if join is None: join = normalize_serial_number.join else: normalize_serial_number.join = join if na is None: na = normalize_serial_number.na else: normalize_serial_number.na = na if invalid_chars is None: invalid_chars = (c for c in charlist.ascii_all if c not in valid_chars) invalid_chars = ''.join(invalid_chars) sn = str(sn).strip(invalid_chars) if strip_whitespace: sn = sn.strip() if invalid_chars: if join: sn = sn.translate(dict(zip(invalid_chars, [''] * len(invalid_chars)))) else: sn = multisplit(sn, invalid_chars)[-1] sn = sn[-max_length:] if strip_whitespace: sn = sn.strip() if na: if isinstance(na, (tuple, set, dict, list)) and sn in na: sn = '' elif na.match(sn): sn = '' if not sn and not (blank is False): return blank if left_fill: sn = left_fill * int(max_length - len(sn) / len(left_fill)) + sn if right_fill: sn = sn + right_fill * (max_length - len(sn) / len(right_fill)) return sn
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'listify'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '7', 'type': 'integer', 'children': [], 'value': '1'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '21', '87', '135']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '15', 'type': 'conditional_expression', 'children': ['16', '17', '20'], 'value': 'if'},{'id': '16', 'type': 'list', 'children': [], 'value': '[]'},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '21', 'type': 'if_statement', 'children': ['22', '34', '42']},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '28'], 'value': 'and'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '27', 'type': 'string', 'children': [], 'value': "'__iter__'"},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '42', 'type': 'else_clause', 'children': ['43']},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '56', '80']},{'id': '45', 'type': 'boolean_operator', 'children': ['46', '51'], 'value': 'and'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'try_statement', 'children': ['58', '68']},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '68', 'type': 'except_clause', 'children': ['69', '74']},{'id': '69', 'type': 'tuple', 'children': ['70', '71', '72', '73']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '78', 'type': 'list', 'children': ['79'], 'value': '[ans]'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '80', 'type': 'else_clause', 'children': ['81']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '85', 'type': 'list', 'children': ['86'], 'value': '[ans]'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '87', 'type': 'if_statement', 'children': ['88', '92', '121']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'if_statement', 'children': ['94', '104']},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '101'], 'value': 'and'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '100'], 'value': '<'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '>'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'augmented_assignment', 'children': ['107', '108'], 'value': '+='},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '114'], 'value': '*'},{'id': '109', 'type': 'list', 'children': ['110'], 'value': '[ans[-1]]'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '112', 'type': 'unary_operator', 'children': ['113'], 'value': '-'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': '()', 'children': ['115']},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '-'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '121', 'type': 'else_clause', 'children': ['122']},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'if_statement', 'children': ['124', '127']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': '>'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ans'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '134'], 'value': '*'},{'id': '132', 'type': 'list', 'children': ['133'], 'value': '[[]]'},{'id': '133', 'type': 'list', 'children': [], 'value': '[]'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ans'}
def listify(values, N=1, delim=None): ans = [] if values is None else values if hasattr(ans, '__iter__') and not isinstance(ans, basestring): ans = list(ans) else: if isinstance(delim, basestring) and isinstance(ans, basestring): try: ans = ans.split(delim) except (IndexError, ValueError, AttributeError, TypeError): ans = [ans] else: ans = [ans] if len(ans): if len(ans) < N and N > 1: ans += [ans[-1]] * (N - len(ans)) else: if N > 1: ans = [[]] * N return ans
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'best_fit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'li'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '6', 'type': 'block', 'children': ['7', '24', '36']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '12', 'type': 'argument_list', 'children': ['13', '18']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'bisect_left'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'li'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '18', 'type': 'binary_operator', 'children': ['19', '23'], 'value': '-'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'li'},{'id': '23', 'type': 'integer', 'children': [], 'value': '1'},{'id': '24', 'type': 'if_statement', 'children': ['25', '33']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '27', 'type': 'tuple', 'children': ['28', '29']},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'li'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '36', 'type': 'if_statement', 'children': ['37', '50', '53']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '43'], 'value': '<'},{'id': '38', 'type': 'binary_operator', 'children': ['39', '42'], 'value': '-'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'li'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '-'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'li'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '-'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '53', 'type': 'else_clause', 'children': ['54']},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '-'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'}
def best_fit(li, value): index = min(bisect_left(li, value), len(li) - 1) if index in (0, len(li)): return index if li[index] - value < value - li[index-1]: return index else: return index-1
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'proj4_to_epsg'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '5', 'type': 'block', 'children': ['6', '32', '43', '56', '77', '89', '163']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'make_definition'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'set_comprehension', 'children': ['13', '22', '30']},{'id': '13', 'type': 'call', 'children': ['14', '21']},{'id': '14', 'type': 'attribute', 'children': ['15', '20']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '30', 'type': 'if_clause', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'EPSG_RE'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'srs'},{'id': '43', 'type': 'if_statement', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pyproj_data_dir'},{'id': '59', 'type': 'call', 'children': ['60', '65']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '65', 'type': 'argument_list', 'children': ['66', '76']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pyproj'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '__file__'},{'id': '76', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pyproj_epsg_file'},{'id': '80', 'type': 'call', 'children': ['81', '86']},{'id': '81', 'type': 'attribute', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'pyproj_data_dir'},{'id': '88', 'type': 'string', 'children': [], 'value': "'epsg'"},{'id': '89', 'type': 'if_statement', 'children': ['90', '98']},{'id': '90', 'type': 'call', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pyproj_epsg_file'},{'id': '98', 'type': 'block', 'children': ['99', '108', '116']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'make_definition'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'srs'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'pyproj_epsg_file'},{'id': '115', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '116', 'type': 'for_statement', 'children': ['117', '118', '123']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'readlines'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'block', 'children': ['124', '133']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'PYPROJ_EPSG_FILE_RE'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '133', 'type': 'if_statement', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '135', 'type': 'block', 'children': ['136', '148']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'file_definition'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'make_definition'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'integer', 'children': [], 'value': '2'},{'id': '148', 'type': 'if_statement', 'children': ['149', '152']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '=='},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'file_definition'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'return_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'return_statement', 'children': ['164']},{'id': '164', 'type': 'None', 'children': []}
def proj4_to_epsg(projection): def make_definition(value): return {x.strip().lower() for x in value.split('+') if x} match = EPSG_RE.search(projection.srs) if match: return int(match.group(1)) pyproj_data_dir = os.path.join(os.path.dirname(pyproj.__file__), 'data') pyproj_epsg_file = os.path.join(pyproj_data_dir, 'epsg') if os.path.exists(pyproj_epsg_file): definition = make_definition(projection.srs) f = open(pyproj_epsg_file, 'r') for line in f.readlines(): match = PYPROJ_EPSG_FILE_RE.search(line) if match: file_definition = make_definition(match.group(2)) if definition == file_definition: return int(match.group(1)) return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'index_pix_in_pixels'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pix'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pixels'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'outside'},{'id': '11', 'type': 'unary_operator', 'children': ['12'], 'value': '-'},{'id': '12', 'type': 'integer', 'children': [], 'value': '1'},{'id': '13', 'type': 'block', 'children': ['14', '26', '36', '77']},{'id': '14', 'type': 'if_statement', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'pixels'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pixels'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pixels'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'pix'},{'id': '36', 'type': 'if_statement', 'children': ['37', '43', '62']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isscalar'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '57']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '56']},{'id': '47', 'type': 'attribute', 'children': ['48', '55']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'in1d'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pix'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pixels'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'outside'},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '76']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '68', 'type': 'unary_operator', 'children': ['69'], 'value': '~'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'in1d'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pix'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pixels'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'outside'},{'id': '77', 'type': 'return_statement', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'index'}
def index_pix_in_pixels(pix,pixels,sort=False,outside=-1): if sort: pixels = np.sort(pixels) index = np.searchsorted(pixels,pix) if np.isscalar(index): if not np.in1d(pix,pixels).any(): index = outside else: index[~np.in1d(pix,pixels)] = outside return index
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'files'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'entity_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'manifest'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '21', '66', '70', '102']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'''\n Get the files or file contents of a file for an entity.\n If all files are requested, a dictionary of filenames and urls for the\n files in the archive are returned.\n If filename is provided, the url of just that file is returned, if it\n exists.\n If filename is provided and read_file is true, the *contents* of the\n file are returned, if the file exists.\n @param entity_id The id of the entity to get files for\n @param manifest The manifest of files for the entity. Providing this\n reduces queries; if not provided, the manifest is looked up in the\n charmstore.\n @param filename The name of the file in the archive to get.\n @param read_file Whether to get the url for the file or the file\n contents.\n @param channel Optional channel name.\n '''"},{'id': '21', 'type': 'if_statement', 'children': ['22', '25']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'manifest'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'block', 'children': ['26', '41', '49', '58']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'manifest_url'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'{}/{}/meta/manifest'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '33', 'type': 'argument_list', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_get_path'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'entity_id'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'manifest_url'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_add_channel'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'manifest_url'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'manifest'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'manifest_url'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'manifest'},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'manifest'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '69', 'type': 'dictionary', 'children': []},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'manifest'},{'id': '73', 'type': 'block', 'children': ['74', '80', '96']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'manifest_name'},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '79', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '87', 'type': 'argument_list', 'children': ['88', '92', '93']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_get_path'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'entity_id'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'manifest_name'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'channel'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'manifest_name'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '102', 'type': 'if_statement', 'children': ['103', '104', '146']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '104', 'type': 'block', 'children': ['105', '115', '126']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '114', 'type': 'None', 'children': []},{'id': '115', 'type': 'if_statement', 'children': ['116', '119']},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '118', 'type': 'None', 'children': []},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'raise_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'EntityNotFound'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'entity_id'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '126', 'type': 'if_statement', 'children': ['127', '128', '142']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '128', 'type': 'block', 'children': ['129', '138']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '142', 'type': 'else_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'file_url'},{'id': '146', 'type': 'else_clause', 'children': ['147']},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'files'}
def files(self, entity_id, manifest=None, filename=None, read_file=False, channel=None): ''' Get the files or file contents of a file for an entity. If all files are requested, a dictionary of filenames and urls for the files in the archive are returned. If filename is provided, the url of just that file is returned, if it exists. If filename is provided and read_file is true, the *contents* of the file are returned, if the file exists. @param entity_id The id of the entity to get files for @param manifest The manifest of files for the entity. Providing this reduces queries; if not provided, the manifest is looked up in the charmstore. @param filename The name of the file in the archive to get. @param read_file Whether to get the url for the file or the file contents. @param channel Optional channel name. ''' if manifest is None: manifest_url = '{}/{}/meta/manifest'.format(self.url, _get_path(entity_id)) manifest_url = _add_channel(manifest_url, channel) manifest = self._get(manifest_url) manifest = manifest.json() files = {} for f in manifest: manifest_name = f['Name'] file_url = self.file_url(_get_path(entity_id), manifest_name, channel=channel) files[manifest_name] = file_url if filename: file_url = files.get(filename, None) if file_url is None: raise EntityNotFound(entity_id, filename) if read_file: data = self._get(file_url) return data.text else: return file_url else: return files
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '33']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'includes'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'doc_type'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'autocomplete'},{'id': '17', 'type': 'False', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'promulgated_only'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '36', '50', '65', '79', '91', '122', '156', '165']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'''\n Search for entities in the charmstore.\n @param text The text to search for.\n @param includes What metadata to return in results (e.g. charm-config).\n @param doc_type Filter to this type: bundle or charm.\n @param limit Maximum number of results to return.\n @param autocomplete Whether to prefix/suffix match search terms.\n @param promulgated_only Whether to filter to only promulgated charms.\n @param tags The tags to filter; can be a list of tags or a single tag.\n @param sort Sorting the result based on the sort string provided\n which can be name, author, series and - in front for descending.\n @param owner Optional owner. If provided, search results will only\n include entities that owner can view.\n @param series The series to filter; can be a list of series or a\n single series.\n '''"},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_common_query_parameters'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46', '47', '48', '49']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'doc_type'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'includes'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'promulgated_only'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '50', 'type': 'if_statement', 'children': ['51', '55']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'tuple', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '68', 'type': 'None', 'children': []},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'tuple', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "'limit'"},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '79', 'type': 'if_statement', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'autocomplete'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'tuple', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': "'autocomplete'"},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'if_statement', 'children': ['92', '95']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'block', 'children': ['96', '113']},{'id': '96', 'type': 'if_statement', 'children': ['97', '103']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '102'], 'value': 'is'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "','"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'tuple', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': "'tags'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '122', 'type': 'if_statement', 'children': ['123', '127', '143']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'string', 'children': [], 'value': "'{}/search?{}'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '135', 'type': 'argument_list', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '143', 'type': 'else_clause', 'children': ['144']},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'string', 'children': [], 'value': "'{}/search'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '165', 'type': 'return_statement', 'children': ['166']},{'id': '166', 'type': 'subscript', 'children': ['167', '172']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'string', 'children': [], 'value': "'Results'"}
def search(self, text, includes=None, doc_type=None, limit=None, autocomplete=False, promulgated_only=False, tags=None, sort=None, owner=None, series=None): ''' Search for entities in the charmstore. @param text The text to search for. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param limit Maximum number of results to return. @param autocomplete Whether to prefix/suffix match search terms. @param promulgated_only Whether to filter to only promulgated charms. @param tags The tags to filter; can be a list of tags or a single tag. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = self._common_query_parameters(doc_type, includes, owner, promulgated_only, series, sort) if len(text): queries.append(('text', text)) if limit is not None: queries.append(('limit', limit)) if autocomplete: queries.append(('autocomplete', 1)) if tags is not None: if type(tags) is list: tags = ','.join(tags) queries.append(('tags', tags)) if len(queries): url = '{}/search?{}'.format(self.url, urlencode(queries)) else: url = '{}/search'.format(self.url) data = self._get(url) return data.json()['Results']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'includes'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'doc_type'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'promulgated_only'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '26', '40', '74', '83']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'''\n List entities in the charmstore.\n @param includes What metadata to return in results (e.g. charm-config).\n @param doc_type Filter to this type: bundle or charm.\n @param promulgated_only Whether to filter to only promulgated charms.\n @param sort Sorting the result based on the sort string provided\n which can be name, author, series and - in front for descending.\n @param owner Optional owner. If provided, search results will only\n include entities that owner can view.\n @param series The series to filter; can be a list of series or a\n single series.\n '''"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_common_query_parameters'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35', '36', '37', '38', '39']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'doc_type'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'includes'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'promulgated_only'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '40', 'type': 'if_statement', 'children': ['41', '45', '61']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'{}/list?{}'"},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '53', 'type': 'argument_list', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'{}/list'"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'subscript', 'children': ['85', '90']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'string', 'children': [], 'value': "'Results'"}
def list(self, includes=None, doc_type=None, promulgated_only=False, sort=None, owner=None, series=None): ''' List entities in the charmstore. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = self._common_query_parameters(doc_type, includes, owner, promulgated_only, series, sort) if len(queries): url = '{}/list?{}'.format(self.url, urlencode(queries)) else: url = '{}/list'.format(self.url) data = self._get(url) return data.json()['Results']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_common_query_parameters'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'doc_type'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'includes'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'promulgated_only'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '11', 'type': 'block', 'children': ['12', '14', '18', '36', '50', '62', '76', '107', '121']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': "'''\n Extract common query parameters between search and list into slice.\n @param includes What metadata to return in results (e.g. charm-config).\n @param doc_type Filter to this type: bundle or charm.\n @param promulgated_only Whether to filter to only promulgated charms.\n @param sort Sorting the result based on the sort string provided\n which can be name, author, series and - in front for descending.\n @param owner Optional owner. If provided, search results will only\n include entities that owner can view.\n @param series The series to filter; can be a list of series or a\n single series.\n '''"},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'includes'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'list_comprehension', 'children': ['30', '33']},{'id': '30', 'type': 'tuple', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'include'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'include'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'includes'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'doc_type'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'tuple', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'doc_type'},{'id': '50', 'type': 'if_statement', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'promulgated_only'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'tuple', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'promulgated'"},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'if_statement', 'children': ['63', '66']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'tuple', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "'owner'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'owner'},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'block', 'children': ['81', '98']},{'id': '81', 'type': 'if_statement', 'children': ['82', '88']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '87'], 'value': 'is'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "','"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'tuple', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'series'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '107', 'type': 'if_statement', 'children': ['108', '111']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'tuple', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'queries'}
def _common_query_parameters(self, doc_type, includes, owner, promulgated_only, series, sort): ''' Extract common query parameters between search and list into slice. @param includes What metadata to return in results (e.g. charm-config). @param doc_type Filter to this type: bundle or charm. @param promulgated_only Whether to filter to only promulgated charms. @param sort Sorting the result based on the sort string provided which can be name, author, series and - in front for descending. @param owner Optional owner. If provided, search results will only include entities that owner can view. @param series The series to filter; can be a list of series or a single series. ''' queries = [] if includes is not None: queries.extend([('include', include) for include in includes]) if doc_type is not None: queries.append(('type', doc_type)) if promulgated_only: queries.append(('promulgated', 1)) if owner is not None: queries.append(('owner', owner)) if series is not None: if type(series) is list: series = ','.join(series) queries.append(('series', series)) if sort is not None: queries.append(('sort', sort)) return queries
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_one'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'P'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '8', 'type': 'block', 'children': ['9', '12', '105', '114', '117', '125', '180', '189', '192']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'yield', 'children': ['11']},{'id': '11', 'type': 'string', 'children': [], 'value': '"*bias*"'},{'id': '12', 'type': 'if_statement', 'children': ['13', '18', '23', '33']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'QUOTE'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'QUOTE_TOKEN'},{'id': '23', 'type': 'elif_clause', 'children': ['24', '28']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isnumberlike'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'NUMBER_TOKEN'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'id': '34', 'type': 'block', 'children': ['35', '50', '58', '82', '90']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'yield', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': '"len(L)={}"'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '44', 'type': 'argument_list', 'children': ['45', '49']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'CLIP'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'in'},{'id': '52', 'type': 'string', 'children': [], 'value': '"."'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'yield', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"L:*period*"'},{'id': '58', 'type': 'if_statement', 'children': ['59', '63']},{'id': '59', 'type': 'not_operator', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'nocase'},{'id': '63', 'type': 'block', 'children': ['64', '71']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'cf'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'case_feature'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '71', 'type': 'if_statement', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'cf'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'yield', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': '"L:{}\'"'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'cf'},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'if_statement', 'children': ['91', '101']},{'id': '91', 'type': 'not_operator', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '94', 'type': 'generator_expression', 'children': ['95', '98']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'VOWELS'},{'id': '98', 'type': 'for_in_clause', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'yield', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': '"L:*no-vowel*"'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'L_feat'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': '"L=\'{}\'"'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'yield', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'L_feat'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'yield', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'string', 'children': [], 'value': '"P=\'{}\'"'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'P'},{'id': '125', 'type': 'if_statement', 'children': ['126', '131', '136', '146']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'QUOTE'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'QUOTE_TOKEN'},{'id': '136', 'type': 'elif_clause', 'children': ['137', '141']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'isnumberlike'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'NUMBER_TOKEN'},{'id': '146', 'type': 'else_clause', 'children': ['147']},{'id': '147', 'type': 'block', 'children': ['148', '172']},{'id': '148', 'type': 'if_statement', 'children': ['149', '153']},{'id': '149', 'type': 'not_operator', 'children': ['150']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'nocase'},{'id': '153', 'type': 'block', 'children': ['154', '161']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'cf'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'case_feature'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '161', 'type': 'if_statement', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'cf'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'yield', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'string', 'children': [], 'value': '"R:{}\'"'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'cf'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '179', 'type': 'argument_list', 'children': []},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'R_feat'},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'string', 'children': [], 'value': '"R=\'{}\'"'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'yield', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'R_feat'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'yield', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'string', 'children': [], 'value': '"{},{}"'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'L_feat'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'R_feat'}
def extract_one(self, L, P, R): yield "*bias*" if match(QUOTE, L): L = QUOTE_TOKEN elif isnumberlike(L): L = NUMBER_TOKEN else: yield "len(L)={}".format(min(len(L), CLIP)) if "." in L: yield "L:*period*" if not self.nocase: cf = case_feature(R) if cf: yield "L:{}'".format(cf) L = L.upper() if not any(char in VOWELS for char in L): yield "L:*no-vowel*" L_feat = "L='{}'".format(L) yield L_feat yield "P='{}'".format(P) if match(QUOTE, R): R = QUOTE_TOKEN elif isnumberlike(R): R = NUMBER_TOKEN else: if not self.nocase: cf = case_feature(R) if cf: yield "R:{}'".format(cf) R = R.upper() R_feat = "R='{}'".format(R) yield R_feat yield "{},{}".format(L_feat, R_feat)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'call'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '24', '34', '38', '105', '121', '179', '229']},{'id': '9', 'type': 'for_statement', 'children': ['10', '11', '16']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_hooks'},{'id': '15', 'type': 'string', 'children': [], 'value': "'precall'"},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '29', 'type': 'argument_list', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'attempt'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'while_statement', 'children': ['39', '40']},{'id': '39', 'type': 'True', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'try_statement', 'children': ['42', '52']},{'id': '42', 'type': 'block', 'children': ['43', '51']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'dictionary_splat', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '51', 'type': 'break_statement', 'children': []},{'id': '52', 'type': 'except_clause', 'children': ['53', '57']},{'id': '53', 'type': 'as_pattern', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ClientError'},{'id': '55', 'type': 'as_pattern_target', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '57', 'type': 'block', 'children': ['58', '66', '70']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'translate_exception'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'augmented_assignment', 'children': ['68', '69'], 'value': '+='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'attempt'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'if_statement', 'children': ['71', '76', '97']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ThroughputException'},{'id': '76', 'type': 'block', 'children': ['77', '90']},{'id': '77', 'type': 'if_statement', 'children': ['78', '83']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '>'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'attempt'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'request_retries'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 're_raise'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'exponential_sleep'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'attempt'},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'exc'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 're_raise'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'for_statement', 'children': ['106', '107', '112']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '107', 'type': 'subscript', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': '_hooks'},{'id': '111', 'type': 'string', 'children': [], 'value': "'postcall'"},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119', '120']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'in'},{'id': '123', 'type': 'string', 'children': [], 'value': "'ConsumedCapacity'"},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '125', 'type': 'block', 'children': ['126', '132', '138']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'is_read'},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'in'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'READ_COMMANDS'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'consumed'},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '137', 'type': 'string', 'children': [], 'value': "'ConsumedCapacity'"},{'id': '138', 'type': 'if_statement', 'children': ['139', '144', '161']},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '141', 'type': 'argument_list', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'consumed'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '149', 'type': 'string', 'children': [], 'value': "'consumed_capacity'"},{'id': '150', 'type': 'list_comprehension', 'children': ['151', '158']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ConsumedCapacity'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'from_response'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'is_read'},{'id': '158', 'type': 'for_in_clause', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'consumed'},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163', '173']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'capacity'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ConsumedCapacity'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'from_response'},{'id': '170', 'type': 'argument_list', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'consumed'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'is_read'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '178']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '177', 'type': 'string', 'children': [], 'value': "'consumed_capacity'"},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'capacity'},{'id': '179', 'type': 'if_statement', 'children': ['180', '183']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': 'in'},{'id': '181', 'type': 'string', 'children': [], 'value': "'consumed_capacity'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '183', 'type': 'block', 'children': ['184', '208']},{'id': '184', 'type': 'if_statement', 'children': ['185', '192', '199']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '187', 'type': 'argument_list', 'children': ['188', '191']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '190', 'type': 'string', 'children': [], 'value': "'consumed_capacity'"},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'all_caps'},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '198', 'type': 'string', 'children': [], 'value': "'consumed_capacity'"},{'id': '199', 'type': 'else_clause', 'children': ['200']},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'all_caps'},{'id': '204', 'type': 'list', 'children': ['205'], 'value': "[data['consumed_capacity']]"},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '207', 'type': 'string', 'children': [], 'value': "'consumed_capacity'"},{'id': '208', 'type': 'for_statement', 'children': ['209', '210', '215']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '210', 'type': 'subscript', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': '_hooks'},{'id': '214', 'type': 'string', 'children': [], 'value': "'capacity'"},{'id': '215', 'type': 'block', 'children': ['216']},{'id': '216', 'type': 'for_statement', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'all_caps'},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '223', 'type': 'argument_list', 'children': ['224', '225', '226', '227', '228']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'cap'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'data'}
def call(self, command, **kwargs): for hook in self._hooks['precall']: hook(self, command, kwargs) op = getattr(self.client, command) attempt = 0 while True: try: data = op(**kwargs) break except ClientError as e: exc = translate_exception(e, kwargs) attempt += 1 if isinstance(exc, ThroughputException): if attempt > self.request_retries: exc.re_raise() self.exponential_sleep(attempt) else: exc.re_raise() for hook in self._hooks['postcall']: hook(self, command, kwargs, data) if 'ConsumedCapacity' in data: is_read = command in READ_COMMANDS consumed = data['ConsumedCapacity'] if isinstance(consumed, list): data['consumed_capacity'] = [ ConsumedCapacity.from_response(cap, is_read) for cap in consumed ] else: capacity = ConsumedCapacity.from_response(consumed, is_read) data['consumed_capacity'] = capacity if 'consumed_capacity' in data: if isinstance(data['consumed_capacity'], list): all_caps = data['consumed_capacity'] else: all_caps = [data['consumed_capacity']] for hook in self._hooks['capacity']: for cap in all_caps: hook(self, command, kwargs, data, cap) return data
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete_item2'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'expr_values'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'return_capacity'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'return_item_collection_metrics'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '25', 'type': 'dictionary_splat_pattern', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '27', 'type': 'block', 'children': ['28', '59', '70', '79', '88', '97', '108']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '31', 'type': 'dictionary', 'children': ['32', '35', '45', '48', '56']},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'TableName'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'Key'"},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'encode_keys'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'pair', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'ReturnValues'"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '48', 'type': 'pair', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'ReturnConsumedCapacity'"},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_default_capacity'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'return_capacity'},{'id': '56', 'type': 'pair', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'ReturnItemCollectionMetrics'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'return_item_collection_metrics'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'build_expression_values'},{'id': '64', 'type': 'argument_list', 'children': ['65', '68', '69']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'expr_values'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '70', 'type': 'if_statement', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '77', 'type': 'string', 'children': [], 'value': "'ExpressionAttributeValues'"},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '79', 'type': 'if_statement', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '86', 'type': 'string', 'children': [], 'value': "'ExpressionAttributeNames'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '88', 'type': 'if_statement', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '96']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '95', 'type': 'string', 'children': [], 'value': "'ConditionExpression'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'delete_item'"},{'id': '106', 'type': 'dictionary_splat', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '108', 'type': 'if_statement', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'Result'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118', '119']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '119', 'type': 'string', 'children': [], 'value': "'Attributes'"}
def delete_item2(self, tablename, key, expr_values=None, alias=None, condition=None, returns=NONE, return_capacity=None, return_item_collection_metrics=NONE, **kwargs): keywords = { 'TableName': tablename, 'Key': self.dynamizer.encode_keys(key), 'ReturnValues': returns, 'ReturnConsumedCapacity': self._default_capacity(return_capacity), 'ReturnItemCollectionMetrics': return_item_collection_metrics, } values = build_expression_values(self.dynamizer, expr_values, kwargs) if values: keywords['ExpressionAttributeValues'] = values if alias: keywords['ExpressionAttributeNames'] = alias if condition: keywords['ConditionExpression'] = condition result = self.call('delete_item', **keywords) if result: return Result(self.dynamizer, result, 'Attributes')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_item'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'updates'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'NONE'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'return_capacity'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'expect_or'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '19', 'type': 'block', 'children': ['20', '31', '35', '39', '51', '83', '116', '142', '165']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'call', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'encode_keys'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'attr_updates'},{'id': '34', 'type': 'dictionary', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'expected'},{'id': '38', 'type': 'dictionary', 'children': []},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '42', 'type': 'dictionary', 'children': ['43']},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'ReturnConsumedCapacity'"},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_default_capacity'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'return_capacity'},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '54']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'updates'},{'id': '54', 'type': 'block', 'children': ['55', '69']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'attr_updates'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'expected'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'expected'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '83', 'type': 'for_statement', 'children': ['84', '87', '99']},{'id': '84', 'type': 'pattern_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'encode_query_kwargs'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '99', 'type': 'block', 'children': ['100', '110']},{'id': '100', 'type': 'if_statement', 'children': ['101', '104']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'in'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'expected'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'raise_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'string', 'children': [], 'value': '"Cannot have more than one condition on a single field"'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '115']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'expected'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '116', 'type': 'if_statement', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'expected'},{'id': '118', 'type': 'block', 'children': ['119', '125']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '123', 'type': 'string', 'children': [], 'value': "'Expected'"},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'expected'},{'id': '125', 'type': 'if_statement', 'children': ['126', '132']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '131'], 'value': '>'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'expected'},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '137', 'type': 'string', 'children': [], 'value': "'ConditionalOperator'"},{'id': '138', 'type': 'conditional_expression', 'children': ['139', '140', '141'], 'value': 'if'},{'id': '139', 'type': 'string', 'children': [], 'value': "'OR'"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'expect_or'},{'id': '141', 'type': 'string', 'children': [], 'value': "'AND'"},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151', '154', '157', '160', '163']},{'id': '150', 'type': 'string', 'children': [], 'value': "'update_item'"},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'TableName'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'Key'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'AttributeUpdates'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'attr_updates'},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ReturnValues'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'returns'},{'id': '163', 'type': 'dictionary_splat', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '165', 'type': 'if_statement', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'return_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'Result'},{'id': '171', 'type': 'argument_list', 'children': ['172', '175', '176']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '176', 'type': 'string', 'children': [], 'value': "'Attributes'"}
def update_item(self, tablename, key, updates, returns=NONE, return_capacity=None, expect_or=False, **kwargs): key = self.dynamizer.encode_keys(key) attr_updates = {} expected = {} keywords = { 'ReturnConsumedCapacity': self._default_capacity(return_capacity), } for update in updates: attr_updates.update(update.attrs(self.dynamizer)) expected.update(update.expected(self.dynamizer)) for k, v in six.iteritems(encode_query_kwargs(self.dynamizer, kwargs)): if k in expected: raise ValueError("Cannot have more than one condition on a single field") expected[k] = v if expected: keywords['Expected'] = expected if len(expected) > 1: keywords['ConditionalOperator'] = 'OR' if expect_or else 'AND' result = self.call('update_item', TableName=tablename, Key=key, AttributeUpdates=attr_updates, ReturnValues=returns, **keywords) if result: return Result(self.dynamizer, result, 'Attributes')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'query'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33', '36']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'consistent'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'return_capacity'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'default_parameter', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'filter_or'},{'id': '32', 'type': 'False', 'children': []},{'id': '33', 'type': 'default_parameter', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'exclusive_start_key'},{'id': '35', 'type': 'None', 'children': []},{'id': '36', 'type': 'dictionary_splat_pattern', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '38', 'type': 'block', 'children': ['39', '70', '81', '92', '126', '145', '160']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '42', 'type': 'dictionary', 'children': ['43', '46', '54', '57', '61']},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'TableName'"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'tablename'},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'ReturnConsumedCapacity'"},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_default_capacity'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'return_capacity'},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'ConsistentRead'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'consistent'},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'ScanIndexForward'"},{'id': '59', 'type': 'not_operator', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '61', 'type': 'pair', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'KeyConditions'"},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'encode_query_kwargs'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '70', 'type': 'if_statement', 'children': ['71', '74']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '80']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '79', 'type': 'string', 'children': [], 'value': "'AttributesToGet'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '81', 'type': 'if_statement', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '90', 'type': 'string', 'children': [], 'value': "'IndexName'"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '92', 'type': 'if_statement', 'children': ['93', '96']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'is'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '95', 'type': 'None', 'children': []},{'id': '96', 'type': 'block', 'children': ['97', '114']},{'id': '97', 'type': 'if_statement', 'children': ['98', '104']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '103'], 'value': '>'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '109', 'type': 'string', 'children': [], 'value': "'ConditionalOperator'"},{'id': '110', 'type': 'conditional_expression', 'children': ['111', '112', '113'], 'value': 'if'},{'id': '111', 'type': 'string', 'children': [], 'value': "'OR'"},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'filter_or'},{'id': '113', 'type': 'string', 'children': [], 'value': "'AND'"},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '118', 'type': 'string', 'children': [], 'value': "'QueryFilter'"},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'encode_query_kwargs'},{'id': '121', 'type': 'argument_list', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'exclusive_start_key'},{'id': '129', 'type': 'None', 'children': []},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '136', '137']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '135', 'type': 'string', 'children': [], 'value': "'ExclusiveStartKey'"},{'id': '136', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '137', 'type': 'call', 'children': ['138', '143']},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'dynamizer'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'maybe_encode_keys'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'exclusive_start_key'},{'id': '145', 'type': 'if_statement', 'children': ['146', '152']},{'id': '146', 'type': 'not_operator', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Limit'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Limit'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '160', 'type': 'if_statement', 'children': ['161', '162', '178']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '162', 'type': 'block', 'children': ['163', '169']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '168']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '167', 'type': 'string', 'children': [], 'value': "'Select'"},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'COUNT'},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': '_count'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176', '177']},{'id': '175', 'type': 'string', 'children': [], 'value': "'query'"},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'keywords'},{'id': '178', 'type': 'else_clause', 'children': ['179']},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'ResultSet'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185', '186', '187']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '186', 'type': 'string', 'children': [], 'value': "'query'"},{'id': '187', 'type': 'dictionary_splat', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'keywords'}
def query(self, tablename, attributes=None, consistent=False, count=False, index=None, limit=None, desc=False, return_capacity=None, filter=None, filter_or=False, exclusive_start_key=None, **kwargs): keywords = { 'TableName': tablename, 'ReturnConsumedCapacity': self._default_capacity(return_capacity), 'ConsistentRead': consistent, 'ScanIndexForward': not desc, 'KeyConditions': encode_query_kwargs(self.dynamizer, kwargs), } if attributes is not None: keywords['AttributesToGet'] = attributes if index is not None: keywords['IndexName'] = index if filter is not None: if len(filter) > 1: keywords['ConditionalOperator'] = 'OR' if filter_or else 'AND' keywords['QueryFilter'] = encode_query_kwargs(self.dynamizer, filter) if exclusive_start_key is not None: keywords['ExclusiveStartKey'] = \ self.dynamizer.maybe_encode_keys(exclusive_start_key) if not isinstance(limit, Limit): limit = Limit(limit) if count: keywords['Select'] = COUNT return self._count('query', limit, keywords) else: return ResultSet(self, limit, 'query', **keywords)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'letter_scales'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '5', 'type': 'block', 'children': ['6', '26', '46', '60']},{'id': '6', 'type': 'try_statement', 'children': ['7', '21']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '11', 'type': 'binary_operator', 'children': ['12', '13'], 'value': '/'},{'id': '12', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'except_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ZeroDivisionError'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'freqs'},{'id': '29', 'type': 'list_comprehension', 'children': ['30', '35', '44']},{'id': '30', 'type': 'tuple', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '*'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '39']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'if_clause', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'cnt'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'freqs'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '54', 'type': 'lambda', 'children': ['55', '57']},{'id': '55', 'type': 'lambda_parameters', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'freqs'}
def letter_scales(counts): try: scale = 1.0 / sum(counts.values()) except ZeroDivisionError: return [] freqs = [(aa, cnt*scale) for aa, cnt in counts.iteritems() if cnt] freqs.sort(key=lambda pair: pair[1]) return freqs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'count_diffs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'feats'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'inseq'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'cutoff'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'block', 'children': ['16', '27', '31', '35', '39', '43', '47', '51', '80', '186', '192', '198', '204', '210', '216', '225', '236', '361', '367']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'nfeats'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'feats'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'insr'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'dels'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '42', 'type': 'integer', 'children': [], 'value': '0'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '46', 'type': 'integer', 'children': [], 'value': '0'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'lastb'},{'id': '50', 'type': 'string', 'children': [], 'value': "''"},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '54', 'type': 'conditional_expression', 'children': ['55', '61', '74'], 'value': 'if'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '68'], 'value': '>'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '87']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'if_statement', 'children': ['89', '104', '157']},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '97'], 'value': 'or'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '96'], 'value': '=='},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '94', 'type': 'integer', 'children': [], 'value': '0'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '96', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '103'], 'value': '=='},{'id': '98', 'type': 'subscript', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '101', 'type': 'integer', 'children': [], 'value': '1'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '103', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '104', 'type': 'block', 'children': ['105', '131']},{'id': '105', 'type': 'if_statement', 'children': ['106', '113']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '112'], 'value': '=='},{'id': '107', 'type': 'subscript', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '112', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '113', 'type': 'block', 'children': ['114', '118', '127']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'augmented_assignment', 'children': ['116', '117'], 'value': '+='},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'insr'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'if_statement', 'children': ['119', '122']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '!='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'lastb'},{'id': '121', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'augmented_assignment', 'children': ['125', '126'], 'value': '+='},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'lastb'},{'id': '130', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '131', 'type': 'if_statement', 'children': ['132', '139']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '138'], 'value': '=='},{'id': '133', 'type': 'subscript', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '138', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '139', 'type': 'block', 'children': ['140', '144', '153']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'augmented_assignment', 'children': ['142', '143'], 'value': '+='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'dels'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '!='},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'lastb'},{'id': '147', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'augmented_assignment', 'children': ['151', '152'], 'value': '+='},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'lastb'},{'id': '156', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '157', 'type': 'else_clause', 'children': ['158']},{'id': '158', 'type': 'block', 'children': ['159', '163']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'lastb'},{'id': '162', 'type': 'string', 'children': [], 'value': "''"},{'id': '163', 'type': 'if_statement', 'children': ['164', '175', '180']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '170'], 'value': '!='},{'id': '165', 'type': 'subscript', 'children': ['166', '169']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '168', 'type': 'integer', 'children': [], 'value': '0'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '170', 'type': 'subscript', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '173', 'type': 'integer', 'children': [], 'value': '1'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'augmented_assignment', 'children': ['178', '179'], 'value': '+='},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '179', 'type': 'integer', 'children': [], 'value': '1'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'augmented_assignment', 'children': ['184', '185'], 'value': '+='},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'gper'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '/'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'nfeats'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'delper'},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '/'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'dels'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'iper'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '/'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'insr'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'mmper'},{'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '/'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'mper'},{'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '/'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'mper2'},{'id': '219', 'type': 'binary_operator', 'children': ['220', '221'], 'value': '/'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'inseq'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '+'},{'id': '234', 'type': 'string', 'children': [], 'value': '"Logger."'},{'id': '235', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '236', 'type': 'if_statement', 'children': ['237', '242']},{'id': '237', 'type': 'boolean_operator', 'children': ['238', '239'], 'value': 'and'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': '>'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '241', 'type': 'integer', 'children': [], 'value': '0'},{'id': '242', 'type': 'block', 'children': ['243', '264', '277', '291', '305', '319', '333', '347']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '+'},{'id': '250', 'type': 'string', 'children': [], 'value': '"Features algined = "'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'string', 'children': [], 'value': '","'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'feats'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '263', 'type': 'argument_list', 'children': []},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'string', 'children': [], 'value': "'{:<22}{:<6d}'"},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276']},{'id': '275', 'type': 'string', 'children': [], 'value': '"Number of feats: "'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'nfeats'},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'string', 'children': [], 'value': "'{:<22}{:<6d}{:<1.2f}'"},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '287', 'type': 'argument_list', 'children': ['288', '289', '290']},{'id': '288', 'type': 'string', 'children': [], 'value': '"Number of gaps: "'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'gper'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'string', 'children': [], 'value': "'{:<22}{:<6d}{:<1.2f}'"},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303', '304']},{'id': '302', 'type': 'string', 'children': [], 'value': '"Number of deletions: "'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'dels'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'delper'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'call', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'string', 'children': [], 'value': "'{:<22}{:<6d}{:<1.2f}'"},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '315', 'type': 'argument_list', 'children': ['316', '317', '318']},{'id': '316', 'type': 'string', 'children': [], 'value': '"Number of insertions: "'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'insr'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'iper'},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'string', 'children': [], 'value': "'{:<22}{:<6d}{:<1.2f}'"},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '329', 'type': 'argument_list', 'children': ['330', '331', '332']},{'id': '330', 'type': 'string', 'children': [], 'value': '"Number of mismatches: "'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'mm'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'mmper'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '338']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'string', 'children': [], 'value': "'{:<22}{:<6d}{:<1.2f}'"},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '343', 'type': 'argument_list', 'children': ['344', '345', '346']},{'id': '344', 'type': 'string', 'children': [], 'value': '"Number of matches: "'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'mper'},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'call', 'children': ['349', '352']},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '352', 'type': 'argument_list', 'children': ['353']},{'id': '353', 'type': 'call', 'children': ['354', '357']},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'string', 'children': [], 'value': "'{:<22}{:<6d}{:<1.2f}'"},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '357', 'type': 'argument_list', 'children': ['358', '359', '360']},{'id': '358', 'type': 'string', 'children': [], 'value': '"Number of matches: "'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'mper2'},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'indel'},{'id': '364', 'type': 'binary_operator', 'children': ['365', '366'], 'value': '+'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'iper'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'delper'},{'id': '367', 'type': 'if_statement', 'children': ['368', '382', '397']},{'id': '368', 'type': 'boolean_operator', 'children': ['369', '379'], 'value': 'and'},{'id': '369', 'type': 'boolean_operator', 'children': ['370', '376'], 'value': 'and'},{'id': '370', 'type': 'comparison_operator', 'children': ['371', '375'], 'value': '>'},{'id': '371', 'type': 'call', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '373', 'type': 'argument_list', 'children': ['374']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'inseq'},{'id': '375', 'type': 'integer', 'children': [], 'value': '6000'},{'id': '376', 'type': 'comparison_operator', 'children': ['377', '378'], 'value': '<'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'mmper'},{'id': '378', 'type': 'float', 'children': [], 'value': '.10'},{'id': '379', 'type': 'comparison_operator', 'children': ['380', '381'], 'value': '>'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'mper2'},{'id': '381', 'type': 'float', 'children': [], 'value': '.80'},{'id': '382', 'type': 'block', 'children': ['383', '393']},{'id': '383', 'type': 'if_statement', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '385', 'type': 'block', 'children': ['386']},{'id': '386', 'type': 'expression_statement', 'children': ['387']},{'id': '387', 'type': 'call', 'children': ['388', '391']},{'id': '388', 'type': 'attribute', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '391', 'type': 'argument_list', 'children': ['392']},{'id': '392', 'type': 'string', 'children': [], 'value': '"Alignment coverage high enough to complete annotation 11"'},{'id': '393', 'type': 'return_statement', 'children': ['394']},{'id': '394', 'type': 'expression_list', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'insr'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'dels'},{'id': '397', 'type': 'else_clause', 'children': ['398']},{'id': '398', 'type': 'block', 'children': ['399', '405']},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'assignment', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'indel_mm'},{'id': '402', 'type': 'binary_operator', 'children': ['403', '404'], 'value': '+'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'indel'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'mper2'},{'id': '405', 'type': 'if_statement', 'children': ['406', '422', '440']},{'id': '406', 'type': 'boolean_operator', 'children': ['407', '419'], 'value': 'and'},{'id': '407', 'type': 'boolean_operator', 'children': ['408', '416'], 'value': 'and'},{'id': '408', 'type': '()', 'children': ['409']},{'id': '409', 'type': 'boolean_operator', 'children': ['410', '413'], 'value': 'or'},{'id': '410', 'type': 'comparison_operator', 'children': ['411', '412'], 'value': '>'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'indel'},{'id': '412', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '413', 'type': 'comparison_operator', 'children': ['414', '415'], 'value': '>'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'mmper'},{'id': '415', 'type': 'float', 'children': [], 'value': '0.05'},{'id': '416', 'type': 'comparison_operator', 'children': ['417', '418'], 'value': '<'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'mper2'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'cutoff'},{'id': '419', 'type': 'comparison_operator', 'children': ['420', '421'], 'value': '!='},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'indel_mm'},{'id': '421', 'type': 'integer', 'children': [], 'value': '1'},{'id': '422', 'type': 'block', 'children': ['423', '433']},{'id': '423', 'type': 'if_statement', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '425', 'type': 'block', 'children': ['426']},{'id': '426', 'type': 'expression_statement', 'children': ['427']},{'id': '427', 'type': 'call', 'children': ['428', '431']},{'id': '428', 'type': 'attribute', 'children': ['429', '430']},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '431', 'type': 'argument_list', 'children': ['432']},{'id': '432', 'type': 'string', 'children': [], 'value': '"Alignment coverage NOT high enough to return annotation"'},{'id': '433', 'type': 'return_statement', 'children': ['434']},{'id': '434', 'type': 'call', 'children': ['435', '436']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '436', 'type': 'argument_list', 'children': ['437']},{'id': '437', 'type': 'keyword_argument', 'children': ['438', '439']},{'id': '438', 'type': 'identifier', 'children': [], 'value': 'complete_annotation'},{'id': '439', 'type': 'False', 'children': []},{'id': '440', 'type': 'else_clause', 'children': ['441']},{'id': '441', 'type': 'block', 'children': ['442', '452']},{'id': '442', 'type': 'if_statement', 'children': ['443', '444']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '444', 'type': 'block', 'children': ['445']},{'id': '445', 'type': 'expression_statement', 'children': ['446']},{'id': '446', 'type': 'call', 'children': ['447', '450']},{'id': '447', 'type': 'attribute', 'children': ['448', '449']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '450', 'type': 'argument_list', 'children': ['451']},{'id': '451', 'type': 'string', 'children': [], 'value': '"Alignment coverage high enough to complete annotation"'},{'id': '452', 'type': 'return_statement', 'children': ['453']},{'id': '453', 'type': 'expression_list', 'children': ['454', '455']},{'id': '454', 'type': 'identifier', 'children': [], 'value': 'insr'},{'id': '455', 'type': 'identifier', 'children': [], 'value': 'dels'}
def count_diffs(align, feats, inseq, locus, cutoff, verbose=False, verbosity=0): nfeats = len(feats.keys()) mm = 0 insr = 0 dels = 0 gaps = 0 match = 0 lastb = '' l = len(align[0]) if len(align[0]) > len(align[1]) else len(align[1]) for i in range(0, l): if align[0][i] == "-" or align[1][i] == "-": if align[0][i] == "-": insr += 1 if lastb != '-': gaps += 1 lastb = "-" if align[1][i] == "-": dels += 1 if lastb != '-': gaps += 1 lastb = "-" else: lastb = '' if align[0][i] != align[1][i]: mm += 1 else: match += 1 gper = gaps / nfeats delper = dels / l iper = insr / l mmper = mm / l mper = match / l mper2 = match / len(inseq) logger = logging.getLogger("Logger." + __name__) if verbose and verbosity > 0: logger.info("Features algined = " + ",".join(list(feats.keys()))) logger.info('{:<22}{:<6d}'.format("Number of feats: ", nfeats)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of gaps: ", gaps, gper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of deletions: ", dels, delper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of insertions: ", insr, iper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of mismatches: ", mm, mmper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of matches: ", match, mper)) logger.info('{:<22}{:<6d}{:<1.2f}'.format("Number of matches: ", match, mper2)) indel = iper + delper if len(inseq) > 6000 and mmper < .10 and mper2 > .80: if verbose: logger.info("Alignment coverage high enough to complete annotation 11") return insr, dels else: indel_mm = indel + mper2 if (indel > 0.5 or mmper > 0.05) and mper2 < cutoff and indel_mm != 1: if verbose: logger.info("Alignment coverage NOT high enough to return annotation") return Annotation(complete_annotation=False) else: if verbose: logger.info("Alignment coverage high enough to complete annotation") return insr, dels
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd_debug'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '7', 'type': 'block', 'children': ['8', '26', '32', '54', '71', '88', '105', '122', '145', '154', '163', '171', '181', '315', '345']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'argparse'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'},{'id': '15', 'type': 'argument_list', 'children': ['16', '23']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'prog'},{'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'},{'id': '19', 'type': 'string', 'children': [], 'value': '"%s debug"'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'progname'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '42', '45', '48']},{'id': '38', 'type': 'string', 'children': [], 'value': '"instance"'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'metavar'},{'id': '44', 'type': 'string', 'children': [], 'value': '"instance"'},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '47', 'type': 'string', 'children': [], 'value': '"Name of the instance from the config."'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62', '65', '68']},{'id': '60', 'type': 'string', 'children': [], 'value': '"-v"'},{'id': '61', 'type': 'string', 'children': [], 'value': '"--verbose"'},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '64', 'type': 'string', 'children': [], 'value': '"verbose"'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '67', 'type': 'string', 'children': [], 'value': '"store_true"'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '70', 'type': 'string', 'children': [], 'value': '"Print more info and output the startup script"'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79', '82', '85']},{'id': '77', 'type': 'string', 'children': [], 'value': '"-c"'},{'id': '78', 'type': 'string', 'children': [], 'value': '"--console-output"'},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '81', 'type': 'string', 'children': [], 'value': '"console_output"'},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '84', 'type': 'string', 'children': [], 'value': '"store_true"'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '87', 'type': 'string', 'children': [], 'value': '"Prints the console output of the instance if available"'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95', '96', '99', '102']},{'id': '94', 'type': 'string', 'children': [], 'value': '"-i"'},{'id': '95', 'type': 'string', 'children': [], 'value': '"--interactive"'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '98', 'type': 'string', 'children': [], 'value': '"interactive"'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '101', 'type': 'string', 'children': [], 'value': '"store_true"'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '104', 'type': 'string', 'children': [], 'value': '"Creates a connection and drops you into an interactive Python session"'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112', '113', '116', '119']},{'id': '111', 'type': 'string', 'children': [], 'value': '"-r"'},{'id': '112', 'type': 'string', 'children': [], 'value': '"--raw"'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '115', 'type': 'string', 'children': [], 'value': '"raw"'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '118', 'type': 'string', 'children': [], 'value': '"store_true"'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '121', 'type': 'string', 'children': [], 'value': '"Outputs the raw possibly compressed startup script"'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129', '130', '133', '136', '139', '142']},{'id': '128', 'type': 'string', 'children': [], 'value': '"-o"'},{'id': '129', 'type': 'string', 'children': [], 'value': '"--override"'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '132', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '138', 'type': 'string', 'children': [], 'value': '"overrides"'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'metavar'},{'id': '141', 'type': 'string', 'children': [], 'value': '"OVERRIDE"'},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '144', 'type': 'string', 'children': [], 'value': '"Option to override instance config for startup script (name=value)."'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'overrides'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': '_parse_overrides'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '168']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'overrides'},{'id': '167', 'type': 'string', 'children': [], 'value': "'instances'"},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '176', 'type': 'subscript', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '180', 'type': 'integer', 'children': [], 'value': '0'},{'id': '181', 'type': 'if_statement', 'children': ['182', '187']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '186', 'type': 'string', 'children': [], 'value': "'startup_script'"},{'id': '187', 'type': 'block', 'children': ['188', '202', '213', '227', '285']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'startup_script'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'startup_script'},{'id': '195', 'type': 'argument_list', 'children': ['196', '199']},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'overrides'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'overrides'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '201', 'type': 'True', 'children': []},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209', '210']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '209', 'type': 'string', 'children': [], 'value': "'max_startup_script_size'"},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '*'},{'id': '211', 'type': 'integer', 'children': [], 'value': '16'},{'id': '212', 'type': 'integer', 'children': [], 'value': '1024'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '218', 'type': 'argument_list', 'children': ['219', '220', '226']},{'id': '219', 'type': 'string', 'children': [], 'value': '"Length of startup script: %s/%s"'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'startup_script'},{'id': '225', 'type': 'string', 'children': [], 'value': "'raw'"},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'max_size'},{'id': '227', 'type': 'if_statement', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'if_statement', 'children': ['233', '238', '276']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': 'in'},{'id': '234', 'type': 'string', 'children': [], 'value': "'startup_script'"},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'if_statement', 'children': ['240', '247', '255', '267']},{'id': '240', 'type': 'comparison_operator', 'children': ['241', '244'], 'value': '=='},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'startup_script'},{'id': '243', 'type': 'string', 'children': [], 'value': "'original'"},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'startup_script'},{'id': '246', 'type': 'string', 'children': [], 'value': "'raw'"},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'string', 'children': [], 'value': '"Startup script:"'},{'id': '255', 'type': 'elif_clause', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'string', 'children': [], 'value': '"Compressed startup script:"'},{'id': '267', 'type': 'else_clause', 'children': ['268']},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'string', 'children': [], 'value': '"Uncompressed startup script:"'},{'id': '276', 'type': 'else_clause', 'children': ['277']},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'string', 'children': [], 'value': '"No startup script specified"'},{'id': '285', 'type': 'if_statement', 'children': ['286', '289', '300']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '293', 'type': 'argument_list', 'children': ['294', '297']},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'startup_script'},{'id': '296', 'type': 'string', 'children': [], 'value': "'raw'"},{'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '299', 'type': 'string', 'children': [], 'value': "''"},{'id': '300', 'type': 'elif_clause', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '308', 'type': 'argument_list', 'children': ['309', '312']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'startup_script'},{'id': '311', 'type': 'string', 'children': [], 'value': "'original'"},{'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '314', 'type': 'string', 'children': [], 'value': "''"},{'id': '315', 'type': 'if_statement', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'console_output'},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'if_statement', 'children': ['321', '326', '336']},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '325', 'type': 'string', 'children': [], 'value': "'get_console_output'"},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'get_console_output'},{'id': '335', 'type': 'argument_list', 'children': []},{'id': '336', 'type': 'else_clause', 'children': ['337']},{'id': '337', 'type': 'block', 'children': ['338']},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'call', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '343', 'type': 'argument_list', 'children': ['344']},{'id': '344', 'type': 'string', 'children': [], 'value': '"The instance doesn\'t support console output."'},{'id': '345', 'type': 'if_statement', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '349', 'type': 'block', 'children': ['350', '353', '358', '378', '385', '408']},{'id': '350', 'type': 'import_statement', 'children': ['351']},{'id': '351', 'type': 'dotted_name', 'children': ['352']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '353', 'type': 'import_from_statement', 'children': ['354', '356']},{'id': '354', 'type': 'dotted_name', 'children': ['355']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'pprint'},{'id': '356', 'type': 'dotted_name', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'pprint'},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'assignment', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'local'},{'id': '361', 'type': 'call', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '363', 'type': 'argument_list', 'children': ['364', '367', '372', '375']},{'id': '364', 'type': 'keyword_argument', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'ctrl'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '367', 'type': 'keyword_argument', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '372', 'type': 'keyword_argument', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '375', 'type': 'keyword_argument', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'pprint'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'pprint'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'call', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'parse_and_bind'},{'id': '383', 'type': 'argument_list', 'children': ['384']},{'id': '384', 'type': 'string', 'children': [], 'value': "'tab: complete'"},{'id': '385', 'type': 'try_statement', 'children': ['386', '404']},{'id': '386', 'type': 'block', 'children': ['387', '390']},{'id': '387', 'type': 'import_statement', 'children': ['388']},{'id': '388', 'type': 'dotted_name', 'children': ['389']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'rlcompleter'},{'id': '390', 'type': 'expression_statement', 'children': ['391']},{'id': '391', 'type': 'call', 'children': ['392', '395']},{'id': '392', 'type': 'attribute', 'children': ['393', '394']},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'set_completer'},{'id': '395', 'type': 'argument_list', 'children': ['396']},{'id': '396', 'type': 'attribute', 'children': ['397', '403']},{'id': '397', 'type': 'call', 'children': ['398', '401']},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'rlcompleter'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'Completer'},{'id': '401', 'type': 'argument_list', 'children': ['402']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'local'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'complete'},{'id': '404', 'type': 'except_clause', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '406', 'type': 'block', 'children': ['407']},{'id': '407', 'type': 'pass_statement', 'children': []},{'id': '408', 'type': 'expression_statement', 'children': ['409']},{'id': '409', 'type': 'call', 'children': ['410', '416']},{'id': '410', 'type': 'attribute', 'children': ['411', '415']},{'id': '411', 'type': 'call', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': '__import__'},{'id': '413', 'type': 'argument_list', 'children': ['414']},{'id': '414', 'type': 'string', 'children': [], 'value': '"code"'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'interact'},{'id': '416', 'type': 'argument_list', 'children': ['417']},{'id': '417', 'type': 'keyword_argument', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'local'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'local'}
def cmd_debug(self, argv, help): parser = argparse.ArgumentParser( prog="%s debug" % self.progname, description=help, ) instances = self.instances parser.add_argument("instance", nargs=1, metavar="instance", help="Name of the instance from the config.", choices=sorted(instances)) parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", help="Print more info and output the startup script") parser.add_argument("-c", "--console-output", dest="console_output", action="store_true", help="Prints the console output of the instance if available") parser.add_argument("-i", "--interactive", dest="interactive", action="store_true", help="Creates a connection and drops you into an interactive Python session") parser.add_argument("-r", "--raw", dest="raw", action="store_true", help="Outputs the raw possibly compressed startup script") parser.add_argument("-o", "--override", nargs="*", type=str, dest="overrides", metavar="OVERRIDE", help="Option to override instance config for startup script (name=value).") args = parser.parse_args(argv) overrides = self._parse_overrides(args) overrides['instances'] = self.instances instance = instances[args.instance[0]] if hasattr(instance, 'startup_script'): startup_script = instance.startup_script(overrides=overrides, debug=True) max_size = getattr(instance, 'max_startup_script_size', 16 * 1024) log.info("Length of startup script: %s/%s", len(startup_script['raw']), max_size) if args.verbose: if 'startup_script' in instance.config: if startup_script['original'] == startup_script['raw']: log.info("Startup script:") elif args.raw: log.info("Compressed startup script:") else: log.info("Uncompressed startup script:") else: log.info("No startup script specified") if args.raw: print(startup_script['raw'], end='') elif args.verbose: print(startup_script['original'], end='') if args.console_output: if hasattr(instance, 'get_console_output'): print(instance.get_console_output()) else: log.error("The instance doesn't support console output.") if args.interactive: import readline from pprint import pprint local = dict( ctrl=self, instances=self.instances, instance=instance, pprint=pprint) readline.parse_and_bind('tab: complete') try: import rlcompleter readline.set_completer(rlcompleter.Completer(local).complete) except ImportError: pass __import__("code").interact(local=local)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd_ssh'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '7', 'type': 'block', 'children': ['8', '26', '37', '59', '74', '81', '85', '89', '146', '191', '197', '213', '271', '277', '289', '295', '311', '321']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'argparse'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'},{'id': '15', 'type': 'argument_list', 'children': ['16', '23']},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'prog'},{'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'},{'id': '19', 'type': 'string', 'children': [], 'value': '"%s ssh"'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'progname'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_instances'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '36', 'type': 'string', 'children': [], 'value': "'init_ssh_key'"},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44', '47', '50', '53']},{'id': '43', 'type': 'string', 'children': [], 'value': '"instance"'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '46', 'type': 'integer', 'children': [], 'value': '1'},{'id': '47', 'type': 'keyword_argument', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'metavar'},{'id': '49', 'type': 'string', 'children': [], 'value': '"instance"'},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '52', 'type': 'string', 'children': [], 'value': '"Name of the instance from the config."'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '71']},{'id': '65', 'type': 'string', 'children': [], 'value': '"..."'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'argparse'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'REMAINDER'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '73', 'type': 'string', 'children': [], 'value': '"ssh options"'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'iargs'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sid_index'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '88', 'type': 'None', 'children': []},{'id': '89', 'type': 'for_statement', 'children': ['90', '93', '94']},{'id': '90', 'type': 'pattern_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'iargs'},{'id': '94', 'type': 'block', 'children': ['95', '109']},{'id': '95', 'type': 'if_statement', 'children': ['96', '103']},{'id': '96', 'type': 'not_operator', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '103', 'type': 'block', 'children': ['104', '108']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sid_index'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '108', 'type': 'break_statement', 'children': []},{'id': '109', 'type': 'if_statement', 'children': ['110', '115', '117']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '114'], 'value': 'in'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '113', 'type': 'integer', 'children': [], 'value': '1'},{'id': '114', 'type': 'string', 'children': [], 'value': "'1246AaCfgKkMNnqsTtVvXxYy'"},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'continue_statement', 'children': []},{'id': '117', 'type': 'elif_clause', 'children': ['118', '123']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '122'], 'value': 'in'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'string', 'children': [], 'value': "'bcDeFiLlmOopRSw'"},{'id': '123', 'type': 'block', 'children': ['124', '132', '145']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'iargs'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'if_statement', 'children': ['133', '138']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': '=='},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '136', 'type': 'integer', 'children': [], 'value': '1'},{'id': '137', 'type': 'string', 'children': [], 'value': "'l'"},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '144', 'type': 'integer', 'children': [], 'value': '1'},{'id': '145', 'type': 'continue_statement', 'children': []},{'id': '146', 'type': 'if_statement', 'children': ['147', '150', '158']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sid_index'},{'id': '149', 'type': 'None', 'children': []},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'list', 'children': [], 'value': '[]'},{'id': '158', 'type': 'else_clause', 'children': ['159']},{'id': '159', 'type': 'block', 'children': ['160', '166', '183']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'sid_index'},{'id': '166', 'type': 'if_statement', 'children': ['167', '170']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'in'},{'id': '168', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '176']},{'id': '173', 'type': 'pattern_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '182', 'type': 'integer', 'children': [], 'value': '1'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'list', 'children': ['190'], 'value': '[sid]'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '197', 'type': 'if_statement', 'children': ['198', '201']},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': 'is'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '200', 'type': 'None', 'children': []},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '205', 'type': 'call', 'children': ['206', '211']},{'id': '206', 'type': 'attribute', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '213', 'type': 'try_statement', 'children': ['214', '226']},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'ssh_info'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'init_ssh_key'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'keyword_argument', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '226', 'type': 'except_clause', 'children': ['227', '239']},{'id': '227', 'type': 'as_pattern', 'children': ['228', '237']},{'id': '228', 'type': 'tuple', 'children': ['229', '234']},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'paramiko'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'SSHException'},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'socket'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '237', 'type': 'as_pattern_target', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '239', 'type': 'block', 'children': ['240', '247', '257', '264']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'string', 'children': [], 'value': '"Couldn\'t validate fingerprint for ssh connection."'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'string', 'children': [], 'value': '"Is the instance finished starting up?"'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'integer', 'children': [], 'value': '1'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '274', 'type': 'subscript', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'ssh_info'},{'id': '276', 'type': 'string', 'children': [], 'value': "'client'"},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'call', 'children': ['279', '288']},{'id': '279', 'type': 'attribute', 'children': ['280', '287']},{'id': '280', 'type': 'attribute', 'children': ['281', '286']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'get_transport'},{'id': '285', 'type': 'argument_list', 'children': []},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'sock'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '288', 'type': 'argument_list', 'children': []},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'client'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '294', 'type': 'argument_list', 'children': []},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '305']},{'id': '297', 'type': 'subscript', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '299', 'type': 'slice', 'children': ['300', '301', '302']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'sid_index'},{'id': '301', 'type': 'colon', 'children': []},{'id': '302', 'type': 'binary_operator', 'children': ['303', '304'], 'value': '+'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'sid_index'},{'id': '304', 'type': 'integer', 'children': [], 'value': '1'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'ssh_args_from_info'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'ssh_info'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '319']},{'id': '313', 'type': 'subscript', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '315', 'type': 'slice', 'children': ['316', '317', '318']},{'id': '316', 'type': 'integer', 'children': [], 'value': '0'},{'id': '317', 'type': 'colon', 'children': []},{'id': '318', 'type': 'integer', 'children': [], 'value': '0'},{'id': '319', 'type': 'list', 'children': ['320'], 'value': "['ssh']"},{'id': '320', 'type': 'string', 'children': [], 'value': "'ssh'"},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '326']},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'execvp'},{'id': '326', 'type': 'argument_list', 'children': ['327', '328']},{'id': '327', 'type': 'string', 'children': [], 'value': "'ssh'"},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'argv'}
def cmd_ssh(self, argv, help): parser = argparse.ArgumentParser( prog="%s ssh" % self.progname, description=help, ) instances = self.get_instances(command='init_ssh_key') parser.add_argument("instance", nargs=1, metavar="instance", help="Name of the instance from the config.", choices=sorted(instances)) parser.add_argument("...", nargs=argparse.REMAINDER, help="ssh options") iargs = enumerate(argv) sid_index = None user = None for i, arg in iargs: if not arg.startswith('-'): sid_index = i break if arg[1] in '1246AaCfgKkMNnqsTtVvXxYy': continue elif arg[1] in 'bcDeFiLlmOopRSw': value = iargs.next() if arg[1] == 'l': user = value[1] continue if sid_index is None: parser.parse_args([]) else: sid = argv[sid_index] if '@' in sid: user, sid = sid.split('@', 1) parser.parse_args([sid]) instance = instances[sid] if user is None: user = instance.config.get('user') try: ssh_info = instance.init_ssh_key(user=user) except (instance.paramiko.SSHException, socket.error) as e: log.error("Couldn't validate fingerprint for ssh connection.") log.error(unicode(e)) log.error("Is the instance finished starting up?") sys.exit(1) client = ssh_info['client'] client.get_transport().sock.close() client.close() argv[sid_index:sid_index + 1] = instance.ssh_args_from_info(ssh_info) argv[0:0] = ['ssh'] os.execvp('ssh', argv)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_alignment'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref_seq'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Annotation'},{'id': '9', 'type': 'block', 'children': ['10', '17', '21', '34', '52', '425', '431']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'seq_features'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_seqs'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ref_seq'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'annoated_align'},{'id': '20', 'type': 'dictionary', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'allele'},{'id': '24', 'type': 'subscript', 'children': ['25', '33']},{'id': '25', 'type': 'call', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ref_seq'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'string', 'children': [], 'value': '","'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '37', 'type': 'subscript', 'children': ['38', '51']},{'id': '38', 'type': 'call', 'children': ['39', '49']},{'id': '39', 'type': 'attribute', 'children': ['40', '48']},{'id': '40', 'type': 'subscript', 'children': ['41', '47']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'allele'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'seq_features'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'if_statement', 'children': ['57', '62', '392']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'in'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '62', 'type': 'block', 'children': ['63', '124']},{'id': '63', 'type': 'if_statement', 'children': ['64', '73', '97']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '66', 'type': 'argument_list', 'children': ['67', '72']},{'id': '67', 'type': 'subscript', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'DBSeq'},{'id': '73', 'type': 'block', 'children': ['74', '88']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'seq_len'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'subscript', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ref_len'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'seq_features'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '97', 'type': 'else_clause', 'children': ['98']},{'id': '98', 'type': 'block', 'children': ['99', '115']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'seq_len'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'attribute', 'children': ['109', '114']},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ref_len'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'seq_features'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '124', 'type': 'if_statement', 'children': ['125', '128', '281']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '=='},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'seq_len'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'ref_len'},{'id': '128', 'type': 'block', 'children': ['129', '142', '158', '233', '262', '271']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'attribute', 'children': ['136', '141']},{'id': '136', 'type': 'subscript', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '145', 'type': 'subscript', 'children': ['146', '157']},{'id': '146', 'type': 'subscript', 'children': ['147', '156']},{'id': '147', 'type': 'subscript', 'children': ['148', '155']},{'id': '148', 'type': 'subscript', 'children': ['149', '154']},{'id': '149', 'type': 'attribute', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'refdata'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'annoated_alignments'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'allele'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '157', 'type': 'string', 'children': [], 'value': "'Gaps'"},{'id': '158', 'type': 'if_statement', 'children': ['159', '168']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '163'], 'value': 'and'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '167'], 'value': '>'},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '167', 'type': 'integer', 'children': [], 'value': '0'},{'id': '168', 'type': 'block', 'children': ['169', '184', '199']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'binary_operator', 'children': ['178', '183'], 'value': '+'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '182'], 'value': '+'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'logname'},{'id': '182', 'type': 'string', 'children': [], 'value': '" Lengths match for "'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'binary_operator', 'children': ['193', '198'], 'value': '+'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '197'], 'value': '+'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'logname'},{'id': '197', 'type': 'string', 'children': [], 'value': '" Gaps at "'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '206']},{'id': '201', 'type': 'attribute', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'binary_operator', 'children': ['208', '211'], 'value': '+'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'logname'},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'list_comprehension', 'children': ['217', '230']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'string', 'children': [], 'value': '","'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'list_comprehension', 'children': ['223', '227']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '230', 'type': 'for_in_clause', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '233', 'type': 'for_statement', 'children': ['234', '235', '243']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239']},{'id': '238', 'type': 'integer', 'children': [], 'value': '0'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '243', 'type': 'block', 'children': ['244']},{'id': '244', 'type': 'for_statement', 'children': ['245', '246', '249']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '246', 'type': 'subscript', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'gaps'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '249', 'type': 'block', 'children': ['250', '254']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '259', 'type': 'argument_list', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '261', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'nseq'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'string', 'children': [], 'value': "''"},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'annoated_align'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'dictionary', 'children': ['278']},{'id': '278', 'type': 'pair', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'nseq'},{'id': '281', 'type': 'else_clause', 'children': ['282']},{'id': '282', 'type': 'block', 'children': ['283', '296', '312', '324', '378']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'in_seq'},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'attribute', 'children': ['290', '295']},{'id': '290', 'type': 'subscript', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'ref_seq'},{'id': '299', 'type': 'subscript', 'children': ['300', '311']},{'id': '300', 'type': 'subscript', 'children': ['301', '310']},{'id': '301', 'type': 'subscript', 'children': ['302', '309']},{'id': '302', 'type': 'subscript', 'children': ['303', '308']},{'id': '303', 'type': 'attribute', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'refdata'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'annoated_alignments'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'allele'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '311', 'type': 'string', 'children': [], 'value': "'Seq'"},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '315', 'type': 'call', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'pairwise2'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'globalxx'},{'id': '321', 'type': 'argument_list', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'in_seq'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'ref_seq'},{'id': '324', 'type': 'if_statement', 'children': ['325', '334']},{'id': '325', 'type': 'boolean_operator', 'children': ['326', '329'], 'value': 'and'},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '329', 'type': 'comparison_operator', 'children': ['330', '333'], 'value': '>'},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'verbosity'},{'id': '333', 'type': 'integer', 'children': [], 'value': '0'},{'id': '334', 'type': 'block', 'children': ['335', '350']},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '342']},{'id': '337', 'type': 'attribute', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'binary_operator', 'children': ['344', '349'], 'value': '+'},{'id': '344', 'type': 'binary_operator', 'children': ['345', '348'], 'value': '+'},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'logname'},{'id': '348', 'type': 'string', 'children': [], 'value': '" Align2 -> in_seq != ref_len "'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '357']},{'id': '352', 'type': 'attribute', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '357', 'type': 'argument_list', 'children': ['358']},{'id': '358', 'type': 'binary_operator', 'children': ['359', '374'], 'value': '+'},{'id': '359', 'type': 'binary_operator', 'children': ['360', '373'], 'value': '+'},{'id': '360', 'type': 'binary_operator', 'children': ['361', '366'], 'value': '+'},{'id': '361', 'type': 'binary_operator', 'children': ['362', '365'], 'value': '+'},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'logname'},{'id': '365', 'type': 'string', 'children': [], 'value': '" "'},{'id': '366', 'type': 'call', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '368', 'type': 'argument_list', 'children': ['369']},{'id': '369', 'type': 'call', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'in_seq'},{'id': '373', 'type': 'string', 'children': [], 'value': '" == "'},{'id': '374', 'type': 'call', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '376', 'type': 'argument_list', 'children': ['377']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'ref_len'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'call', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'annoated_align'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '383', 'type': 'argument_list', 'children': ['384']},{'id': '384', 'type': 'dictionary', 'children': ['385']},{'id': '385', 'type': 'pair', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '387', 'type': 'subscript', 'children': ['388', '391']},{'id': '388', 'type': 'subscript', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '390', 'type': 'integer', 'children': [], 'value': '0'},{'id': '391', 'type': 'integer', 'children': [], 'value': '0'},{'id': '392', 'type': 'else_clause', 'children': ['393']},{'id': '393', 'type': 'block', 'children': ['394', '415']},{'id': '394', 'type': 'expression_statement', 'children': ['395']},{'id': '395', 'type': 'assignment', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'nseq'},{'id': '397', 'type': 'call', 'children': ['398', '401']},{'id': '398', 'type': 'attribute', 'children': ['399', '400']},{'id': '399', 'type': 'string', 'children': [], 'value': "''"},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '401', 'type': 'argument_list', 'children': ['402']},{'id': '402', 'type': 'call', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '404', 'type': 'argument_list', 'children': ['405']},{'id': '405', 'type': 'call', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '407', 'type': 'argument_list', 'children': ['408', '409']},{'id': '408', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '409', 'type': 'call', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '411', 'type': 'argument_list', 'children': ['412']},{'id': '412', 'type': 'subscript', 'children': ['413', '414']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'seq_features'},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '415', 'type': 'expression_statement', 'children': ['416']},{'id': '416', 'type': 'call', 'children': ['417', '420']},{'id': '417', 'type': 'attribute', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'annoated_align'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '420', 'type': 'argument_list', 'children': ['421']},{'id': '421', 'type': 'dictionary', 'children': ['422']},{'id': '422', 'type': 'pair', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'feat'},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'nseq'},{'id': '425', 'type': 'expression_statement', 'children': ['426']},{'id': '426', 'type': 'assignment', 'children': ['427', '430']},{'id': '427', 'type': 'attribute', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'aligned'},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'annoated_align'},{'id': '431', 'type': 'return_statement', 'children': ['432']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'annotation'}
def add_alignment(self, ref_seq, annotation) -> Annotation: seq_features = get_seqs(ref_seq) annoated_align = {} allele = ref_seq.description.split(",")[0] locus = allele.split("*")[0].split("-")[1] for feat in seq_features: if feat in annotation.annotation: if isinstance(annotation.annotation[feat], DBSeq): seq_len = len(str(annotation.annotation[feat])) ref_len = len(seq_features[feat]) else: seq_len = len(str(annotation.annotation[feat].seq)) ref_len = len(seq_features[feat]) if seq_len == ref_len: seq = list(annotation.annotation[feat].seq) gaps = self.refdata.annoated_alignments[locus][allele][feat]['Gaps'] if self.verbose and self.verbosity > 0: self.logger.info(self.logname + " Lengths match for " + feat) self.logger.info(self.logname + " Gaps at " + feat) self.logger.info(self.logname + "-".join([",".join([str(s) for s in g]) for g in gaps])) for i in range(0, len(gaps)): for j in gaps[i]: loc = j seq.insert(loc, '-') nseq = ''.join(seq) annoated_align.update({feat: nseq}) else: in_seq = str(annotation.annotation[feat].seq) ref_seq = self.refdata.annoated_alignments[locus][allele][feat]['Seq'] alignment = pairwise2.align.globalxx(in_seq, ref_seq) if self.verbose and self.verbosity > 0: self.logger.info(self.logname + " Align2 -> in_seq != ref_len " + feat) self.logger.info(self.logname + " " + str(len(in_seq)) + " == " + str(ref_len)) annoated_align.update({feat: alignment[0][0]}) else: nseq = ''.join(list(repeat('-', len(seq_features[feat])))) annoated_align.update({feat: nseq}) annotation.aligned = annoated_align return annotation
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_tree'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tagname'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '12', 'type': 'integer', 'children': [], 'value': '0'},{'id': '13', 'type': 'block', 'children': ['14', '16', '25', '46']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'string', 'children': [], 'value': "''"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '28', 'type': 'conditional_expression', 'children': ['29', '40', '45'], 'value': 'if'},{'id': '29', 'type': '()', 'children': ['30']},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'},{'id': '31', 'type': 'string', 'children': [], 'value': "'\\n%s'"},{'id': '32', 'type': '()', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '39'], 'value': '*'},{'id': '34', 'type': 'subscript', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '__options'},{'id': '38', 'type': 'string', 'children': [], 'value': "'indent'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '40', 'type': 'subscript', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '__options'},{'id': '44', 'type': 'string', 'children': [], 'value': "'indent'"},{'id': '45', 'type': 'string', 'children': [], 'value': "''"},{'id': '46', 'type': 'if_statement', 'children': ['47', '54', '229', '251']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'DictTypes'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '72', '94']},{'id': '56', 'type': 'boolean_operator', 'children': ['57', '62'], 'value': 'and'},{'id': '57', 'type': 'subscript', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '__options'},{'id': '61', 'type': 'string', 'children': [], 'value': "'hasattr'"},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'check_structure'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'block', 'children': ['73', '84']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '78']},{'id': '75', 'type': 'pattern_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'pickdata'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'build_tree'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '92', '93']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'tagname'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '94', 'type': 'else_clause', 'children': ['95']},{'id': '95', 'type': 'block', 'children': ['96', '115', '123', '152', '211']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '__tree'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '%'},{'id': '105', 'type': 'string', 'children': [], 'value': "'%s%s'"},{'id': '106', 'type': 'tuple', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tag_start'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'tagname'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'if_statement', 'children': ['124', '129']},{'id': '124', 'type': 'subscript', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '__options'},{'id': '128', 'type': 'string', 'children': [], 'value': "'ksort'"},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137', '145']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'lambda', 'children': ['140', '142']},{'id': '140', 'type': 'lambda_parameters', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '147', 'type': 'subscript', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': '__options'},{'id': '151', 'type': 'string', 'children': [], 'value': "'reverse'"},{'id': '152', 'type': 'for_statement', 'children': ['153', '156', '157']},{'id': '153', 'type': 'pattern_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '157', 'type': 'block', 'children': ['158', '162', '199']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '161', 'type': 'dictionary', 'children': []},{'id': '162', 'type': 'if_statement', 'children': ['163', '187']},{'id': '163', 'type': 'boolean_operator', 'children': ['164', '177'], 'value': 'and'},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '170'], 'value': 'and'},{'id': '165', 'type': 'subscript', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '__options'},{'id': '169', 'type': 'string', 'children': [], 'value': "'hasattr'"},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'DictTypes'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'check_structure'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '193']},{'id': '190', 'type': 'pattern_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'pickdata'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'build_tree'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207', '208']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '+'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '210', 'type': 'integer', 'children': [], 'value': '1'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '218']},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': '__tree'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'binary_operator', 'children': ['220', '221'], 'value': '%'},{'id': '220', 'type': 'string', 'children': [], 'value': "'%s%s'"},{'id': '221', 'type': 'tuple', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'tag_end'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'tagname'},{'id': '229', 'type': 'elif_clause', 'children': ['230', '236']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'is_iterable'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'for_statement', 'children': ['238', '239', '240']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'build_tree'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248', '249', '250']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'tagname'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '251', 'type': 'else_clause', 'children': ['252']},{'id': '252', 'type': 'block', 'children': ['253', '262', '276']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '260']},{'id': '255', 'type': 'attribute', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': '__tree'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'indent'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'safedata'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '271', 'type': 'subscript', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': '__options'},{'id': '275', 'type': 'string', 'children': [], 'value': "'cdata'"},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '283']},{'id': '278', 'type': 'attribute', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '281', 'type': 'identifier', 'children': [], 'value': '__tree'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'build_tag'},{'id': '288', 'type': 'argument_list', 'children': ['289', '290', '291']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'tagname'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'attrs'}
def build_tree(self, data, tagname, attrs=None, depth=0): r if data is None: data = '' indent = ('\n%s' % (self.__options['indent'] * depth)) if self.__options['indent'] else '' if isinstance(data, utils.DictTypes): if self.__options['hasattr'] and self.check_structure(data.keys()): attrs, values = self.pickdata(data) self.build_tree(values, tagname, attrs, depth) else: self.__tree.append('%s%s' % (indent, self.tag_start(tagname, attrs))) iter = data.iteritems() if self.__options['ksort']: iter = sorted(iter, key=lambda x:x[0], reverse=self.__options['reverse']) for k, v in iter: attrs = {} if self.__options['hasattr'] and isinstance(v, utils.DictTypes) and self.check_structure(v.keys()): attrs, v = self.pickdata(v) self.build_tree(v, k, attrs, depth+1) self.__tree.append('%s%s' % (indent, self.tag_end(tagname))) elif utils.is_iterable(data): for v in data: self.build_tree(v, tagname, attrs, depth) else: self.__tree.append(indent) data = self.safedata(data, self.__options['cdata']) self.__tree.append(self.build_tag(tagname, data, attrs))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_remind'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '8', 'type': 'string', 'children': [], 'value': "''"},{'id': '9', 'type': 'block', 'children': ['10', '14', '18', '37', '58', '107', '115', '278', '344']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '17', 'type': 'dictionary', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '20', 'type': 'block', 'children': ['21', '25', '31']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '24', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '36', 'type': 'dictionary', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '40', 'type': 'list', 'children': ['41', '42', '43', '48', '49', '50', '51', '52'], 'value': "['remind', '-l', '-s%d' % self._month, '-b1', '-y', '-r',\n filename, str(self._startdate)]"},{'id': '41', 'type': 'string', 'children': [], 'value': "'remind'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'-l'"},{'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '%'},{'id': '44', 'type': 'string', 'children': [], 'value': "'-s%d'"},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_month'},{'id': '48', 'type': 'string', 'children': [], 'value': "'-b1'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'-y'"},{'id': '50', 'type': 'string', 'children': [], 'value': "'-r'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_startdate'},{'id': '58', 'type': 'try_statement', 'children': ['59', '92']},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'rem'},{'id': '63', 'type': 'call', 'children': ['64', '90']},{'id': '64', 'type': 'attribute', 'children': ['65', '89']},{'id': '65', 'type': 'subscript', 'children': ['66', '88']},{'id': '66', 'type': 'call', 'children': ['67', '79']},{'id': '67', 'type': 'attribute', 'children': ['68', '78']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72', '75']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'input'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '92', 'type': 'except_clause', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'raise_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '%'},{'id': '100', 'type': 'string', 'children': [], 'value': "'Error running: %s'"},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "' '"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'rem'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'rem'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'for_statement', 'children': ['116', '119', '135']},{'id': '116', 'type': 'tuple_pattern', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'fileinfo'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '121', 'type': 'argument_list', 'children': ['122', '128']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'rem'},{'id': '124', 'type': 'slice', 'children': ['125', '126', '127']},{'id': '125', 'type': 'colon', 'children': []},{'id': '126', 'type': 'colon', 'children': []},{'id': '127', 'type': 'integer', 'children': [], 'value': '2'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'rem'},{'id': '130', 'type': 'slice', 'children': ['131', '132', '133', '134']},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'colon', 'children': []},{'id': '133', 'type': 'colon', 'children': []},{'id': '134', 'type': 'integer', 'children': [], 'value': '2'},{'id': '135', 'type': 'block', 'children': ['136', '144', '150', '194', '209', '219']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'fileinfo'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'fileinfo'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'fileinfo'},{'id': '149', 'type': 'integer', 'children': [], 'value': '3'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'not'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '154', 'type': 'block', 'children': ['155', '168', '174', '181']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '160']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '160', 'type': 'call', 'children': ['161', '167']},{'id': '161', 'type': 'attribute', 'children': ['162', '166']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'readlines'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '173', 'type': 'dictionary', 'children': []},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'mtime'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'getmtime'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '181', 'type': 'if_statement', 'children': ['182', '187']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': '>'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'mtime'},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_mtime'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': '_mtime'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'mtime'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '197', 'type': 'subscript', 'children': ['198', '201']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '208'], 'value': '-'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'fileinfo'},{'id': '207', 'type': 'integer', 'children': [], 'value': '2'},{'id': '208', 'type': 'integer', 'children': [], 'value': '1'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': '_parse_remind_line'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '219', 'type': 'if_statement', 'children': ['220', '227', '254']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '224'], 'value': 'in'},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '223', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '227', 'type': 'block', 'children': ['228', '242']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'augmented_assignment', 'children': ['230', '239'], 'value': '+='},{'id': '230', 'type': 'subscript', 'children': ['231', '238']},{'id': '231', 'type': 'subscript', 'children': ['232', '235']},{'id': '232', 'type': 'subscript', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '237', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '238', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '241', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'augmented_assignment', 'children': ['244', '253'], 'value': '+='},{'id': '244', 'type': 'subscript', 'children': ['245', '252']},{'id': '245', 'type': 'subscript', 'children': ['246', '249']},{'id': '246', 'type': 'subscript', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '251', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '252', 'type': 'string', 'children': [], 'value': "'line'"},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '254', 'type': 'else_clause', 'children': ['255']},{'id': '255', 'type': 'block', 'children': ['256', '266']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '265']},{'id': '258', 'type': 'subscript', 'children': ['259', '262']},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '264', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '277']},{'id': '268', 'type': 'subscript', 'children': ['269', '276']},{'id': '269', 'type': 'subscript', 'children': ['270', '273']},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'src_filename'},{'id': '273', 'type': 'subscript', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '275', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '276', 'type': 'string', 'children': [], 'value': "'line'"},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '278', 'type': 'for_statement', 'children': ['279', '280', '285']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '284', 'type': 'argument_list', 'children': []},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'for_statement', 'children': ['287', '288', '289']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'if_statement', 'children': ['291', '297']},{'id': '291', 'type': 'call', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'string', 'children': [], 'value': "'include'"},{'id': '297', 'type': 'block', 'children': ['298', '313']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'new_file'},{'id': '301', 'type': 'call', 'children': ['302', '312']},{'id': '302', 'type': 'attribute', 'children': ['303', '311']},{'id': '303', 'type': 'subscript', 'children': ['304', '310']},{'id': '304', 'type': 'call', 'children': ['305', '308']},{'id': '305', 'type': 'attribute', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'string', 'children': [], 'value': "' '"},{'id': '310', 'type': 'integer', 'children': [], 'value': '1'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'if_statement', 'children': ['314', '317']},{'id': '314', 'type': 'comparison_operator', 'children': ['315', '316'], 'value': 'not'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'new_file'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '317', 'type': 'block', 'children': ['318', '324', '331']},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '323']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'reminders'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'new_file'},{'id': '323', 'type': 'dictionary', 'children': []},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'mtime'},{'id': '327', 'type': 'call', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'getmtime'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'new_file'},{'id': '331', 'type': 'if_statement', 'children': ['332', '337']},{'id': '332', 'type': 'comparison_operator', 'children': ['333', '334'], 'value': '>'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'mtime'},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '336', 'type': 'identifier', 'children': [], 'value': '_mtime'},{'id': '337', 'type': 'block', 'children': ['338']},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'assignment', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '342', 'type': 'identifier', 'children': [], 'value': '_mtime'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'mtime'},{'id': '344', 'type': 'return_statement', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'reminders'}
def _parse_remind(self, filename, lines=''): files = {} reminders = {} if lines: filename = '-' files[filename] = lines reminders[filename] = {} cmd = ['remind', '-l', '-s%d' % self._month, '-b1', '-y', '-r', filename, str(self._startdate)] try: rem = Popen(cmd, stdin=PIPE, stdout=PIPE).communicate(input=lines.encode('utf-8'))[0].decode('utf-8') except OSError: raise OSError('Error running: %s' % ' '.join(cmd)) rem = rem.splitlines() for (fileinfo, line) in zip(rem[::2], rem[1::2]): fileinfo = fileinfo.split() src_filename = fileinfo[3] if src_filename not in files: files[src_filename] = open(src_filename).readlines() reminders[src_filename] = {} mtime = getmtime(src_filename) if mtime > self._mtime: self._mtime = mtime text = files[src_filename][int(fileinfo[2]) - 1] event = self._parse_remind_line(line, text) if event['uid'] in reminders[src_filename]: reminders[src_filename][event['uid']]['dtstart'] += event['dtstart'] reminders[src_filename][event['uid']]['line'] += line else: reminders[src_filename][event['uid']] = event reminders[src_filename][event['uid']]['line'] = line for source in files.values(): for line in source: if line.startswith('include'): new_file = line.split(' ')[1].strip() if new_file not in reminders: reminders[new_file] = {} mtime = getmtime(new_file) if mtime > self._mtime: self._mtime = mtime return reminders
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_parse_remind_line'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '7', 'type': 'block', 'children': ['8', '12', '22', '40', '132', '154', '174', '203', '219', '230', '237', '257', '276', '295']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '11', 'type': 'dictionary', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'integer', 'children': [], 'value': '6'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '25', 'type': 'list_comprehension', 'children': ['26', '30']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '32', 'type': 'call', 'children': ['33', '38']},{'id': '33', 'type': 'attribute', 'children': ['34', '37']},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '36', 'type': 'integer', 'children': [], 'value': '0'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '40', 'type': 'if_statement', 'children': ['41', '46', '112']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '45'], 'value': '!='},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '44', 'type': 'integer', 'children': [], 'value': '4'},{'id': '45', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '46', 'type': 'block', 'children': ['47', '60', '89']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '52', 'type': 'argument_list', 'children': ['53', '59']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '58', 'type': 'integer', 'children': [], 'value': '4'},{'id': '59', 'type': 'integer', 'children': [], 'value': '60'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '64', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '65', 'type': 'list', 'children': ['66'], 'value': '[datetime(dat[0], dat[1], dat[2], start[0], start[1], tzinfo=self._localtz)]'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '68', 'type': 'argument_list', 'children': ['69', '72', '75', '78', '81', '84']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '77', 'type': 'integer', 'children': [], 'value': '2'},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_localtz'},{'id': '89', 'type': 'if_statement', 'children': ['90', '95']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '!='},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '93', 'type': 'integer', 'children': [], 'value': '3'},{'id': '94', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '100', 'type': 'string', 'children': [], 'value': "'duration'"},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'minutes'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '111', 'type': 'integer', 'children': [], 'value': '3'},{'id': '112', 'type': 'else_clause', 'children': ['113']},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '118', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '119', 'type': 'list', 'children': ['120'], 'value': '[date(dat[0], dat[1], dat[2])]'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '122', 'type': 'argument_list', 'children': ['123', '126', '129']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '125', 'type': 'integer', 'children': [], 'value': '0'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'dat'},{'id': '131', 'type': 'integer', 'children': [], 'value': '2'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '135', 'type': 'conditional_expression', 'children': ['136', '146', '151'], 'value': 'if'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': "' '"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '143', 'type': 'slice', 'children': ['144', '145']},{'id': '144', 'type': 'integer', 'children': [], 'value': '5'},{'id': '145', 'type': 'colon', 'children': []},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '=='},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '149', 'type': 'integer', 'children': [], 'value': '4'},{'id': '150', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '153', 'type': 'integer', 'children': [], 'value': '6'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '157', 'type': 'call', 'children': ['158', '171']},{'id': '158', 'type': 'attribute', 'children': ['159', '170']},{'id': '159', 'type': 'call', 'children': ['160', '167']},{'id': '160', 'type': 'attribute', 'children': ['161', '166']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169']},{'id': '168', 'type': 'string', 'children': [], 'value': "'%_'"},{'id': '169', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'string', 'children': [], 'value': '\'["["]\''},{'id': '173', 'type': 'string', 'children': [], 'value': "'['"},{'id': '174', 'type': 'if_statement', 'children': ['175', '178', '195']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'in'},{'id': '176', 'type': 'string', 'children': [], 'value': "' at '"},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '188']},{'id': '181', 'type': 'tuple_pattern', 'children': ['182', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '184', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '187', 'type': 'string', 'children': [], 'value': "'location'"},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194']},{'id': '193', 'type': 'string', 'children': [], 'value': "' at '"},{'id': '194', 'type': 'integer', 'children': [], 'value': '1'},{'id': '195', 'type': 'else_clause', 'children': ['196']},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '202']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '201', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '203', 'type': 'if_statement', 'children': ['204', '207']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'in'},{'id': '205', 'type': 'string', 'children': [], 'value': '\'%"\''},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '213']},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '212', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '216', 'type': 'identifier', 'children': [], 'value': '_gen_description'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '222', 'type': 'call', 'children': ['223', '228']},{'id': '223', 'type': 'attribute', 'children': ['224', '227']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '226', 'type': 'integer', 'children': [], 'value': '2'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'string', 'children': [], 'value': "','"},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '233', 'type': 'list', 'children': ['234', '235', '236'], 'value': "['PUBLIC', 'PRIVATE', 'CONFIDENTIAL']"},{'id': '234', 'type': 'string', 'children': [], 'value': "'PUBLIC'"},{'id': '235', 'type': 'string', 'children': [], 'value': "'PRIVATE'"},{'id': '236', 'type': 'string', 'children': [], 'value': "'CONFIDENTIAL'"},{'id': '237', 'type': 'for_statement', 'children': ['238', '239', '245']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '239', 'type': 'subscript', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '241', 'type': 'slice', 'children': ['242', '243']},{'id': '242', 'type': 'colon', 'children': []},{'id': '243', 'type': 'unary_operator', 'children': ['244'], 'value': '-'},{'id': '244', 'type': 'integer', 'children': [], 'value': '1'},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'if_statement', 'children': ['247', '250']},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '249'], 'value': 'in'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '256']},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '255', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '262']},{'id': '259', 'type': 'subscript', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '261', 'type': 'string', 'children': [], 'value': "'categories'"},{'id': '262', 'type': 'list_comprehension', 'children': ['263', '264', '272']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '264', 'type': 'for_in_clause', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '268', 'type': 'slice', 'children': ['269', '270']},{'id': '269', 'type': 'colon', 'children': []},{'id': '270', 'type': 'unary_operator', 'children': ['271'], 'value': '-'},{'id': '271', 'type': 'integer', 'children': [], 'value': '1'},{'id': '272', 'type': 'if_clause', 'children': ['273']},{'id': '273', 'type': 'comparison_operator', 'children': ['274', '275'], 'value': 'not'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '281']},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '280', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '281', 'type': 'binary_operator', 'children': ['282', '283'], 'value': '%'},{'id': '282', 'type': 'string', 'children': [], 'value': "'%s@%s'"},{'id': '283', 'type': 'tuple', 'children': ['284', '292']},{'id': '284', 'type': 'subscript', 'children': ['285', '289']},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '287', 'type': 'unary_operator', 'children': ['288'], 'value': '-'},{'id': '288', 'type': 'integer', 'children': [], 'value': '1'},{'id': '289', 'type': 'slice', 'children': ['290', '291']},{'id': '290', 'type': 'integer', 'children': [], 'value': '7'},{'id': '291', 'type': 'colon', 'children': []},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'getfqdn'},{'id': '294', 'type': 'argument_list', 'children': []},{'id': '295', 'type': 'return_statement', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'event'}
def _parse_remind_line(self, line, text): event = {} line = line.split(None, 6) dat = [int(f) for f in line[0].split('/')] if line[4] != '*': start = divmod(int(line[4]), 60) event['dtstart'] = [datetime(dat[0], dat[1], dat[2], start[0], start[1], tzinfo=self._localtz)] if line[3] != '*': event['duration'] = timedelta(minutes=int(line[3])) else: event['dtstart'] = [date(dat[0], dat[1], dat[2])] msg = ' '.join(line[5:]) if line[4] == '*' else line[6] msg = msg.strip().replace('%_', '\n').replace('["["]', '[') if ' at ' in msg: (event['msg'], event['location']) = msg.rsplit(' at ', 1) else: event['msg'] = msg if '%"' in text: event['description'] = Remind._gen_description(text) tags = line[2].split(',') classes = ['PUBLIC', 'PRIVATE', 'CONFIDENTIAL'] for tag in tags[:-1]: if tag in classes: event['class'] = tag event['categories'] = [tag for tag in tags[:-1] if tag not in classes] event['uid'] = '%s@%s' % (tags[-1][7:], getfqdn()) return event
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_gen_vevent'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '7', 'type': 'block', 'children': ['8', '23', '41', '54', '67', '85', '112', '130', '148', '281']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '18']},{'id': '10', 'type': 'attribute', 'children': ['11', '17']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '21', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '33']},{'id': '25', 'type': 'attribute', 'children': ['26', '32']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'dtstamp'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'fromtimestamp'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_mtime'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '51']},{'id': '43', 'type': 'attribute', 'children': ['44', '50']},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'summary'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '53', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '64']},{'id': '56', 'type': 'attribute', 'children': ['57', '63']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '66', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'},{'id': '69', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '82']},{'id': '74', 'type': 'attribute', 'children': ['75', '81']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '84', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '85', 'type': 'if_statement', 'children': ['86', '98']},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '90'], 'value': 'and'},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'},{'id': '88', 'type': 'string', 'children': [], 'value': "'categories'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '97'], 'value': '>'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '96', 'type': 'string', 'children': [], 'value': "'categories'"},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '109']},{'id': '101', 'type': 'attribute', 'children': ['102', '108']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': "'categories'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '111', 'type': 'string', 'children': [], 'value': "'categories'"},{'id': '112', 'type': 'if_statement', 'children': ['113', '116']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'in'},{'id': '114', 'type': 'string', 'children': [], 'value': "'location'"},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '127']},{'id': '119', 'type': 'attribute', 'children': ['120', '126']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': "'location'"},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '129', 'type': 'string', 'children': [], 'value': "'location'"},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'in'},{'id': '132', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '145']},{'id': '137', 'type': 'attribute', 'children': ['138', '144']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '147', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '148', 'type': 'if_statement', 'children': ['149', '158', '249']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '151', 'type': 'argument_list', 'children': ['152', '157']},{'id': '152', 'type': 'subscript', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '155', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '156', 'type': 'integer', 'children': [], 'value': '0'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '158', 'type': 'block', 'children': ['159', '214']},{'id': '159', 'type': 'if_statement', 'children': ['160', '167']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '164'], 'value': '!='},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': '_alarm'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'block', 'children': ['168', '177', '190', '201']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'valarm'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': "'valarm'"},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '187']},{'id': '179', 'type': 'attribute', 'children': ['180', '186']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'valarm'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'string', 'children': [], 'value': "'trigger'"},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': '_alarm'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '200']},{'id': '192', 'type': 'attribute', 'children': ['193', '199']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'valarm'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '200', 'type': 'string', 'children': [], 'value': "'DISPLAY'"},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '211']},{'id': '203', 'type': 'attribute', 'children': ['204', '210']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'valarm'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '213', 'type': 'string', 'children': [], 'value': "'msg'"},{'id': '214', 'type': 'if_statement', 'children': ['215', '218', '232']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': 'in'},{'id': '216', 'type': 'string', 'children': [], 'value': "'duration'"},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '229']},{'id': '221', 'type': 'attribute', 'children': ['222', '228']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'string', 'children': [], 'value': "'duration'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '231', 'type': 'string', 'children': [], 'value': "'duration'"},{'id': '232', 'type': 'else_clause', 'children': ['233']},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '244']},{'id': '236', 'type': 'attribute', 'children': ['237', '243']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'string', 'children': [], 'value': "'dtend'"},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '244', 'type': 'subscript', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '247', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '248', 'type': 'integer', 'children': [], 'value': '0'},{'id': '249', 'type': 'elif_clause', 'children': ['250', '258']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '257'], 'value': '=='},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '256', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '257', 'type': 'integer', 'children': [], 'value': '1'},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '269']},{'id': '261', 'type': 'attribute', 'children': ['262', '268']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'string', 'children': [], 'value': "'dtend'"},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '269', 'type': 'binary_operator', 'children': ['270', '275'], 'value': '+'},{'id': '270', 'type': 'subscript', 'children': ['271', '274']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '273', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '274', 'type': 'integer', 'children': [], 'value': '0'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '280', 'type': 'integer', 'children': [], 'value': '1'},{'id': '281', 'type': 'if_statement', 'children': ['282', '290']},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '289'], 'value': '>'},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '288', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '289', 'type': 'integer', 'children': [], 'value': '1'},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '295', 'type': 'identifier', 'children': [], 'value': '_gen_dtend_rrule'},{'id': '296', 'type': 'argument_list', 'children': ['297', '300']},{'id': '297', 'type': 'subscript', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '299', 'type': 'string', 'children': [], 'value': "'dtstart'"},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'vevent'}
def _gen_vevent(self, event, vevent): vevent.add('dtstart').value = event['dtstart'][0] vevent.add('dtstamp').value = datetime.fromtimestamp(self._mtime) vevent.add('summary').value = event['msg'] vevent.add('uid').value = event['uid'] if 'class' in event: vevent.add('class').value = event['class'] if 'categories' in event and len(event['categories']) > 0: vevent.add('categories').value = event['categories'] if 'location' in event: vevent.add('location').value = event['location'] if 'description' in event: vevent.add('description').value = event['description'] if isinstance(event['dtstart'][0], datetime): if self._alarm != timedelta(): valarm = vevent.add('valarm') valarm.add('trigger').value = self._alarm valarm.add('action').value = 'DISPLAY' valarm.add('description').value = event['msg'] if 'duration' in event: vevent.add('duration').value = event['duration'] else: vevent.add('dtend').value = event['dtstart'][0] elif len(event['dtstart']) == 1: vevent.add('dtend').value = event['dtstart'][0] + timedelta(days=1) if len(event['dtstart']) > 1: Remind._gen_dtend_rrule(event['dtstart'], vevent)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_remind'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '20', 'type': 'string', 'children': [], 'value': '" "'},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'postdate'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'default_parameter', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'posttime'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'block', 'children': ['28', '33', '37', '55', '63', '85', '89', '104', '126', '159', '169', '181', '195', '204', '257', '320', '357', '383', '404', '437', '452']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '31', 'type': 'list', 'children': ['32'], 'value': "['REM']"},{'id': '32', 'type': 'string', 'children': [], 'value': "'REM'"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'trigdates'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'if_statement', 'children': ['38', '43']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '42', 'type': 'string', 'children': [], 'value': "'rrule'"},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'trigdates'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_parse_rruleset'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'rruleset'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '63', 'type': 'if_statement', 'children': ['64', '73']},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '70'], 'value': 'and'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'astimezone'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_localtz'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '88', 'type': 'None', 'children': []},{'id': '89', 'type': 'if_statement', 'children': ['90', '95']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '94', 'type': 'string', 'children': [], 'value': "'dtend'"},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '104', 'type': 'if_statement', 'children': ['105', '114']},{'id': '105', 'type': 'boolean_operator', 'children': ['106', '111'], 'value': 'and'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'astimezone'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': '_localtz'},{'id': '126', 'type': 'if_statement', 'children': ['127', '140']},{'id': '127', 'type': 'boolean_operator', 'children': ['128', '134'], 'value': 'and'},{'id': '128', 'type': 'not_operator', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '133', 'type': 'string', 'children': [], 'value': "'rdate'"},{'id': '134', 'type': 'not_operator', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '137', 'type': 'argument_list', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'trigdates'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '156']},{'id': '148', 'type': 'attribute', 'children': ['149', '155']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'string', 'children': [], 'value': "'%b %d %Y'"},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': "' 0'"},{'id': '158', 'type': 'string', 'children': [], 'value': "' '"},{'id': '159', 'type': 'if_statement', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'postdate'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'postdate'},{'id': '169', 'type': 'if_statement', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '%'},{'id': '179', 'type': 'string', 'children': [], 'value': "'PRIORITY %s'"},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '181', 'type': 'if_statement', 'children': ['182', '187']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'trigdates'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'trigdates'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '201', 'type': 'identifier', 'children': [], 'value': '_event_duration'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '204', 'type': 'if_statement', 'children': ['205', '217']},{'id': '205', 'type': 'boolean_operator', 'children': ['206', '212'], 'value': 'and'},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '211'], 'value': 'is'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '212', 'type': 'comparison_operator', 'children': ['213', '216'], 'value': '>'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '216', 'type': 'integer', 'children': [], 'value': '1'},{'id': '217', 'type': 'block', 'children': ['218', '225']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'string', 'children': [], 'value': "'*1'"},{'id': '225', 'type': 'if_statement', 'children': ['226', '229']},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': 'is'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '228', 'type': 'None', 'children': []},{'id': '229', 'type': 'block', 'children': ['230', '239']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'augmented_assignment', 'children': ['232', '233'], 'value': '-='},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'days'},{'id': '238', 'type': 'integer', 'children': [], 'value': '1'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '254']},{'id': '246', 'type': 'attribute', 'children': ['247', '253']},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'dtend'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'string', 'children': [], 'value': "'UNTIL %b %d %Y'"},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256']},{'id': '255', 'type': 'string', 'children': [], 'value': "' 0'"},{'id': '256', 'type': 'string', 'children': [], 'value': "' '"},{'id': '257', 'type': 'if_statement', 'children': ['258', '263']},{'id': '258', 'type': 'call', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '260', 'type': 'argument_list', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '263', 'type': 'block', 'children': ['264', '282', '292']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '279']},{'id': '271', 'type': 'attribute', 'children': ['272', '278']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'dtstart'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'string', 'children': [], 'value': "'AT %H:%M'"},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '279', 'type': 'argument_list', 'children': ['280', '281']},{'id': '280', 'type': 'string', 'children': [], 'value': "' 0'"},{'id': '281', 'type': 'string', 'children': [], 'value': "' '"},{'id': '282', 'type': 'if_statement', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'posttime'},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'posttime'},{'id': '292', 'type': 'if_statement', 'children': ['293', '300']},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '299'], 'value': '>'},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '298', 'type': 'argument_list', 'children': []},{'id': '299', 'type': 'integer', 'children': [], 'value': '0'},{'id': '300', 'type': 'block', 'children': ['301']},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'binary_operator', 'children': ['308', '309'], 'value': '%'},{'id': '308', 'type': 'string', 'children': [], 'value': "'DURATION %d:%02d'"},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'divmod'},{'id': '311', 'type': 'argument_list', 'children': ['312', '319']},{'id': '312', 'type': 'binary_operator', 'children': ['313', '318'], 'value': '/'},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '317', 'type': 'argument_list', 'children': []},{'id': '318', 'type': 'integer', 'children': [], 'value': '60'},{'id': '319', 'type': 'integer', 'children': [], 'value': '60'},{'id': '320', 'type': 'if_statement', 'children': ['321', '326', '343']},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '325', 'type': 'string', 'children': [], 'value': "'rdate'"},{'id': '326', 'type': 'block', 'children': ['327']},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'call', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '332', 'type': 'argument_list', 'children': ['333']},{'id': '333', 'type': 'call', 'children': ['334', '337']},{'id': '334', 'type': 'attribute', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '336', 'type': 'identifier', 'children': [], 'value': '_parse_rdate'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'attribute', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'rdate'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '343', 'type': 'elif_clause', 'children': ['344', '349']},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '346', 'type': 'argument_list', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'trigdates'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '349', 'type': 'block', 'children': ['350']},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'trigdates'},{'id': '357', 'type': 'if_statement', 'children': ['358', '363']},{'id': '358', 'type': 'call', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '360', 'type': 'argument_list', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '362', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '363', 'type': 'block', 'children': ['364']},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'binary_operator', 'children': ['371', '372'], 'value': '%'},{'id': '371', 'type': 'string', 'children': [], 'value': "'TAG %s'"},{'id': '372', 'type': 'call', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '375', 'type': 'identifier', 'children': [], 'value': '_abbr_tag'},{'id': '376', 'type': 'argument_list', 'children': ['377']},{'id': '377', 'type': 'call', 'children': ['378', '381']},{'id': '378', 'type': 'attribute', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'getChildValue'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '383', 'type': 'if_statement', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '385', 'type': 'block', 'children': ['386']},{'id': '386', 'type': 'expression_statement', 'children': ['387']},{'id': '387', 'type': 'call', 'children': ['388', '391']},{'id': '388', 'type': 'attribute', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '391', 'type': 'argument_list', 'children': ['392']},{'id': '392', 'type': 'list_comprehension', 'children': ['393', '401']},{'id': '393', 'type': 'binary_operator', 'children': ['394', '395'], 'value': '%'},{'id': '394', 'type': 'string', 'children': [], 'value': "'TAG %s'"},{'id': '395', 'type': 'call', 'children': ['396', '399']},{'id': '396', 'type': 'attribute', 'children': ['397', '398']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '398', 'type': 'identifier', 'children': [], 'value': '_abbr_tag'},{'id': '399', 'type': 'argument_list', 'children': ['400']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '401', 'type': 'for_in_clause', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '404', 'type': 'if_statement', 'children': ['405', '410']},{'id': '405', 'type': 'call', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '407', 'type': 'argument_list', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '409', 'type': 'string', 'children': [], 'value': "'categories_list'"},{'id': '410', 'type': 'block', 'children': ['411']},{'id': '411', 'type': 'for_statement', 'children': ['412', '413', '416']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '413', 'type': 'attribute', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'categories_list'},{'id': '416', 'type': 'block', 'children': ['417']},{'id': '417', 'type': 'for_statement', 'children': ['418', '419', '422']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '422', 'type': 'block', 'children': ['423']},{'id': '423', 'type': 'expression_statement', 'children': ['424']},{'id': '424', 'type': 'call', 'children': ['425', '428']},{'id': '425', 'type': 'attribute', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '428', 'type': 'argument_list', 'children': ['429']},{'id': '429', 'type': 'binary_operator', 'children': ['430', '431'], 'value': '%'},{'id': '430', 'type': 'string', 'children': [], 'value': "'TAG %s'"},{'id': '431', 'type': 'call', 'children': ['432', '435']},{'id': '432', 'type': 'attribute', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '434', 'type': 'identifier', 'children': [], 'value': '_abbr_tag'},{'id': '435', 'type': 'argument_list', 'children': ['436']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '437', 'type': 'expression_statement', 'children': ['438']},{'id': '438', 'type': 'call', 'children': ['439', '442']},{'id': '439', 'type': 'attribute', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '442', 'type': 'argument_list', 'children': ['443']},{'id': '443', 'type': 'call', 'children': ['444', '447']},{'id': '444', 'type': 'attribute', 'children': ['445', '446']},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'Remind'},{'id': '446', 'type': 'identifier', 'children': [], 'value': '_gen_msg'},{'id': '447', 'type': 'argument_list', 'children': ['448', '449', '450', '451']},{'id': '448', 'type': 'identifier', 'children': [], 'value': 'vevent'},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '450', 'type': 'identifier', 'children': [], 'value': 'tail'},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '452', 'type': 'return_statement', 'children': ['453']},{'id': '453', 'type': 'binary_operator', 'children': ['454', '460'], 'value': '+'},{'id': '454', 'type': 'call', 'children': ['455', '458']},{'id': '455', 'type': 'attribute', 'children': ['456', '457']},{'id': '456', 'type': 'string', 'children': [], 'value': "' '"},{'id': '457', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '458', 'type': 'argument_list', 'children': ['459']},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'remind'},{'id': '460', 'type': 'string', 'children': [], 'value': "'\\n'"}
def to_remind(self, vevent, label=None, priority=None, tags=None, tail=None, sep=" ", postdate=None, posttime=None): remind = ['REM'] trigdates = None if hasattr(vevent, 'rrule'): trigdates = Remind._parse_rruleset(vevent.rruleset) dtstart = vevent.dtstart.value if isinstance(dtstart, datetime) and dtstart.tzinfo: dtstart = dtstart.astimezone(self._localtz) dtend = None if hasattr(vevent, 'dtend'): dtend = vevent.dtend.value if isinstance(dtend, datetime) and dtend.tzinfo: dtend = dtend.astimezone(self._localtz) if not hasattr(vevent, 'rdate') and not isinstance(trigdates, str): remind.append(dtstart.strftime('%b %d %Y').replace(' 0', ' ')) if postdate: remind.append(postdate) if priority: remind.append('PRIORITY %s' % priority) if isinstance(trigdates, list): remind.extend(trigdates) duration = Remind._event_duration(vevent) if type(dtstart) is date and duration.days > 1: remind.append('*1') if dtend is not None: dtend -= timedelta(days=1) remind.append(dtend.strftime('UNTIL %b %d %Y').replace(' 0', ' ')) if isinstance(dtstart, datetime): remind.append(dtstart.strftime('AT %H:%M').replace(' 0', ' ')) if posttime: remind.append(posttime) if duration.total_seconds() > 0: remind.append('DURATION %d:%02d' % divmod(duration.total_seconds() / 60, 60)) if hasattr(vevent, 'rdate'): remind.append(Remind._parse_rdate(vevent.rdate.value)) elif isinstance(trigdates, str): remind.append(trigdates) if hasattr(vevent, 'class'): remind.append('TAG %s' % Remind._abbr_tag(vevent.getChildValue('class'))) if tags: remind.extend(['TAG %s' % Remind._abbr_tag(tag) for tag in tags]) if hasattr(vevent, 'categories_list'): for categories in vevent.categories_list: for category in categories.value: remind.append('TAG %s' % Remind._abbr_tag(category)) remind.append(Remind._gen_msg(vevent, label, tail, sep)) return ' '.join(remind) + '\n'
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'module_name_from_path'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '20', '31', '42', '48', '55', '59', '69', '170', '180', '186', '195']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '12', 'type': 'subscript', 'children': ['13', '19']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'.pyc'"},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '23', 'type': 'subscript', 'children': ['24', '30']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "'.py'"},{'id': '30', 'type': 'integer', 'children': [], 'value': '0'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '34', 'type': 'call', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'normpath'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '+'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '47', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_python_package'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '58', 'type': 'list', 'children': [], 'value': '[]'},{'id': '59', 'type': 'if_statement', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'tuple', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "'folder_name'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'folder_name'},{'id': '69', 'type': 'while_statement', 'children': ['70', '71']},{'id': '70', 'type': 'True', 'children': []},{'id': '71', 'type': 'block', 'children': ['72', '83', '97', '121', '142', '160']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'call', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '95']},{'id': '90', 'type': 'attribute', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '97', 'type': 'if_statement', 'children': ['98', '108']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '107'], 'value': '=='},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'package'},{'id': '108', 'type': 'block', 'children': ['109', '120']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '112', 'type': 'call', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '120', 'type': 'break_statement', 'children': []},{'id': '121', 'type': 'if_statement', 'children': ['122', '132']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '131'], 'value': '=='},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '132', 'type': 'block', 'children': ['133', '141']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '138']},{'id': '135', 'type': 'pattern_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '138', 'type': 'expression_list', 'children': ['139', '140']},{'id': '139', 'type': 'None', 'children': []},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'break_statement', 'children': []},{'id': '142', 'type': 'if_statement', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'tuple', 'children': ['150', '151', '152']},{'id': '150', 'type': 'string', 'children': [], 'value': "'path'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '152', 'type': 'call', 'children': ['153', '158']},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '160', 'type': 'if_statement', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'tuple', 'children': ['168', '169']},{'id': '168', 'type': 'string', 'children': [], 'value': "'module'"},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '170', 'type': 'if_statement', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'tuple', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "'module'"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'expression_list', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'path'}
def module_name_from_path(folder_name, verbose=False): folder_name = folder_name.split('.pyc')[0] folder_name = folder_name.split('.py')[0] folder_name = os.path.normpath(folder_name) path = folder_name + '/' package = get_python_package(path) module = [] if verbose: print(('folder_name', folder_name)) while True: path = os.path.dirname(path) module.append(os.path.basename(path)) if os.path.basename(path) == package: path = os.path.dirname(path) break if os.path.dirname(path) == path: path, module = None, None break if verbose: print(('path', path, os.path.dirname(path))) if verbose: print(('module', module)) if verbose: print(('module', module)) module.reverse() module = '.'.join(module) return module, path
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'main'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '13', '30', '47', '61', '75', '89', '97', '103', '109', '113', '122', '126', '135', '139', '148', '152', '161', '181', '185', '211', '223', '354']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'argparse'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20', '21', '24', '27']},{'id': '19', 'type': 'string', 'children': [], 'value': '"-f"'},{'id': '20', 'type': 'string', 'children': [], 'value': '"--file"'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '23', 'type': 'True', 'children': []},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '26', 'type': 'string', 'children': [], 'value': '"input file"'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38', '41', '44']},{'id': '36', 'type': 'string', 'children': [], 'value': '"-l"'},{'id': '37', 'type': 'string', 'children': [], 'value': '"--locus"'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '40', 'type': 'True', 'children': []},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '43', 'type': 'string', 'children': [], 'value': '"Locus"'},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '58']},{'id': '53', 'type': 'string', 'children': [], 'value': '"-k"'},{'id': '54', 'type': 'string', 'children': [], 'value': '"--kir"'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '57', 'type': 'string', 'children': [], 'value': '"Option for running with KIR"'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '60', 'type': 'string', 'children': [], 'value': "'store_true'"},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68', '69', '72']},{'id': '67', 'type': 'string', 'children': [], 'value': '"-s"'},{'id': '68', 'type': 'string', 'children': [], 'value': '"--server"'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '71', 'type': 'string', 'children': [], 'value': '"Option for running with a server"'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '74', 'type': 'string', 'children': [], 'value': "'store_true'"},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83', '86']},{'id': '81', 'type': 'string', 'children': [], 'value': '"-v"'},{'id': '82', 'type': 'string', 'children': [], 'value': '"--verbose"'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '85', 'type': 'string', 'children': [], 'value': '"Option for running in verbose"'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '88', 'type': 'string', 'children': [], 'value': "'store_true'"},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'fastafile'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '112', 'type': 'False', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '121', 'type': 'True', 'children': []},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '125', 'type': 'False', 'children': []},{'id': '126', 'type': 'if_statement', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '134', 'type': 'True', 'children': []},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'kir'},{'id': '138', 'type': 'False', 'children': []},{'id': '139', 'type': 'if_statement', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'kir'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'kir'},{'id': '147', 'type': 'True', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'serv'},{'id': '151', 'type': 'False', 'children': []},{'id': '152', 'type': 'if_statement', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'serv'},{'id': '160', 'type': 'True', 'children': []},{'id': '161', 'type': 'if_statement', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'basicConfig'},{'id': '169', 'type': 'argument_list', 'children': ['170', '173', '176']},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '172', 'type': 'string', 'children': [], 'value': "'%(asctime)s - %(name)-35s - %(levelname)-5s - %(message)s'"},{'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'datefmt'},{'id': '175', 'type': 'string', 'children': [], 'value': "'%m/%d/%Y %I:%M:%S %p'"},{'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'INFO'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '184', 'type': 'None', 'children': []},{'id': '185', 'type': 'if_statement', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'serv'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'BioSeqDatabase'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'open_database'},{'id': '195', 'type': 'argument_list', 'children': ['196', '199', '202', '205', '208']},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'driver'},{'id': '198', 'type': 'string', 'children': [], 'value': '"pymysql"'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '201', 'type': 'string', 'children': [], 'value': '"root"'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'passwd'},{'id': '204', 'type': 'string', 'children': [], 'value': '""'},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '207', 'type': 'string', 'children': [], 'value': '"localhost"'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '210', 'type': 'string', 'children': [], 'value': '"bioseqdb"'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'seqann'},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'BioSeqAnn'},{'id': '216', 'type': 'argument_list', 'children': ['217', '220']},{'id': '217', 'type': 'keyword_argument', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '219', 'type': 'True', 'children': []},{'id': '220', 'type': 'keyword_argument', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'kir'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'kir'},{'id': '223', 'type': 'for_statement', 'children': ['224', '225', '232']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'fastafile'},{'id': '231', 'type': 'string', 'children': [], 'value': '"fasta"'},{'id': '232', 'type': 'block', 'children': ['233', '245', '262', '266', '349']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'seqann'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'annotate'},{'id': '240', 'type': 'argument_list', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '242', 'type': 'keyword_argument', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'locus'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'string', 'children': [], 'value': "'{:*^20} {:^20} {:*^20}'"},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255', '261']},{'id': '254', 'type': 'string', 'children': [], 'value': '""'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '261', 'type': 'string', 'children': [], 'value': '""'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '265', 'type': 'integer', 'children': [], 'value': '0'},{'id': '266', 'type': 'for_statement', 'children': ['267', '268', '271']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'if_statement', 'children': ['273', '282', '313']},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '275', 'type': 'argument_list', 'children': ['276', '281']},{'id': '276', 'type': 'subscript', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'DBSeq'},{'id': '282', 'type': 'block', 'children': ['283', '302']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '286', 'type': 'argument_list', 'children': ['287', '288', '291', '299']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'subscript', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '301', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'augmented_assignment', 'children': ['304', '305'], 'value': '+='},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'subscript', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '313', 'type': 'else_clause', 'children': ['314']},{'id': '314', 'type': 'block', 'children': ['315', '336']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'call', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '318', 'type': 'argument_list', 'children': ['319', '320', '323', '333']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '323', 'type': 'call', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'attribute', 'children': ['327', '332']},{'id': '327', 'type': 'subscript', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '333', 'type': 'keyword_argument', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '335', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'augmented_assignment', 'children': ['338', '339'], 'value': '+='},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'attribute', 'children': ['343', '348']},{'id': '343', 'type': 'subscript', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'ann'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'annotation'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '352', 'type': 'argument_list', 'children': ['353']},{'id': '353', 'type': 'string', 'children': [], 'value': '""'},{'id': '354', 'type': 'if_statement', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'serv'},{'id': '356', 'type': 'block', 'children': ['357']},{'id': '357', 'type': 'expression_statement', 'children': ['358']},{'id': '358', 'type': 'call', 'children': ['359', '362']},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'server'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '362', 'type': 'argument_list', 'children': []}
def main(): parser = argparse.ArgumentParser() parser.add_argument("-f", "--file", required=True, help="input file", type=str) parser.add_argument("-l", "--locus", required=True, help="Locus", type=str) parser.add_argument("-k", "--kir", help="Option for running with KIR", action='store_true') parser.add_argument("-s", "--server", help="Option for running with a server", action='store_true') parser.add_argument("-v", "--verbose", help="Option for running in verbose", action='store_true') args = parser.parse_args() fastafile = args.file locus = args.locus verbose = False if args.verbose: verbose = True verbose = False if args.verbose: verbose = True kir = False if args.kir: kir = True serv = False if args.server: serv = True if verbose: logging.basicConfig(format='%(asctime)s - %(name)-35s - %(levelname)-5s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) server = None if serv: server = BioSeqDatabase.open_database(driver="pymysql", user="root", passwd="", host="localhost", db="bioseqdb") seqann = BioSeqAnn(verbose=True, kir=kir) for seq in SeqIO.parse(fastafile, "fasta"): ann = seqann.annotate(seq, locus=locus) print('{:*^20} {:^20} {:*^20}'.format("", str(seq.description), "")) l = 0 for f in ann.annotation: if isinstance(ann.annotation[f], DBSeq): print(f, ann.method, str(ann.annotation[f]), sep="\t") l += len(ann.annotation[f]) else: print(f, ann.method, str(ann.annotation[f].seq), sep="\t") l += len(ann.annotation[f].seq) print("") if serv: server.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_push_subtree'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'generic_type', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '10', 'type': 'type_parameter', 'children': ['11']},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '13', 'type': 'block', 'children': ['14', '21', '36', '49', '67', '82', '87', '105', '115', '130']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '21', 'type': 'if_statement', 'children': ['22', '28']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '27'], 'value': '!='},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'count_bits_set'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'raise_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'},{'id': '34', 'type': 'string', 'children': [], 'value': '"invalid subtree with size != 2^k: %s"'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '41']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'subtree_h'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'mintree_h'},{'id': '41', 'type': 'expression_list', 'children': ['42', '46']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'lowest_bit_set'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '__mintree_height'},{'id': '49', 'type': 'if_statement', 'children': ['50', '57']},{'id': '50', 'type': 'boolean_operator', 'children': ['51', '54'], 'value': 'and'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '>'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'mintree_h'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': '>'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'subtree_h'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'mintree_h'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '%'},{'id': '63', 'type': 'string', 'children': [], 'value': '"subtree %s > current smallest subtree %s"'},{'id': '64', 'type': 'tuple', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'subtree_h'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'mintree_h'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '72']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'root_hash'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'hashes'},{'id': '72', 'type': 'call', 'children': ['73', '78']},{'id': '73', 'type': 'attribute', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '__hasher'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '_hash_full'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80', '81']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '82', 'type': 'assert_statement', 'children': ['83']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '=='},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'hashes'},{'id': '85', 'type': 'tuple', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'root_hash'},{'id': '87', 'type': 'if_statement', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'hashStore'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'hashes'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'hashStore'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'writeLeaf'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'new_node_hashes'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': '__push_subtree_hash'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'subtree_h'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'root_hash'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '118', 'type': 'list_comprehension', 'children': ['119', '125']},{'id': '119', 'type': 'tuple', 'children': ['120', '123', '124']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'tree_size'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '125', 'type': 'for_in_clause', 'children': ['126', '129']},{'id': '126', 'type': 'pattern_list', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'new_node_hashes'},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'hashStore'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'for_statement', 'children': ['136', '137', '138']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'hashStore'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'writeNode'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'node'}
def _push_subtree(self, leaves: List[bytes]): size = len(leaves) if count_bits_set(size) != 1: raise ValueError("invalid subtree with size != 2^k: %s" % size) subtree_h, mintree_h = lowest_bit_set(size), self.__mintree_height if mintree_h > 0 and subtree_h > mintree_h: raise ValueError("subtree %s > current smallest subtree %s" % ( subtree_h, mintree_h)) root_hash, hashes = self.__hasher._hash_full(leaves, 0, size) assert hashes == (root_hash,) if self.hashStore: for h in hashes: self.hashStore.writeLeaf(h) new_node_hashes = self.__push_subtree_hash(subtree_h, root_hash) nodes = [(self.tree_size, height, h) for h, height in new_node_hashes] if self.hashStore: for node in nodes: self.hashStore.writeNode(node)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'blocks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '7', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '17', '108', '121', '140', '150', '171', '175', '205']},{'id': '12', 'type': 'assert_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '17', 'type': 'if_statement', 'children': ['18', '21', '45']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'function_definition', 'children': ['23', '24', '26']},{'id': '23', 'type': 'function_name', 'children': [], 'value': 'pct_nongaps'},{'id': '24', 'type': 'parameters', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': ['28']},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '-'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': '()', 'children': ['31']},{'id': '31', 'type': 'binary_operator', 'children': ['32', '41'], 'value': '/'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '45', 'type': 'else_clause', 'children': ['46']},{'id': '46', 'type': 'block', 'children': ['47', '62']},{'id': '47', 'type': 'if_statement', 'children': ['48', '53']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'in'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '50', 'type': 'tuple', 'children': ['51', '52']},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'True', 'children': []},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sequence_weights'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '61', 'type': 'string', 'children': [], 'value': "'avg1'"},{'id': '62', 'type': 'function_definition', 'children': ['63', '64', '66']},{'id': '63', 'type': 'function_name', 'children': [], 'value': 'pct_nongaps'},{'id': '64', 'type': 'parameters', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '66', 'type': 'block', 'children': ['67', '77', '98']},{'id': '67', 'type': 'assert_statement', 'children': ['68']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '73'], 'value': '=='},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ngaps'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '82', 'type': 'generator_expression', 'children': ['83', '89']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '*'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '=='},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '88', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '93']},{'id': '90', 'type': 'pattern_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '-'},{'id': '100', 'type': 'integer', 'children': [], 'value': '1'},{'id': '101', 'type': '()', 'children': ['102']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '/'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'ngaps'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'seqstrs'},{'id': '111', 'type': 'list_comprehension', 'children': ['112', '118']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '118', 'type': 'for_in_clause', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'clean_cols'},{'id': '124', 'type': 'list_comprehension', 'children': ['125', '126', '133']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '126', 'type': 'for_in_clause', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'list_splat', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'seqstrs'},{'id': '133', 'type': 'if_clause', 'children': ['134']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '139'], 'value': '>='},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pct_nongaps'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'alphabet'},{'id': '143', 'type': 'attribute', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'alphabet'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'clean_seqs'},{'id': '153', 'type': 'list_comprehension', 'children': ['154', '164']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'Seq'},{'id': '156', 'type': 'argument_list', 'children': ['157', '163']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "''"},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'alphabet'},{'id': '164', 'type': 'for_in_clause', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'list_splat', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'clean_cols'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'clean_recs'},{'id': '174', 'type': 'list', 'children': [], 'value': '[]'},{'id': '175', 'type': 'for_statement', 'children': ['176', '179', '184']},{'id': '176', 'type': 'pattern_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'clean_seqs'},{'id': '184', 'type': 'block', 'children': ['185', '192', '198']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'newrec'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'newrec'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'clean_recs'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'newrec'},{'id': '205', 'type': 'return_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'MultipleSeqAlignment'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'clean_recs'},{'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'alphabet'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'alphabet'}
def blocks(aln, threshold=0.5, weights=None): assert len(aln) if weights == False: def pct_nongaps(col): return 1 - (float(col.count('-')) / len(col)) else: if weights in (None, True): weights = sequence_weights(aln, 'avg1') def pct_nongaps(col): assert len(col) == len(weights) ngaps = sum(wt * (c == '-') for wt, c in zip(weights, col)) return 1 - (ngaps / len(col)) seqstrs = [str(rec.seq) for rec in aln] clean_cols = [col for col in zip(*seqstrs) if pct_nongaps(col) >= threshold] alphabet = aln[0].seq.alphabet clean_seqs = [Seq(''.join(row), alphabet) for row in zip(*clean_cols)] clean_recs = [] for rec, seq in zip(aln, clean_seqs): newrec = deepcopy(rec) newrec.seq = seq clean_recs.append(newrec) return MultipleSeqAlignment(clean_recs, alphabet=alphabet)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sequence_weights'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'scaling'},{'id': '7', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'gap_chars'},{'id': '10', 'type': 'string', 'children': [], 'value': "'-.'"},{'id': '11', 'type': 'block', 'children': ['12', '117', '212', '222', '226', '279', '301', '384']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'expectk'},{'id': '15', 'type': 'list', 'children': ['16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '115', '116'], 'value': '[0.0, 1.0, 1.953, 2.861, 3.705, 4.524, 5.304, 6.026, 6.724, 7.397,\n 8.04, 8.622, 9.191, 9.739, 10.264, 10.758, 11.194, 11.635,\n 12.049, 12.468, 12.806, 13.185, 13.539, 13.863, 14.177, 14.466,\n 14.737, 15.005, 15.245, 15.491, 15.681, 15.916, 16.12, 16.301,\n 16.485, 16.671, 16.831, 16.979, 17.151, 17.315, 17.427, 17.559,\n 17.68, 17.791, 17.914, 18.009, 18.113, 18.203, 18.298, 18.391,\n 18.46, 18.547, 18.617, 18.669, 18.77, 18.806, 18.858, 18.934,\n 18.978, 19.027, 19.085, 19.119, 19.169, 19.202, 19.256, 19.291,\n 19.311, 19.357, 19.399, 19.416, 19.456, 19.469, 19.5, 19.53,\n 19.553, 19.562, 19.602, 19.608, 19.629, 19.655, 19.67, 19.681,\n 19.7, 19.716, 19.724, 19.748, 19.758, 19.765, 19.782, 19.791,\n 19.799, 19.812, 19.82, 19.828, 19.844, 19.846, 19.858, 19.863,\n 19.862, 19.871, 19.882]'},{'id': '16', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '17', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '18', 'type': 'float', 'children': [], 'value': '1.953'},{'id': '19', 'type': 'float', 'children': [], 'value': '2.861'},{'id': '20', 'type': 'float', 'children': [], 'value': '3.705'},{'id': '21', 'type': 'float', 'children': [], 'value': '4.524'},{'id': '22', 'type': 'float', 'children': [], 'value': '5.304'},{'id': '23', 'type': 'float', 'children': [], 'value': '6.026'},{'id': '24', 'type': 'float', 'children': [], 'value': '6.724'},{'id': '25', 'type': 'float', 'children': [], 'value': '7.397'},{'id': '26', 'type': 'float', 'children': [], 'value': '8.04'},{'id': '27', 'type': 'float', 'children': [], 'value': '8.622'},{'id': '28', 'type': 'float', 'children': [], 'value': '9.191'},{'id': '29', 'type': 'float', 'children': [], 'value': '9.739'},{'id': '30', 'type': 'float', 'children': [], 'value': '10.264'},{'id': '31', 'type': 'float', 'children': [], 'value': '10.758'},{'id': '32', 'type': 'float', 'children': [], 'value': '11.194'},{'id': '33', 'type': 'float', 'children': [], 'value': '11.635'},{'id': '34', 'type': 'float', 'children': [], 'value': '12.049'},{'id': '35', 'type': 'float', 'children': [], 'value': '12.468'},{'id': '36', 'type': 'float', 'children': [], 'value': '12.806'},{'id': '37', 'type': 'float', 'children': [], 'value': '13.185'},{'id': '38', 'type': 'float', 'children': [], 'value': '13.539'},{'id': '39', 'type': 'float', 'children': [], 'value': '13.863'},{'id': '40', 'type': 'float', 'children': [], 'value': '14.177'},{'id': '41', 'type': 'float', 'children': [], 'value': '14.466'},{'id': '42', 'type': 'float', 'children': [], 'value': '14.737'},{'id': '43', 'type': 'float', 'children': [], 'value': '15.005'},{'id': '44', 'type': 'float', 'children': [], 'value': '15.245'},{'id': '45', 'type': 'float', 'children': [], 'value': '15.491'},{'id': '46', 'type': 'float', 'children': [], 'value': '15.681'},{'id': '47', 'type': 'float', 'children': [], 'value': '15.916'},{'id': '48', 'type': 'float', 'children': [], 'value': '16.12'},{'id': '49', 'type': 'float', 'children': [], 'value': '16.301'},{'id': '50', 'type': 'float', 'children': [], 'value': '16.485'},{'id': '51', 'type': 'float', 'children': [], 'value': '16.671'},{'id': '52', 'type': 'float', 'children': [], 'value': '16.831'},{'id': '53', 'type': 'float', 'children': [], 'value': '16.979'},{'id': '54', 'type': 'float', 'children': [], 'value': '17.151'},{'id': '55', 'type': 'float', 'children': [], 'value': '17.315'},{'id': '56', 'type': 'float', 'children': [], 'value': '17.427'},{'id': '57', 'type': 'float', 'children': [], 'value': '17.559'},{'id': '58', 'type': 'float', 'children': [], 'value': '17.68'},{'id': '59', 'type': 'float', 'children': [], 'value': '17.791'},{'id': '60', 'type': 'float', 'children': [], 'value': '17.914'},{'id': '61', 'type': 'float', 'children': [], 'value': '18.009'},{'id': '62', 'type': 'float', 'children': [], 'value': '18.113'},{'id': '63', 'type': 'float', 'children': [], 'value': '18.203'},{'id': '64', 'type': 'float', 'children': [], 'value': '18.298'},{'id': '65', 'type': 'float', 'children': [], 'value': '18.391'},{'id': '66', 'type': 'float', 'children': [], 'value': '18.46'},{'id': '67', 'type': 'float', 'children': [], 'value': '18.547'},{'id': '68', 'type': 'float', 'children': [], 'value': '18.617'},{'id': '69', 'type': 'float', 'children': [], 'value': '18.669'},{'id': '70', 'type': 'float', 'children': [], 'value': '18.77'},{'id': '71', 'type': 'float', 'children': [], 'value': '18.806'},{'id': '72', 'type': 'float', 'children': [], 'value': '18.858'},{'id': '73', 'type': 'float', 'children': [], 'value': '18.934'},{'id': '74', 'type': 'float', 'children': [], 'value': '18.978'},{'id': '75', 'type': 'float', 'children': [], 'value': '19.027'},{'id': '76', 'type': 'float', 'children': [], 'value': '19.085'},{'id': '77', 'type': 'float', 'children': [], 'value': '19.119'},{'id': '78', 'type': 'float', 'children': [], 'value': '19.169'},{'id': '79', 'type': 'float', 'children': [], 'value': '19.202'},{'id': '80', 'type': 'float', 'children': [], 'value': '19.256'},{'id': '81', 'type': 'float', 'children': [], 'value': '19.291'},{'id': '82', 'type': 'float', 'children': [], 'value': '19.311'},{'id': '83', 'type': 'float', 'children': [], 'value': '19.357'},{'id': '84', 'type': 'float', 'children': [], 'value': '19.399'},{'id': '85', 'type': 'float', 'children': [], 'value': '19.416'},{'id': '86', 'type': 'float', 'children': [], 'value': '19.456'},{'id': '87', 'type': 'float', 'children': [], 'value': '19.469'},{'id': '88', 'type': 'float', 'children': [], 'value': '19.5'},{'id': '89', 'type': 'float', 'children': [], 'value': '19.53'},{'id': '90', 'type': 'float', 'children': [], 'value': '19.553'},{'id': '91', 'type': 'float', 'children': [], 'value': '19.562'},{'id': '92', 'type': 'float', 'children': [], 'value': '19.602'},{'id': '93', 'type': 'float', 'children': [], 'value': '19.608'},{'id': '94', 'type': 'float', 'children': [], 'value': '19.629'},{'id': '95', 'type': 'float', 'children': [], 'value': '19.655'},{'id': '96', 'type': 'float', 'children': [], 'value': '19.67'},{'id': '97', 'type': 'float', 'children': [], 'value': '19.681'},{'id': '98', 'type': 'float', 'children': [], 'value': '19.7'},{'id': '99', 'type': 'float', 'children': [], 'value': '19.716'},{'id': '100', 'type': 'float', 'children': [], 'value': '19.724'},{'id': '101', 'type': 'float', 'children': [], 'value': '19.748'},{'id': '102', 'type': 'float', 'children': [], 'value': '19.758'},{'id': '103', 'type': 'float', 'children': [], 'value': '19.765'},{'id': '104', 'type': 'float', 'children': [], 'value': '19.782'},{'id': '105', 'type': 'float', 'children': [], 'value': '19.791'},{'id': '106', 'type': 'float', 'children': [], 'value': '19.799'},{'id': '107', 'type': 'float', 'children': [], 'value': '19.812'},{'id': '108', 'type': 'float', 'children': [], 'value': '19.82'},{'id': '109', 'type': 'float', 'children': [], 'value': '19.828'},{'id': '110', 'type': 'float', 'children': [], 'value': '19.844'},{'id': '111', 'type': 'float', 'children': [], 'value': '19.846'},{'id': '112', 'type': 'float', 'children': [], 'value': '19.858'},{'id': '113', 'type': 'float', 'children': [], 'value': '19.863'},{'id': '114', 'type': 'float', 'children': [], 'value': '19.862'},{'id': '115', 'type': 'float', 'children': [], 'value': '19.871'},{'id': '116', 'type': 'float', 'children': [], 'value': '19.882'},{'id': '117', 'type': 'function_definition', 'children': ['118', '119', '121']},{'id': '118', 'type': 'function_name', 'children': [], 'value': 'col_weight'},{'id': '119', 'type': 'parameters', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '121', 'type': 'block', 'children': ['122', '135', '161', '168', '175', '198', '208']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'min_nongap'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129']},{'id': '128', 'type': 'integer', 'children': [], 'value': '2'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '*'},{'id': '130', 'type': 'float', 'children': [], 'value': '.2'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '135', 'type': 'if_statement', 'children': ['136', '150']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '149'], 'value': '<'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'list_comprehension', 'children': ['141', '142', '145']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '142', 'type': 'for_in_clause', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '145', 'type': 'if_clause', 'children': ['146']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': 'not'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'gap_chars'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'min_nongap'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'return_statement', 'children': ['152']},{'id': '152', 'type': 'tuple', 'children': ['153', '160']},{'id': '153', 'type': 'binary_operator', 'children': ['154', '156'], 'value': '*'},{'id': '154', 'type': 'list', 'children': ['155'], 'value': '[0]'},{'id': '155', 'type': 'integer', 'children': [], 'value': '0'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'n_residues'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'freqs'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '180', 'type': 'generator_expression', 'children': ['181', '189']},{'id': '181', 'type': 'tuple', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '/'},{'id': '184', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '185', 'type': '()', 'children': ['186']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '*'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'n_residues'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '189', 'type': 'for_in_clause', 'children': ['190', '193']},{'id': '190', 'type': 'pattern_list', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '201', 'type': 'list_comprehension', 'children': ['202', '205']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'freqs'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '205', 'type': 'for_in_clause', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '208', 'type': 'return_statement', 'children': ['209']},{'id': '209', 'type': 'tuple', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'n_residues'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '215', 'type': 'binary_operator', 'children': ['216', '218'], 'value': '*'},{'id': '216', 'type': 'list', 'children': ['217'], 'value': '[0]'},{'id': '217', 'type': 'integer', 'children': [], 'value': '0'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'tot_nres'},{'id': '225', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '226', 'type': 'for_statement', 'children': ['227', '228', '233']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'list_splat', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '233', 'type': 'block', 'children': ['234', '243', '250', '264']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '239']},{'id': '236', 'type': 'pattern_list', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'nres'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'col_weight'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '243', 'type': 'assert_statement', 'children': ['244']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '249'], 'value': '<='},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '249', 'type': 'integer', 'children': [], 'value': '20'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'augmented_assignment', 'children': ['252', '253'], 'value': '+='},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'tot_nres'},{'id': '253', 'type': 'conditional_expression', 'children': ['254', '257', '263'], 'value': 'if'},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'expectk'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'nres'},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': '<'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'nres'},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'expectk'},{'id': '263', 'type': 'integer', 'children': [], 'value': '20'},{'id': '264', 'type': 'for_statement', 'children': ['265', '268', '272']},{'id': '265', 'type': 'pattern_list', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'augmented_assignment', 'children': ['275', '278'], 'value': '+='},{'id': '275', 'type': 'subscript', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '279', 'type': 'if_statement', 'children': ['280', '283']},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': '=='},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'scaling'},{'id': '282', 'type': 'string', 'children': [], 'value': "'none'"},{'id': '283', 'type': 'block', 'children': ['284', '293']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'avg_seq_len'},{'id': '287', 'type': 'binary_operator', 'children': ['288', '289'], 'value': '/'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'tot_nres'},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '293', 'type': 'return_statement', 'children': ['294']},{'id': '294', 'type': 'list_comprehension', 'children': ['295', '298']},{'id': '295', 'type': 'binary_operator', 'children': ['296', '297'], 'value': '/'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'avg_seq_len'},{'id': '298', 'type': 'for_in_clause', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '301', 'type': 'if_statement', 'children': ['302', '305', '315', '329', '346', '375']},{'id': '302', 'type': 'comparison_operator', 'children': ['303', '304'], 'value': '=='},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'scaling'},{'id': '304', 'type': 'string', 'children': [], 'value': "'max1'"},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '309', 'type': 'binary_operator', 'children': ['310', '311'], 'value': '/'},{'id': '310', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '311', 'type': 'call', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '315', 'type': 'elif_clause', 'children': ['316', '319']},{'id': '316', 'type': 'comparison_operator', 'children': ['317', '318'], 'value': '=='},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'scaling'},{'id': '318', 'type': 'string', 'children': [], 'value': "'sum1'"},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '323', 'type': 'binary_operator', 'children': ['324', '325'], 'value': '/'},{'id': '324', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '329', 'type': 'elif_clause', 'children': ['330', '333']},{'id': '330', 'type': 'comparison_operator', 'children': ['331', '332'], 'value': '=='},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'scaling'},{'id': '332', 'type': 'string', 'children': [], 'value': "'avg1'"},{'id': '333', 'type': 'block', 'children': ['334']},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '337', 'type': 'binary_operator', 'children': ['338', '342'], 'value': '/'},{'id': '338', 'type': 'call', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '346', 'type': 'elif_clause', 'children': ['347', '350']},{'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': '=='},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'scaling'},{'id': '349', 'type': 'string', 'children': [], 'value': "'andy'"},{'id': '350', 'type': 'block', 'children': ['351', '363']},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'assignment', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '354', 'type': 'binary_operator', 'children': ['355', '359'], 'value': '/'},{'id': '355', 'type': 'call', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '357', 'type': 'argument_list', 'children': ['358']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '359', 'type': 'call', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '363', 'type': 'return_statement', 'children': ['364']},{'id': '364', 'type': 'list_comprehension', 'children': ['365', '372']},{'id': '365', 'type': 'call', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '367', 'type': 'argument_list', 'children': ['368', '371']},{'id': '368', 'type': 'binary_operator', 'children': ['369', '370'], 'value': '*'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '371', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '372', 'type': 'for_in_clause', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '375', 'type': 'else_clause', 'children': ['376']},{'id': '376', 'type': 'block', 'children': ['377']},{'id': '377', 'type': 'raise_statement', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'binary_operator', 'children': ['382', '383'], 'value': '%'},{'id': '382', 'type': 'string', 'children': [], 'value': '"Unknown scaling scheme \'%s\'"'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'scaling'},{'id': '384', 'type': 'return_statement', 'children': ['385']},{'id': '385', 'type': 'list_comprehension', 'children': ['386', '389']},{'id': '386', 'type': 'binary_operator', 'children': ['387', '388'], 'value': '*'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '389', 'type': 'for_in_clause', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'seq_weights'}
def sequence_weights(aln, scaling='none', gap_chars='-.'): expectk = [0.0, 1.0, 1.953, 2.861, 3.705, 4.524, 5.304, 6.026, 6.724, 7.397, 8.04, 8.622, 9.191, 9.739, 10.264, 10.758, 11.194, 11.635, 12.049, 12.468, 12.806, 13.185, 13.539, 13.863, 14.177, 14.466, 14.737, 15.005, 15.245, 15.491, 15.681, 15.916, 16.12, 16.301, 16.485, 16.671, 16.831, 16.979, 17.151, 17.315, 17.427, 17.559, 17.68, 17.791, 17.914, 18.009, 18.113, 18.203, 18.298, 18.391, 18.46, 18.547, 18.617, 18.669, 18.77, 18.806, 18.858, 18.934, 18.978, 19.027, 19.085, 19.119, 19.169, 19.202, 19.256, 19.291, 19.311, 19.357, 19.399, 19.416, 19.456, 19.469, 19.5, 19.53, 19.553, 19.562, 19.602, 19.608, 19.629, 19.655, 19.67, 19.681, 19.7, 19.716, 19.724, 19.748, 19.758, 19.765, 19.782, 19.791, 19.799, 19.812, 19.82, 19.828, 19.844, 19.846, 19.858, 19.863, 19.862, 19.871, 19.882] def col_weight(column): min_nongap = max(2, .2*len(column)) if len([c for c in column if c not in gap_chars]) < min_nongap: return ([0] * len(column), 0) counts = Counter(column) n_residues = len(counts) freqs = dict((aa, 1.0 / (n_residues * count)) for aa, count in counts.iteritems()) weights = [freqs[aa] for aa in column] return (weights, n_residues) seq_weights = [0] * len(aln) tot_nres = 0.0 for col in zip(*aln): wts, nres = col_weight(col) assert sum(wts) <= 20 tot_nres += expectk[nres] if nres < len(expectk) else 20 for idx, wt in enumerate(wts): seq_weights[idx] += wt if scaling == 'none': avg_seq_len = tot_nres / len(aln) return [wt/avg_seq_len for wt in seq_weights] if scaling == 'max1': scale = 1.0 / max(seq_weights) elif scaling == 'sum1': scale = 1.0 / sum(seq_weights) elif scaling == 'avg1': scale = len(aln) / sum(seq_weights) elif scaling == 'andy': scale = len(aln) / sum(seq_weights) return [min(scale * wt, 1.0) for wt in seq_weights] else: raise ValueError("Unknown scaling scheme '%s'" % scaling) return [scale * wt for wt in seq_weights]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_and_append'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'instrument_dict'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'raise_errors'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '21', '25', '32', '36', '282']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '20', 'type': 'dictionary', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'},{'id': '24', 'type': 'dictionary', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'loaded_failed'},{'id': '35', 'type': 'dictionary', 'children': []},{'id': '36', 'type': 'for_statement', 'children': ['37', '40', '45']},{'id': '37', 'type': 'pattern_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'instrument_dict'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'block', 'children': ['46', '50', '54']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'instrument_settings'},{'id': '49', 'type': 'None', 'children': []},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'if_statement', 'children': ['55', '74', '92']},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '66', '67'], 'value': 'and'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '=='},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '73', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '74', 'type': 'block', 'children': ['75', '86']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': '()', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'string', 'children': [], 'value': "'WARNING: instrument {:s} already exists. Did not load!'"},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'loaded_failed'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '92', 'type': 'else_clause', 'children': ['93']},{'id': '93', 'type': 'block', 'children': ['94', '98', '276']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'instrument_instance'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'if_statement', 'children': ['99', '104', '206', '237']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '104', 'type': 'block', 'children': ['105', '116', '125', '134', '143', '150', '158']},{'id': '105', 'type': 'if_statement', 'children': ['106', '109']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'in'},{'id': '107', 'type': 'string', 'children': [], 'value': "'settings'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'instrument_settings'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '115', 'type': 'string', 'children': [], 'value': "'settings'"},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'instrument_filepath'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '124', 'type': 'string', 'children': [], 'value': "'filepath'"},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '133', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '139']},{'id': '136', 'type': 'pattern_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'path_to_module'},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'module_name_from_path'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'instrument_filepath'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'path_to_module'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'class_of_instrument'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '158', 'type': 'try_statement', 'children': ['159', '188']},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'if_statement', 'children': ['161', '164', '174']},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'is'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'instrument_settings'},{'id': '163', 'type': 'None', 'children': []},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'instrument_instance'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'class_of_instrument'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '174', 'type': 'else_clause', 'children': ['175']},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'instrument_instance'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'class_of_instrument'},{'id': '181', 'type': 'argument_list', 'children': ['182', '185']},{'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'instrument_settings'},{'id': '188', 'type': 'except_clause', 'children': ['189', '193']},{'id': '189', 'type': 'as_pattern', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '191', 'type': 'as_pattern_target', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '193', 'type': 'block', 'children': ['194', '200', '205']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '199']},{'id': '196', 'type': 'subscript', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'loaded_failed'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '200', 'type': 'if_statement', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'raise_errors'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'raise_statement', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '205', 'type': 'continue_statement', 'children': []},{'id': '206', 'type': 'elif_clause', 'children': ['207', '212']},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'Instrument'},{'id': '212', 'type': 'block', 'children': ['213', '219', '235']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '218', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'instrument_filepath'},{'id': '222', 'type': 'call', 'children': ['223', '228']},{'id': '223', 'type': 'attribute', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'getfile'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '235', 'type': 'raise_statement', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '237', 'type': 'elif_clause', 'children': ['238', '243']},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '240', 'type': 'argument_list', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'Instrument'},{'id': '243', 'type': 'block', 'children': ['244', '248']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'class_of_instrument'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'instrument_class_name'},{'id': '248', 'type': 'if_statement', 'children': ['249', '252', '262']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': 'is'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'instrument_settings'},{'id': '251', 'type': 'None', 'children': []},{'id': '252', 'type': 'block', 'children': ['253']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'instrument_instance'},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'class_of_instrument'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '262', 'type': 'else_clause', 'children': ['263']},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'instrument_instance'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'class_of_instrument'},{'id': '269', 'type': 'argument_list', 'children': ['270', '273']},{'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'instrument_settings'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '281']},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'instrument_instance'},{'id': '282', 'type': 'return_statement', 'children': ['283']},{'id': '283', 'type': 'expression_list', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'loaded_failed'}
def load_and_append(instrument_dict, instruments=None, raise_errors=False): if instruments is None: instruments = {} updated_instruments = {} updated_instruments.update(instruments) loaded_failed = {} for instrument_name, instrument_class_name in instrument_dict.items(): instrument_settings = None module = None if instrument_name in list(instruments.keys()) \ and instrument_class_name == instruments[instrument_name].__name__: print(('WARNING: instrument {:s} already exists. Did not load!'.format(instrument_name))) loaded_failed[instrument_name] = instrument_name else: instrument_instance = None if isinstance(instrument_class_name, dict): if 'settings' in instrument_class_name: instrument_settings = instrument_class_name['settings'] instrument_filepath = str(instrument_class_name['filepath']) instrument_class_name = str(instrument_class_name['class']) path_to_module, _ = module_name_from_path(instrument_filepath) module = import_module(path_to_module) class_of_instrument = getattr(module, instrument_class_name) try: if instrument_settings is None: instrument_instance = class_of_instrument(name=instrument_name) else: instrument_instance = class_of_instrument(name=instrument_name, settings=instrument_settings) except Exception as e: loaded_failed[instrument_name] = e if raise_errors: raise e continue elif isinstance(instrument_class_name, Instrument): instrument_class_name = instrument_class_name.__class__ instrument_filepath = os.path.dirname(inspect.getfile(instrument_class_name)) raise NotImplementedError elif issubclass(instrument_class_name, Instrument): class_of_instrument = instrument_class_name if instrument_settings is None: instrument_instance = class_of_instrument(name=instrument_name) else: instrument_instance = class_of_instrument(name=instrument_name, settings=instrument_settings) updated_instruments[instrument_name] = instrument_instance return updated_instruments, loaded_failed
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_scan_nodes'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'nodelist'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'instance_types'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ignore_blocks'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '18', '301']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nodelist'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'if_statement', 'children': ['23', '28', '36', '110', '126', '184', '200', '256']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'instance_types'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '36', 'type': 'elif_clause', 'children': ['37', '42']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'IncludeNode'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'if_statement', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '47', 'type': 'block', 'children': ['48', '81', '98']},{'id': '48', 'type': 'if_statement', 'children': ['49', '61', '73']},{'id': '49', 'type': 'not_operator', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '55', 'type': 'argument_list', 'children': ['56', '59', '60']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '59', 'type': 'string', 'children': [], 'value': "'render'"},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'get_template'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'var'},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '81', 'type': 'if_statement', 'children': ['82', '91']},{'id': '82', 'type': 'boolean_operator', 'children': ['83', '86'], 'value': 'and'},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'TemplateAdapter'},{'id': '85', 'type': 'None', 'children': []},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'TemplateAdapter'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'augmented_assignment', 'children': ['100', '101'], 'value': '+='},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': '_scan_nodes'},{'id': '103', 'type': 'argument_list', 'children': ['104', '107', '108', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'nodelist'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'instance_types'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '110', 'type': 'elif_clause', 'children': ['111', '116']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ExtendsNode'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'augmented_assignment', 'children': ['119', '120'], 'value': '+='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_extend_nodelist'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'instance_types'},{'id': '126', 'type': 'elif_clause', 'children': ['127', '134']},{'id': '127', 'type': 'boolean_operator', 'children': ['128', '133'], 'value': 'and'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'VariableNode'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'if_statement', 'children': ['136', '143']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '142'], 'value': '=='},{'id': '137', 'type': 'attribute', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'filter_expression'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '142', 'type': 'string', 'children': [], 'value': "'block.super'"},{'id': '143', 'type': 'block', 'children': ['144', '168']},{'id': '144', 'type': 'if_statement', 'children': ['145', '153']},{'id': '145', 'type': 'not_operator', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '148', 'type': 'argument_list', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '152', 'type': 'string', 'children': [], 'value': "'nodelist'"},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'raise_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'TemplateSyntaxError'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'concatenated_string', 'children': ['161', '162']},{'id': '161', 'type': 'string', 'children': [], 'value': '"Cannot read {{{{ block.super }}}} for {{% block {0} %}}, "'},{'id': '162', 'type': 'string', 'children': [], 'value': '"the parent template doesn\'t have this block."'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'augmented_assignment', 'children': ['170', '171'], 'value': '+='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': '_scan_nodes'},{'id': '173', 'type': 'argument_list', 'children': ['174', '179', '180', '181']},{'id': '174', 'type': 'attribute', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'nodelist'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'instance_types'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '184', 'type': 'elif_clause', 'children': ['185', '198']},{'id': '185', 'type': 'boolean_operator', 'children': ['186', '193'], 'value': 'and'},{'id': '186', 'type': 'boolean_operator', 'children': ['187', '192'], 'value': 'and'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'BlockNode'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'ignore_blocks'},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '197'], 'value': 'in'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ignore_blocks'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'continue_statement', 'children': []},{'id': '200', 'type': 'elif_clause', 'children': ['201', '206']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '205', 'type': 'string', 'children': [], 'value': "'child_nodelists'"},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'for_statement', 'children': ['208', '209', '212']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'nodelist_name'},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'child_nodelists'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'if_statement', 'children': ['214', '219']},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '216', 'type': 'argument_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'nodelist_name'},{'id': '219', 'type': 'block', 'children': ['220', '228']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'subnodelist'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'nodelist_name'},{'id': '228', 'type': 'if_statement', 'children': ['229', '234']},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '231', 'type': 'argument_list', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'subnodelist'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'NodeList'},{'id': '234', 'type': 'block', 'children': ['235', '246']},{'id': '235', 'type': 'if_statement', 'children': ['236', '241']},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '238', 'type': 'argument_list', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'BlockNode'},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'augmented_assignment', 'children': ['248', '249'], 'value': '+='},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': '_scan_nodes'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253', '254', '255']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'subnodelist'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'instance_types'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '256', 'type': 'else_clause', 'children': ['257']},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'for_statement', 'children': ['259', '260', '264']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '264', 'type': 'block', 'children': ['265', '273']},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'assignment', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '270', 'type': 'argument_list', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '273', 'type': 'if_statement', 'children': ['274', '279']},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '276', 'type': 'argument_list', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'NodeList'},{'id': '279', 'type': 'block', 'children': ['280', '291']},{'id': '280', 'type': 'if_statement', 'children': ['281', '286']},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '283', 'type': 'argument_list', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'BlockNode'},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'augmented_assignment', 'children': ['293', '294'], 'value': '+='},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': '_scan_nodes'},{'id': '296', 'type': 'argument_list', 'children': ['297', '298', '299', '300']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'instance_types'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'current_block'},{'id': '301', 'type': 'return_statement', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'results'}
def _scan_nodes(nodelist, context, instance_types, current_block=None, ignore_blocks=None): results = [] for node in nodelist: if isinstance(node, instance_types): results.append(node) elif isinstance(node, IncludeNode): if node.template: if not callable(getattr(node.template, 'render', None)): template = get_template(node.template.var) else: template = node.template if TemplateAdapter is not None and isinstance(template, TemplateAdapter): template = template.template results += _scan_nodes(template.nodelist, context, instance_types, current_block) elif isinstance(node, ExtendsNode): results += _extend_nodelist(node, context, instance_types) elif isinstance(node, VariableNode) and current_block: if node.filter_expression.token == 'block.super': if not hasattr(current_block.parent, 'nodelist'): raise TemplateSyntaxError( "Cannot read {{{{ block.super }}}} for {{% block {0} %}}, " "the parent template doesn't have this block.".format( current_block.name )) results += _scan_nodes(current_block.parent.nodelist, context, instance_types, current_block.parent) elif isinstance(node, BlockNode) and ignore_blocks and node.name in ignore_blocks: continue elif hasattr(node, 'child_nodelists'): for nodelist_name in node.child_nodelists: if hasattr(node, nodelist_name): subnodelist = getattr(node, nodelist_name) if isinstance(subnodelist, NodeList): if isinstance(node, BlockNode): current_block = node results += _scan_nodes(subnodelist, context, instance_types, current_block) else: for attr in dir(node): obj = getattr(node, attr) if isinstance(obj, NodeList): if isinstance(node, BlockNode): current_block = node results += _scan_nodes(obj, context, instance_types, current_block) return results
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_command'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '18', '177', '182', '221', '231', '237', '245', '264', '276']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'use_shell'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'subprocess_flags'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '22', '83']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '=='},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sysstr'},{'id': '21', 'type': 'string', 'children': [], 'value': "'Windows'"},{'id': '22', 'type': 'block', 'children': ['23', '45', '48', '52', '63', '67', '75']},{'id': '23', 'type': 'if_statement', 'children': ['24', '29']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "' '"},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '37', 'type': 'generator_expression', 'children': ['38', '42']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '45', 'type': 'import_statement', 'children': ['46']},{'id': '46', 'type': 'dotted_name', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ctypes'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'SEM_NOGPFAULTERRORBOX'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0x0002'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '61']},{'id': '54', 'type': 'attribute', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ctypes'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'windll'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kernel32'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'SetErrorMode'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'SEM_NOGPFAULTERRORBOX'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'subprocess_flags'},{'id': '66', 'type': 'integer', 'children': [], 'value': '0x8000000'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'STARTUPINFO'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'augmented_assignment', 'children': ['77', '80'], 'value': '|='},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dwFlags'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'STARTF_USESHOWWINDOW'},{'id': '83', 'type': 'else_clause', 'children': ['84']},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'if_statement', 'children': ['86', '90', '95']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'is_string'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'use_shell'},{'id': '94', 'type': 'True', 'children': []},{'id': '95', 'type': 'elif_clause', 'children': ['96', '101']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '101', 'type': 'block', 'children': ['102', '146']},{'id': '102', 'type': 'if_statement', 'children': ['103', '131']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '117', '118'], 'value': 'or'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '110', '116'], 'value': '=='},{'id': '105', 'type': 'subscript', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'integer', 'children': [], 'value': '0'},{'id': '110', 'type': 'subscript', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'unary_operator', 'children': ['115'], 'value': '-'},{'id': '115', 'type': 'integer', 'children': [], 'value': '1'},{'id': '116', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '117', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '124', '130'], 'value': '=='},{'id': '119', 'type': 'subscript', 'children': ['120', '123']},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'integer', 'children': [], 'value': '0'},{'id': '124', 'type': 'subscript', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'unary_operator', 'children': ['129'], 'value': '-'},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '136', 'type': 'integer', 'children': [], 'value': '0'},{'id': '137', 'type': 'subscript', 'children': ['138', '141']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'slice', 'children': ['142', '143', '144']},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'colon', 'children': []},{'id': '144', 'type': 'unary_operator', 'children': ['145'], 'value': '-'},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'for_statement', 'children': ['147', '150', '154']},{'id': '147', 'type': 'pattern_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'if_statement', 'children': ['156', '167']},{'id': '156', 'type': 'boolean_operator', 'children': ['157', '162'], 'value': 'or'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191', '194', '199', '207', '212', '215', '218']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'use_shell'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'PIPE'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'devnull'},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'STDOUT'},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'universal_newlines'},{'id': '214', 'type': 'True', 'children': []},{'id': '215', 'type': 'keyword_argument', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'startupinfo'},{'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'creationflags'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'subprocess_flags'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '226']},{'id': '223', 'type': 'pattern_list', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '230', 'type': 'argument_list', 'children': []},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'recode'},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '237', 'type': 'if_statement', 'children': ['238', '241']},{'id': '238', 'type': 'comparison_operator', 'children': ['239', '240'], 'value': 'is'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '240', 'type': 'None', 'children': []},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'return_statement', 'children': ['243']},{'id': '243', 'type': 'list', 'children': ['244'], 'value': "['']"},{'id': '244', 'type': 'string', 'children': [], 'value': "''"},{'id': '245', 'type': 'if_statement', 'children': ['246', '253']},{'id': '246', 'type': 'boolean_operator', 'children': ['247', '250'], 'value': 'and'},{'id': '247', 'type': 'comparison_operator', 'children': ['248', '249'], 'value': 'is'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'recode'},{'id': '249', 'type': 'None', 'children': []},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '!='},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'recode'},{'id': '252', 'type': 'integer', 'children': [], 'value': '0'},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'raise_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'CalledProcessError'},{'id': '259', 'type': 'argument_list', 'children': ['260', '262', '263']},{'id': '260', 'type': 'unary_operator', 'children': ['261'], 'value': '-'},{'id': '261', 'type': 'integer', 'children': [], 'value': '1'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '263', 'type': 'string', 'children': [], 'value': '"ERROR occurred when running subprocess!"'},{'id': '264', 'type': 'if_statement', 'children': ['265', '268']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'in'},{'id': '266', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'return_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'out'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '276', 'type': 'return_statement', 'children': ['277']},{'id': '277', 'type': 'list', 'children': ['278'], 'value': '[out]'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'out'}
def run_command(commands): use_shell = False subprocess_flags = 0 startupinfo = None if sysstr == 'Windows': if isinstance(commands, list): commands = ' '.join(str(c) for c in commands) import ctypes SEM_NOGPFAULTERRORBOX = 0x0002 ctypes.windll.kernel32.SetErrorMode(SEM_NOGPFAULTERRORBOX) subprocess_flags = 0x8000000 startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW else: if is_string(commands): use_shell = True elif isinstance(commands, list): if commands[0][0] == commands[0][-1] == '"' or \ commands[0][0] == commands[0][-1] == "'": commands[0] = commands[0][1:-1] for idx, v in enumerate(commands): if isinstance(v, int) or isinstance(v, float): commands[idx] = repr(v) print(commands) process = subprocess.Popen(commands, shell=use_shell, stdout=subprocess.PIPE, stdin=open(os.devnull), stderr=subprocess.STDOUT, universal_newlines=True, startupinfo=startupinfo, creationflags=subprocess_flags) out, err = process.communicate() recode = process.returncode if out is None: return [''] if recode is not None and recode != 0: raise subprocess.CalledProcessError(-1, commands, "ERROR occurred when running subprocess!") if '\n' in out: return out.split('\n') return [out]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'intersect_keys'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'reffile'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'clean_accs'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '17', '107', '139', '153']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'if_statement', 'children': ['18', '19', '101']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '19', 'type': 'block', 'children': ['20', '26']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'refcache'},{'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '+'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'reffile'},{'id': '25', 'type': 'string', 'children': [], 'value': "'.sqlite'"},{'id': '26', 'type': 'if_statement', 'children': ['27', '35']},{'id': '27', 'type': 'call', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'refcache'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'if_statement', 'children': ['37', '54', '62']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '46'], 'value': '<'},{'id': '38', 'type': 'attribute', 'children': ['39', '45']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'refcache'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'st_mtime'},{'id': '46', 'type': 'attribute', 'children': ['47', '53']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'reffile'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'st_mtime'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': '"Outdated cache; rebuilding index"'},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'try_statement', 'children': ['65', '87']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '69', 'type': '()', 'children': ['70']},{'id': '70', 'type': 'conditional_expression', 'children': ['71', '80', '81'], 'value': 'if'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'index_db'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'refcache'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key_function'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'clean_accession'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'clean_accs'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'index_db'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'refcache'},{'id': '87', 'type': 'except_clause', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '89', 'type': 'block', 'children': ['90', '97']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': '"Skipping corrupted cache; rebuilding index"'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '100', 'type': 'None', 'children': []},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'refcache'},{'id': '106', 'type': 'string', 'children': [], 'value': "':memory:'"},{'id': '107', 'type': 'if_statement', 'children': ['108', '111']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '110', 'type': 'None', 'children': []},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '115', 'type': '()', 'children': ['116']},{'id': '116', 'type': 'conditional_expression', 'children': ['117', '129', '130'], 'value': 'if'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'index_db'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123', '125', '126']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'refcache'},{'id': '123', 'type': 'list', 'children': ['124'], 'value': '[reffile]'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'reffile'},{'id': '125', 'type': 'string', 'children': [], 'value': "'fasta'"},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'key_function'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'clean_accession'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'clean_accs'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'index_db'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136', '138']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'refcache'},{'id': '136', 'type': 'list', 'children': ['137'], 'value': '[reffile]'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'reffile'},{'id': '138', 'type': 'string', 'children': [], 'value': "'fasta'"},{'id': '139', 'type': 'if_statement', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'clean_accs'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '145', 'type': 'generator_expression', 'children': ['146', '150']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'clean_accession'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '150', 'type': 'for_in_clause', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '156', 'type': 'block', 'children': ['157', '180']},{'id': '157', 'type': 'try_statement', 'children': ['158', '165']},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '165', 'type': 'except_clause', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'LookupError'},{'id': '167', 'type': 'block', 'children': ['168', '179']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'string', 'children': [], 'value': '"No match: %s"'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'repr'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '179', 'type': 'continue_statement', 'children': []},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'yield', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'record'}
def intersect_keys(keys, reffile, cache=False, clean_accs=False): index = None if cache: refcache = reffile + '.sqlite' if os.path.exists(refcache): if os.stat(refcache).st_mtime < os.stat(reffile).st_mtime: logging.warn("Outdated cache; rebuilding index") else: try: index = (SeqIO.index_db(refcache, key_function=clean_accession) if clean_accs else SeqIO.index_db(refcache)) except Exception: logging.warn("Skipping corrupted cache; rebuilding index") index = None else: refcache = ':memory:' if index is None: index = (SeqIO.index_db(refcache, [reffile], 'fasta', key_function=clean_accession) if clean_accs else SeqIO.index_db(refcache, [reffile], 'fasta')) if clean_accs: keys = (clean_accession(k) for k in keys) for key in keys: try: record = index[key] except LookupError: logging.info("No match: %s", repr(key)) continue yield record
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'family_check'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '22']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '13']},{'id': '8', 'type': 'attribute', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': '"Checking family relations for {0}"'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'family_id'},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '27']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'individuals'},{'id': '27', 'type': 'block', 'children': ['28', '42', '50', '64', '92', '98', '104', '225']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '"Checking individual {0}"'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '45', 'type': 'subscript', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'individuals'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': '"Checking if individual {0} is affected"'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'affected'},{'id': '68', 'type': 'block', 'children': ['69', '83']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': '"Found affected individual {0}"'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'affected_individuals'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'father'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'father'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'mother'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'mother'},{'id': '104', 'type': 'if_statement', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'has_parents'},{'id': '108', 'type': 'block', 'children': ['109', '123', '129', '170']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '116']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': '"Individual {0} has parents"'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'no_relations'},{'id': '128', 'type': 'False', 'children': []},{'id': '129', 'type': 'try_statement', 'children': ['130', '151']},{'id': '130', 'type': 'block', 'children': ['131', '141']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'check_parent'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'father'},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'father'},{'id': '140', 'type': 'True', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'check_parent'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'mother'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'father'},{'id': '150', 'type': 'False', 'children': []},{'id': '151', 'type': 'except_clause', 'children': ['152', '156']},{'id': '152', 'type': 'as_pattern', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'PedigreeError'},{'id': '154', 'type': 'as_pattern_target', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '156', 'type': 'block', 'children': ['157', '168']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '168', 'type': 'raise_statement', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '170', 'type': 'if_statement', 'children': ['171', '174', '190', '209']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'has_both_parents'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'trios'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'list', 'children': ['187', '188', '189'], 'value': '[individual_id, father, mother]'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'father'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'mother'},{'id': '190', 'type': 'elif_clause', 'children': ['191', '194']},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '!='},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'father'},{'id': '193', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '202']},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'duos'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'list', 'children': ['207', '208'], 'value': '[individual_id, father]'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'father'},{'id': '209', 'type': 'else_clause', 'children': ['210']},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '218']},{'id': '213', 'type': 'attribute', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'duos'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'list', 'children': ['223', '224'], 'value': '[individual_id, mother]'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'mother'},{'id': '225', 'type': 'for_statement', 'children': ['226', '227', '230']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'individual_2_id'},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'individuals'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'if_statement', 'children': ['232', '235']},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '234'], 'value': '!='},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'individual_2_id'},{'id': '235', 'type': 'block', 'children': ['236']},{'id': '236', 'type': 'if_statement', 'children': ['237', '244']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'check_siblings'},{'id': '241', 'type': 'argument_list', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'individual_2_id'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '252']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'siblings'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'individual_2_id'}
def family_check(self): self.logger.info("Checking family relations for {0}".format( self.family_id) ) for individual_id in self.individuals: self.logger.debug("Checking individual {0}".format(individual_id)) individual = self.individuals[individual_id] self.logger.debug("Checking if individual {0} is affected".format( individual_id)) if individual.affected: self.logger.debug("Found affected individual {0}".format( individual_id) ) self.affected_individuals.add(individual_id) father = individual.father mother = individual.mother if individual.has_parents: self.logger.debug("Individual {0} has parents".format( individual_id)) self.no_relations = False try: self.check_parent(father, father=True) self.check_parent(mother, father=False) except PedigreeError as e: self.logger.error(e.message) raise e if individual.has_both_parents: self.trios.append(set([individual_id, father, mother])) elif father != '0': self.duos.append(set([individual_id, father])) else: self.duos.append(set([individual_id, mother])) for individual_2_id in self.individuals: if individual_id != individual_2_id: if self.check_siblings(individual_id, individual_2_id): individual.siblings.add(individual_2_id)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_ped'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '20', '28', '65', '84', '113']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ped_header'},{'id': '12', 'type': 'list', 'children': ['13', '14', '16', '17', '18', '19'], 'value': "[\n '\n 'IndividualID',\n 'PaternalID',\n 'MaternalID', \n 'Sex',\n 'Phenotype',\n ]"},{'id': '13', 'type': 'string', 'children': [], 'value': "'\n '"},{'id': '14', 'type': 'ERROR', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'IndividualID'},{'id': '16', 'type': 'string', 'children': [], 'value': "'PaternalID'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'MaternalID'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'Sex'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'Phenotype'"},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'extra_headers'},{'id': '23', 'type': 'list', 'children': ['24', '25', '26', '27'], 'value': "[\n 'InheritanceModel',\n 'Proband',\n 'Consultand',\n 'Alive'\n ]"},{'id': '24', 'type': 'string', 'children': [], 'value': "'InheritanceModel'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'Proband'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'Consultand'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'Alive'"},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '33']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'individuals'},{'id': '33', 'type': 'block', 'children': ['34', '42']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'individuals'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'individual_id'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '47']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'extra_info'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'if_statement', 'children': ['49', '52']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'extra_headers'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'not'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ped_header'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ped_header'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '72']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': '"Ped headers found: {0}"'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': "', '"},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ped_header'},{'id': '84', 'type': 'if_statement', 'children': ['85', '86', '101']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'binary_operator', 'children': ['94', '100'], 'value': '+'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'ped_header'},{'id': '100', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ped_header'},{'id': '113', 'type': 'for_statement', 'children': ['114', '115', '120']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'to_json'},{'id': '119', 'type': 'argument_list', 'children': []},{'id': '120', 'type': 'block', 'children': ['121', '125', '134', '143', '152', '161', '170', '179', '210']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '124', 'type': 'list', 'children': [], 'value': '[]'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '133', 'type': 'string', 'children': [], 'value': "'family_id'"},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '142', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '151', 'type': 'string', 'children': [], 'value': "'father'"},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '160', 'type': 'string', 'children': [], 'value': "'mother'"},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '169', 'type': 'string', 'children': [], 'value': "'sex'"},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '178', 'type': 'string', 'children': [], 'value': "'phenotype'"},{'id': '179', 'type': 'if_statement', 'children': ['180', '186']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '185'], 'value': '>'},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ped_header'},{'id': '185', 'type': 'integer', 'children': [], 'value': '6'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'for_statement', 'children': ['188', '189', '194']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ped_header'},{'id': '191', 'type': 'slice', 'children': ['192', '193']},{'id': '192', 'type': 'integer', 'children': [], 'value': '6'},{'id': '193', 'type': 'colon', 'children': []},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '207']},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'individual'},{'id': '205', 'type': 'string', 'children': [], 'value': "'extra_info'"},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '209', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '210', 'type': 'if_statement', 'children': ['211', '212', '227']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'binary_operator', 'children': ['220', '226'], 'value': '+'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'ped_info'},{'id': '226', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '227', 'type': 'else_clause', 'children': ['228']},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'ped_info'}
def to_ped(self, outfile=None): ped_header = [ ' 'IndividualID', 'PaternalID', 'MaternalID', 'Sex', 'Phenotype', ] extra_headers = [ 'InheritanceModel', 'Proband', 'Consultand', 'Alive' ] for individual_id in self.individuals: individual = self.individuals[individual_id] for info in individual.extra_info: if info in extra_headers: if info not in ped_header: ped_header.append(info) self.logger.debug("Ped headers found: {0}".format( ', '.join(ped_header) )) if outfile: outfile.write('\t'.join(ped_header)+'\n') else: print('\t'.join(ped_header)) for individual in self.to_json(): ped_info = [] ped_info.append(individual['family_id']) ped_info.append(individual['id']) ped_info.append(individual['father']) ped_info.append(individual['mother']) ped_info.append(individual['sex']) ped_info.append(individual['phenotype']) if len(ped_header) > 6: for header in ped_header[6:]: ped_info.append(individual['extra_info'].get(header, '.')) if outfile: outfile.write('\t'.join(ped_info)+'\n') else: print('\t'.join(ped_info))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'refresh_instruments'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '21', '118', '127', '156']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'list_access_nested_dict'},{'id': '8', 'type': 'parameters', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'somelist'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '15', 'type': 'argument_list', 'children': ['16', '19', '20']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'operator'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'getitem'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'somelist'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '21', 'type': 'function_definition', 'children': ['22', '23', '25']},{'id': '22', 'type': 'function_name', 'children': [], 'value': 'update'},{'id': '23', 'type': 'parameters', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'isExpanded'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'for_statement', 'children': ['34', '35', '43']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'childCount'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'block', 'children': ['44', '53']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '53', 'type': 'if_statement', 'children': ['54', '61', '111']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '60'], 'value': '=='},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'childCount'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'integer', 'children': [], 'value': '0'},{'id': '61', 'type': 'block', 'children': ['62', '72', '78', '105']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'pattern_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'instrument'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'path_to_instrument'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_instrument'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path_to_instrument'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'try_statement', 'children': ['79', '92']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'instrument'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'read_probes'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'path_to_instrument'},{'id': '90', 'type': 'unary_operator', 'children': ['91'], 'value': '-'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'except_clause', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'AssertionError'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'list_access_nested_dict'},{'id': '100', 'type': 'argument_list', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'instrument'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'path_to_instrument'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '111', 'type': 'else_clause', 'children': ['112']},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'tree_settings'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'blockSignals'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'True', 'children': []},{'id': '127', 'type': 'for_statement', 'children': ['128', '129', '139']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '138']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'tree_settings'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'topLevelItemCount'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'block', 'children': ['140', '151']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'instrument'},{'id': '143', 'type': 'call', 'children': ['144', '149']},{'id': '144', 'type': 'attribute', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'tree_settings'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'topLevelItem'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'instrument'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'tree_settings'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'blockSignals'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'False', 'children': []}
def refresh_instruments(self): def list_access_nested_dict(dict, somelist): return reduce(operator.getitem, somelist, dict) def update(item): if item.isExpanded(): for index in range(item.childCount()): child = item.child(index) if child.childCount() == 0: instrument, path_to_instrument = child.get_instrument() path_to_instrument.reverse() try: value = instrument.read_probes(path_to_instrument[-1]) except AssertionError: value = list_access_nested_dict(instrument.settings, path_to_instrument) child.value = value else: update(child) self.tree_settings.blockSignals(True) for index in range(self.tree_settings.topLevelItemCount()): instrument = self.tree_settings.topLevelItem(index) update(instrument) self.tree_settings.blockSignals(False)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'post'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'parallelism'},{'id': '9', 'type': 'integer', 'children': [], 'value': '5'},{'id': '10', 'type': 'block', 'children': ['11', '45', '57', '71', '79', '115', '127', '131', '138', '205', '242']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '14', 'type': 'dictionary', 'children': ['15', '18', '21', '29', '37']},{'id': '15', 'type': 'pair', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': '"Content-Type"'},{'id': '17', 'type': 'string', 'children': [], 'value': '"application/json"'},{'id': '18', 'type': 'pair', 'children': ['19', '20']},{'id': '19', 'type': 'string', 'children': [], 'value': '"Accept"'},{'id': '20', 'type': 'string', 'children': [], 'value': '"application/json"'},{'id': '21', 'type': 'pair', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': '"x-standardize-only"'},{'id': '23', 'type': 'conditional_expression', 'children': ['24', '25', '28'], 'value': 'if'},{'id': '24', 'type': 'string', 'children': [], 'value': '"true"'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'standardize'},{'id': '28', 'type': 'string', 'children': [], 'value': '"false"'},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': '"x-include-invalid"'},{'id': '31', 'type': 'conditional_expression', 'children': ['32', '33', '36'], 'value': 'if'},{'id': '32', 'type': 'string', 'children': [], 'value': '"true"'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'invalid'},{'id': '36', 'type': 'string', 'children': [], 'value': '"false"'},{'id': '37', 'type': 'pair', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '"x-accept-keypair"'},{'id': '39', 'type': 'conditional_expression', 'children': ['40', '41', '44'], 'value': 'if'},{'id': '40', 'type': 'string', 'children': [], 'value': '"true"'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'accept_keypair'},{'id': '44', 'type': 'string', 'children': [], 'value': '"false"'},{'id': '45', 'type': 'if_statement', 'children': ['46', '50']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '55', 'type': 'string', 'children': [], 'value': '"x-suppress-logging"'},{'id': '56', 'type': 'string', 'children': [], 'value': '"false"'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '60', 'type': 'dictionary', 'children': ['61', '66']},{'id': '61', 'type': 'pair', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': '"auth-id"'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'auth_id'},{'id': '66', 'type': 'pair', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': '"auth-token"'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'auth_token'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '74', 'type': 'binary_operator', 'children': ['75', '78'], 'value': '+'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'BASE_URL'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '82', 'type': 'generator_expression', 'children': ['83', '108']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'grequests'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '87', 'type': 'argument_list', 'children': ['88', '91', '102', '105']},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'stringify'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'data_chunk'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '108', 'type': 'for_in_clause', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'data_chunk'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'chunker'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '114', 'type': 'integer', 'children': [], 'value': '100'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'responses'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'grequests'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'rs'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'parallelism'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '130', 'type': 'dictionary', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'addresses'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'AddressCollection'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'list', 'children': [], 'value': '[]'},{'id': '138', 'type': 'for_statement', 'children': ['139', '140', '141']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'responses'},{'id': '141', 'type': 'block', 'children': ['142', '171']},{'id': '142', 'type': 'if_statement', 'children': ['143', '152', '161']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': 'not'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '160']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'augmented_assignment', 'children': ['165', '170'], 'value': '+='},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '170', 'type': 'integer', 'children': [], 'value': '1'},{'id': '171', 'type': 'if_statement', 'children': ['172', '177', '194']},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '176'], 'value': '=='},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '176', 'type': 'integer', 'children': [], 'value': '200'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '186']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'addresses'},{'id': '182', 'type': 'slice', 'children': ['183', '184', '185']},{'id': '183', 'type': 'integer', 'children': [], 'value': '0'},{'id': '184', 'type': 'colon', 'children': []},{'id': '185', 'type': 'integer', 'children': [], 'value': '0'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'AddressCollection'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'elif_clause', 'children': ['195', '200']},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '199'], 'value': '=='},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '199', 'type': 'integer', 'children': [], 'value': '401'},{'id': '200', 'type': 'block', 'children': ['201']},{'id': '201', 'type': 'raise_statement', 'children': ['202']},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ERROR_CODES'},{'id': '204', 'type': 'integer', 'children': [], 'value': '401'},{'id': '205', 'type': 'if_statement', 'children': ['206', '216']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '215'], 'value': '=='},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '214', 'type': 'argument_list', 'children': []},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'if_statement', 'children': ['218', '221', '226']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'in'},{'id': '219', 'type': 'integer', 'children': [], 'value': '200'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'return_statement', 'children': ['223']},{'id': '223', 'type': 'expression_list', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'addresses'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '226', 'type': 'else_clause', 'children': ['227']},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'raise_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'ERROR_CODES'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '233', 'type': 'argument_list', 'children': ['234', '241']},{'id': '234', 'type': 'subscript', 'children': ['235', '240']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'status_codes'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '239', 'type': 'argument_list', 'children': []},{'id': '240', 'type': 'integer', 'children': [], 'value': '0'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'SmartyStreetsError'},{'id': '242', 'type': 'return_statement', 'children': ['243']},{'id': '243', 'type': 'expression_list', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'addresses'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'status_codes'}
def post(self, endpoint, data, parallelism=5): headers = { "Content-Type": "application/json", "Accept": "application/json", "x-standardize-only": "true" if self.standardize else "false", "x-include-invalid": "true" if self.invalid else "false", "x-accept-keypair": "true" if self.accept_keypair else "false", } if not self.logging: headers["x-suppress-logging"] = "false" params = {"auth-id": self.auth_id, "auth-token": self.auth_token} url = self.BASE_URL + endpoint rs = ( grequests.post( url=url, data=json.dumps(stringify(data_chunk)), params=params, headers=headers, ) for data_chunk in chunker(data, 100) ) responses = grequests.imap(rs, size=parallelism) status_codes = {} addresses = AddressCollection([]) for response in responses: if response.status_code not in status_codes.keys(): status_codes[response.status_code] = 1 else: status_codes[response.status_code] += 1 if response.status_code == 200: addresses[0:0] = AddressCollection( response.json() ) elif response.status_code == 401: raise ERROR_CODES[401] if len(status_codes.keys()) == 1: if 200 in status_codes: return addresses, status_codes else: raise ERROR_CODES.get(status_codes.keys()[0], SmartyStreetsError) return addresses, status_codes
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_contents_static'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'block_alias'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '7', 'type': 'block', 'children': ['8', '15', '23', '66', '72', '79', '88', '270', '276', '287', '296', '306', '327', '331', '387']},{'id': '8', 'type': 'if_statement', 'children': ['9', '12']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '11'], 'value': 'not'},{'id': '10', 'type': 'string', 'children': [], 'value': "'request'"},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'string', 'children': [], 'value': "''"},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'current_url'},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '21', 'type': 'string', 'children': [], 'value': "'request'"},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '23', 'type': 'try_statement', 'children': ['24', '59']},{'id': '24', 'type': 'block', 'children': ['25', '32', '36', '49']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'resolver_match'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'resolve'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'current_url'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '35', 'type': 'string', 'children': [], 'value': "''"},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'resolver_match'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'resolver_match'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'namespaces'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'resolved_view_name'},{'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '%'},{'id': '53', 'type': 'string', 'children': [], 'value': "':%s:%s'"},{'id': '54', 'type': 'tuple', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'resolver_match'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'url_name'},{'id': '59', 'type': 'except_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'Resolver404'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'resolved_view_name'},{'id': '65', 'type': 'None', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': '_cache_init'},{'id': '71', 'type': 'argument_list', 'children': []},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cache_entry_name'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'cache_get_key'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'block_alias'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': '_cache_get'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'cache_entry_name'},{'id': '88', 'type': 'if_statement', 'children': ['89', '91']},{'id': '89', 'type': 'not_operator', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '91', 'type': 'block', 'children': ['92', '114', '126', '262']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '95', 'type': 'call', 'children': ['96', '111']},{'id': '96', 'type': 'attribute', 'children': ['97', '110']},{'id': '97', 'type': 'call', 'children': ['98', '103']},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Block'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '103', 'type': 'argument_list', 'children': ['104', '107']},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'block_alias'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '109', 'type': 'False', 'children': []},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'only'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '113', 'type': 'string', 'children': [], 'value': "'contents'"},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '117', 'type': 'list', 'children': ['118', '122'], 'value': '[defaultdict(list), defaultdict(list)]'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '126', 'type': 'for_statement', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '129', 'type': 'block', 'children': ['130', '190']},{'id': '130', 'type': 'if_statement', 'children': ['131', '136', '143', '175']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '=='},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '135', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '143', 'type': 'elif_clause', 'children': ['144', '152']},{'id': '144', 'type': 'call', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': "':'"},{'id': '152', 'type': 'block', 'children': ['153', '159']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '159', 'type': 'if_statement', 'children': ['160', '168']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '167'], 'value': '=='},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'string', 'children': [], 'value': "':'"},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'},{'id': '173', 'type': 'string', 'children': [], 'value': "':%s'"},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '175', 'type': 'else_clause', 'children': ['176']},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '%'},{'id': '186', 'type': 'string', 'children': [], 'value': "r'%s'"},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '190', 'type': 'if_statement', 'children': ['191', '194', '210', '230']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'access_guest'},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '206']},{'id': '197', 'type': 'attribute', 'children': ['198', '205']},{'id': '198', 'type': 'subscript', 'children': ['199', '204']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'IDX_GUEST'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '210', 'type': 'elif_clause', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'access_loggedin'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'call', 'children': ['217', '226']},{'id': '217', 'type': 'attribute', 'children': ['218', '225']},{'id': '218', 'type': 'subscript', 'children': ['219', '224']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'IDX_AUTH'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '230', 'type': 'else_clause', 'children': ['231']},{'id': '231', 'type': 'block', 'children': ['232', '247']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '243']},{'id': '234', 'type': 'attribute', 'children': ['235', '242']},{'id': '235', 'type': 'subscript', 'children': ['236', '241']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'IDX_GUEST'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '258']},{'id': '249', 'type': 'attribute', 'children': ['250', '257']},{'id': '250', 'type': 'subscript', 'children': ['251', '256']},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'IDX_AUTH'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'url_re'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': '_cache_set'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'cache_entry_name'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '274', 'type': 'identifier', 'children': [], 'value': '_cache_save'},{'id': '275', 'type': 'argument_list', 'children': []},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '279', 'type': 'call', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '281', 'type': 'argument_list', 'children': ['282', '285', '286']},{'id': '282', 'type': 'subscript', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '284', 'type': 'string', 'children': [], 'value': "'request'"},{'id': '285', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '286', 'type': 'None', 'children': []},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294', '295']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '294', 'type': 'string', 'children': [], 'value': "'is_authenticated'"},{'id': '295', 'type': 'False', 'children': []},{'id': '296', 'type': 'if_statement', 'children': ['297', '299']},{'id': '297', 'type': 'not_operator', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'DJANGO_2'},{'id': '299', 'type': 'block', 'children': ['300']},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '305', 'type': 'argument_list', 'children': []},{'id': '306', 'type': 'if_statement', 'children': ['307', '308', '317']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'},{'id': '308', 'type': 'block', 'children': ['309']},{'id': '309', 'type': 'expression_statement', 'children': ['310']},{'id': '310', 'type': 'assignment', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'lookup_area'},{'id': '312', 'type': 'subscript', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'IDX_AUTH'},{'id': '317', 'type': 'else_clause', 'children': ['318']},{'id': '318', 'type': 'block', 'children': ['319']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'lookup_area'},{'id': '322', 'type': 'subscript', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'siteblocks_static'},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'IDX_GUEST'},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'assignment', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'static_block_contents'},{'id': '330', 'type': 'string', 'children': [], 'value': "''"},{'id': '331', 'type': 'if_statement', 'children': ['332', '335', '345', '359']},{'id': '332', 'type': 'comparison_operator', 'children': ['333', '334'], 'value': 'in'},{'id': '333', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'lookup_area'},{'id': '335', 'type': 'block', 'children': ['336']},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'assignment', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'static_block_contents'},{'id': '339', 'type': 'call', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'subscript', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'lookup_area'},{'id': '344', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '345', 'type': 'elif_clause', 'children': ['346', '349']},{'id': '346', 'type': 'comparison_operator', 'children': ['347', '348'], 'value': 'in'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'resolved_view_name'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'lookup_area'},{'id': '349', 'type': 'block', 'children': ['350']},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'assignment', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'static_block_contents'},{'id': '353', 'type': 'call', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'subscript', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'lookup_area'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'resolved_view_name'},{'id': '359', 'type': 'else_clause', 'children': ['360']},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'for_statement', 'children': ['362', '365', '370']},{'id': '362', 'type': 'pattern_list', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'lookup_area'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '369', 'type': 'argument_list', 'children': []},{'id': '370', 'type': 'block', 'children': ['371']},{'id': '371', 'type': 'if_statement', 'children': ['372', '378']},{'id': '372', 'type': 'call', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '376', 'type': 'argument_list', 'children': ['377']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'current_url'},{'id': '378', 'type': 'block', 'children': ['379', '386']},{'id': '379', 'type': 'expression_statement', 'children': ['380']},{'id': '380', 'type': 'assignment', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'static_block_contents'},{'id': '382', 'type': 'call', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'contents'},{'id': '386', 'type': 'break_statement', 'children': []},{'id': '387', 'type': 'return_statement', 'children': ['388']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'static_block_contents'}
def get_contents_static(self, block_alias, context): if 'request' not in context: return '' current_url = context['request'].path try: resolver_match = resolve(current_url) namespace = '' if resolver_match.namespaces: namespace = resolver_match.namespaces[0] resolved_view_name = ':%s:%s' % (namespace, resolver_match.url_name) except Resolver404: resolved_view_name = None self._cache_init() cache_entry_name = cache_get_key(block_alias) siteblocks_static = self._cache_get(cache_entry_name) if not siteblocks_static: blocks = Block.objects.filter(alias=block_alias, hidden=False).only('url', 'contents') siteblocks_static = [defaultdict(list), defaultdict(list)] for block in blocks: if block.url == '*': url_re = block.url elif block.url.startswith(':'): url_re = block.url if url_re.count(':') == 1: url_re = ':%s' % url_re else: url_re = re.compile(r'%s' % block.url) if block.access_guest: siteblocks_static[self.IDX_GUEST][url_re].append(block.contents) elif block.access_loggedin: siteblocks_static[self.IDX_AUTH][url_re].append(block.contents) else: siteblocks_static[self.IDX_GUEST][url_re].append(block.contents) siteblocks_static[self.IDX_AUTH][url_re].append(block.contents) self._cache_set(cache_entry_name, siteblocks_static) self._cache_save() user = getattr(context['request'], 'user', None) is_authenticated = getattr(user, 'is_authenticated', False) if not DJANGO_2: is_authenticated = is_authenticated() if is_authenticated: lookup_area = siteblocks_static[self.IDX_AUTH] else: lookup_area = siteblocks_static[self.IDX_GUEST] static_block_contents = '' if '*' in lookup_area: static_block_contents = choice(lookup_area['*']) elif resolved_view_name in lookup_area: static_block_contents = choice(lookup_area[resolved_view_name]) else: for url, contents in lookup_area.items(): if url.match(current_url): static_block_contents = choice(contents) break return static_block_contents
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'files_to_pif'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'quality_report'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '21', '45', '54', '73', '79', '89', '109', '122', '126', '179', '185', '312', '327']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'''Given a directory that contains output from\n a DFT calculation, parse the data and return\n a pif object\n Input:\n files - [str] list of files from which the parser is allowed to read.\n verbose - int, How much status messages to print\n Output:\n pif - ChemicalSystem, Results and settings of\n the DFT calculation in pif format\n '''"},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'found_parser'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'for_statement', 'children': ['22', '23', '26']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'possible_parser'},{'id': '23', 'type': 'list', 'children': ['24', '25'], 'value': '[PwscfParser, VaspParser]'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'PwscfParser'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'VaspParser'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'try_statement', 'children': ['28', '41']},{'id': '28', 'type': 'block', 'children': ['29', '36', '40']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'possible_parser'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'found_parser'},{'id': '39', 'type': 'True', 'children': []},{'id': '40', 'type': 'break_statement', 'children': []},{'id': '41', 'type': 'except_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'InvalidIngesterException'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'pass_statement', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '48']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'found_parser'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "'Directory is not in correct format for an existing parser'"},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '>'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '57', 'type': 'integer', 'children': [], 'value': '0'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': '"Found a {} directory"'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'get_name'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'chem'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'ChemicalSystem'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'chem'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'chemical_formula'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'get_composition'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'software'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'Software'},{'id': '94', 'type': 'argument_list', 'children': ['95', '102']},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get_name'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'get_version_number'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'Method'},{'id': '114', 'type': 'argument_list', 'children': ['115', '118']},{'id': '115', 'type': 'keyword_argument', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '117', 'type': 'string', 'children': [], 'value': "'Density Functional Theory'"},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'software'},{'id': '120', 'type': 'list', 'children': ['121'], 'value': '[software]'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'software'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '125', 'type': 'list', 'children': [], 'value': '[]'},{'id': '126', 'type': 'for_statement', 'children': ['127', '130', '139']},{'id': '127', 'type': 'pattern_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '130', 'type': 'call', 'children': ['131', '138']},{'id': '131', 'type': 'attribute', 'children': ['132', '137']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'get_setting_functions'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'block', 'children': ['140', '150', '156', '166', '172']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '143', 'type': 'call', 'children': ['144', '149']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '153', 'type': 'None', 'children': []},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'continue_statement', 'children': []},{'id': '156', 'type': 'if_statement', 'children': ['157', '164']},{'id': '157', 'type': 'boolean_operator', 'children': ['158', '159'], 'value': 'and'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '163'], 'value': 'is'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '163', 'type': 'None', 'children': []},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'continue_statement', 'children': []},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'cond'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'chem'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '184', 'type': 'list', 'children': [], 'value': '[]'},{'id': '185', 'type': 'for_statement', 'children': ['186', '189', '198']},{'id': '186', 'type': 'pattern_list', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '189', 'type': 'call', 'children': ['190', '197']},{'id': '190', 'type': 'attribute', 'children': ['191', '196']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'get_result_functions'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'block', 'children': ['199', '209', '215', '225', '231', '238', '244', '260', '303']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '202', 'type': 'call', 'children': ['203', '208']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '208', 'type': 'argument_list', 'children': []},{'id': '209', 'type': 'if_statement', 'children': ['210', '213']},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': 'is'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '212', 'type': 'None', 'children': []},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'continue_statement', 'children': []},{'id': '215', 'type': 'if_statement', 'children': ['216', '223']},{'id': '216', 'type': 'boolean_operator', 'children': ['217', '218'], 'value': 'and'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'inline'},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '222'], 'value': 'is'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '222', 'type': 'None', 'children': []},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'continue_statement', 'children': []},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'methods'},{'id': '236', 'type': 'list', 'children': ['237'], 'value': '[method,]'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'data_type'},{'id': '243', 'type': 'string', 'children': [], 'value': "'COMPUTATIONAL'"},{'id': '244', 'type': 'if_statement', 'children': ['245', '254']},{'id': '245', 'type': 'boolean_operator', 'children': ['246', '249'], 'value': 'and'},{'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': '>'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '248', 'type': 'integer', 'children': [], 'value': '0'},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'Value'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '260', 'type': 'if_statement', 'children': ['261', '266', '273']},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '265'], 'value': 'is'},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '265', 'type': 'None', 'children': []},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '273', 'type': 'else_clause', 'children': ['274']},{'id': '274', 'type': 'block', 'children': ['275', '294']},{'id': '275', 'type': 'if_statement', 'children': ['276', '284']},{'id': '276', 'type': 'not_operator', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '279', 'type': 'argument_list', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '284', 'type': 'block', 'children': ['285']},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '290', 'type': 'list', 'children': ['291'], 'value': '[prop.conditions]'},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '294', 'type': 'expression_statement', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '301']},{'id': '296', 'type': 'attribute', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '310']},{'id': '305', 'type': 'attribute', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'chem'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '312', 'type': 'if_statement', 'children': ['313', '320']},{'id': '313', 'type': 'boolean_operator', 'children': ['314', '315'], 'value': 'and'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'quality_report'},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '317', 'type': 'argument_list', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'VaspParser'},{'id': '320', 'type': 'block', 'children': ['321']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': '_add_quality_report'},{'id': '324', 'type': 'argument_list', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'chem'},{'id': '327', 'type': 'return_statement', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'chem'}
def files_to_pif(files, verbose=0, quality_report=True, inline=True): '''Given a directory that contains output from a DFT calculation, parse the data and return a pif object Input: files - [str] list of files from which the parser is allowed to read. verbose - int, How much status messages to print Output: pif - ChemicalSystem, Results and settings of the DFT calculation in pif format ''' found_parser = False for possible_parser in [PwscfParser, VaspParser]: try: parser = possible_parser(files) found_parser = True break except InvalidIngesterException: pass if not found_parser: raise Exception('Directory is not in correct format for an existing parser') if verbose > 0: print("Found a {} directory".format(parser.get_name())) chem = ChemicalSystem() chem.chemical_formula = parser.get_composition() software = Software(name=parser.get_name(), version=parser.get_version_number()) method = Method(name='Density Functional Theory', software=[software]) conditions = [] for name, func in parser.get_setting_functions().items(): cond = getattr(parser, func)() if cond is None: continue if inline and cond.files is not None: continue cond.name = name conditions.append(cond) chem.properties = [] for name, func in parser.get_result_functions().items(): prop = getattr(parser, func)() if prop is None: continue if inline and prop.files is not None: continue prop.name = name prop.methods = [method,] prop.data_type='COMPUTATIONAL' if verbose > 0 and isinstance(prop, Value): print(name) if prop.conditions is None: prop.conditions = conditions else: if not isinstance(prop.conditions, list): prop.conditions = [prop.conditions] prop.conditions.extend(conditions) chem.properties.append(prop) if quality_report and isinstance(parser, VaspParser): _add_quality_report(parser, chem) return chem
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_cards'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'cards'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Generator'},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'block', 'children': ['12', '14']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': "'''sort cards by blocknum and blockseq'''"},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '17', 'type': 'argument_list', 'children': ['18', '25']},{'id': '18', 'type': 'list_comprehension', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'card'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'card'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'cards'},{'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32']},{'id': '30', 'type': 'string', 'children': [], 'value': "'blocknum'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'blockseq'"},{'id': '32', 'type': 'string', 'children': [], 'value': "'cardseq'"}
def _sort_cards(self, cards: Generator) -> list: '''sort cards by blocknum and blockseq''' return sorted([card.__dict__ for card in cards], key=itemgetter('blocknum', 'blockseq', 'cardseq'))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_label'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Find the label for the output files \n for this calculation\n '''"},{'id': '8', 'type': 'if_statement', 'children': ['9', '14', '219']},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'is'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_label'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '19', '205']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'foundfiles'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_files'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'in'},{'id': '27', 'type': 'string', 'children': [], 'value': '".files"'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '29', 'type': 'block', 'children': ['30', '34', '47']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'foundfiles'},{'id': '33', 'type': 'True', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_label'},{'id': '39', 'type': 'subscript', 'children': ['40', '46']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': '"."'},{'id': '46', 'type': 'integer', 'children': [], 'value': '0'},{'id': '47', 'type': 'with_statement', 'children': ['48', '62']},{'id': '48', 'type': 'with_clause', 'children': ['49']},{'id': '49', 'type': 'with_item', 'children': ['50']},{'id': '50', 'type': 'as_pattern', 'children': ['51', '60']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '53', 'type': 'argument_list', 'children': ['54', '59']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '58'], 'value': '+'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': '_label'},{'id': '58', 'type': 'string', 'children': [], 'value': "'.files'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '60', 'type': 'as_pattern_target', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '62', 'type': 'block', 'children': ['63', '77', '97', '111', '131', '145', '165', '179', '199']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '66', 'type': 'subscript', 'children': ['67', '76']},{'id': '67', 'type': 'call', 'children': ['68', '75']},{'id': '68', 'type': 'attribute', 'children': ['69', '74']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'integer', 'children': [], 'value': '0'},{'id': '77', 'type': 'if_statement', 'children': ['78', '85']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '!='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '84'], 'value': '+'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_label'},{'id': '84', 'type': 'string', 'children': [], 'value': '".in"'},{'id': '85', 'type': 'block', 'children': ['86', '92']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'raise_statement', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': "'first line must be label.in'"},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '100', 'type': 'subscript', 'children': ['101', '110']},{'id': '101', 'type': 'call', 'children': ['102', '109']},{'id': '102', 'type': 'attribute', 'children': ['103', '108']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'if_statement', 'children': ['112', '119']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '!='},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '118'], 'value': '+'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_label'},{'id': '118', 'type': 'string', 'children': [], 'value': '".txt"'},{'id': '119', 'type': 'block', 'children': ['120', '126']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'raise_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': "'second line must be label.txt'"},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '134', 'type': 'subscript', 'children': ['135', '144']},{'id': '135', 'type': 'call', 'children': ['136', '143']},{'id': '136', 'type': 'attribute', 'children': ['137', '142']},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'if_statement', 'children': ['146', '153']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '!='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '148', 'type': 'binary_operator', 'children': ['149', '152'], 'value': '+'},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_label'},{'id': '152', 'type': 'string', 'children': [], 'value': '"i"'},{'id': '153', 'type': 'block', 'children': ['154', '160']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '159', 'type': 'argument_list', 'children': []},{'id': '160', 'type': 'raise_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': "'third line must be labeli'"},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '168', 'type': 'subscript', 'children': ['169', '178']},{'id': '169', 'type': 'call', 'children': ['170', '177']},{'id': '170', 'type': 'attribute', 'children': ['171', '176']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '175', 'type': 'argument_list', 'children': []},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '177', 'type': 'argument_list', 'children': []},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'if_statement', 'children': ['180', '187']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '!='},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '182', 'type': 'binary_operator', 'children': ['183', '186'], 'value': '+'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_label'},{'id': '186', 'type': 'string', 'children': [], 'value': '"o"'},{'id': '187', 'type': 'block', 'children': ['188', '194']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'raise_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'string', 'children': [], 'value': "'fourth line must be labelo'"},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '204', 'type': 'argument_list', 'children': []},{'id': '205', 'type': 'if_statement', 'children': ['206', '207', '212']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'foundfiles'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'return_statement', 'children': ['209']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '211', 'type': 'identifier', 'children': [], 'value': '_label'},{'id': '212', 'type': 'else_clause', 'children': ['213']},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'raise_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'string', 'children': [], 'value': "'label.files not found'"},{'id': '219', 'type': 'else_clause', 'children': ['220']},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'return_statement', 'children': ['222']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '224', 'type': 'identifier', 'children': [], 'value': '_label'}
def _get_label(self): '''Find the label for the output files for this calculation ''' if self._label is None: foundfiles = False for f in self._files: if ".files" in f: foundfiles = True self._label = f.split(".")[0] with open(self._label + '.files', 'r') as fp: line = fp.readline().split()[0] if line != self._label + ".in": fp.close() raise Exception('first line must be label.in') line = fp.readline().split()[0] if line != self._label + ".txt": fp.close() raise Exception('second line must be label.txt') line = fp.readline().split()[0] if line != self._label + "i": fp.close() raise Exception('third line must be labeli') line = fp.readline().split()[0] if line != self._label + "o": fp.close() raise Exception('fourth line must be labelo') fp.close() if foundfiles: return self._label else: raise Exception('label.files not found') else: return self._label
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_estimate_progress'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '18', '27', '125', '363']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'estimate'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'current_subscript'},{'id': '13', 'type': 'subscript', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': '_current_subscript_stage'},{'id': '17', 'type': 'string', 'children': [], 'value': "'current_subscript'"},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'num_subscripts'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'scripts'},{'id': '27', 'type': 'if_statement', 'children': ['28', '33', '42', '114']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': '=='},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'iterator_type'},{'id': '32', 'type': 'string', 'children': [], 'value': "'loop'"},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'num_iterations'},{'id': '37', 'type': 'subscript', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '41', 'type': 'string', 'children': [], 'value': "'num_loops'"},{'id': '42', 'type': 'elif_clause', 'children': ['43', '48']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': '=='},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'iterator_type'},{'id': '47', 'type': 'string', 'children': [], 'value': "'sweep'"},{'id': '48', 'type': 'block', 'children': ['49', '57']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sweep_range'},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '56', 'type': 'string', 'children': [], 'value': "'sweep_range'"},{'id': '57', 'type': 'if_statement', 'children': ['58', '65', '86', '101']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '64'], 'value': '=='},{'id': '59', 'type': 'subscript', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '63', 'type': 'string', 'children': [], 'value': "'stepping_mode'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'value_step'"},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'num_iterations'},{'id': '69', 'type': 'binary_operator', 'children': ['70', '85'], 'value': '+'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'binary_operator', 'children': ['74', '82'], 'value': '/'},{'id': '74', 'type': '()', 'children': ['75']},{'id': '75', 'type': 'binary_operator', 'children': ['76', '79'], 'value': '-'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sweep_range'},{'id': '78', 'type': 'string', 'children': [], 'value': "'max_value'"},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sweep_range'},{'id': '81', 'type': 'string', 'children': [], 'value': "'min_value'"},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sweep_range'},{'id': '84', 'type': 'string', 'children': [], 'value': "'N/value_step'"},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'elif_clause', 'children': ['87', '94']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '93'], 'value': '=='},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '92', 'type': 'string', 'children': [], 'value': "'stepping_mode'"},{'id': '93', 'type': 'string', 'children': [], 'value': "'N'"},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'num_iterations'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sweep_range'},{'id': '100', 'type': 'string', 'children': [], 'value': "'N/value_step'"},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'raise_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '+'},{'id': '108', 'type': 'string', 'children': [], 'value': "'unknown key'"},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '113', 'type': 'string', 'children': [], 'value': "'stepping_mode'"},{'id': '114', 'type': 'else_clause', 'children': ['115']},{'id': '115', 'type': 'block', 'children': ['116', '121']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "'unknown iterator type in Iterator receive signal - can\\'t estimate ramining time'"},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'estimate'},{'id': '124', 'type': 'False', 'children': []},{'id': '125', 'type': 'if_statement', 'children': ['126', '127', '357']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'estimate'},{'id': '127', 'type': 'block', 'children': ['128', '134', '342']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'loop_index'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'loop_index'},{'id': '134', 'type': 'if_statement', 'children': ['135', '138']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '>'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'num_subscripts'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'block', 'children': ['139', '143', '147', '174', '193', '214', '218', '279', '283', '319']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'loop_execution_time'},{'id': '142', 'type': 'float', 'children': [], 'value': '0.'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sub_progress_time'},{'id': '146', 'type': 'float', 'children': [], 'value': '0.'},{'id': '147', 'type': 'if_statement', 'children': ['148', '151', '168']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'current_subscript'},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'current_subscript_exec_duration'},{'id': '155', 'type': 'call', 'children': ['156', '167']},{'id': '156', 'type': 'attribute', 'children': ['157', '166']},{'id': '157', 'type': 'subscript', 'children': ['158', '163']},{'id': '158', 'type': 'subscript', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': '_current_subscript_stage'},{'id': '162', 'type': 'string', 'children': [], 'value': "'subscript_exec_duration'"},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'current_subscript'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'else_clause', 'children': ['169']},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'current_subscript_exec_duration'},{'id': '173', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'current_subscript_elapsed_time'},{'id': '177', 'type': 'call', 'children': ['178', '192']},{'id': '178', 'type': 'attribute', 'children': ['179', '191']},{'id': '179', 'type': '()', 'children': ['180']},{'id': '180', 'type': 'binary_operator', 'children': ['181', '188'], 'value': '-'},{'id': '181', 'type': 'call', 'children': ['182', '187']},{'id': '182', 'type': 'attribute', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '187', 'type': 'argument_list', 'children': []},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'current_subscript'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'if_statement', 'children': ['194', '197']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': '=='},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'current_subscript_exec_duration'},{'id': '196', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '197', 'type': 'block', 'children': ['198', '208']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'remaining_time'},{'id': '201', 'type': 'call', 'children': ['202', '207']},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'current_subscript'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'remaining_time'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '207', 'type': 'argument_list', 'children': []},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'current_subscript_exec_duration'},{'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '+'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'remaining_time'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'current_subscript_elapsed_time'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'remaining_scripts'},{'id': '217', 'type': 'integer', 'children': [], 'value': '0'},{'id': '218', 'type': 'for_statement', 'children': ['219', '222', '231']},{'id': '219', 'type': 'pattern_list', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'subscript_name'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '222', 'type': 'call', 'children': ['223', '230']},{'id': '223', 'type': 'attribute', 'children': ['224', '229']},{'id': '224', 'type': 'subscript', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_current_subscript_stage'},{'id': '228', 'type': 'string', 'children': [], 'value': "'subscript_exec_duration'"},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '230', 'type': 'argument_list', 'children': []},{'id': '231', 'type': 'block', 'children': ['232', '245', '253']},{'id': '232', 'type': 'if_statement', 'children': ['233', '240']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '239'], 'value': '=='},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '238', 'type': 'argument_list', 'children': []},{'id': '239', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'augmented_assignment', 'children': ['243', '244'], 'value': '+='},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'remaining_scripts'},{'id': '244', 'type': 'integer', 'children': [], 'value': '1'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'augmented_assignment', 'children': ['247', '248'], 'value': '+='},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'loop_execution_time'},{'id': '248', 'type': 'call', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '252', 'type': 'argument_list', 'children': []},{'id': '253', 'type': 'if_statement', 'children': ['254', '270']},{'id': '254', 'type': 'boolean_operator', 'children': ['255', '264', '265'], 'value': 'and'},{'id': '255', 'type': 'comparison_operator', 'children': ['256', '263'], 'value': '=='},{'id': '256', 'type': 'subscript', 'children': ['257', '262']},{'id': '257', 'type': 'subscript', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '260', 'type': 'identifier', 'children': [], 'value': '_current_subscript_stage'},{'id': '261', 'type': 'string', 'children': [], 'value': "'subscript_exec_count'"},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'subscript_name'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'loop_index'},{'id': '264', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'is'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'subscript_name'},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'current_subscript'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '270', 'type': 'block', 'children': ['271']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'augmented_assignment', 'children': ['273', '274'], 'value': '+='},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'sub_progress_time'},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'total_seconds'},{'id': '278', 'type': 'argument_list', 'children': []},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'augmented_assignment', 'children': ['281', '282'], 'value': '+='},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'sub_progress_time'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'current_subscript_elapsed_time'},{'id': '283', 'type': 'if_statement', 'children': ['284', '287', '294', '310']},{'id': '284', 'type': 'comparison_operator', 'children': ['285', '286'], 'value': '=='},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'remaining_scripts'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'num_subscripts'},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'loop_execution_time'},{'id': '291', 'type': 'binary_operator', 'children': ['292', '293'], 'value': '*'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'num_subscripts'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'current_subscript_exec_duration'},{'id': '294', 'type': 'elif_clause', 'children': ['295', '298']},{'id': '295', 'type': 'comparison_operator', 'children': ['296', '297'], 'value': '>'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'remaining_scripts'},{'id': '297', 'type': 'integer', 'children': [], 'value': '1'},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'loop_execution_time'},{'id': '302', 'type': 'binary_operator', 'children': ['303', '306'], 'value': '/'},{'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '*'},{'id': '304', 'type': 'float', 'children': [], 'value': '1.'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'num_subscripts'},{'id': '306', 'type': '()', 'children': ['307']},{'id': '307', 'type': 'binary_operator', 'children': ['308', '309'], 'value': '-'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'num_subscripts'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'remaining_scripts'},{'id': '310', 'type': 'elif_clause', 'children': ['311', '314']},{'id': '311', 'type': 'comparison_operator', 'children': ['312', '313'], 'value': '=='},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'remaining_scripts'},{'id': '313', 'type': 'integer', 'children': [], 'value': '1'},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'augmented_assignment', 'children': ['317', '318'], 'value': '+='},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'loop_execution_time'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'current_subscript_exec_duration'},{'id': '319', 'type': 'if_statement', 'children': ['320', '323', '332']},{'id': '320', 'type': 'comparison_operator', 'children': ['321', '322'], 'value': '>'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'loop_execution_time'},{'id': '322', 'type': 'integer', 'children': [], 'value': '0'},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'progress_subscript'},{'id': '327', 'type': 'binary_operator', 'children': ['328', '331'], 'value': '/'},{'id': '328', 'type': 'binary_operator', 'children': ['329', '330'], 'value': '*'},{'id': '329', 'type': 'float', 'children': [], 'value': '100.'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'sub_progress_time'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'loop_execution_time'},{'id': '332', 'type': 'else_clause', 'children': ['333']},{'id': '333', 'type': 'block', 'children': ['334']},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'progress_subscript'},{'id': '337', 'type': 'binary_operator', 'children': ['338', '341'], 'value': '/'},{'id': '338', 'type': 'binary_operator', 'children': ['339', '340'], 'value': '*'},{'id': '339', 'type': 'float', 'children': [], 'value': '1.'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'progress_subscript'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'num_subscripts'},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'assignment', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '345', 'type': 'binary_operator', 'children': ['346', '356'], 'value': '/'},{'id': '346', 'type': 'binary_operator', 'children': ['347', '348'], 'value': '*'},{'id': '347', 'type': 'float', 'children': [], 'value': '100.'},{'id': '348', 'type': '()', 'children': ['349']},{'id': '349', 'type': 'binary_operator', 'children': ['350', '353'], 'value': '+'},{'id': '350', 'type': 'binary_operator', 'children': ['351', '352'], 'value': '-'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'loop_index'},{'id': '352', 'type': 'float', 'children': [], 'value': '1.'},{'id': '353', 'type': 'binary_operator', 'children': ['354', '355'], 'value': '*'},{'id': '354', 'type': 'float', 'children': [], 'value': '0.01'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'progress_subscript'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'num_iterations'},{'id': '357', 'type': 'else_clause', 'children': ['358']},{'id': '358', 'type': 'block', 'children': ['359']},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'assignment', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '362', 'type': 'integer', 'children': [], 'value': '50'},{'id': '363', 'type': 'return_statement', 'children': ['364']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'progress'}
def _estimate_progress(self): estimate = True current_subscript = self._current_subscript_stage['current_subscript'] num_subscripts = len(self.scripts) if self.iterator_type == 'loop': num_iterations = self.settings['num_loops'] elif self.iterator_type == 'sweep': sweep_range = self.settings['sweep_range'] if self.settings['stepping_mode'] == 'value_step': num_iterations = int((sweep_range['max_value'] - sweep_range['min_value']) / sweep_range['N/value_step']) + 1 elif self.settings['stepping_mode'] == 'N': num_iterations = sweep_range['N/value_step'] else: raise KeyError('unknown key' + self.settings['stepping_mode']) else: print('unknown iterator type in Iterator receive signal - can\'t estimate ramining time') estimate = False if estimate: loop_index = self.loop_index if num_subscripts > 1: loop_execution_time = 0. sub_progress_time = 0. if current_subscript is not None: current_subscript_exec_duration = self._current_subscript_stage['subscript_exec_duration'][ current_subscript.name].total_seconds() else: current_subscript_exec_duration = 0.0 current_subscript_elapsed_time = (datetime.datetime.now() - current_subscript.start_time).total_seconds() if current_subscript_exec_duration == 0.0: remaining_time = current_subscript.remaining_time.total_seconds() current_subscript_exec_duration = remaining_time + current_subscript_elapsed_time remaining_scripts = 0 for subscript_name, duration in self._current_subscript_stage['subscript_exec_duration'].items(): if duration.total_seconds() == 0.0: remaining_scripts += 1 loop_execution_time += duration.total_seconds() if self._current_subscript_stage['subscript_exec_count'][subscript_name] == loop_index \ and subscript_name is not current_subscript.name: sub_progress_time += duration.total_seconds() sub_progress_time += current_subscript_elapsed_time if remaining_scripts == num_subscripts: loop_execution_time = num_subscripts * current_subscript_exec_duration elif remaining_scripts > 1: loop_execution_time = 1. * num_subscripts / (num_subscripts - remaining_scripts) elif remaining_scripts == 1: loop_execution_time += current_subscript_exec_duration if loop_execution_time > 0: progress_subscript = 100. * sub_progress_time / loop_execution_time else: progress_subscript = 1. * progress_subscript / num_subscripts progress = 100. * (loop_index - 1. + 0.01 * progress_subscript) / num_iterations else: progress = 50 return progress
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_default_settings'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sub_scripts'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'script_order'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'script_execution_freq'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'iterator_type'},{'id': '8', 'type': 'block', 'children': ['9', '240', '368']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '17']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'populate_sweep_param'},{'id': '11', 'type': 'parameters', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'scripts'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'trace'},{'id': '16', 'type': 'string', 'children': [], 'value': "''"},{'id': '17', 'type': 'block', 'children': ['18', '20', '134', '238']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'string', 'children': [], 'value': "'''\n Args:\n scripts: a dict of {'class name': <class object>} pairs\n Returns: A list of all parameters of the input scripts\n '''"},{'id': '20', 'type': 'function_definition', 'children': ['21', '22', '29']},{'id': '21', 'type': 'function_name', 'children': [], 'value': 'get_parameter_from_dict'},{'id': '22', 'type': 'parameters', 'children': ['23', '24', '25', '26']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'trace'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'valid_values'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'block', 'children': ['30', '47', '132']},{'id': '30', 'type': 'if_statement', 'children': ['31', '40']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '35'], 'value': 'and'},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'valid_values'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'valid_values'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'valid_values'},{'id': '47', 'type': 'for_statement', 'children': ['48', '51', '56']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '63', '82', '123']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '60', 'type': 'argument_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'get_parameter_from_dict'},{'id': '69', 'type': 'argument_list', 'children': ['70', '75', '76', '77']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '74'], 'value': '+'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'trace'},{'id': '73', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '77', 'type': 'subscript', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'valid_values'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '82', 'type': 'elif_clause', 'children': ['83', '111']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '92', '93'], 'value': 'or'},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '89'], 'value': 'in'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'valid_values'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'tuple', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '92', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '93', 'type': '()', 'children': ['94']},{'id': '94', 'type': 'boolean_operator', 'children': ['95', '102'], 'value': 'and'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '97', 'type': 'argument_list', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'valid_values'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '108'], 'value': 'in'},{'id': '103', 'type': 'subscript', 'children': ['104', '107']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'valid_values'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'tuple', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '122'], 'value': '+'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '+'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'trace'},{'id': '121', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'tuple', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "'ignoring sweep parameter'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '132', 'type': 'return_statement', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '134', 'type': 'for_statement', 'children': ['135', '136', '144']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'scripts'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'block', 'children': ['145', '151', '155', '174']},{'id': '145', 'type': 'import_from_statement', 'children': ['146', '149']},{'id': '146', 'type': 'dotted_name', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'pylabcontrol'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'core'},{'id': '149', 'type': 'dotted_name', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'ScriptIterator'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'script_trace'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'trace'},{'id': '155', 'type': 'if_statement', 'children': ['156', '159', '164']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': '=='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'script_trace'},{'id': '158', 'type': 'string', 'children': [], 'value': "''"},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'script_trace'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '164', 'type': 'else_clause', 'children': ['165']},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'script_trace'},{'id': '169', 'type': 'binary_operator', 'children': ['170', '173'], 'value': '+'},{'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '+'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'script_trace'},{'id': '172', 'type': 'string', 'children': [], 'value': "'->'"},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '174', 'type': 'if_statement', 'children': ['175', '182', '201']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '177', 'type': 'argument_list', 'children': ['178', '181']},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'scripts'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ScriptIterator'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'populate_sweep_param'},{'id': '186', 'type': 'argument_list', 'children': ['187', '195', '198']},{'id': '187', 'type': 'subscript', 'children': ['188', '194']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'vars'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'scripts'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '194', 'type': 'string', 'children': [], 'value': "'_SCRIPTS'"},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'trace'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'script_trace'},{'id': '201', 'type': 'else_clause', 'children': ['202']},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'for_statement', 'children': ['204', '205', '206', '228']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'setting'},{'id': '205', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '206', 'type': 'subscript', 'children': ['207', '227']},{'id': '207', 'type': 'list_comprehension', 'children': ['208', '211', '221']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '210', 'type': 'integer', 'children': [], 'value': '1'},{'id': '211', 'type': 'for_in_clause', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'getmembers'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'scripts'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '221', 'type': 'if_clause', 'children': ['222']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '226'], 'value': '=='},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '225', 'type': 'integer', 'children': [], 'value': '0'},{'id': '226', 'type': 'string', 'children': [], 'value': "'_DEFAULT_SETTINGS'"},{'id': '227', 'type': 'integer', 'children': [], 'value': '0'},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'get_parameter_from_dict'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'script_trace'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'setting'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '238', 'type': 'return_statement', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'parameter_list'},{'id': '240', 'type': 'if_statement', 'children': ['241', '244', '273', '351']},{'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': '=='},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'iterator_type'},{'id': '243', 'type': 'string', 'children': [], 'value': "'loop'"},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'script_default_settings'},{'id': '248', 'type': 'list', 'children': ['249', '254', '259', '266'], 'value': "[\n Parameter('script_order', script_order),\n Parameter('script_execution_freq', script_execution_freq),\n Parameter('num_loops', 0, int, 'times the subscripts will be executed'),\n Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass')\n ]"},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '251', 'type': 'argument_list', 'children': ['252', '253']},{'id': '252', 'type': 'string', 'children': [], 'value': "'script_order'"},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'script_order'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': "'script_execution_freq'"},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'script_execution_freq'},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263', '264', '265']},{'id': '262', 'type': 'string', 'children': [], 'value': "'num_loops'"},{'id': '263', 'type': 'integer', 'children': [], 'value': '0'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '265', 'type': 'string', 'children': [], 'value': "'times the subscripts will be executed'"},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270', '271', '272']},{'id': '269', 'type': 'string', 'children': [], 'value': "'run_all_first'"},{'id': '270', 'type': 'True', 'children': []},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '272', 'type': 'string', 'children': [], 'value': "'Run all scripts with nonzero frequency in first pass'"},{'id': '273', 'type': 'elif_clause', 'children': ['274', '277']},{'id': '274', 'type': 'comparison_operator', 'children': ['275', '276'], 'value': '=='},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'iterator_type'},{'id': '276', 'type': 'string', 'children': [], 'value': "'sweep'"},{'id': '277', 'type': 'block', 'children': ['278', '286']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'sweep_params'},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'populate_sweep_param'},{'id': '283', 'type': 'argument_list', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'sub_scripts'},{'id': '285', 'type': 'list', 'children': [], 'value': '[]'},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'script_default_settings'},{'id': '289', 'type': 'list', 'children': ['290', '295', '300', '309', '335', '344'], 'value': "[\n Parameter('script_order', script_order),\n Parameter('script_execution_freq', script_execution_freq),\n Parameter('sweep_param', sweep_params[0], sweep_params, 'variable over which to sweep'),\n Parameter('sweep_range',\n [Parameter('min_value', 0, float, 'min parameter value'),\n Parameter('max_value', 0, float, 'max parameter value'),\n Parameter('N/value_step', 0, float,\n 'either number of steps or parameter value step, depending on mode')]),\n Parameter('stepping_mode', 'N', ['N', 'value_step'],\n 'Switch between number of steps and step amount'),\n Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass')\n ]"},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'string', 'children': [], 'value': "'script_order'"},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'script_order'},{'id': '295', 'type': 'call', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '297', 'type': 'argument_list', 'children': ['298', '299']},{'id': '298', 'type': 'string', 'children': [], 'value': "'script_execution_freq'"},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'script_execution_freq'},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '302', 'type': 'argument_list', 'children': ['303', '304', '307', '308']},{'id': '303', 'type': 'string', 'children': [], 'value': "'sweep_param'"},{'id': '304', 'type': 'subscript', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'sweep_params'},{'id': '306', 'type': 'integer', 'children': [], 'value': '0'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'sweep_params'},{'id': '308', 'type': 'string', 'children': [], 'value': "'variable over which to sweep'"},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '311', 'type': 'argument_list', 'children': ['312', '313']},{'id': '312', 'type': 'string', 'children': [], 'value': "'sweep_range'"},{'id': '313', 'type': 'list', 'children': ['314', '321', '328'], 'value': "[Parameter('min_value', 0, float, 'min parameter value'),\n Parameter('max_value', 0, float, 'max parameter value'),\n Parameter('N/value_step', 0, float,\n 'either number of steps or parameter value step, depending on mode')]"},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '316', 'type': 'argument_list', 'children': ['317', '318', '319', '320']},{'id': '317', 'type': 'string', 'children': [], 'value': "'min_value'"},{'id': '318', 'type': 'integer', 'children': [], 'value': '0'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '320', 'type': 'string', 'children': [], 'value': "'min parameter value'"},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325', '326', '327']},{'id': '324', 'type': 'string', 'children': [], 'value': "'max_value'"},{'id': '325', 'type': 'integer', 'children': [], 'value': '0'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '327', 'type': 'string', 'children': [], 'value': "'max parameter value'"},{'id': '328', 'type': 'call', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '330', 'type': 'argument_list', 'children': ['331', '332', '333', '334']},{'id': '331', 'type': 'string', 'children': [], 'value': "'N/value_step'"},{'id': '332', 'type': 'integer', 'children': [], 'value': '0'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '334', 'type': 'string', 'children': [], 'value': "'either number of steps or parameter value step, depending on mode'"},{'id': '335', 'type': 'call', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '337', 'type': 'argument_list', 'children': ['338', '339', '340', '343']},{'id': '338', 'type': 'string', 'children': [], 'value': "'stepping_mode'"},{'id': '339', 'type': 'string', 'children': [], 'value': "'N'"},{'id': '340', 'type': 'list', 'children': ['341', '342'], 'value': "['N', 'value_step']"},{'id': '341', 'type': 'string', 'children': [], 'value': "'N'"},{'id': '342', 'type': 'string', 'children': [], 'value': "'value_step'"},{'id': '343', 'type': 'string', 'children': [], 'value': "'Switch between number of steps and step amount'"},{'id': '344', 'type': 'call', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'Parameter'},{'id': '346', 'type': 'argument_list', 'children': ['347', '348', '349', '350']},{'id': '347', 'type': 'string', 'children': [], 'value': "'run_all_first'"},{'id': '348', 'type': 'True', 'children': []},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '350', 'type': 'string', 'children': [], 'value': "'Run all scripts with nonzero frequency in first pass'"},{'id': '351', 'type': 'else_clause', 'children': ['352']},{'id': '352', 'type': 'block', 'children': ['353', '361']},{'id': '353', 'type': 'expression_statement', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '356', 'type': 'argument_list', 'children': ['357']},{'id': '357', 'type': '()', 'children': ['358']},{'id': '358', 'type': 'binary_operator', 'children': ['359', '360'], 'value': '+'},{'id': '359', 'type': 'string', 'children': [], 'value': "'unknown iterator type '"},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'iterator_type'},{'id': '361', 'type': 'raise_statement', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'binary_operator', 'children': ['366', '367'], 'value': '+'},{'id': '366', 'type': 'string', 'children': [], 'value': "'unknown iterator type '"},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'iterator_type'},{'id': '368', 'type': 'return_statement', 'children': ['369']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'script_default_settings'}
def get_default_settings(sub_scripts, script_order, script_execution_freq, iterator_type): def populate_sweep_param(scripts, parameter_list, trace=''): ''' Args: scripts: a dict of {'class name': <class object>} pairs Returns: A list of all parameters of the input scripts ''' def get_parameter_from_dict(trace, dic, parameter_list, valid_values=None): if valid_values is None and isinstance(dic, Parameter): valid_values = dic.valid_values for key, value in dic.items(): if isinstance(value, dict): parameter_list = get_parameter_from_dict(trace + '.' + key, value, parameter_list, dic.valid_values[key]) elif (valid_values[key] in (float, int)) or \ (isinstance(valid_values[key], list) and valid_values[key][0] in (float, int)): parameter_list.append(trace + '.' + key) else: print(('ignoring sweep parameter', key)) return parameter_list for script_name in list(scripts.keys()): from pylabcontrol.core import ScriptIterator script_trace = trace if script_trace == '': script_trace = script_name else: script_trace = script_trace + '->' + script_name if issubclass(scripts[script_name], ScriptIterator): populate_sweep_param(vars(scripts[script_name])['_SCRIPTS'], parameter_list=parameter_list, trace=script_trace) else: for setting in \ [elem[1] for elem in inspect.getmembers(scripts[script_name]) if elem[0] == '_DEFAULT_SETTINGS'][0]: parameter_list = get_parameter_from_dict(script_trace, setting, parameter_list) return parameter_list if iterator_type == 'loop': script_default_settings = [ Parameter('script_order', script_order), Parameter('script_execution_freq', script_execution_freq), Parameter('num_loops', 0, int, 'times the subscripts will be executed'), Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass') ] elif iterator_type == 'sweep': sweep_params = populate_sweep_param(sub_scripts, []) script_default_settings = [ Parameter('script_order', script_order), Parameter('script_execution_freq', script_execution_freq), Parameter('sweep_param', sweep_params[0], sweep_params, 'variable over which to sweep'), Parameter('sweep_range', [Parameter('min_value', 0, float, 'min parameter value'), Parameter('max_value', 0, float, 'max parameter value'), Parameter('N/value_step', 0, float, 'either number of steps or parameter value step, depending on mode')]), Parameter('stepping_mode', 'N', ['N', 'value_step'], 'Switch between number of steps and step amount'), Parameter('run_all_first', True, bool, 'Run all scripts with nonzero frequency in first pass') ] else: print(('unknown iterator type ' + iterator_type)) raise TypeError('unknown iterator type ' + iterator_type) return script_default_settings
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'consensus'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'gap_threshold'},{'id': '10', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'trim_ends'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '136', '304']},{'id': '18', 'type': 'if_statement', 'children': ['19', '20', '56']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'simple'},{'id': '20', 'type': 'block', 'children': ['21', '33']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'col_consensus'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'make_simple_col_consensus'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'alnutils'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'aa_frequencies'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '33', 'type': 'function_definition', 'children': ['34', '35', '37']},{'id': '34', 'type': 'function_name', 'children': [], 'value': 'is_majority_gap'},{'id': '35', 'type': 'parameters', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': '()', 'children': ['40']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '55'], 'value': '>='},{'id': '41', 'type': 'binary_operator', 'children': ['42', '51'], 'value': '/'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'gap_threshold'},{'id': '56', 'type': 'else_clause', 'children': ['57']},{'id': '57', 'type': 'block', 'children': ['58', '79', '91', '98']},{'id': '58', 'type': 'if_statement', 'children': ['59', '62', '73']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '61', 'type': 'None', 'children': []},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'alnutils'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sequence_weights'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '72', 'type': 'string', 'children': [], 'value': "'avg1'"},{'id': '73', 'type': 'else_clause', 'children': ['74']},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'aa_frequencies'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'alnutils'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'aa_frequencies'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'col_consensus'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'make_entropy_col_consensus'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'aa_frequencies'},{'id': '98', 'type': 'function_definition', 'children': ['99', '100', '102']},{'id': '99', 'type': 'function_name', 'children': [], 'value': 'is_majority_gap'},{'id': '100', 'type': 'parameters', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '102', 'type': 'block', 'children': ['103', '107', '126']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'gap_count'},{'id': '106', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '107', 'type': 'for_statement', 'children': ['108', '111', '116']},{'id': '108', 'type': 'pattern_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'if_statement', 'children': ['118', '121']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '120', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'augmented_assignment', 'children': ['124', '125'], 'value': '+='},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'gap_count'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': '()', 'children': ['128']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '135'], 'value': '>='},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '/'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'gap_count'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'seq_weights'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'gap_threshold'},{'id': '136', 'type': 'function_definition', 'children': ['137', '138', '140']},{'id': '137', 'type': 'function_name', 'children': [], 'value': 'col_wise_consensus'},{'id': '138', 'type': 'parameters', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '140', 'type': 'block', 'children': ['141', '153', '293']},{'id': '141', 'type': 'if_statement', 'children': ['142', '144']},{'id': '142', 'type': 'not_operator', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'trim_ends'},{'id': '144', 'type': 'block', 'children': ['145', '149']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'in_left_end'},{'id': '148', 'type': 'True', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'maybe_right_tail'},{'id': '152', 'type': 'list', 'children': [], 'value': '[]'},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '156', 'type': 'block', 'children': ['157', '178', '217', '224', '243', '252', '259']},{'id': '157', 'type': 'if_statement', 'children': ['158', '173']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '160', 'type': 'generator_expression', 'children': ['161', '166', '169']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'islower'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'for_in_clause', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '169', 'type': 'if_clause', 'children': ['170']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'not'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '172', 'type': 'string', 'children': [], 'value': "'.-'"},{'id': '173', 'type': 'block', 'children': ['174', '177']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'yield', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '177', 'type': 'continue_statement', 'children': []},{'id': '178', 'type': 'if_statement', 'children': ['179', '190']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '181', 'type': 'generator_expression', 'children': ['182', '187']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'islower'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'for_in_clause', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '190', 'type': 'block', 'children': ['191', '207']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'binary_operator', 'children': ['198', '201'], 'value': '+'},{'id': '198', 'type': 'concatenated_string', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': "'Mixed lowercase and uppercase letters in a '"},{'id': '200', 'type': 'string', 'children': [], 'value': "'column: '"},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': "''"},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '212', 'type': 'argument_list', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'is_gap'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'is_majority_gap'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '224', 'type': 'if_statement', 'children': ['225', '227']},{'id': '225', 'type': 'not_operator', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'trim_ends'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'if_statement', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'in_left_end'},{'id': '230', 'type': 'block', 'children': ['231', '239']},{'id': '231', 'type': 'if_statement', 'children': ['232', '234']},{'id': '232', 'type': 'not_operator', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'is_gap'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'in_left_end'},{'id': '238', 'type': 'False', 'children': []},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'is_gap'},{'id': '242', 'type': 'False', 'children': []},{'id': '243', 'type': 'if_statement', 'children': ['244', '247']},{'id': '244', 'type': 'boolean_operator', 'children': ['245', '246'], 'value': 'and'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'is_gap'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'trim_ends'},{'id': '247', 'type': 'block', 'children': ['248', '251']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'yield', 'children': ['250']},{'id': '250', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '251', 'type': 'continue_statement', 'children': []},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'cons_char'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'col_consensus'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '259', 'type': 'if_statement', 'children': ['260', '261', '265']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'trim_ends'},{'id': '261', 'type': 'block', 'children': ['262']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'yield', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'cons_char'},{'id': '265', 'type': 'else_clause', 'children': ['266']},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'if_statement', 'children': ['268', '269', '277']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'is_gap'},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'maybe_right_tail'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'cons_char'},{'id': '277', 'type': 'else_clause', 'children': ['278']},{'id': '278', 'type': 'block', 'children': ['279', '286', '290']},{'id': '279', 'type': 'for_statement', 'children': ['280', '281', '282']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'maybe_right_tail'},{'id': '282', 'type': 'block', 'children': ['283']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'yield', 'children': ['285']},{'id': '285', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'maybe_right_tail'},{'id': '289', 'type': 'list', 'children': [], 'value': '[]'},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'yield', 'children': ['292']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'cons_char'},{'id': '293', 'type': 'if_statement', 'children': ['294', '296']},{'id': '294', 'type': 'not_operator', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'trim_ends'},{'id': '296', 'type': 'block', 'children': ['297']},{'id': '297', 'type': 'for_statement', 'children': ['298', '299', '300']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'maybe_right_tail'},{'id': '300', 'type': 'block', 'children': ['301']},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'yield', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'char'},{'id': '304', 'type': 'return_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'string', 'children': [], 'value': "''"},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'col_wise_consensus'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'list_splat', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'aln'}
def consensus(aln, weights=None, gap_threshold=0.5, simple=False, trim_ends=True): if simple: col_consensus = make_simple_col_consensus(alnutils.aa_frequencies(aln)) def is_majority_gap(col): return (float(col.count('-')) / len(col) >= gap_threshold) else: if weights is None: seq_weights = alnutils.sequence_weights(aln, 'avg1') else: seq_weights = weights aa_frequencies = alnutils.aa_frequencies(aln, weights=seq_weights) col_consensus = make_entropy_col_consensus(aa_frequencies) def is_majority_gap(col): gap_count = 0.0 for wt, char in zip(seq_weights, col): if char == '-': gap_count += wt return (gap_count / sum(seq_weights) >= gap_threshold) def col_wise_consensus(columns): if not trim_ends: in_left_end = True maybe_right_tail = [] for col in columns: if all(c.islower() for c in col if c not in '.-'): yield '-' continue if any(c.islower() for c in col): logging.warn('Mixed lowercase and uppercase letters in a ' 'column: ' + ''.join(col)) col = map(str.upper, col) is_gap = is_majority_gap(col) if not trim_ends: if in_left_end: if not is_gap: in_left_end = False is_gap = False if is_gap and trim_ends: yield '-' continue cons_char = col_consensus(col) if trim_ends: yield cons_char else: if is_gap: maybe_right_tail.append(cons_char) else: for char in maybe_right_tail: yield '-' maybe_right_tail = [] yield cons_char if not trim_ends: for char in maybe_right_tail: yield char return ''.join(col_wise_consensus(zip(*aln)))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_simple_col_consensus'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bg_freqs'},{'id': '5', 'type': 'block', 'children': ['6', '192']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '16']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'col_consensus'},{'id': '8', 'type': 'parameters', 'children': ['9', '10', '13']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'prev_col'},{'id': '12', 'type': 'list', 'children': [], 'value': '[]'},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'prev_char'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'block', 'children': ['17', '26', '29', '50', '64', '176', '183', '190']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'aa_counts'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sequtils'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'aa_frequencies'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '26', 'type': 'assert_statement', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'aa_counts'},{'id': '28', 'type': 'string', 'children': [], 'value': '"Column is all gaps! That\'s not allowed."'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'pattern_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'best_char'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'best_score'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '36', 'type': 'argument_list', 'children': ['37', '42']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'aa_counts'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '44', 'type': 'lambda', 'children': ['45', '47']},{'id': '45', 'type': 'lambda_parameters', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'kv'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'kv'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '53', 'type': 'list_comprehension', 'children': ['54', '55', '58']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '55', 'type': 'for_in_clause', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'aa_counts'},{'id': '58', 'type': 'if_clause', 'children': ['59']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': '=='},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'aa_counts'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'best_score'},{'id': '64', 'type': 'if_statement', 'children': ['65', '71', '163']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '70'], 'value': '>'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'block', 'children': ['72', '135', '157']},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '75'], 'value': 'and'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'prev_char'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'prev_col'},{'id': '76', 'type': 'block', 'children': ['77', '108', '128']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'mc_next'},{'id': '80', 'type': 'call', 'children': ['81', '107']},{'id': '81', 'type': 'attribute', 'children': ['82', '106']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'list_comprehension', 'children': ['86', '87', '96']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '87', 'type': 'for_in_clause', 'children': ['88', '91']},{'id': '88', 'type': 'pattern_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'prev_col'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '96', 'type': 'if_clause', 'children': ['97']},{'id': '97', 'type': 'boolean_operator', 'children': ['98', '103'], 'value': 'and'},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '=='},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'prev_char'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'in'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'ties_next'},{'id': '111', 'type': 'list_comprehension', 'children': ['112', '115', '118']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'mc_next'},{'id': '118', 'type': 'if_clause', 'children': ['119']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '123'], 'value': '=='},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'subscript', 'children': ['124', '127']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'mc_next'},{'id': '126', 'type': 'integer', 'children': [], 'value': '0'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'if_statement', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ties_next'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ties_next'},{'id': '135', 'type': 'if_statement', 'children': ['136', '142']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '141'], 'value': '>'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '141', 'type': 'integer', 'children': [], 'value': '1'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '151', 'type': 'lambda', 'children': ['152', '154']},{'id': '152', 'type': 'lambda_parameters', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'bg_freqs'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'aa'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'best_char'},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '162', 'type': 'integer', 'children': [], 'value': '0'},{'id': '163', 'type': 'else_clause', 'children': ['164']},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'assert_statement', 'children': ['166', '171']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': '=='},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'best_char'},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '170', 'type': 'integer', 'children': [], 'value': '0'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '%'},{'id': '172', 'type': 'string', 'children': [], 'value': "'WTF %s != %s[0]'"},{'id': '173', 'type': 'tuple', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'best_char'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '182']},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'prev_col'},{'id': '180', 'type': 'slice', 'children': ['181']},{'id': '181', 'type': 'colon', 'children': []},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '189']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'prev_char'},{'id': '187', 'type': 'slice', 'children': ['188']},{'id': '188', 'type': 'colon', 'children': []},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'best_char'},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'best_char'},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'col_consensus'}
def make_simple_col_consensus(bg_freqs): def col_consensus(col, prev_col=[], prev_char=[]): aa_counts = sequtils.aa_frequencies(col) assert aa_counts, "Column is all gaps! That's not allowed." best_char, best_score = max(aa_counts.iteritems(), key=lambda kv: kv[1]) ties = [aa for aa in aa_counts if aa_counts[aa] == best_score] if len(ties) > 1: if prev_char and prev_col: mc_next = Counter( [b for a, b in zip(prev_col, col) if a == prev_char[0] and b in ties] ).most_common() ties_next = [x[0] for x in mc_next if x[1] == mc_next[0][1]] if ties_next: ties = ties_next if len(ties) > 1: ties.sort(key=lambda aa: bg_freqs[aa]) best_char = ties[0] else: assert best_char == ties[0], \ 'WTF %s != %s[0]' % (best_char, ties) prev_col[:] = col prev_char[:] = best_char return best_char return col_consensus
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'supported'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'aln'},{'id': '5', 'type': 'block', 'children': ['6', '191']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'col_consensus'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '14', 'type': 'block', 'children': ['15', '52', '91', '110', '121']},{'id': '15', 'type': 'if_statement', 'children': ['16', '47']},{'id': '16', 'type': '()', 'children': ['17']},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '32'], 'value': 'or'},{'id': '18', 'type': '()', 'children': ['19']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '26'], 'value': '>='},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '26', 'type': 'binary_operator', 'children': ['27', '31'], 'value': '/'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '31', 'type': 'integer', 'children': [], 'value': '2'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '34', 'type': 'generator_expression', 'children': ['35', '40', '43']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'islower'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '43', 'type': 'if_clause', 'children': ['44']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'not'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '46', 'type': 'string', 'children': [], 'value': "'.-'"},{'id': '47', 'type': 'block', 'children': ['48', '51']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'yield', 'children': ['50']},{'id': '50', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '51', 'type': 'continue_statement', 'children': []},{'id': '52', 'type': 'if_statement', 'children': ['53', '64']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '55', 'type': 'generator_expression', 'children': ['56', '61']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'islower'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '64', 'type': 'block', 'children': ['65', '81']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'binary_operator', 'children': ['72', '75'], 'value': '+'},{'id': '72', 'type': 'concatenated_string', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'Mixed lowercase and uppercase letters in a '"},{'id': '74', 'type': 'string', 'children': [], 'value': "'column: '"},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "''"},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '86', 'type': 'argument_list', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '94', 'type': 'call', 'children': ['95', '109']},{'id': '95', 'type': 'attribute', 'children': ['96', '108']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'list_comprehension', 'children': ['100', '101', '104']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'col'},{'id': '104', 'type': 'if_clause', 'children': ['105']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'not'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '107', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'if_statement', 'children': ['111', '113']},{'id': '111', 'type': 'not_operator', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': '"Column is all gaps! How did that happen?"'},{'id': '121', 'type': 'if_statement', 'children': ['122', '129', '133', '182']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '128'], 'value': '=='},{'id': '123', 'type': 'subscript', 'children': ['124', '127']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '126', 'type': 'integer', 'children': [], 'value': '0'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'yield', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '133', 'type': 'elif_clause', 'children': ['134', '153']},{'id': '134', 'type': '()', 'children': ['135']},{'id': '135', 'type': 'boolean_operator', 'children': ['136', '142'], 'value': 'and'},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '141'], 'value': '>'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '141', 'type': 'integer', 'children': [], 'value': '1'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '148'], 'value': '=='},{'id': '143', 'type': 'subscript', 'children': ['144', '147']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'subscript', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'block', 'children': ['154', '174']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '157', 'type': 'list_comprehension', 'children': ['158', '161', '164']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'id': '161', 'type': 'for_in_clause', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '164', 'type': 'if_clause', 'children': ['165']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '169'], 'value': '=='},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'subscript', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '172', 'type': 'integer', 'children': [], 'value': '0'},{'id': '173', 'type': 'integer', 'children': [], 'value': '1'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'yield', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "''"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ties'},{'id': '182', 'type': 'else_clause', 'children': ['183']},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'yield', 'children': ['186']},{'id': '186', 'type': 'subscript', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'},{'id': '191', 'type': 'return_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'col_consensus'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'list_splat', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'aln'}
def supported(aln): def col_consensus(columns): for col in columns: if ( (col.count('-') >= len(col)/2) or all(c.islower() for c in col if c not in '.-') ): yield '-' continue if any(c.islower() for c in col): logging.warn('Mixed lowercase and uppercase letters in a ' 'column: ' + ''.join(col)) col = map(str.upper, col) most_common = Counter( [c for c in col if c not in '-'] ).most_common() if not most_common: logging.warn("Column is all gaps! How did that happen?") if most_common[0][1] == 1: yield '-' elif (len(most_common) > 1 and most_common[0][1] == most_common[1][1]): ties = [x[0] for x in most_common if x[1] == most_common[0][1]] yield ''.join(ties) else: yield most_common[0][0] return list(col_consensus(zip(*aln)))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_aliases'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '34']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_cache_init'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'if_statement', 'children': ['14', '16']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'aliases'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'parent_aliases'},{'id': '22', 'type': 'call', 'children': ['23', '33']},{'id': '23', 'type': 'attribute', 'children': ['24', '32']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_cache_get_entry'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'CACHE_NAME_PARENTS'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'list_comprehension', 'children': ['36', '37', '40']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'parent_alias'},{'id': '37', 'type': 'for_in_clause', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'parent_alias'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'parent_aliases'},{'id': '40', 'type': 'if_clause', 'children': ['41']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'in'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'parent_alias'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'aliases'}
def sort_aliases(self, aliases): self._cache_init() if not aliases: return aliases parent_aliases = self._cache_get_entry(self.CACHE_NAME_PARENTS).keys() return [parent_alias for parent_alias in parent_aliases if parent_alias in aliases]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_and_append'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'probe_dict'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'probes'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '8', 'type': 'dictionary', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '14', '18', '25', '29', '36', '59', '127', '207']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'loaded_failed'},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'updated_probes'},{'id': '17', 'type': 'dictionary', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'updated_probes'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'probes'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'},{'id': '28', 'type': 'dictionary', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'new_instruments'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '51'], 'value': '-'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'probe_dict'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'probes'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '!='},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'new_instruments'},{'id': '62', 'type': 'list', 'children': [], 'value': '[]'},{'id': '63', 'type': 'block', 'children': ['64', '82']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'pattern_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'Instrument'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'load_and_append'},{'id': '73', 'type': 'argument_list', 'children': ['74', '81']},{'id': '74', 'type': 'dictionary_comprehension', 'children': ['75', '78']},{'id': '75', 'type': 'pair', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '78', 'type': 'for_in_clause', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'new_instruments'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '82', 'type': 'if_statement', 'children': ['83', '86']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '!='},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '85', 'type': 'list', 'children': [], 'value': '[]'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'for_statement', 'children': ['88', '89', '102']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'failed_instrument'},{'id': '89', 'type': 'binary_operator', 'children': ['90', '94'], 'value': '-'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'failed'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'instruments'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'block', 'children': ['103', '123']},{'id': '103', 'type': 'for_statement', 'children': ['104', '105', '108']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'probe_name'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'probe_dict'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'failed_instrument'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'loaded_failed'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'probe_name'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'failed to load instrument {:s} already exists. Did not load!'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'failed_instrument'},{'id': '123', 'type': 'delete_statement', 'children': ['124']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'probe_dict'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'failed_instrument'},{'id': '127', 'type': 'for_statement', 'children': ['128', '131', '136']},{'id': '128', 'type': 'pattern_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'probe_names'},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'probe_dict'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'block', 'children': ['137', '153']},{'id': '137', 'type': 'if_statement', 'children': ['138', '142']},{'id': '138', 'type': 'not_operator', 'children': ['139']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': 'in'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'updated_probes'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'updated_probes'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'dictionary', 'children': ['150']},{'id': '150', 'type': 'pair', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '152', 'type': 'dictionary', 'children': []},{'id': '153', 'type': 'for_statement', 'children': ['154', '155', '161']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'probe_name'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'probe_names'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'string', 'children': [], 'value': "','"},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'if_statement', 'children': ['163', '168', '183']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'in'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'probe_name'},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'updated_probes'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'loaded_failed'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'probe_name'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'string', 'children': [], 'value': "'failed to load probe {:s} already exists. Did not load!'"},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'probe_name'},{'id': '183', 'type': 'else_clause', 'children': ['184']},{'id': '184', 'type': 'block', 'children': ['185', '195']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'probe_instance'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'Probe'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'probe_name'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '202']},{'id': '197', 'type': 'attribute', 'children': ['198', '201']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'updated_probes'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'instrument_name'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'dictionary', 'children': ['204']},{'id': '204', 'type': 'pair', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'probe_name'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'probe_instance'},{'id': '207', 'type': 'return_statement', 'children': ['208']},{'id': '208', 'type': 'expression_list', 'children': ['209', '210', '211']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'updated_probes'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'loaded_failed'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'updated_instruments'}
def load_and_append(probe_dict, probes, instruments={}): loaded_failed = {} updated_probes = {} updated_probes.update(probes) updated_instruments = {} updated_instruments.update(instruments) new_instruments = list(set(probe_dict.keys())-set(probes.keys())) if new_instruments != []: updated_instruments, failed = Instrument.load_and_append({instrument_name: instrument_name for instrument_name in new_instruments}, instruments) if failed != []: for failed_instrument in set(failed) - set(instruments.keys()): for probe_name in probe_dict[failed_instrument]: loaded_failed[probe_name] = ValueError('failed to load instrument {:s} already exists. Did not load!'.format(failed_instrument)) del probe_dict[failed_instrument] for instrument_name, probe_names in probe_dict.items(): if not instrument_name in updated_probes: updated_probes.update({instrument_name:{}}) for probe_name in probe_names.split(','): if probe_name in updated_probes[instrument_name]: loaded_failed[probe_name] = ValueError('failed to load probe {:s} already exists. Did not load!'.format(probe_name)) else: probe_instance = Probe(updated_instruments[instrument_name], probe_name) updated_probes[instrument_name].update({probe_name: probe_instance}) return updated_probes, loaded_failed, updated_instruments
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_line'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'search_file'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'return_string'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'case_sens'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '16']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'''Return the first line containing a set of strings in a file.\n If return_string is False, we just return whether such a line\n was found. If case_sens is False, the search is case\n insensitive.\n '''"},{'id': '16', 'type': 'if_statement', 'children': ['17', '25', '122']},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'search_file'},{'id': '25', 'type': 'block', 'children': ['26', '42', '58']},{'id': '26', 'type': 'if_statement', 'children': ['27', '36']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': '=='},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "''"},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '40', 'type': 'list', 'children': ['41'], 'value': '[search_string]'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '42', 'type': 'if_statement', 'children': ['43', '45']},{'id': '43', 'type': 'not_operator', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'case_sens'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '55']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'for_in_clause', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '58', 'type': 'with_statement', 'children': ['59', '68']},{'id': '59', 'type': 'with_clause', 'children': ['60']},{'id': '60', 'type': 'with_item', 'children': ['61']},{'id': '61', 'type': 'as_pattern', 'children': ['62', '66']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'search_file'},{'id': '66', 'type': 'as_pattern_target', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '68', 'type': 'block', 'children': ['69', '101']},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'fp'},{'id': '72', 'type': 'block', 'children': ['73', '84']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'query_line'},{'id': '76', 'type': 'conditional_expression', 'children': ['77', '78', '79'], 'value': 'if'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'case_sens'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'if_statement', 'children': ['85', '95']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'list_comprehension', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'in'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'query_line'},{'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'conditional_expression', 'children': ['98', '99', '100'], 'value': 'if'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'return_string'},{'id': '100', 'type': 'True', 'children': []},{'id': '101', 'type': 'if_statement', 'children': ['102', '103', '118']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'return_string'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'raise_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '%'},{'id': '109', 'type': 'string', 'children': [], 'value': "'%s not found in %s'"},{'id': '110', 'type': 'tuple', 'children': ['111', '117']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': "' & '"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'search_string'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'search_file'},{'id': '118', 'type': 'else_clause', 'children': ['119']},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'False', 'children': []},{'id': '122', 'type': 'else_clause', 'children': ['123']},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'raise_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '%'},{'id': '129', 'type': 'string', 'children': [], 'value': "'%s file does not exist'"},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'search_file'}
def _get_line(self, search_string, search_file, return_string=True, case_sens=True): '''Return the first line containing a set of strings in a file. If return_string is False, we just return whether such a line was found. If case_sens is False, the search is case insensitive. ''' if os.path.isfile(search_file): if type(search_string) == type(''): search_string = [search_string] if not case_sens: search_string = [i.lower() for i in search_string] with open(search_file) as fp: for line in fp: query_line = line if case_sens else line.lower() if all([i in query_line for i in search_string]): return line if return_string else True if return_string: raise Exception('%s not found in %s'%(' & '.join(search_string), search_file)) else: return False else: raise Exception('%s file does not exist'%search_file)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'action_remove'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '7', 'type': 'block', 'children': ['8', '25', '40', '51', '62', '73', '83', '95', '119', '127', '186', '199', '207', '247']},{'id': '8', 'type': 'if_statement', 'children': ['9', '15']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'allow_remove'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'raise_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'SitecatsSecurityException'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '%'},{'id': '21', 'type': 'string', 'children': [], 'value': "'`action_remove()` is not supported by parent `%s`category.'"},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'category_id'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'POST'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'category_id'"},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'if_statement', 'children': ['41', '43']},{'id': '41', 'type': 'not_operator', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'category_id'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'raise_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'SitecatsSecurityException'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'},{'id': '49', 'type': 'string', 'children': [], 'value': "'Unsupported `category_id` value - `%s` - is passed to `action_remove()`.'"},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'category_id'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '54', 'type': 'call', 'children': ['55', '60']},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_cache'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_category_by_id'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'category_id'},{'id': '62', 'type': 'if_statement', 'children': ['63', '65']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'SitecatsSecurityException'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '%'},{'id': '71', 'type': 'string', 'children': [], 'value': "'Unable to get `%s` category in `action_remove()`.'"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'category_id'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'cat_ident'},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '80'], 'value': 'or'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'is_locked'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'raise_statement', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'SitecatsSecurityException'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '%'},{'id': '93', 'type': 'string', 'children': [], 'value': "'`action_remove()` is not supported by `%s` category.'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'cat_ident'},{'id': '95', 'type': 'if_statement', 'children': ['96', '105']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '100'], 'value': '!='},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_id'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'raise_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'SitecatsSecurityException'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'binary_operator', 'children': ['111', '114'], 'value': '%'},{'id': '111', 'type': 'concatenated_string', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'`action_remove()` is unable to remove `%s`: '"},{'id': '113', 'type': 'string', 'children': [], 'value': "'not a child of parent `%s` category.'"},{'id': '114', 'type': 'tuple', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'cat_ident'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'min_num'},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'min_num'},{'id': '127', 'type': 'function_definition', 'children': ['128', '129', '131']},{'id': '128', 'type': 'function_name', 'children': [], 'value': 'check_min_num'},{'id': '129', 'type': 'parameters', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'if_statement', 'children': ['133', '142']},{'id': '133', 'type': 'boolean_operator', 'children': ['134', '137'], 'value': 'and'},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'is'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'min_num'},{'id': '136', 'type': 'None', 'children': []},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '141'], 'value': '<'},{'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '-'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'min_num'},{'id': '142', 'type': 'block', 'children': ['143', '152', '181']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'subcats_str'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'ungettext_lazy'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151']},{'id': '149', 'type': 'string', 'children': [], 'value': "'subcategory'"},{'id': '150', 'type': 'string', 'children': [], 'value': "'subcategories'"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'min_num'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '162'], 'value': '%'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'concatenated_string', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': '\'Unable to remove "%(target_category)s" category from "%(parent_category)s": \''},{'id': '161', 'type': 'string', 'children': [], 'value': "'parent category requires at least %(num)s %(subcats_str)s.'"},{'id': '162', 'type': 'dictionary', 'children': ['163', '168', '175', '178']},{'id': '163', 'type': 'pair', 'children': ['164', '165']},{'id': '164', 'type': 'string', 'children': [], 'value': "'target_category'"},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '168', 'type': 'pair', 'children': ['169', '170']},{'id': '169', 'type': 'string', 'children': [], 'value': "'parent_category'"},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'get_title'},{'id': '174', 'type': 'argument_list', 'children': []},{'id': '175', 'type': 'pair', 'children': ['176', '177']},{'id': '176', 'type': 'string', 'children': [], 'value': "'num'"},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'min_num'},{'id': '178', 'type': 'pair', 'children': ['179', '180']},{'id': '179', 'type': 'string', 'children': [], 'value': "'subcats_str'"},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'subcats_str'},{'id': '181', 'type': 'raise_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'SitecatsValidationError'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'child_ids'},{'id': '189', 'type': 'call', 'children': ['190', '195']},{'id': '190', 'type': 'attribute', 'children': ['191', '194']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'get_cache'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'get_child_ids'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'check_min_num'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'child_ids'},{'id': '207', 'type': 'if_statement', 'children': ['208', '213', '220']},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '212'], 'value': 'is'},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '212', 'type': 'None', 'children': []},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'delete'},{'id': '219', 'type': 'argument_list', 'children': []},{'id': '220', 'type': 'else_clause', 'children': ['221']},{'id': '221', 'type': 'block', 'children': ['222', '238']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'check_min_num'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '237']},{'id': '227', 'type': 'attribute', 'children': ['228', '236']},{'id': '228', 'type': 'call', 'children': ['229', '234']},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'get_ties_for_categories_qs'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'child_ids'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '245']},{'id': '240', 'type': 'attribute', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'remove_from_category'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '247', 'type': 'return_statement', 'children': ['248']},{'id': '248', 'type': 'True', 'children': []}
def action_remove(cls, request, category_list): if not category_list.editor.allow_remove: raise SitecatsSecurityException( '`action_remove()` is not supported by parent `%s`category.' % category_list.alias) category_id = int(request.POST.get('category_id', 0)) if not category_id: raise SitecatsSecurityException( 'Unsupported `category_id` value - `%s` - is passed to `action_remove()`.' % category_id) category = get_cache().get_category_by_id(category_id) if not category: raise SitecatsSecurityException('Unable to get `%s` category in `action_remove()`.' % category_id) cat_ident = category.alias or category.id if category.is_locked: raise SitecatsSecurityException('`action_remove()` is not supported by `%s` category.' % cat_ident) if category.parent_id != category_list.get_id(): raise SitecatsSecurityException( '`action_remove()` is unable to remove `%s`: ' 'not a child of parent `%s` category.' % (cat_ident, category_list.alias) ) min_num = category_list.editor.min_num def check_min_num(num): if min_num is not None and num-1 < min_num: subcats_str = ungettext_lazy('subcategory', 'subcategories', min_num) error_msg = _( 'Unable to remove "%(target_category)s" category from "%(parent_category)s": ' 'parent category requires at least %(num)s %(subcats_str)s.' ) % { 'target_category': category.title, 'parent_category': category_list.get_title(), 'num': min_num, 'subcats_str': subcats_str } raise SitecatsValidationError(error_msg) child_ids = get_cache().get_child_ids(category_list.alias) check_min_num(len(child_ids)) if category_list.obj is None: category.delete() else: check_min_num(category_list.obj.get_ties_for_categories_qs(child_ids).count()) category_list.obj.remove_from_category(category) return True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'action_add'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '7', 'type': 'block', 'children': ['8', '25', '41', '52', '95', '154', '158', '330']},{'id': '8', 'type': 'if_statement', 'children': ['9', '15']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'allow_add'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'raise_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'SitecatsSecurityException'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '%'},{'id': '21', 'type': 'string', 'children': [], 'value': "'`action_add()` is not supported by `%s` category.'"},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '28', 'type': 'call', 'children': ['29', '40']},{'id': '29', 'type': 'attribute', 'children': ['30', '39']},{'id': '30', 'type': 'call', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'POST'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'category_title'"},{'id': '38', 'type': 'string', 'children': [], 'value': "''"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'if_statement', 'children': ['42', '44']},{'id': '42', 'type': 'not_operator', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'raise_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'SitecatsSecurityException'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '%'},{'id': '50', 'type': 'string', 'children': [], 'value': "'Unsupported `category_title` value - `%s` - is passed to `action_add()`.'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '52', 'type': 'if_statement', 'children': ['53', '60', '66']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '59'], 'value': 'is'},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'category_separator'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '64', 'type': 'list', 'children': ['65'], 'value': '[titles]'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '71', 'type': 'list_comprehension', 'children': ['72', '77', '89']},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'category_separator'},{'id': '89', 'type': 'if_clause', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'function_definition', 'children': ['96', '97', '101']},{'id': '96', 'type': 'function_name', 'children': [], 'value': 'check_max_num'},{'id': '97', 'type': 'parameters', 'children': ['98', '99', '100']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'category_title'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'if_statement', 'children': ['103', '112']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '107'], 'value': 'and'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '106', 'type': 'None', 'children': []},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '>'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '112', 'type': 'block', 'children': ['113', '122', '149']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'subcats_str'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ungettext_lazy'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121']},{'id': '119', 'type': 'string', 'children': [], 'value': "'subcategory'"},{'id': '120', 'type': 'string', 'children': [], 'value': "'subcategories'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '132'], 'value': '%'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'concatenated_string', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': '\'Unable to add "%(target_category)s" category into "%(parent_category)s": \''},{'id': '131', 'type': 'string', 'children': [], 'value': "'parent category can have at most %(num)s %(subcats_str)s.'"},{'id': '132', 'type': 'dictionary', 'children': ['133', '136', '143', '146']},{'id': '133', 'type': 'pair', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': "'target_category'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'category_title'},{'id': '136', 'type': 'pair', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'parent_category'"},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'get_title'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'pair', 'children': ['144', '145']},{'id': '144', 'type': 'string', 'children': [], 'value': "'num'"},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '146', 'type': 'pair', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': "'subcats_str'"},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'subcats_str'},{'id': '149', 'type': 'raise_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'SitecatsValidationError'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'target_category'},{'id': '157', 'type': 'None', 'children': []},{'id': '158', 'type': 'for_statement', 'children': ['159', '160', '161']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'category_title'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'titles'},{'id': '161', 'type': 'block', 'children': ['162', '176', '187', '224', '232', '245', '293']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'get_cache'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'find_category'},{'id': '171', 'type': 'argument_list', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'category_title'},{'id': '176', 'type': 'if_statement', 'children': ['177', '184']},{'id': '177', 'type': 'boolean_operator', 'children': ['178', '179'], 'value': 'and'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '183'], 'value': 'is'},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '183', 'type': 'None', 'children': []},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'return_statement', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '187', 'type': 'if_statement', 'children': ['188', '197']},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '191'], 'value': 'and'},{'id': '189', 'type': 'not_operator', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '191', 'type': 'not_operator', 'children': ['192']},{'id': '192', 'type': 'attribute', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'allow_new'},{'id': '197', 'type': 'block', 'children': ['198', '219']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '208'], 'value': '%'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'concatenated_string', 'children': ['206', '207']},{'id': '206', 'type': 'string', 'children': [], 'value': '\'Unable to create a new "%(new_category)s" category inside of "%(parent_category)s": \''},{'id': '207', 'type': 'string', 'children': [], 'value': "'parent category does not support this action.'"},{'id': '208', 'type': 'dictionary', 'children': ['209', '212']},{'id': '209', 'type': 'pair', 'children': ['210', '211']},{'id': '210', 'type': 'string', 'children': [], 'value': "'new_category'"},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'category_title'},{'id': '212', 'type': 'pair', 'children': ['213', '214']},{'id': '213', 'type': 'string', 'children': [], 'value': "'parent_category'"},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'get_title'},{'id': '218', 'type': 'argument_list', 'children': []},{'id': '219', 'type': 'raise_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'SitecatsNewCategoryException'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'error_msg'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '227', 'type': 'attribute', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'editor'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'child_ids'},{'id': '235', 'type': 'call', 'children': ['236', '241']},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'get_cache'},{'id': '239', 'type': 'argument_list', 'children': []},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'get_child_ids'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'alias'},{'id': '245', 'type': 'if_statement', 'children': ['246', '248', '287']},{'id': '246', 'type': 'not_operator', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '248', 'type': 'block', 'children': ['249', '266']},{'id': '249', 'type': 'if_statement', 'children': ['250', '255']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '254'], 'value': 'is'},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '254', 'type': 'None', 'children': []},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'check_max_num'},{'id': '259', 'type': 'argument_list', 'children': ['260', '264', '265']},{'id': '260', 'type': 'call', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'child_ids'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'category_title'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'target_category'},{'id': '269', 'type': 'call', 'children': ['270', '275']},{'id': '270', 'type': 'attribute', 'children': ['271', '274']},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'get_category_model'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '275', 'type': 'argument_list', 'children': ['276', '277', '280']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'category_title'},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'get_category_model'},{'id': '286', 'type': 'argument_list', 'children': []},{'id': '287', 'type': 'else_clause', 'children': ['288']},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'target_category'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '293', 'type': 'if_statement', 'children': ['294', '299']},{'id': '294', 'type': 'comparison_operator', 'children': ['295', '298'], 'value': 'is'},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '298', 'type': 'None', 'children': []},{'id': '299', 'type': 'block', 'children': ['300', '318']},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'call', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'check_max_num'},{'id': '303', 'type': 'argument_list', 'children': ['304', '316', '317']},{'id': '304', 'type': 'call', 'children': ['305', '315']},{'id': '305', 'type': 'attribute', 'children': ['306', '314']},{'id': '306', 'type': 'call', 'children': ['307', '312']},{'id': '307', 'type': 'attribute', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'get_ties_for_categories_qs'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'child_ids'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '315', 'type': 'argument_list', 'children': []},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'max_num'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'category_title'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '325']},{'id': '320', 'type': 'attribute', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'category_list'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'add_to_category'},{'id': '325', 'type': 'argument_list', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'target_category'},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '330', 'type': 'return_statement', 'children': ['331']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'target_category'}
def action_add(cls, request, category_list): if not category_list.editor.allow_add: raise SitecatsSecurityException('`action_add()` is not supported by `%s` category.' % category_list.alias) titles = request.POST.get('category_title', '').strip() if not titles: raise SitecatsSecurityException( 'Unsupported `category_title` value - `%s` - is passed to `action_add()`.' % titles) if category_list.editor.category_separator is None: titles = [titles] else: titles = [ title.strip() for title in titles.split(category_list.editor.category_separator) if title.strip() ] def check_max_num(num, max_num, category_title): if max_num is not None and num+1 > max_num: subcats_str = ungettext_lazy('subcategory', 'subcategories', max_num) error_msg = _( 'Unable to add "%(target_category)s" category into "%(parent_category)s": ' 'parent category can have at most %(num)s %(subcats_str)s.' ) % { 'target_category': category_title, 'parent_category': category_list.get_title(), 'num': max_num, 'subcats_str': subcats_str } raise SitecatsValidationError(error_msg) target_category = None for category_title in titles: exists = get_cache().find_category(category_list.alias, category_title) if exists and category_list.obj is None: return exists if not exists and not category_list.editor.allow_new: error_msg = _( 'Unable to create a new "%(new_category)s" category inside of "%(parent_category)s": ' 'parent category does not support this action.' ) % { 'new_category': category_title, 'parent_category': category_list.get_title() } raise SitecatsNewCategoryException(error_msg) max_num = category_list.editor.max_num child_ids = get_cache().get_child_ids(category_list.alias) if not exists: if category_list.obj is None: check_max_num(len(child_ids), max_num, category_title) target_category = get_category_model().add( category_title, request.user, parent=category_list.get_category_model() ) else: target_category = exists if category_list.obj is not None: check_max_num(category_list.obj.get_ties_for_categories_qs(child_ids).count(), max_num, category_title) category_list.obj.add_to_category(target_category, request.user) return target_category
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'verify'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '24', '35', '46', '68', '92', '106', '128', '140', '161', '174', '188', '198', '210', '220', '226', '234', '263']},{'id': '16', 'type': 'if_statement', 'children': ['17', '21']},{'id': '17', 'type': 'not_operator', 'children': ['18']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'in'},{'id': '19', 'type': 'string', 'children': [], 'value': "'authorization'"},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'auth_type'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'auth_params'},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'parse_authorization_header'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '34', 'type': 'string', 'children': [], 'value': "'authorization'"},{'id': '35', 'type': 'if_statement', 'children': ['36', '43']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '42'], 'value': '!='},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'auth_type'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'string', 'children': [], 'value': "'signature'"},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'False', 'children': []},{'id': '46', 'type': 'for_statement', 'children': ['47', '48', '52']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '48', 'type': 'tuple', 'children': ['49', '50', '51']},{'id': '49', 'type': 'string', 'children': [], 'value': "'algorithm'"},{'id': '50', 'type': 'string', 'children': [], 'value': "'keyId'"},{'id': '51', 'type': 'string', 'children': [], 'value': "'signature'"},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'not'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'auth_params'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'VerifierException'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': '"Unsupported HTTP signature, missing \'{}\'"'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'auth_headers'},{'id': '71', 'type': 'call', 'children': ['72', '91']},{'id': '72', 'type': 'attribute', 'children': ['73', '90']},{'id': '73', 'type': 'call', 'children': ['74', '89']},{'id': '74', 'type': 'attribute', 'children': ['75', '88']},{'id': '75', 'type': 'call', 'children': ['76', '87']},{'id': '76', 'type': 'attribute', 'children': ['77', '86']},{'id': '77', 'type': '()', 'children': ['78']},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '85'], 'value': 'or'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'auth_params'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "'headers'"},{'id': '85', 'type': 'string', 'children': [], 'value': "'date'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'missing_reqd'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '102'], 'value': '-'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_required_headers'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'auth_headers'},{'id': '106', 'type': 'if_statement', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'missing_reqd'},{'id': '108', 'type': 'block', 'children': ['109', '118']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'error_headers'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': "', '"},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'missing_reqd'},{'id': '118', 'type': 'raise_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'VerifierException'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': "'One or more required headers not provided: {}'"},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'error_headers'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '133']},{'id': '130', 'type': 'pattern_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'key_id'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'algo'},{'id': '133', 'type': 'expression_list', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'auth_params'},{'id': '136', 'type': 'string', 'children': [], 'value': "'keyId'"},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'auth_params'},{'id': '139', 'type': 'string', 'children': [], 'value': "'algorithm'"},{'id': '140', 'type': 'if_statement', 'children': ['141', '150']},{'id': '141', 'type': 'not_operator', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_handlers'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'supports'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'algo'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'raise_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'VerifierException'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': '"Unsupported HTTP signature algorithm \'{}\'"'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'algo'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'pubkey'},{'id': '164', 'type': 'await', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': '_key_finder'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'find_key'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'key_id'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'algo'},{'id': '174', 'type': 'if_statement', 'children': ['175', '177']},{'id': '175', 'type': 'not_operator', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'pubkey'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'raise_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'VerifierException'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'string', 'children': [], 'value': '"Cannot locate public key for \'{}\'"'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'key_id'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'LOGGER'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195', '196', '197']},{'id': '194', 'type': 'string', 'children': [], 'value': '"Got %s public key for \'%s\': %s"'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'algo'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'key_id'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'pubkey'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '201', 'type': 'call', 'children': ['202', '207']},{'id': '202', 'type': 'attribute', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': '_handlers'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'create_verifier'},{'id': '207', 'type': 'argument_list', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'algo'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'pubkey'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'generate_message'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217', '218', '219']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'auth_headers'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'auth_params'},{'id': '225', 'type': 'string', 'children': [], 'value': "'signature'"},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'raw_signature'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'decode_string'},{'id': '231', 'type': 'argument_list', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '233', 'type': 'string', 'children': [], 'value': "'base64'"},{'id': '234', 'type': 'if_statement', 'children': ['235', '242']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'verify'},{'id': '239', 'type': 'argument_list', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'raw_signature'},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'return_statement', 'children': ['244']},{'id': '244', 'type': 'dictionary', 'children': ['245', '248', '251', '254', '257', '260']},{'id': '245', 'type': 'pair', 'children': ['246', '247']},{'id': '246', 'type': 'string', 'children': [], 'value': "'verified'"},{'id': '247', 'type': 'True', 'children': []},{'id': '248', 'type': 'pair', 'children': ['249', '250']},{'id': '249', 'type': 'string', 'children': [], 'value': "'algorithm'"},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'algo'},{'id': '251', 'type': 'pair', 'children': ['252', '253']},{'id': '252', 'type': 'string', 'children': [], 'value': "'headers'"},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'auth_headers'},{'id': '254', 'type': 'pair', 'children': ['255', '256']},{'id': '255', 'type': 'string', 'children': [], 'value': "'keyId'"},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'key_id'},{'id': '257', 'type': 'pair', 'children': ['258', '259']},{'id': '258', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'pubkey'},{'id': '260', 'type': 'pair', 'children': ['261', '262']},{'id': '261', 'type': 'string', 'children': [], 'value': "'signature'"},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '263', 'type': 'raise_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'VerifierException'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'string', 'children': [], 'value': '"Signature could not be verified for keyId \'{}\'"'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'key_id'}
async def verify(self, headers: Mapping, method=None, path=None): if not 'authorization' in headers: return False auth_type, auth_params = parse_authorization_header(headers['authorization']) if auth_type.lower() != 'signature': return False for param in ('algorithm', 'keyId', 'signature'): if param not in auth_params: raise VerifierException("Unsupported HTTP signature, missing '{}'".format(param)) auth_headers = (auth_params.get('headers') or 'date').lower().strip().split() missing_reqd = set(self._required_headers) - set(auth_headers) if missing_reqd: error_headers = ', '.join(missing_reqd) raise VerifierException( 'One or more required headers not provided: {}'.format(error_headers)) key_id, algo = auth_params['keyId'], auth_params['algorithm'] if not self._handlers.supports(algo): raise VerifierException("Unsupported HTTP signature algorithm '{}'".format(algo)) pubkey = await self._key_finder.find_key(key_id, algo) if not pubkey: raise VerifierException("Cannot locate public key for '{}'".format(key_id)) LOGGER.debug("Got %s public key for '%s': %s", algo, key_id, pubkey) handler = self._handlers.create_verifier(algo, pubkey) message = generate_message(auth_headers, headers, method, path) signature = auth_params['signature'] raw_signature = decode_string(signature, 'base64') if handler.verify(message, raw_signature): return { 'verified': True, 'algorithm': algo, 'headers': auth_headers, 'keyId': key_id, 'key': pubkey, 'signature': signature } raise VerifierException("Signature could not be verified for keyId '{}'".format(key_id))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_config'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '7', 'type': 'block', 'children': ['8', '12', '41', '72', '103', '119', '150', '181', '214', '245', '261', '277', '308', '332', '366']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'in'},{'id': '14', 'type': 'string', 'children': [], 'value': "'stdopt'"},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '16', 'type': 'block', 'children': ['17', '26', '35']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'stdopt'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'stdopt'"},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '29', 'type': '()', 'children': ['30']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': '!='},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'stdopt'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'stdopt'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'stdopt'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'stdopt'},{'id': '41', 'type': 'if_statement', 'children': ['42', '45']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'},{'id': '43', 'type': 'string', 'children': [], 'value': "'attachopt'"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '45', 'type': 'block', 'children': ['46', '55', '66']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'attachopt'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'attachopt'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '58', 'type': 'boolean_operator', 'children': ['59', '60'], 'value': 'or'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '60', 'type': '()', 'children': ['61']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '!='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'attachopt'},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'attachopt'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'attachopt'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'attachopt'},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'},{'id': '74', 'type': 'string', 'children': [], 'value': "'attachvalue'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '76', 'type': 'block', 'children': ['77', '86', '97']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'attachvalue'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'string', 'children': [], 'value': "'attachvalue'"},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '89', 'type': 'boolean_operator', 'children': ['90', '91'], 'value': 'or'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '91', 'type': '()', 'children': ['92']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '!='},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'attachvalue'},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'attachvalue'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'attachvalue'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'attachvalue'},{'id': '103', 'type': 'if_statement', 'children': ['104', '107']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'in'},{'id': '105', 'type': 'string', 'children': [], 'value': "'auto2dashes'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'auto2dashes'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'string', 'children': [], 'value': "'auto2dashes'"},{'id': '119', 'type': 'if_statement', 'children': ['120', '123']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'in'},{'id': '121', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '123', 'type': 'block', 'children': ['124', '133', '144']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '136', 'type': 'boolean_operator', 'children': ['137', '138'], 'value': 'or'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '138', 'type': '()', 'children': ['139']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '!='},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'in'},{'id': '152', 'type': 'string', 'children': [], 'value': "'help'"},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '154', 'type': 'block', 'children': ['155', '166']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'string', 'children': [], 'value': "'help'"},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_set_or_remove_extra_handler'},{'id': '171', 'type': 'argument_list', 'children': ['172', '175', '178']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '175', 'type': 'tuple', 'children': ['176', '177']},{'id': '176', 'type': 'string', 'children': [], 'value': "'--help'"},{'id': '177', 'type': 'string', 'children': [], 'value': "'-h'"},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'help_handler'},{'id': '181', 'type': 'if_statement', 'children': ['182', '185']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'in'},{'id': '183', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '185', 'type': 'block', 'children': ['186', '197']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': '_set_or_remove_extra_handler'},{'id': '202', 'type': 'argument_list', 'children': ['203', '208', '211']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '207'], 'value': 'is'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '207', 'type': 'None', 'children': []},{'id': '208', 'type': 'tuple', 'children': ['209', '210']},{'id': '209', 'type': 'string', 'children': [], 'value': "'--version'"},{'id': '210', 'type': 'string', 'children': [], 'value': "'-v'"},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'version_handler'},{'id': '214', 'type': 'if_statement', 'children': ['215', '218']},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': 'in'},{'id': '216', 'type': 'string', 'children': [], 'value': "'case_sensitive'"},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '218', 'type': 'block', 'children': ['219', '228', '239']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'string', 'children': [], 'value': "'case_sensitive'"},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '231', 'type': 'boolean_operator', 'children': ['232', '233'], 'value': 'or'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '233', 'type': '()', 'children': ['234']},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '236'], 'value': '!='},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'case_sensitive'},{'id': '245', 'type': 'if_statement', 'children': ['246', '249']},{'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': 'in'},{'id': '247', 'type': 'string', 'children': [], 'value': "'optionsfirst'"},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'options_first'},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'string', 'children': [], 'value': "'optionsfirst'"},{'id': '261', 'type': 'if_statement', 'children': ['262', '265']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': 'in'},{'id': '263', 'type': 'string', 'children': [], 'value': "'appearedonly'"},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'appeared_only'},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'string', 'children': [], 'value': "'appearedonly'"},{'id': '277', 'type': 'if_statement', 'children': ['278', '281']},{'id': '278', 'type': 'comparison_operator', 'children': ['279', '280'], 'value': 'in'},{'id': '279', 'type': 'string', 'children': [], 'value': "'namedoptions'"},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '281', 'type': 'block', 'children': ['282', '291', '302']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'namedoptions'},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'string', 'children': [], 'value': "'namedoptions'"},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '294', 'type': 'boolean_operator', 'children': ['295', '296'], 'value': 'or'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '296', 'type': '()', 'children': ['297']},{'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': '!='},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'namedoptions'},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'namedoptions'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'namedoptions'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'namedoptions'},{'id': '308', 'type': 'if_statement', 'children': ['309', '312']},{'id': '309', 'type': 'comparison_operator', 'children': ['310', '311'], 'value': 'in'},{'id': '310', 'type': 'string', 'children': [], 'value': "'extra'"},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '320']},{'id': '315', 'type': 'attribute', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '324', 'type': 'identifier', 'children': [], 'value': '_formal_extra'},{'id': '325', 'type': 'argument_list', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'string', 'children': [], 'value': "'extra'"},{'id': '332', 'type': 'if_statement', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'raise_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'binary_operator', 'children': ['340', '341'], 'value': '%'},{'id': '340', 'type': 'string', 'children': [], 'value': "'`%s` %s not accepted key argument%s'"},{'id': '341', 'type': 'tuple', 'children': ['342', '348', '357']},{'id': '342', 'type': 'call', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'string', 'children': [], 'value': "'`, `'"},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '348', 'type': 'conditional_expression', 'children': ['349', '350', '356'], 'value': 'if'},{'id': '349', 'type': 'string', 'children': [], 'value': "'is'"},{'id': '350', 'type': 'comparison_operator', 'children': ['351', '355'], 'value': '=='},{'id': '351', 'type': 'call', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '353', 'type': 'argument_list', 'children': ['354']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '355', 'type': 'integer', 'children': [], 'value': '1'},{'id': '356', 'type': 'string', 'children': [], 'value': "'are'"},{'id': '357', 'type': 'conditional_expression', 'children': ['358', '359', '365'], 'value': 'if'},{'id': '358', 'type': 'string', 'children': [], 'value': "''"},{'id': '359', 'type': 'comparison_operator', 'children': ['360', '364'], 'value': '=='},{'id': '360', 'type': 'call', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '364', 'type': 'integer', 'children': [], 'value': '1'},{'id': '365', 'type': 'string', 'children': [], 'value': "'s'"},{'id': '366', 'type': 'if_statement', 'children': ['367', '374']},{'id': '367', 'type': 'boolean_operator', 'children': ['368', '373'], 'value': 'and'},{'id': '368', 'type': 'comparison_operator', 'children': ['369', '372'], 'value': 'is'},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '372', 'type': 'None', 'children': []},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'reinit'},{'id': '374', 'type': 'block', 'children': ['375', '384']},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'call', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'concatenated_string', 'children': ['382', '383']},{'id': '382', 'type': 'string', 'children': [], 'value': "'You changed the config that requires re-initialized'"},{'id': '383', 'type': 'string', 'children': [], 'value': "' `Docpie` object. Create a new one instead'"},{'id': '384', 'type': 'expression_statement', 'children': ['385']},{'id': '385', 'type': 'call', 'children': ['386', '389']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '388', 'type': 'identifier', 'children': [], 'value': '_init'},{'id': '389', 'type': 'argument_list', 'children': []}
def set_config(self, **config): reinit = False if 'stdopt' in config: stdopt = config.pop('stdopt') reinit = (stdopt != self.stdopt) self.stdopt = stdopt if 'attachopt' in config: attachopt = config.pop('attachopt') reinit = reinit or (attachopt != self.attachopt) self.attachopt = attachopt if 'attachvalue' in config: attachvalue = config.pop('attachvalue') reinit = reinit or (attachvalue != self.attachvalue) self.attachvalue = attachvalue if 'auto2dashes' in config: self.auto2dashes = config.pop('auto2dashes') if 'name' in config: name = config.pop('name') reinit = reinit or (name != self.name) self.name = name if 'help' in config: self.help = config.pop('help') self._set_or_remove_extra_handler( self.help, ('--help', '-h'), self.help_handler) if 'version' in config: self.version = config.pop('version') self._set_or_remove_extra_handler( self.version is not None, ('--version', '-v'), self.version_handler) if 'case_sensitive' in config: case_sensitive = config.pop('case_sensitive') reinit = reinit or (case_sensitive != self.case_sensitive) self.case_sensitive = case_sensitive if 'optionsfirst' in config: self.options_first = config.pop('optionsfirst') if 'appearedonly' in config: self.appeared_only = config.pop('appearedonly') if 'namedoptions' in config: namedoptions = config.pop('namedoptions') reinit = reinit or (namedoptions != self.namedoptions) self.namedoptions = namedoptions if 'extra' in config: self.extra.update(self._formal_extra(config.pop('extra'))) if config: raise ValueError( '`%s` %s not accepted key argument%s' % ( '`, `'.join(config), 'is' if len(config) == 1 else 'are', '' if len(config) == 1 else 's' )) if self.doc is not None and reinit: logger.warning( 'You changed the config that requires re-initialized' ' `Docpie` object. Create a new one instead' ) self._init()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'preview'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '10', 'type': 'block', 'children': ['11', '17', '33', '38', '49', '54', '61', '66', '72', '94', '99', '110', '119', '132', '137', '196', '207', '216', '229', '234', '293', '304', '309']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '30']},{'id': '22', 'type': 'attribute', 'children': ['23', '29']},{'id': '23', 'type': '()', 'children': ['24']},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '%'},{'id': '25', 'type': 'string', 'children': [], 'value': "'[Quick preview of Docpie %s]'"},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_version'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'integer', 'children': [], 'value': '80'},{'id': '32', 'type': 'string', 'children': [], 'value': "'='"},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "' sections '"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'integer', 'children': [], 'value': '80'},{'id': '48', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'usage_text'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'option_sections'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'option_sections'},{'id': '72', 'type': 'if_statement', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'option_sections'},{'id': '74', 'type': 'block', 'children': ['75', '80']},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'option_sections'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "' str '"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'integer', 'children': [], 'value': '80'},{'id': '109', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '%'},{'id': '115', 'type': 'string', 'children': [], 'value': "'\\n[%s]\\n'"},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'usage_name'},{'id': '119', 'type': 'for_statement', 'children': ['120', '121', '124']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'usages'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '%'},{'id': '130', 'type': 'string', 'children': [], 'value': "' %s\\n'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'string', 'children': [], 'value': "'\\n[Options:]\\n\\n'"},{'id': '137', 'type': 'for_statement', 'children': ['138', '141', '148']},{'id': '138', 'type': 'pattern_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'sections'},{'id': '141', 'type': 'call', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '147', 'type': 'argument_list', 'children': []},{'id': '148', 'type': 'block', 'children': ['149', '170', '175', '180', '191']},{'id': '149', 'type': 'if_statement', 'children': ['150', '151', '162']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '151', 'type': 'block', 'children': ['152']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'full_title'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '%'},{'id': '156', 'type': 'string', 'children': [], 'value': "'%s %s'"},{'id': '157', 'type': 'tuple', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'option_name'},{'id': '162', 'type': 'else_clause', 'children': ['163']},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'full_title'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'option_name'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'full_title'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '180', 'type': 'for_statement', 'children': ['181', '182', '183']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sections'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '%'},{'id': '189', 'type': 'string', 'children': [], 'value': "' %s\\n'"},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'string', 'children': [], 'value': "' repr '"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'integer', 'children': [], 'value': '80'},{'id': '206', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '%'},{'id': '212', 'type': 'string', 'children': [], 'value': "'\\n[%s]\\n'"},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'usage_name'},{'id': '216', 'type': 'for_statement', 'children': ['217', '218', '221']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'usages'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '%'},{'id': '227', 'type': 'string', 'children': [], 'value': "' %r\\n'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'string', 'children': [], 'value': "'\\n[Options:]\\n\\n'"},{'id': '234', 'type': 'for_statement', 'children': ['235', '238', '245']},{'id': '235', 'type': 'pattern_list', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sections'},{'id': '238', 'type': 'call', 'children': ['239', '244']},{'id': '239', 'type': 'attribute', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '244', 'type': 'argument_list', 'children': []},{'id': '245', 'type': 'block', 'children': ['246', '267', '272', '277', '288']},{'id': '246', 'type': 'if_statement', 'children': ['247', '248', '259']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'full_title'},{'id': '252', 'type': 'binary_operator', 'children': ['253', '254'], 'value': '%'},{'id': '253', 'type': 'string', 'children': [], 'value': "'%s %s'"},{'id': '254', 'type': 'tuple', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'option_name'},{'id': '259', 'type': 'else_clause', 'children': ['260']},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'full_title'},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'option_name'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'full_title'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '277', 'type': 'for_statement', 'children': ['278', '279', '280']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'sections'},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'binary_operator', 'children': ['286', '287'], 'value': '%'},{'id': '286', 'type': 'string', 'children': [], 'value': "' %r\\n'"},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'each'},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'string', 'children': [], 'value': "' auto handlers '"},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '301', 'type': 'argument_list', 'children': ['302', '303']},{'id': '302', 'type': 'integer', 'children': [], 'value': '80'},{'id': '303', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '309', 'type': 'for_statement', 'children': ['310', '313', '320']},{'id': '310', 'type': 'pattern_list', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '313', 'type': 'call', 'children': ['314', '319']},{'id': '314', 'type': 'attribute', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '319', 'type': 'argument_list', 'children': []},{'id': '320', 'type': 'block', 'children': ['321']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'call', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'binary_operator', 'children': ['326', '327'], 'value': '%'},{'id': '326', 'type': 'string', 'children': [], 'value': "'%s %s\\n'"},{'id': '327', 'type': 'tuple', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'value'}
def preview(self, stream=sys.stdout): write = stream.write write(('[Quick preview of Docpie %s]' % self._version).center(80, '=')) write('\n') write(' sections '.center(80, '-')) write('\n') write(self.usage_text) write('\n') option_sections = self.option_sections if option_sections: write('\n') write('\n'.join(option_sections.values())) write('\n') write(' str '.center(80, '-')) write('\n[%s]\n' % self.usage_name) for each in self.usages: write(' %s\n' % each) write('\n[Options:]\n\n') for title, sections in self.options.items(): if title: full_title = '%s %s' % (title, self.option_name) else: full_title = self.option_name write(full_title) write('\n') for each in sections: write(' %s\n' % each) write('\n') write(' repr '.center(80, '-')) write('\n[%s]\n' % self.usage_name) for each in self.usages: write(' %r\n' % each) write('\n[Options:]\n\n') for title, sections in self.options.items(): if title: full_title = '%s %s' % (title, self.option_name) else: full_title = self.option_name write(full_title) write('\n') for each in sections: write(' %r\n' % each) write('\n') write(' auto handlers '.center(80, '-')) write('\n') for key, value in self.extra.items(): write('%s %s\n' % (key, value))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parts'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '16', '20', '24', '28', '38', '42', '110', '180', '207', '242', '251']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'max_upload_size'},{'id': '23', 'type': 'integer', 'children': [], 'value': '700000'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'base_part_size'},{'id': '27', 'type': 'integer', 'children': [], 'value': '118'},{'id': '28', 'type': 'if_statement', 'children': ['29', '33']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'replace_all'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'augmented_assignment', 'children': ['36', '37'], 'value': '+='},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'base_part_size'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'part_size'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'base_part_size'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '47']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '47', 'type': 'block', 'children': ['48', '88', '102']},{'id': '48', 'type': 'if_statement', 'children': ['49', '59']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '58'], 'value': '>='},{'id': '50', 'type': '()', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'part_size'},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'upserts_size'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'max_upload_size'},{'id': '59', 'type': 'block', 'children': ['60', '74', '80', '84']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'BatchPart'},{'id': '68', 'type': 'argument_list', 'children': ['69', '72', '73']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'replace_all'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '83', 'type': 'list', 'children': [], 'value': '[]'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'part_size'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'base_part_size'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '97']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '92', 'type': 'subscript', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'lower_val_to_val'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '97', 'type': 'subscript', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'augmented_assignment', 'children': ['104', '105'], 'value': '+='},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'part_size'},{'id': '105', 'type': 'subscript', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'upserts_size'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '110', 'type': 'for_statement', 'children': ['111', '112', '115']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '115', 'type': 'block', 'children': ['116', '157', '171']},{'id': '116', 'type': 'if_statement', 'children': ['117', '128']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '127'], 'value': '>='},{'id': '118', 'type': '()', 'children': ['119']},{'id': '119', 'type': 'binary_operator', 'children': ['120', '126'], 'value': '+'},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '+'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'part_size'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '126', 'type': 'integer', 'children': [], 'value': '4'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'max_upload_size'},{'id': '128', 'type': 'block', 'children': ['129', '143', '149', '153']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'BatchPart'},{'id': '137', 'type': 'argument_list', 'children': ['138', '141', '142']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'replace_all'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '152', 'type': 'list', 'children': [], 'value': '[]'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'part_size'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'base_part_size'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'dictionary', 'children': ['164']},{'id': '164', 'type': 'pair', 'children': ['165', '166']},{'id': '165', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '166', 'type': 'subscript', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'lower_val_to_val'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'augmented_assignment', 'children': ['173', '174'], 'value': '+='},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'part_size'},{'id': '174', 'type': 'binary_operator', 'children': ['175', '179'], 'value': '+'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '179', 'type': 'integer', 'children': [], 'value': '4'},{'id': '180', 'type': 'if_statement', 'children': ['181', '192']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '191'], 'value': '>'},{'id': '182', 'type': 'binary_operator', 'children': ['183', '187'], 'value': '+'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '191', 'type': 'integer', 'children': [], 'value': '0'},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'BatchPart'},{'id': '201', 'type': 'argument_list', 'children': ['202', '205', '206']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'replace_all'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'upserts'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'deletes'},{'id': '207', 'type': 'if_statement', 'children': ['208', '214']},{'id': '208', 'type': 'comparison_operator', 'children': ['209', '213'], 'value': '=='},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '213', 'type': 'integer', 'children': [], 'value': '0'},{'id': '214', 'type': 'block', 'children': ['215', '226']},{'id': '215', 'type': 'if_statement', 'children': ['216', '220']},{'id': '216', 'type': 'not_operator', 'children': ['217']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'replace_all'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'raise_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'string', 'children': [], 'value': '"Batch has no data, and \'replace_all\' is False"'},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'BatchPart'},{'id': '234', 'type': 'argument_list', 'children': ['235', '238', '241']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'replace_all'},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'list', 'children': [], 'value': '[]'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '250']},{'id': '244', 'type': 'attribute', 'children': ['245', '249']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '247', 'type': 'unary_operator', 'children': ['248'], 'value': '-'},{'id': '248', 'type': 'integer', 'children': [], 'value': '1'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'set_last_part'},{'id': '250', 'type': 'argument_list', 'children': []},{'id': '251', 'type': 'return_statement', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'parts'}
def parts(self): parts = [] upserts = dict() deletes = [] max_upload_size = 700000 base_part_size = 118 if not self.replace_all: base_part_size += 1 part_size = base_part_size for value in self.upserts: if (part_size + self.upserts_size[value]) >= max_upload_size: parts.append(BatchPart(self.replace_all, upserts, deletes)) upserts = dict() deletes = [] part_size = base_part_size upserts[self.lower_val_to_val[value]] = self.upserts[value] part_size += self.upserts_size[value] for value in self.deletes: if (part_size + len(value) + 4) >= max_upload_size: parts.append(BatchPart(self.replace_all, upserts, deletes)) upserts = dict() deletes = [] part_size = base_part_size deletes.append({'value': self.lower_val_to_val[value]}) part_size += len(value) + 4 if len(upserts) + len(deletes) > 0: parts.append(BatchPart(self.replace_all, upserts, deletes)) if len(parts) == 0: if not self.replace_all: raise ValueError("Batch has no data, and 'replace_all' is False") parts.append(BatchPart(self.replace_all, dict(), [])) parts[-1].set_last_part() return parts
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compare_versions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'version_a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'version_b'},{'id': '6', 'type': 'block', 'children': ['7', '16', '23', '55', '165']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14', '15']},{'id': '13', 'type': 'string', 'children': [], 'value': "'compare_versions(%s, %s)'"},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'version_a'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'version_b'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'version_a'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'version_b'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'a_eq_b'},{'id': '23', 'type': 'try_statement', 'children': ['24', '39']},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '30', 'type': 'expression_list', 'children': ['31', '35']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'version_a'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'version_b'},{'id': '39', 'type': 'except_clause', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'raise_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'RpmError'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'concatenated_string', 'children': ['49', '50']},{'id': '49', 'type': 'string', 'children': [], 'value': "'Could not compare {0} to '"},{'id': '50', 'type': 'string', 'children': [], 'value': "'{1}'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'version_a'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'version_b'},{'id': '55', 'type': 'while_statement', 'children': ['56', '69']},{'id': '56', 'type': 'boolean_operator', 'children': ['57', '63'], 'value': 'and'},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '62'], 'value': '!='},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '68'], 'value': '!='},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'block', 'children': ['70', '81', '87', '134', '150', '158']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79', '80']},{'id': '76', 'type': 'concatenated_string', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "'starting loop comparing %s '"},{'id': '78', 'type': 'string', 'children': [], 'value': "'to %s'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': '_check_leading'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '87', 'type': 'if_statement', 'children': ['88', '99', '116', '125']},{'id': '88', 'type': 'boolean_operator', 'children': ['89', '94'], 'value': 'and'},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '=='},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': '=='},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '103', 'type': 'argument_list', 'children': ['104', '113']},{'id': '104', 'type': 'lambda', 'children': ['105', '107']},{'id': '105', 'type': 'lambda_parameters', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'tuple', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '116', 'type': 'elif_clause', 'children': ['117', '122']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': '=='},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'return_statement', 'children': ['124']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'b_newer'},{'id': '125', 'type': 'elif_clause', 'children': ['126', '131']},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '=='},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'return_statement', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'a_newer'},{'id': '134', 'type': 'if_statement', 'children': ['135', '148']},{'id': '135', 'type': 'boolean_operator', 'children': ['136', '142'], 'value': 'or'},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '141'], 'value': '=='},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '141', 'type': 'integer', 'children': [], 'value': '0'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '147'], 'value': '=='},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'break_statement', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'block_res'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': '_get_block_result'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '158', 'type': 'if_statement', 'children': ['159', '162']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '!='},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'block_res'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'a_eq_b'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'return_statement', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'block_res'},{'id': '165', 'type': 'if_statement', 'children': ['166', '175', '185']},{'id': '166', 'type': 'comparison_operator', 'children': ['167', '171'], 'value': '=='},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '175', 'type': 'block', 'children': ['176', '183']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'string', 'children': [], 'value': "'versions are equal'"},{'id': '183', 'type': 'return_statement', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'a_eq_b'},{'id': '185', 'type': 'else_clause', 'children': ['186']},{'id': '186', 'type': 'block', 'children': ['187', '194']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'string', 'children': [], 'value': "'versions not equal'"},{'id': '194', 'type': 'return_statement', 'children': ['195']},{'id': '195', 'type': 'conditional_expression', 'children': ['196', '197', '206'], 'value': 'if'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'a_newer'},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '202'], 'value': '>'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'chars_a'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'chars_b'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'b_newer'}
def compare_versions(version_a, version_b): logger.debug('compare_versions(%s, %s)', version_a, version_b) if version_a == version_b: return a_eq_b try: chars_a, chars_b = list(version_a), list(version_b) except TypeError: raise RpmError('Could not compare {0} to ' '{1}'.format(version_a, version_b)) while len(chars_a) != 0 and len(chars_b) != 0: logger.debug('starting loop comparing %s ' 'to %s', chars_a, chars_b) _check_leading(chars_a, chars_b) if chars_a[0] == '~' and chars_b[0] == '~': map(lambda x: x.pop(0), (chars_a, chars_b)) elif chars_a[0] == '~': return b_newer elif chars_b[0] == '~': return a_newer if len(chars_a) == 0 or len(chars_b) == 0: break block_res = _get_block_result(chars_a, chars_b) if block_res != a_eq_b: return block_res if len(chars_a) == len(chars_b): logger.debug('versions are equal') return a_eq_b else: logger.debug('versions not equal') return a_newer if len(chars_a) > len(chars_b) else b_newer
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_compare_blocks'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'block_a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'block_b'},{'id': '6', 'type': 'block', 'children': ['7', '16', '62']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14', '15']},{'id': '13', 'type': 'string', 'children': [], 'value': "'_compare_blocks(%s, %s)'"},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'block_a'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'block_b'},{'id': '16', 'type': 'if_statement', 'children': ['17', '24']},{'id': '17', 'type': 'call', 'children': ['18', '23']},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'block_a'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'block', 'children': ['25', '31']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_trim_zeros'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'block_a'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'block_b'},{'id': '31', 'type': 'if_statement', 'children': ['32', '41']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '37'], 'value': '!='},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'block_a'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'block_b'},{'id': '41', 'type': 'block', 'children': ['42', '49']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'string', 'children': [], 'value': "'block lengths are not equal'"},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'conditional_expression', 'children': ['51', '52', '61'], 'value': 'if'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'a_newer'},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '57'], 'value': '>'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'block_a'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'block_b'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'b_newer'},{'id': '62', 'type': 'if_statement', 'children': ['63', '66', '76']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '=='},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'block_a'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'block_b'},{'id': '66', 'type': 'block', 'children': ['67', '74']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "'blocks are equal'"},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'a_eq_b'},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78', '85']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'string', 'children': [], 'value': "'blocks are not equal'"},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'conditional_expression', 'children': ['87', '88', '91'], 'value': 'if'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'a_newer'},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '>'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'block_a'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'block_b'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'b_newer'}
def _compare_blocks(block_a, block_b): logger.debug('_compare_blocks(%s, %s)', block_a, block_b) if block_a[0].isdigit(): _trim_zeros(block_a, block_b) if len(block_a) != len(block_b): logger.debug('block lengths are not equal') return a_newer if len(block_a) > len(block_b) else b_newer if block_a == block_b: logger.debug('blocks are equal') return a_eq_b else: logger.debug('blocks are not equal') return a_newer if block_a > block_b else b_newer
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'Find'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '7', 'type': 'block', 'children': ['8', '10', '75']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'string', 'children': [], 'value': "'''\n method for finding specific types of notation from nodes.\n will currently return the first one it encounters because this method's only really intended\n for some types of notation for which the exact value doesn't really\n matter.\n :param node_type: the type of node to look under\n :param item_type: the type of item (notation) being searched for\n :return: first item_type object encountered\n '''"},{'id': '10', 'type': 'if_statement', 'children': ['11', '16']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': '=='},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'OtherNodes'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DirectionNode'},{'id': '16', 'type': 'block', 'children': ['17', '33']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'GetChild'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '32'], 'value': '-'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '32', 'type': 'integer', 'children': [], 'value': '1'},{'id': '33', 'type': 'while_statement', 'children': ['34', '48']},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '38'], 'value': 'and'},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '41', 'type': 'argument_list', 'children': ['42', '47']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'GetItem'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '48', 'type': 'block', 'children': ['49', '66']},{'id': '49', 'type': 'if_statement', 'children': ['50', '63']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '60'], 'value': '=='},{'id': '51', 'type': 'attribute', 'children': ['52', '59']},{'id': '52', 'type': 'attribute', 'children': ['53', '58']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'GetItem'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '62', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'True', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'GetChild'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'if_statement', 'children': ['76', '81']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'OtherNodes'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ExpressionNode'},{'id': '81', 'type': 'block', 'children': ['82', '98']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'GetChild'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'binary_operator', 'children': ['91', '97'], 'value': '-'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '97', 'type': 'integer', 'children': [], 'value': '2'},{'id': '98', 'type': 'while_statement', 'children': ['99', '113']},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '103'], 'value': 'and'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'not_operator', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '106', 'type': 'argument_list', 'children': ['107', '112']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'GetItem'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '113', 'type': 'block', 'children': ['114', '131']},{'id': '114', 'type': 'if_statement', 'children': ['115', '128']},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '125'], 'value': '=='},{'id': '116', 'type': 'attribute', 'children': ['117', '124']},{'id': '117', 'type': 'attribute', 'children': ['118', '123']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'GetItem'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'item_type'},{'id': '127', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'return_statement', 'children': ['130']},{'id': '130', 'type': 'True', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'GetChild'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'integer', 'children': [], 'value': '0'}
def Find(self, node_type, item_type): ''' method for finding specific types of notation from nodes. will currently return the first one it encounters because this method's only really intended for some types of notation for which the exact value doesn't really matter. :param node_type: the type of node to look under :param item_type: the type of item (notation) being searched for :return: first item_type object encountered ''' if node_type == OtherNodes.DirectionNode: child = self.GetChild(len(self.children) - 1) while child is not None and not isinstance( child.GetItem(), item_type): if child.GetItem().__class__.__name__ == item_type.__name__: return True child = child.GetChild(0) if node_type == OtherNodes.ExpressionNode: child = self.GetChild(len(self.children) - 2) while child is not None and not isinstance( child.GetItem(), item_type): if child.GetItem().__class__.__name__ == item_type.__name__: return True child = child.GetChild(0)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'SplitString'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '5', 'type': 'block', 'children': ['6', '13', '22', '29', '33', '83', '246']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'string_length'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '/'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'string_length'},{'id': '21', 'type': 'integer', 'children': [], 'value': '10'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '32', 'type': 'string', 'children': [], 'value': '""'},{'id': '33', 'type': 'if_statement', 'children': ['34', '37']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '>'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'block', 'children': ['38', '42', '79']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '41', 'type': 'string', 'children': [], 'value': '"\\\\markup { \\n\\r \\column { "'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '51']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '51', 'type': 'block', 'children': ['52', '56', '62', '75']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'augmented_assignment', 'children': ['54', '55'], 'value': '+='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '55', 'type': 'string', 'children': [], 'value': '"\\n\\r\\r \\\\line { \\""'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '*'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '61', 'type': 'integer', 'children': [], 'value': '10'},{'id': '62', 'type': 'for_statement', 'children': ['63', '64', '68']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'augmented_assignment', 'children': ['71', '72'], 'value': '+='},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'augmented_assignment', 'children': ['77', '78'], 'value': '+='},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '78', 'type': 'string', 'children': [], 'value': '"\\" \\r\\r}"'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'augmented_assignment', 'children': ['81', '82'], 'value': '+='},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '82', 'type': 'string', 'children': [], 'value': '"\\n\\r } \\n }"'},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '=='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '86', 'type': 'string', 'children': [], 'value': '""'},{'id': '87', 'type': 'block', 'children': ['88', '114', '118']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '91', 'type': 'list_comprehension', 'children': ['92', '93', '102']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '93', 'type': 'for_in_clause', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '102', 'type': 'if_clause', 'children': ['103']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '109'], 'value': 'or'},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '108', 'type': 'string', 'children': [], 'value': '"\\r"'},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '=='},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '113', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '117', 'type': 'string', 'children': [], 'value': '"\\\\markup { \\n\\r \\column { "'},{'id': '118', 'type': 'if_statement', 'children': ['119', '125', '139']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '124'], 'value': '=='},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'augmented_assignment', 'children': ['128', '129'], 'value': '+='},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '138'], 'value': '+'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '+'},{'id': '131', 'type': 'string', 'children': [], 'value': '"\\n\\r\\r \\\\line { \\""'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': '""'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '138', 'type': 'string', 'children': [], 'value': '"\\" \\n\\r\\r } \\n\\r } \\n }"'},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141', '145', '155', '162', '221', '242']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '144', 'type': 'list', 'children': [], 'value': '[]'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'row_1'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '150', 'type': 'slice', 'children': ['151', '152']},{'id': '151', 'type': 'colon', 'children': []},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '154', 'type': 'integer', 'children': [], 'value': '0'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'row_1'},{'id': '162', 'type': 'for_statement', 'children': ['163', '164', '171']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '171', 'type': 'block', 'children': ['172', '178', '205', '214']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '178', 'type': 'if_statement', 'children': ['179', '187', '196']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '!='},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '181', 'type': 'binary_operator', 'children': ['182', '186'], 'value': '-'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'indexes'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'string_list'},{'id': '210', 'type': 'slice', 'children': ['211', '212', '213']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '212', 'type': 'colon', 'children': []},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '221', 'type': 'for_statement', 'children': ['222', '223', '224']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '224', 'type': 'block', 'children': ['225', '229', '238']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'augmented_assignment', 'children': ['227', '228'], 'value': '+='},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '228', 'type': 'string', 'children': [], 'value': '"\\n\\r\\r \\\\line { \\""'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'augmented_assignment', 'children': ['231', '232'], 'value': '+='},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'string', 'children': [], 'value': '""'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'augmented_assignment', 'children': ['240', '241'], 'value': '+='},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '241', 'type': 'string', 'children': [], 'value': '"\\" \\r\\r}"'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'augmented_assignment', 'children': ['244', '245'], 'value': '+='},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'lstring'},{'id': '245', 'type': 'string', 'children': [], 'value': '"\\n\\r } \\n }"'},{'id': '246', 'type': 'return_statement', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'lstring'}
def SplitString(value): string_length = len(value) chunks = int(string_length / 10) string_list = list(value) lstring = "" if chunks > 1: lstring = "\\markup { \n\r \column { " for i in range(int(chunks)): lstring += "\n\r\r \\line { \"" index = i * 10 for i in range(index): lstring += string_list[i] lstring += "\" \r\r}" lstring += "\n\r } \n }" if lstring == "": indexes = [ i for i in range( len(string_list)) if string_list[i] == "\r" or string_list[i] == "\n"] lstring = "\\markup { \n\r \column { " if len(indexes) == 0: lstring += "\n\r\r \\line { \"" + \ "".join(string_list) + "\" \n\r\r } \n\r } \n }" else: rows = [] row_1 = string_list[:indexes[0]] rows.append(row_1) for i in range(len(indexes)): start = indexes[i] if i != len(indexes) - 1: end = indexes[i + 1] else: end = len(string_list) row = string_list[start:end] rows.append(row) for row in rows: lstring += "\n\r\r \\line { \"" lstring += "".join(row) lstring += "\" \r\r}" lstring += "\n\r } \n }" return lstring
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'NumbersToWords'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '5', 'type': 'block', 'children': ['6', '19', '32', '36', '186']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '9', 'type': 'list', 'children': ['10', '11', '12', '13', '14', '15', '16', '17', '18'], 'value': "[\n 'one',\n 'two',\n 'three',\n 'four',\n 'five',\n 'six',\n 'seven',\n 'eight',\n 'nine']"},{'id': '10', 'type': 'string', 'children': [], 'value': "'one'"},{'id': '11', 'type': 'string', 'children': [], 'value': "'two'"},{'id': '12', 'type': 'string', 'children': [], 'value': "'three'"},{'id': '13', 'type': 'string', 'children': [], 'value': "'four'"},{'id': '14', 'type': 'string', 'children': [], 'value': "'five'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'six'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'seven'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'eight'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'nine'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tens'},{'id': '22', 'type': 'list', 'children': ['23', '24', '25', '26', '27', '28', '29', '30', '31'], 'value': "[\n 'ten',\n 'twenty',\n 'thirty',\n 'forty',\n 'fifty',\n 'sixty',\n 'seventy',\n 'eighty',\n 'ninety']"},{'id': '23', 'type': 'string', 'children': [], 'value': "'ten'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'twenty'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'thirty'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'forty'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'fifty'"},{'id': '28', 'type': 'string', 'children': [], 'value': "'sixty'"},{'id': '29', 'type': 'string', 'children': [], 'value': "'seventy'"},{'id': '30', 'type': 'string', 'children': [], 'value': "'eighty'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'ninety'"},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '35', 'type': 'string', 'children': [], 'value': '""'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40', '180']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '!='},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'block', 'children': ['41', '48', '116', '158']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'number'},{'id': '48', 'type': 'if_statement', 'children': ['49', '56']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51', '55'], 'value': '>'},{'id': '50', 'type': 'integer', 'children': [], 'value': '4'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '55', 'type': 'integer', 'children': [], 'value': '2'},{'id': '56', 'type': 'block', 'children': ['57', '70', '74']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'augmented_assignment', 'children': ['59', '60'], 'value': '+='},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '69'], 'value': '-'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'augmented_assignment', 'children': ['72', '73'], 'value': '+='},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '73', 'type': 'string', 'children': [], 'value': '"hundred"'},{'id': '74', 'type': 'if_statement', 'children': ['75', '80']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '!='},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '78', 'type': 'integer', 'children': [], 'value': '1'},{'id': '79', 'type': 'integer', 'children': [], 'value': '0'},{'id': '80', 'type': 'block', 'children': ['81', '96']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '+='},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '+'},{'id': '85', 'type': 'string', 'children': [], 'value': '"and"'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tens'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '95'], 'value': '-'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'if_statement', 'children': ['97', '102']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '101'], 'value': '!='},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '100', 'type': 'integer', 'children': [], 'value': '2'},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'augmented_assignment', 'children': ['105', '106'], 'value': '+='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '115'], 'value': '-'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '114', 'type': 'integer', 'children': [], 'value': '2'},{'id': '115', 'type': 'integer', 'children': [], 'value': '1'},{'id': '116', 'type': 'if_statement', 'children': ['117', '124']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119', '123'], 'value': '>'},{'id': '118', 'type': 'integer', 'children': [], 'value': '3'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'block', 'children': ['125', '138']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '+='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'tens'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '137'], 'value': '-'},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '136', 'type': 'integer', 'children': [], 'value': '0'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'if_statement', 'children': ['139', '144']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '143'], 'value': '!='},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'augmented_assignment', 'children': ['147', '148'], 'value': '+='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '157'], 'value': '-'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '156', 'type': 'integer', 'children': [], 'value': '1'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'if_statement', 'children': ['159', '166']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161', '165'], 'value': '>'},{'id': '160', 'type': 'integer', 'children': [], 'value': '2'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'augmented_assignment', 'children': ['169', '170'], 'value': '+='},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'units'},{'id': '172', 'type': 'binary_operator', 'children': ['173', '179'], 'value': '-'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'str_val'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'integer', 'children': [], 'value': '1'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '185', 'type': 'string', 'children': [], 'value': '"zero"'},{'id': '186', 'type': 'return_statement', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'output'}
def NumbersToWords(number): units = [ 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] tens = [ 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'] output = "" if number != 0: str_val = str(number) if 4 > len(str_val) > 2: output += units[int(str_val[0]) - 1] output += "hundred" if str_val[1] != 0: output += "and" + tens[int(str_val[1]) - 1] if str_val[2] != 0: output += units[int(str_val[2]) - 1] if 3 > len(str_val) > 1: output += tens[int(str_val[0]) - 1] if str_val[1] != 0: output += units[int(str_val[1]) - 1] if 2 > len(str_val) == 1: output += units[int(str_val[0]) - 1] else: output = "zero" return output
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_generate_image'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'foreground'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'image_format'},{'id': '12', 'type': 'block', 'children': ['13', '42', '51', '59', '67', '152', '158', '178', '203', '211', '217']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'Image'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '41']},{'id': '21', 'type': 'string', 'children': [], 'value': '"RGBA"'},{'id': '22', 'type': 'tuple', 'children': ['23', '32']},{'id': '23', 'type': 'binary_operator', 'children': ['24', '29'], 'value': '+'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '+'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '28', 'type': 'integer', 'children': [], 'value': '2'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '31', 'type': 'integer', 'children': [], 'value': '3'},{'id': '32', 'type': 'binary_operator', 'children': ['33', '38'], 'value': '+'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '+'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'background'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'draw'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ImageDraw'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'Draw'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'block_width'},{'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '//'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'block_height'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '//'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'height'},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '67', 'type': 'for_statement', 'children': ['68', '71', '75']},{'id': '68', 'type': 'pattern_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'row_columns'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'for_statement', 'children': ['77', '80', '84']},{'id': '77', 'type': 'pattern_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'cell'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'row_columns'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cell'},{'id': '87', 'type': 'block', 'children': ['88', '98', '108', '123', '138']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x1'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '95'], 'value': '+'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '94', 'type': 'integer', 'children': [], 'value': '2'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '*'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'block_width'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'y1'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '105'], 'value': '+'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '*'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'block_height'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'x2'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '122'], 'value': '-'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '116'], 'value': '+'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '115', 'type': 'integer', 'children': [], 'value': '2'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '121'], 'value': '*'},{'id': '117', 'type': '()', 'children': ['118']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'block_width'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'y2'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '137'], 'value': '-'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '131'], 'value': '+'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'binary_operator', 'children': ['132', '136'], 'value': '*'},{'id': '132', 'type': '()', 'children': ['133']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '+'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '135', 'type': 'integer', 'children': [], 'value': '1'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'block_height'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'draw'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'rectangle'},{'id': '143', 'type': 'argument_list', 'children': ['144', '149']},{'id': '144', 'type': 'tuple', 'children': ['145', '146', '147', '148']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'x1'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'y1'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'x2'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'y2'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'fill'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'foreground'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'BytesIO'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'if_statement', 'children': ['159', '166']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '165'], 'value': '=='},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'image_format'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '164', 'type': 'argument_list', 'children': []},{'id': '165', 'type': 'string', 'children': [], 'value': '"JPEG"'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '177', 'type': 'string', 'children': [], 'value': '"RGB"'},{'id': '178', 'type': 'try_statement', 'children': ['179', '193']},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'save'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187', '190']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'image_format'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'optimize'},{'id': '192', 'type': 'True', 'children': []},{'id': '193', 'type': 'except_clause', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'raise_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '%'},{'id': '201', 'type': 'string', 'children': [], 'value': '"Pillow does not support requested image format: %s"'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'image_format'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'image_raw'},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'getvalue'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '216', 'type': 'argument_list', 'children': []},{'id': '217', 'type': 'return_statement', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'image_raw'}
def _generate_image(self, matrix, width, height, padding, foreground, background, image_format): image = Image.new("RGBA", (width + padding[2] + padding[3], height + padding[0] + padding[1]), background) draw = ImageDraw.Draw(image) block_width = width // self.columns block_height = height // self.rows for row, row_columns in enumerate(matrix): for column, cell in enumerate(row_columns): if cell: x1 = padding[2] + column * block_width y1 = padding[0] + row * block_height x2 = padding[2] + (column + 1) * block_width - 1 y2 = padding[0] + (row + 1) * block_height - 1 draw.rectangle((x1, y1, x2, y2), fill=foreground) stream = BytesIO() if image_format.upper() == "JPEG": image = image.convert(mode="RGB") try: image.save(stream, format=image_format, optimize=True) except KeyError: raise ValueError("Pillow does not support requested image format: %s" % image_format) image_raw = stream.getvalue() stream.close() return image_raw
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'alignment_to_reads'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sam_merged'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_PARAMETERS'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'save_memory'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'list_splat_pattern', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'bin_fasta'},{'id': '14', 'type': 'block', 'children': ['15', '40', '46', '74', '83', '92', '107', '157', '174', '327', '341']},{'id': '15', 'type': 'function_definition', 'children': ['16', '17', '19']},{'id': '16', 'type': 'function_name', 'children': [], 'value': 'get_file_string'},{'id': '17', 'type': 'parameters', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'file_thing'},{'id': '19', 'type': 'block', 'children': ['20', '38']},{'id': '20', 'type': 'try_statement', 'children': ['21', '28']},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'file_string'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'file_thing'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '28', 'type': 'except_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'file_string'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'file_thing'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'file_string'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'bin_chunks'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'bin_fasta'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '59']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '58', 'type': 'string', 'children': [], 'value': '"fasta"'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'bin_chunks'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'tuple', 'children': ['67', '71']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'get_file_string'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '82', 'type': 'string', 'children': [], 'value': '"chunk_size"'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'mapq_threshold'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '91', 'type': 'string', 'children': [], 'value': '"mapq_threshold"'},{'id': '92', 'type': 'function_definition', 'children': ['93', '94', '96']},{'id': '93', 'type': 'function_name', 'children': [], 'value': 'read_name'},{'id': '94', 'type': 'parameters', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'subscript', 'children': ['99', '106']},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'query_name'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'integer', 'children': [], 'value': '0'},{'id': '107', 'type': 'function_definition', 'children': ['108', '109', '111']},{'id': '108', 'type': 'function_name', 'children': [], 'value': 'get_base_name'},{'id': '109', 'type': 'parameters', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '111', 'type': 'block', 'children': ['112', '138', '155']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'base_name'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': '"."'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'subscript', 'children': ['121', '134']},{'id': '121', 'type': 'call', 'children': ['122', '132']},{'id': '122', 'type': 'attribute', 'children': ['123', '131']},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': '"."'},{'id': '134', 'type': 'slice', 'children': ['135', '136']},{'id': '135', 'type': 'colon', 'children': []},{'id': '136', 'type': 'unary_operator', 'children': ['137'], 'value': '-'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'output_path'},{'id': '141', 'type': 'call', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'output_dir'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': '"{}.readnames"'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'base_name'},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'output_path'},{'id': '157', 'type': 'if_statement', 'children': ['158', '159', '166']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'save_memory'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'read_names'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '173', 'type': 'argument_list', 'children': []},{'id': '174', 'type': 'with_statement', 'children': ['175', '187']},{'id': '175', 'type': 'with_clause', 'children': ['176']},{'id': '176', 'type': 'with_item', 'children': ['177']},{'id': '177', 'type': 'as_pattern', 'children': ['178', '185']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'pysam'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'AlignmentFile'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'sam_merged'},{'id': '184', 'type': 'string', 'children': [], 'value': '"rb"'},{'id': '185', 'type': 'as_pattern_target', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'alignment_merged_handle'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'for_statement', 'children': ['189', '192', '199']},{'id': '189', 'type': 'tuple_pattern', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'my_read_name'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'alignment_pool'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'alignment_merged_handle'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'read_name'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '203']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'my_alignment'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'alignment_pool'},{'id': '203', 'type': 'block', 'children': ['204', '210', '216', '222', '232', '240']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'relative_position'},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'my_alignment'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'reference_start'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'contig_name'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'my_alignment'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'reference_name'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'chunk_position'},{'id': '219', 'type': 'binary_operator', 'children': ['220', '221'], 'value': '//'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'relative_position'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'chunk_size'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'chunk_name'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'string', 'children': [], 'value': '"{}_{}"'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'contig_name'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'chunk_position'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'quality_test'},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '239'], 'value': '>'},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'my_alignment'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'mapping_quality'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'mapq_threshold'},{'id': '240', 'type': 'for_statement', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'bin_fasta'},{'id': '243', 'type': 'block', 'children': ['244', '250']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'chunk_tuple'},{'id': '247', 'type': 'tuple', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'chunk_name'},{'id': '250', 'type': 'if_statement', 'children': ['251', '256']},{'id': '251', 'type': 'boolean_operator', 'children': ['252', '255'], 'value': 'and'},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': 'in'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'chunk_tuple'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'bin_chunks'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'quality_test'},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'if_statement', 'children': ['258', '259', '304']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'save_memory'},{'id': '259', 'type': 'block', 'children': ['260', '267', '292']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'assignment', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'output_path'},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'get_base_name'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '267', 'type': 'try_statement', 'children': ['268', '275']},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'output_handle'},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '275', 'type': 'except_clause', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '277', 'type': 'block', 'children': ['278', '286']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'output_handle'},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '283', 'type': 'argument_list', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'output_path'},{'id': '285', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '291']},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'output_handle'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'output_handle'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'string', 'children': [], 'value': '"@{}\\n"'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'my_read_name'},{'id': '304', 'type': 'else_clause', 'children': ['305']},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'try_statement', 'children': ['307', '317']},{'id': '307', 'type': 'block', 'children': ['308']},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '315']},{'id': '310', 'type': 'attribute', 'children': ['311', '314']},{'id': '311', 'type': 'subscript', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'read_names'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'my_read_name'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '317', 'type': 'except_clause', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '319', 'type': 'block', 'children': ['320']},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '325']},{'id': '322', 'type': 'subscript', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'read_names'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'my_read_name'},{'id': '325', 'type': 'list', 'children': ['326'], 'value': '[bin_file]'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'bin_file'},{'id': '327', 'type': 'for_statement', 'children': ['328', '329', '334']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'file_handle'},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '333', 'type': 'argument_list', 'children': []},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'file_handle'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '340', 'type': 'argument_list', 'children': []},{'id': '341', 'type': 'if_statement', 'children': ['342', '343', '350']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'save_memory'},{'id': '343', 'type': 'block', 'children': ['344']},{'id': '344', 'type': 'return_statement', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'opened_files'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '349', 'type': 'argument_list', 'children': []},{'id': '350', 'type': 'else_clause', 'children': ['351']},{'id': '351', 'type': 'block', 'children': ['352']},{'id': '352', 'type': 'return_statement', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'read_names'}
def alignment_to_reads( sam_merged, output_dir, parameters=DEFAULT_PARAMETERS, save_memory=True, *bin_fasta ): def get_file_string(file_thing): try: file_string = file_thing.name except AttributeError: file_string = str(file_thing) return file_string bin_chunks = set() for bin_file in bin_fasta: for record in SeqIO.parse(bin_file, "fasta"): bin_chunks.add((get_file_string(bin_file), record.id)) chunk_size = int(parameters["chunk_size"]) mapq_threshold = int(parameters["mapq_threshold"]) def read_name(read): return read.query_name.split()[0] def get_base_name(bin_file): base_name = ".".join(os.path.basename(bin_file).split(".")[:-1]) output_path = os.path.join( output_dir, "{}.readnames".format(base_name) ) return output_path if save_memory: opened_files = dict() else: read_names = dict() with pysam.AlignmentFile(sam_merged, "rb") as alignment_merged_handle: for (my_read_name, alignment_pool) in itertools.groupby( alignment_merged_handle, read_name ): for my_alignment in alignment_pool: relative_position = my_alignment.reference_start contig_name = my_alignment.reference_name chunk_position = relative_position // chunk_size chunk_name = "{}_{}".format(contig_name, chunk_position) quality_test = my_alignment.mapping_quality > mapq_threshold for bin_file in bin_fasta: chunk_tuple = (bin_file, chunk_name) if chunk_tuple in bin_chunks and quality_test: if save_memory: output_path = get_base_name(bin_file) try: output_handle = opened_files[bin_file] except KeyError: output_handle = open(output_path, "w") opened_files[bin_file] = output_handle output_handle.write("@{}\n".format(my_read_name)) else: try: read_names[my_read_name].append(bin_file) except KeyError: read_names[my_read_name] = [bin_file] for file_handle in opened_files.values(): file_handle.close() if save_memory: return opened_files.keys() else: return read_names
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_validate_config'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '5', 'type': 'block', 'children': ['6', '19']},{'id': '6', 'type': 'if_statement', 'children': ['7', '13']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'raise_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'Config must be a list'"},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'config_dict'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '22', 'type': 'block', 'children': ['23', '36', '46', '52', '65', '75', '99', '109', '124', '134', '182', '202']},{'id': '23', 'type': 'if_statement', 'children': ['24', '30']},{'id': '24', 'type': 'not_operator', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'config_dict'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'raise_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'Config must be a list of dictionaries'"},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '39', 'type': 'subscript', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'config_dict'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '49', 'type': 'subscript', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'config_dict'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '52', 'type': 'if_statement', 'children': ['53', '59']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'raise_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "'Config structure is broken'"},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'not'},{'id': '67', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'raise_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': "'Config entries must have a value for host'"},{'id': '75', 'type': 'if_statement', 'children': ['76', '93']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '85'], 'value': 'and'},{'id': '77', 'type': 'not_operator', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '80', 'type': 'argument_list', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '83', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '85', 'type': 'not_operator', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '88', 'type': 'argument_list', 'children': ['89', '92']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '91', 'type': 'string', 'children': [], 'value': "'host'"},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'raise_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'string', 'children': [], 'value': "'Host must be a string or a list.'"},{'id': '99', 'type': 'if_statement', 'children': ['100', '103']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'not'},{'id': '101', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'raise_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': "'Config entries must have a value for port'"},{'id': '109', 'type': 'if_statement', 'children': ['110', '118']},{'id': '110', 'type': 'not_operator', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '113', 'type': 'argument_list', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '116', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'raise_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': "'Port must be an int'"},{'id': '124', 'type': 'if_statement', 'children': ['125', '128']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'not'},{'id': '126', 'type': 'string', 'children': [], 'value': "'dbpath'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'raise_statement', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': "'Config entries must have a value for dbpath'"},{'id': '134', 'type': 'if_statement', 'children': ['135', '143']},{'id': '135', 'type': 'not_operator', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '138', 'type': 'argument_list', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '141', 'type': 'string', 'children': [], 'value': "'dbpath'"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '143', 'type': 'block', 'children': ['144', '161']},{'id': '144', 'type': 'if_statement', 'children': ['145', '153']},{'id': '145', 'type': 'not_operator', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '148', 'type': 'argument_list', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '151', 'type': 'string', 'children': [], 'value': "'dbpath'"},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'raise_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'concatenated_string', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "'Dbpath must either a string or a list of '"},{'id': '160', 'type': 'string', 'children': [], 'value': "'strings'"},{'id': '161', 'type': 'for_statement', 'children': ['162', '163', '166']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'dbpath'},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '165', 'type': 'string', 'children': [], 'value': "'dbpath'"},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'if_statement', 'children': ['168', '174']},{'id': '168', 'type': 'not_operator', 'children': ['169']},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'dbpath'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'raise_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'concatenated_string', 'children': ['180', '181']},{'id': '180', 'type': 'string', 'children': [], 'value': "'Dbpath must either a string or a list '"},{'id': '181', 'type': 'string', 'children': [], 'value': "'of strings'"},{'id': '182', 'type': 'if_statement', 'children': ['183', '196']},{'id': '183', 'type': '()', 'children': ['184']},{'id': '184', 'type': 'boolean_operator', 'children': ['185', '188'], 'value': 'and'},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': 'in'},{'id': '186', 'type': 'string', 'children': [], 'value': "'read_preference'"},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '188', 'type': 'not_operator', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '191', 'type': 'argument_list', 'children': ['192', '195']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '194', 'type': 'string', 'children': [], 'value': "'read_preference'"},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'raise_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'string', 'children': [], 'value': "'Read_preference must be a string'"},{'id': '202', 'type': 'if_statement', 'children': ['203', '216']},{'id': '203', 'type': '()', 'children': ['204']},{'id': '204', 'type': 'boolean_operator', 'children': ['205', '208'], 'value': 'and'},{'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': 'in'},{'id': '206', 'type': 'string', 'children': [], 'value': "'replicaSet'"},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '208', 'type': 'not_operator', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '211', 'type': 'argument_list', 'children': ['212', '215']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '214', 'type': 'string', 'children': [], 'value': "'replicaSet'"},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'raise_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'string', 'children': [], 'value': "'replicaSet must be a string'"}
def _validate_config(config): if not isinstance(config, list): raise TypeError('Config must be a list') for config_dict in config: if not isinstance(config_dict, dict): raise TypeError('Config must be a list of dictionaries') label = config_dict.keys()[0] cfg = config_dict[label] if not isinstance(cfg, dict): raise TypeError('Config structure is broken') if 'host' not in cfg: raise TypeError('Config entries must have a value for host') if not isinstance(cfg['host'], str) and not isinstance(cfg['host'], list): raise TypeError('Host must be a string or a list.') if 'port' not in cfg: raise TypeError('Config entries must have a value for port') if not isinstance(cfg['port'], int): raise TypeError('Port must be an int') if 'dbpath' not in cfg: raise TypeError('Config entries must have a value for dbpath') if not isinstance(cfg['dbpath'], str): if not isinstance(cfg['dbpath'], list): raise TypeError('Dbpath must either a string or a list of ' 'strings') for dbpath in cfg['dbpath']: if not isinstance(dbpath, str): raise TypeError('Dbpath must either a string or a list ' 'of strings') if ('read_preference' in cfg and not isinstance(cfg['read_preference'], str)): raise TypeError('Read_preference must be a string') if ('replicaSet' in cfg and not isinstance(cfg['replicaSet'], str)): raise TypeError('replicaSet must be a string')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'taskinfo'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '21', '38', '46', '60', '74', '88', '104', '120', '137', '144', '150', '480']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'task_input'},{'id': '9', 'type': 'dictionary', 'children': ['10', '13']},{'id': '10', 'type': 'pair', 'children': ['11', '12']},{'id': '11', 'type': 'string', 'children': [], 'value': "'taskName'"},{'id': '12', 'type': 'string', 'children': [], 'value': "'QueryTask'"},{'id': '13', 'type': 'pair', 'children': ['14', '15']},{'id': '14', 'type': 'string', 'children': [], 'value': "'inputParameters'"},{'id': '15', 'type': 'dictionary', 'children': ['16']},{'id': '16', 'type': 'pair', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': '"Task_Name"'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_name'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'taskengine'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30', '33']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'task_input'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_engine'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'cwd'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_cwd'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '41', 'type': 'subscript', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '44', 'type': 'string', 'children': [], 'value': "'outputParameters'"},{'id': '45', 'type': 'string', 'children': [], 'value': "'DEFINITION'"},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '51']},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '50', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'NAME'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '64', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "'DESCRIPTION'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '78', 'type': 'string', 'children': [], 'value': "'displayName'"},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'string', 'children': [], 'value': "'DISPLAY_NAME'"},{'id': '88', 'type': 'if_statement', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'in'},{'id': '90', 'type': 'string', 'children': [], 'value': "'COMMUTE_ON_SUBSET'"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '97', 'type': 'string', 'children': [], 'value': "'commute_on_subset'"},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'string', 'children': [], 'value': "'COMMUTE_ON_SUBSET'"},{'id': '104', 'type': 'if_statement', 'children': ['105', '108']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'in'},{'id': '106', 'type': 'string', 'children': [], 'value': "'COMMUTE_ON_DOWNSAMPLE'"},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '113', 'type': 'string', 'children': [], 'value': "'commute_on_downsample'"},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'COMMUTE_ON_DOWNSAMPLE'"},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '125', '126']},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '124', 'type': 'string', 'children': [], 'value': "'parameters'"},{'id': '125', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '126', 'type': 'list_comprehension', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '130', 'type': 'call', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '134', 'type': 'string', 'children': [], 'value': "'PARAMETERS'"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '136', 'type': 'argument_list', 'children': []},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'string', 'children': [], 'value': "'PARAMETERS'"},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'task_def'},{'id': '149', 'type': 'string', 'children': [], 'value': "'parameters'"},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '153']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '153', 'type': 'block', 'children': ['154', '168', '182', '196', '210', '226', '242', '316', '332', '352', '384', '416', '432', '448', '464']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '158', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "'NAME'"},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '173']},{'id': '170', 'type': 'subscript', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '172', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': "'DESCRIPTION'"},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '186', 'type': 'string', 'children': [], 'value': "'display_name'"},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'string', 'children': [], 'value': "'DISPLAY_NAME'"},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '201']},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '200', 'type': 'string', 'children': [], 'value': "'required'"},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'string', 'children': [], 'value': "'REQUIRED'"},{'id': '210', 'type': 'if_statement', 'children': ['211', '214']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'in'},{'id': '212', 'type': 'string', 'children': [], 'value': "'MIN'"},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '220']},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '219', 'type': 'string', 'children': [], 'value': "'min'"},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'string', 'children': [], 'value': "'MIN'"},{'id': '226', 'type': 'if_statement', 'children': ['227', '230']},{'id': '227', 'type': 'comparison_operator', 'children': ['228', '229'], 'value': 'in'},{'id': '228', 'type': 'string', 'children': [], 'value': "'MAX'"},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '236']},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '235', 'type': 'string', 'children': [], 'value': "'max'"},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'string', 'children': [], 'value': "'MAX'"},{'id': '242', 'type': 'if_statement', 'children': ['243', '251', '293']},{'id': '243', 'type': 'call', 'children': ['244', '249']},{'id': '244', 'type': 'attribute', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '247', 'type': 'string', 'children': [], 'value': "'TYPE'"},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'string', 'children': [], 'value': "'['"},{'id': '251', 'type': 'block', 'children': ['252', '272', '282']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '261']},{'id': '254', 'type': 'pattern_list', 'children': ['255', '258']},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '257', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '260', 'type': 'string', 'children': [], 'value': "'dimensions'"},{'id': '261', 'type': 'call', 'children': ['262', '270']},{'id': '262', 'type': 'attribute', 'children': ['263', '269']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'string', 'children': [], 'value': "'TYPE'"},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'string', 'children': [], 'value': "'['"},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '277']},{'id': '274', 'type': 'subscript', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '276', 'type': 'string', 'children': [], 'value': "'dimensions'"},{'id': '277', 'type': 'binary_operator', 'children': ['278', '279'], 'value': '+'},{'id': '278', 'type': 'string', 'children': [], 'value': "'['"},{'id': '279', 'type': 'subscript', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '281', 'type': 'string', 'children': [], 'value': "'dimensions'"},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '287']},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '286', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '287', 'type': 'call', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '292', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '293', 'type': 'else_clause', 'children': ['294']},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '300']},{'id': '297', 'type': 'subscript', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '299', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'subscript', 'children': ['304', '315']},{'id': '304', 'type': 'call', 'children': ['305', '313']},{'id': '305', 'type': 'attribute', 'children': ['306', '312']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'string', 'children': [], 'value': "'TYPE'"},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'string', 'children': [], 'value': "'ARRAY'"},{'id': '315', 'type': 'integer', 'children': [], 'value': '0'},{'id': '316', 'type': 'if_statement', 'children': ['317', '320']},{'id': '317', 'type': 'comparison_operator', 'children': ['318', '319'], 'value': 'in'},{'id': '318', 'type': 'string', 'children': [], 'value': "'DIMENSIONS'"},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '320', 'type': 'block', 'children': ['321']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'assignment', 'children': ['323', '326']},{'id': '323', 'type': 'subscript', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '325', 'type': 'string', 'children': [], 'value': "'dimensions'"},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'string', 'children': [], 'value': "'DIMENSIONS'"},{'id': '332', 'type': 'if_statement', 'children': ['333', '336']},{'id': '333', 'type': 'comparison_operator', 'children': ['334', '335'], 'value': 'in'},{'id': '334', 'type': 'string', 'children': [], 'value': "'DIRECTION'"},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '336', 'type': 'block', 'children': ['337']},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'assignment', 'children': ['339', '342']},{'id': '339', 'type': 'subscript', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '341', 'type': 'string', 'children': [], 'value': "'direction'"},{'id': '342', 'type': 'call', 'children': ['343', '351']},{'id': '343', 'type': 'attribute', 'children': ['344', '350']},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'string', 'children': [], 'value': "'DIRECTION'"},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '351', 'type': 'argument_list', 'children': []},{'id': '352', 'type': 'if_statement', 'children': ['353', '356']},{'id': '353', 'type': 'comparison_operator', 'children': ['354', '355'], 'value': 'in'},{'id': '354', 'type': 'string', 'children': [], 'value': "'DEFAULT'"},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '356', 'type': 'block', 'children': ['357']},{'id': '357', 'type': 'if_statement', 'children': ['358', '363', '375']},{'id': '358', 'type': 'comparison_operator', 'children': ['359', '362'], 'value': 'is'},{'id': '359', 'type': 'subscript', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '361', 'type': 'string', 'children': [], 'value': "'DEFAULT'"},{'id': '362', 'type': 'None', 'children': []},{'id': '363', 'type': 'block', 'children': ['364']},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'assignment', 'children': ['366', '369']},{'id': '366', 'type': 'subscript', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '368', 'type': 'string', 'children': [], 'value': "'default_value'"},{'id': '369', 'type': 'call', 'children': ['370', '373']},{'id': '370', 'type': 'attribute', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '373', 'type': 'argument_list', 'children': ['374']},{'id': '374', 'type': 'string', 'children': [], 'value': "'DEFAULT'"},{'id': '375', 'type': 'else_clause', 'children': ['376']},{'id': '376', 'type': 'block', 'children': ['377']},{'id': '377', 'type': 'expression_statement', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '382', 'type': 'argument_list', 'children': ['383']},{'id': '383', 'type': 'string', 'children': [], 'value': "'DEFAULT'"},{'id': '384', 'type': 'if_statement', 'children': ['385', '388']},{'id': '385', 'type': 'comparison_operator', 'children': ['386', '387'], 'value': 'in'},{'id': '386', 'type': 'string', 'children': [], 'value': "'CHOICE_LIST'"},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '388', 'type': 'block', 'children': ['389']},{'id': '389', 'type': 'if_statement', 'children': ['390', '395', '407']},{'id': '390', 'type': 'comparison_operator', 'children': ['391', '394'], 'value': 'is'},{'id': '391', 'type': 'subscript', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '393', 'type': 'string', 'children': [], 'value': "'CHOICE_LIST'"},{'id': '394', 'type': 'None', 'children': []},{'id': '395', 'type': 'block', 'children': ['396']},{'id': '396', 'type': 'expression_statement', 'children': ['397']},{'id': '397', 'type': 'assignment', 'children': ['398', '401']},{'id': '398', 'type': 'subscript', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '400', 'type': 'string', 'children': [], 'value': "'choice_list'"},{'id': '401', 'type': 'call', 'children': ['402', '405']},{'id': '402', 'type': 'attribute', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '405', 'type': 'argument_list', 'children': ['406']},{'id': '406', 'type': 'string', 'children': [], 'value': "'CHOICE_LIST'"},{'id': '407', 'type': 'else_clause', 'children': ['408']},{'id': '408', 'type': 'block', 'children': ['409']},{'id': '409', 'type': 'expression_statement', 'children': ['410']},{'id': '410', 'type': 'call', 'children': ['411', '414']},{'id': '411', 'type': 'attribute', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '414', 'type': 'argument_list', 'children': ['415']},{'id': '415', 'type': 'string', 'children': [], 'value': "'CHOICE_LIST'"},{'id': '416', 'type': 'if_statement', 'children': ['417', '420']},{'id': '417', 'type': 'comparison_operator', 'children': ['418', '419'], 'value': 'in'},{'id': '418', 'type': 'string', 'children': [], 'value': "'FOLD_CASE'"},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '420', 'type': 'block', 'children': ['421']},{'id': '421', 'type': 'expression_statement', 'children': ['422']},{'id': '422', 'type': 'assignment', 'children': ['423', '426']},{'id': '423', 'type': 'subscript', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '425', 'type': 'string', 'children': [], 'value': "'fold_case'"},{'id': '426', 'type': 'call', 'children': ['427', '430']},{'id': '427', 'type': 'attribute', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '429', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '430', 'type': 'argument_list', 'children': ['431']},{'id': '431', 'type': 'string', 'children': [], 'value': "'FOLD_CASE'"},{'id': '432', 'type': 'if_statement', 'children': ['433', '436']},{'id': '433', 'type': 'comparison_operator', 'children': ['434', '435'], 'value': 'in'},{'id': '434', 'type': 'string', 'children': [], 'value': "'AUTO_EXTENSION'"},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '436', 'type': 'block', 'children': ['437']},{'id': '437', 'type': 'expression_statement', 'children': ['438']},{'id': '438', 'type': 'assignment', 'children': ['439', '442']},{'id': '439', 'type': 'subscript', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '441', 'type': 'string', 'children': [], 'value': "'auto_extension'"},{'id': '442', 'type': 'call', 'children': ['443', '446']},{'id': '443', 'type': 'attribute', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '446', 'type': 'argument_list', 'children': ['447']},{'id': '447', 'type': 'string', 'children': [], 'value': "'AUTO_EXTENSION'"},{'id': '448', 'type': 'if_statement', 'children': ['449', '452']},{'id': '449', 'type': 'comparison_operator', 'children': ['450', '451'], 'value': 'in'},{'id': '450', 'type': 'string', 'children': [], 'value': "'IS_TEMPORARY'"},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '452', 'type': 'block', 'children': ['453']},{'id': '453', 'type': 'expression_statement', 'children': ['454']},{'id': '454', 'type': 'assignment', 'children': ['455', '458']},{'id': '455', 'type': 'subscript', 'children': ['456', '457']},{'id': '456', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '457', 'type': 'string', 'children': [], 'value': "'is_temporary'"},{'id': '458', 'type': 'call', 'children': ['459', '462']},{'id': '459', 'type': 'attribute', 'children': ['460', '461']},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '461', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '462', 'type': 'argument_list', 'children': ['463']},{'id': '463', 'type': 'string', 'children': [], 'value': "'IS_TEMPORARY'"},{'id': '464', 'type': 'if_statement', 'children': ['465', '468']},{'id': '465', 'type': 'comparison_operator', 'children': ['466', '467'], 'value': 'in'},{'id': '466', 'type': 'string', 'children': [], 'value': "'IS_DIRECTORY'"},{'id': '467', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '468', 'type': 'block', 'children': ['469']},{'id': '469', 'type': 'expression_statement', 'children': ['470']},{'id': '470', 'type': 'assignment', 'children': ['471', '474']},{'id': '471', 'type': 'subscript', 'children': ['472', '473']},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '473', 'type': 'string', 'children': [], 'value': "'is_directory'"},{'id': '474', 'type': 'call', 'children': ['475', '478']},{'id': '475', 'type': 'attribute', 'children': ['476', '477']},{'id': '476', 'type': 'identifier', 'children': [], 'value': 'parameter'},{'id': '477', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '478', 'type': 'argument_list', 'children': ['479']},{'id': '479', 'type': 'string', 'children': [], 'value': "'IS_DIRECTORY'"},{'id': '480', 'type': 'return_statement', 'children': ['481']},{'id': '481', 'type': 'identifier', 'children': [], 'value': 'task_def'}
def taskinfo(self): task_input = {'taskName': 'QueryTask', 'inputParameters': {"Task_Name": self._name}} info = taskengine.execute(task_input, self._engine, cwd=self._cwd) task_def = info['outputParameters']['DEFINITION'] task_def['name'] = str(task_def.pop('NAME')) task_def['description'] = str(task_def.pop('DESCRIPTION')) task_def['displayName'] = str(task_def.pop('DISPLAY_NAME')) if 'COMMUTE_ON_SUBSET' in task_def: task_def['commute_on_subset'] = task_def.pop('COMMUTE_ON_SUBSET') if 'COMMUTE_ON_DOWNSAMPLE' in task_def: task_def['commute_on_downsample'] = task_def.pop('COMMUTE_ON_DOWNSAMPLE') task_def['parameters'] = \ [v for v in task_def['PARAMETERS'].values()] task_def.pop('PARAMETERS') parameters = task_def['parameters'] for parameter in parameters: parameter['name'] = str(parameter.pop('NAME')) parameter['description'] = str(parameter.pop('DESCRIPTION')) parameter['display_name'] = str(parameter.pop('DISPLAY_NAME')) parameter['required'] = bool(parameter.pop('REQUIRED')) if 'MIN' in parameter: parameter['min'] = parameter.pop('MIN') if 'MAX' in parameter: parameter['max'] = parameter.pop('MAX') if parameter['TYPE'].count('['): parameter['type'], parameter['dimensions'] = parameter.pop('TYPE').split('[') parameter['dimensions'] = '[' + parameter['dimensions'] parameter['type'] = str(parameter['type']) else: parameter['type'] = str(parameter.pop('TYPE').split('ARRAY')[0]) if 'DIMENSIONS' in parameter: parameter['dimensions'] = parameter.pop('DIMENSIONS') if 'DIRECTION' in parameter: parameter['direction'] = parameter.pop('DIRECTION').lower() if 'DEFAULT' in parameter: if parameter['DEFAULT'] is not None: parameter['default_value'] = parameter.pop('DEFAULT') else: parameter.pop('DEFAULT') if 'CHOICE_LIST' in parameter: if parameter['CHOICE_LIST'] is not None: parameter['choice_list'] = parameter.pop('CHOICE_LIST') else: parameter.pop('CHOICE_LIST') if 'FOLD_CASE' in parameter: parameter['fold_case'] = parameter.pop('FOLD_CASE') if 'AUTO_EXTENSION' in parameter: parameter['auto_extension'] = parameter.pop('AUTO_EXTENSION') if 'IS_TEMPORARY' in parameter: parameter['is_temporary'] = parameter.pop('IS_TEMPORARY') if 'IS_DIRECTORY' in parameter: parameter['is_directory'] = parameter.pop('IS_DIRECTORY') return task_def