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', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'process'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'for_statement', 'children': ['8', '9', '17']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'tool_name'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '24']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tool_name'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'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': '_log'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '%'},{'id': '31', 'type': 'string', 'children': [], 'value': '"Using tool \'%s\', %s"'},{'id': '32', 'type': 'tuple', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'tool_name'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'version'}
def process(self, versions): for tool_name in sorted(versions.keys()): version = versions[tool_name] self._log("Using tool '%s', %s" % (tool_name, version))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'databasesKEGG'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ens_ids'},{'id': '6', 'type': 'block', 'children': ['7', '20', '29', '33', '171', '182', '193', '210', '219', '281']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'all_genes'},{'id': '10', 'type': 'call', 'children': ['11', '19']},{'id': '11', 'type': 'attribute', 'children': ['12', '18']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'urlopen'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '+'},{'id': '16', 'type': 'string', 'children': [], 'value': '"http://rest.kegg.jp/list/"'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'all_genes'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'all_genes'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'dbs'},{'id': '32', 'type': 'list', 'children': [], 'value': '[]'},{'id': '33', 'type': 'while_statement', 'children': ['34', '40']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], 'value': '=='},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dbs'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'for_statement', 'children': ['42', '43', '44']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'all_genes'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'if_statement', 'children': ['46', '52', '168']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '51'], 'value': '=='},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dbs'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'block', 'children': ['53', '64', '77', '86', '98']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'kid'},{'id': '56', 'type': 'subscript', 'children': ['57', '63']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'g'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '63', 'type': 'integer', 'children': [], 'value': '0'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '67', 'type': 'call', 'children': ['68', '76']},{'id': '68', 'type': 'attribute', 'children': ['69', '75']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'urlopen'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '+'},{'id': '73', 'type': 'string', 'children': [], 'value': '"http://rest.kegg.jp/get/"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'kid'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'DBLINKS'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'DBLINKS'},{'id': '89', 'type': 'list_comprehension', 'children': ['90', '91', '94']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '91', 'type': 'for_in_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'DBLINKS'},{'id': '94', 'type': 'if_clause', 'children': ['95']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'},{'id': '96', 'type': 'string', 'children': [], 'value': '":"'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '98', 'type': 'for_statement', 'children': ['99', '100', '101']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'DBLINKS'},{'id': '101', 'type': 'block', 'children': ['102', '111', '122']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': '" "'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '121'], 'value': '-'},{'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': 'test'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'if_statement', 'children': ['123', '126']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'in'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ens_ids'},{'id': '126', 'type': 'block', 'children': ['127', '139', '150', '161']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'DBLINK'},{'id': '130', 'type': 'list_comprehension', 'children': ['131', '132', '135']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '132', 'type': 'for_in_clause', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'DBLINKS'},{'id': '135', 'type': 'if_clause', 'children': ['136']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'in'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'test'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'DBLINK'},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'DBLINK'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': '":"'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'DBLINK'},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'DBLINK'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '160'], 'value': '-'},{'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': 'DBLINK'},{'id': '160', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'dbs'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'DBLINK'},{'id': '168', 'type': 'else_clause', 'children': ['169']},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'break_statement', 'children': []},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'ens_db'},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'dbs'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': '" "'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ens_db'},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ens_db'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '192'], 'value': '-'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ens_db'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'test_db'},{'id': '196', 'type': 'call', 'children': ['197', '209']},{'id': '197', 'type': 'attribute', 'children': ['198', '208']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'urlopen'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'binary_operator', 'children': ['202', '207'], 'value': '+'},{'id': '202', 'type': 'binary_operator', 'children': ['203', '206'], 'value': '+'},{'id': '203', 'type': 'binary_operator', 'children': ['204', '205'], 'value': '+'},{'id': '204', 'type': 'string', 'children': [], 'value': '"http://rest.genome.jp/link/"'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ens_db'},{'id': '206', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'test_db'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'test_db'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '219', 'type': 'if_statement', 'children': ['220', '226', '260']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '225'], 'value': '=='},{'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': 'test_db'},{'id': '225', 'type': 'integer', 'children': [], 'value': '1'},{'id': '226', 'type': 'block', 'children': ['227', '238', '243', '248', '256']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'binary_operator', 'children': ['232', '237'], 'value': '+'},{'id': '232', 'type': 'binary_operator', 'children': ['233', '236'], 'value': '+'},{'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '+'},{'id': '234', 'type': 'string', 'children': [], 'value': '"For "'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '236', 'type': 'string', 'children': [], 'value': '" the following db was found: "'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'ens_db'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'string', 'children': [], 'value': '"This database does not seem to be valid KEGG-linked database identifier"'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'string', 'children': [], 'value': '"For \\n\'hsa\' use \'ensembl-hsa\'\\n\'mmu\' use \'ensembl-mmu\'\\n\'cel\' use \'EnsemblGenomes-Gn\'\\n\'dme\' use \'FlyBase\'"'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '255']},{'id': '250', 'type': 'attribute', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '255', 'type': 'argument_list', 'children': []},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'ens_db'},{'id': '259', 'type': 'None', 'children': []},{'id': '260', 'type': 'else_clause', 'children': ['261']},{'id': '261', 'type': 'block', 'children': ['262', '273']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'binary_operator', 'children': ['267', '272'], 'value': '+'},{'id': '267', 'type': 'binary_operator', 'children': ['268', '271'], 'value': '+'},{'id': '268', 'type': 'binary_operator', 'children': ['269', '270'], 'value': '+'},{'id': '269', 'type': 'string', 'children': [], 'value': '"For "'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '271', 'type': 'string', 'children': [], 'value': '" the following db was found: "'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'ens_db'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '280']},{'id': '275', 'type': 'attribute', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '280', 'type': 'argument_list', 'children': []},{'id': '281', 'type': 'return_statement', 'children': ['282']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'ens_db'}
def databasesKEGG(organism,ens_ids): all_genes=urlopen("http://rest.kegg.jp/list/"+organism).read() all_genes=all_genes.split("\n") dbs=[] while len(dbs) == 0: for g in all_genes: if len(dbs) == 0: kid = g.split("\t")[0] gene=urlopen("http://rest.kegg.jp/get/"+kid).read() DBLINKS=gene.split("\n") DBLINKS=[ s for s in DBLINKS if ":" in s ] for d in DBLINKS: test=d.split(" ") test=test[len(test)-1] if test in ens_ids: DBLINK=[ s for s in DBLINKS if test in s ] DBLINK=DBLINK[0].split(":") DBLINK=DBLINK[len(DBLINK)-2] dbs.append(DBLINK) else: break ens_db=dbs[0].split(" ") ens_db=ens_db[len(ens_db)-1] test_db=urlopen("http://rest.genome.jp/link/"+ens_db+"/"+organism).read() test_db=test_db.split("\n") if len(test_db) == 1: print("For "+organism+" the following db was found: "+ens_db) print("This database does not seem to be valid KEGG-linked database identifier") print("For \n'hsa' use 'ensembl-hsa'\n'mmu' use 'ensembl-mmu'\n'cel' use 'EnsemblGenomes-Gn'\n'dme' use 'FlyBase'") sys.stdout.flush() ens_db = None else: print("For "+organism+" the following db was found: "+ens_db) sys.stdout.flush() return ens_db
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'process'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '7', 'type': 'block', 'children': ['8', '21', '30', '36', '416', '436']},{'id': '8', 'type': 'if_statement', 'children': ['9', '15']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'FormMeta'},{'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': 'TypeError'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'Given form is not a valid WTForm.'"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 're_field_name'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "r'\\%([a-zA-Z0-9_]*)\\%'"},{'id': '30', 'type': 'class_definition', 'children': ['31', '32', '34']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'pass_statement', 'children': []},{'id': '36', 'type': 'for_statement', 'children': ['37', '40', '45']},{'id': '37', 'type': 'pattern_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'block', 'children': ['46', '157', '161', '359', '369', '379', '389', '399']},{'id': '46', 'type': 'if_statement', 'children': ['47', '52', '54']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'in'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'continue_statement', 'children': []},{'id': '54', 'type': 'else_clause', 'children': ['55']},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'if_statement', 'children': ['57', '62', '71', '154']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'in'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '62', 'type': 'block', 'children': ['63', '67']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'current_set_number'},{'id': '70', 'type': 'None', 'children': []},{'id': '71', 'type': 'elif_clause', 'children': ['72', '115']},{'id': '72', 'type': '()', 'children': ['73']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '87'], 'value': 'and'},{'id': '74', 'type': 'call', 'children': ['75', '86']},{'id': '75', 'type': 'attribute', 'children': ['76', '85']},{'id': '76', 'type': 'subscript', 'children': ['77', '83']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '83', 'type': 'unary_operator', 'children': ['84'], 'value': '-'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '108'], 'value': 'in'},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '90', 'type': 'slice', 'children': ['91', '92']},{'id': '91', 'type': 'colon', 'children': []},{'id': '92', 'type': 'binary_operator', 'children': ['93', '107'], 'value': '-'},{'id': '93', 'type': 'unary_operator', 'children': ['94'], 'value': '-'},{'id': '94', 'type': '()', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'subscript', 'children': ['99', '105']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'integer', 'children': [], 'value': '1'},{'id': '108', 'type': 'call', 'children': ['109', '114']},{'id': '109', 'type': 'attribute', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'block', 'children': ['116', '139']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '121', 'type': 'slice', 'children': ['122', '123']},{'id': '122', 'type': 'colon', 'children': []},{'id': '123', 'type': 'binary_operator', 'children': ['124', '138'], 'value': '-'},{'id': '124', 'type': 'unary_operator', 'children': ['125'], 'value': '-'},{'id': '125', 'type': '()', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'subscript', 'children': ['130', '136']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '136', 'type': 'unary_operator', 'children': ['137'], 'value': '-'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'current_set_number'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'subscript', 'children': ['146', '152']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '152', 'type': 'unary_operator', 'children': ['153'], 'value': '-'},{'id': '153', 'type': 'integer', 'children': [], 'value': '1'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'continue_statement', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'validators'},{'id': '160', 'type': 'list', 'children': [], 'value': '[]'},{'id': '161', 'type': 'if_statement', 'children': ['162', '169']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'in'},{'id': '163', 'type': 'string', 'children': [], 'value': "'validators'"},{'id': '164', 'type': 'subscript', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'for_statement', 'children': ['171', '172', '179']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '172', 'type': 'subscript', 'children': ['173', '178']},{'id': '173', 'type': 'subscript', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '178', 'type': 'string', 'children': [], 'value': "'validators'"},{'id': '179', 'type': 'block', 'children': ['180', '184', '188', '264', '346']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '183', 'type': 'list', 'children': [], 'value': '[]'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '187', 'type': 'dictionary', 'children': []},{'id': '188', 'type': 'if_statement', 'children': ['189', '201']},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'in'},{'id': '190', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '191', 'type': 'subscript', 'children': ['192', '197', '198']},{'id': '192', 'type': 'subscript', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '197', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '200', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'if_statement', 'children': ['203', '205', '221']},{'id': '203', 'type': 'not_operator', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'current_set_number'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '209', 'type': 'subscript', 'children': ['210', '220']},{'id': '210', 'type': 'subscript', 'children': ['211', '216', '217']},{'id': '211', 'type': 'subscript', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '214', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '216', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '219', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '220', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '221', 'type': 'else_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'for_statement', 'children': ['224', '225', '237']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '225', 'type': 'subscript', 'children': ['226', '236']},{'id': '226', 'type': 'subscript', 'children': ['227', '232', '233']},{'id': '227', 'type': 'subscript', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '230', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '232', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '235', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '236', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '237', 'type': 'block', 'children': ['238', '257']},{'id': '238', 'type': 'try_statement', 'children': ['239', '254']},{'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': 'arg'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 're_field_name'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '247', 'type': 'argument_list', 'children': ['248', '253']},{'id': '248', 'type': 'binary_operator', 'children': ['249', '252'], 'value': '+'},{'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '+'},{'id': '250', 'type': 'string', 'children': [], 'value': "r'\\1'"},{'id': '251', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'current_set_number'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '254', 'type': 'except_clause', 'children': ['255']},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'pass_statement', 'children': []},{'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': 'args'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '264', 'type': 'if_statement', 'children': ['265', '277']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'in'},{'id': '266', 'type': 'string', 'children': [], 'value': "'kwargs'"},{'id': '267', 'type': 'subscript', 'children': ['268', '273', '274']},{'id': '268', 'type': 'subscript', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '271', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '273', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '276', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'if_statement', 'children': ['279', '281', '297']},{'id': '279', 'type': 'not_operator', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'current_set_number'},{'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': 'kwargs'},{'id': '285', 'type': 'subscript', 'children': ['286', '296']},{'id': '286', 'type': 'subscript', 'children': ['287', '292', '293']},{'id': '287', 'type': 'subscript', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '290', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '292', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '295', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '296', 'type': 'string', 'children': [], 'value': "'kwargs'"},{'id': '297', 'type': 'else_clause', 'children': ['298']},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'for_statement', 'children': ['300', '303', '320']},{'id': '300', 'type': 'pattern_list', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '303', 'type': 'call', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'subscript', 'children': ['309', '319']},{'id': '309', 'type': 'subscript', 'children': ['310', '315', '316']},{'id': '310', 'type': 'subscript', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '313', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '315', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '318', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '319', 'type': 'string', 'children': [], 'value': "'kwargs'"},{'id': '320', 'type': 'block', 'children': ['321', '340']},{'id': '321', 'type': 'try_statement', 'children': ['322', '337']},{'id': '322', 'type': 'block', 'children': ['323']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 're_field_name'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '330', 'type': 'argument_list', 'children': ['331', '336']},{'id': '331', 'type': 'binary_operator', 'children': ['332', '335'], 'value': '+'},{'id': '332', 'type': 'binary_operator', 'children': ['333', '334'], 'value': '+'},{'id': '333', 'type': 'string', 'children': [], 'value': "r'\\1'"},{'id': '334', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'current_set_number'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '337', 'type': 'except_clause', 'children': ['338']},{'id': '338', 'type': 'block', 'children': ['339']},{'id': '339', 'type': 'pass_statement', 'children': []},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '345']},{'id': '342', 'type': 'subscript', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'validators'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'validator'},{'id': '354', 'type': 'argument_list', 'children': ['355', '357']},{'id': '355', 'type': 'list_splat', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '357', 'type': 'dictionary_splat', 'children': ['358']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '359', 'type': 'expression_statement', 'children': ['360']},{'id': '360', 'type': 'assignment', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'field_type'},{'id': '362', 'type': 'subscript', 'children': ['363', '368']},{'id': '363', 'type': 'subscript', 'children': ['364', '367']},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '366', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '368', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'assignment', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'field_label'},{'id': '372', 'type': 'subscript', 'children': ['373', '378']},{'id': '373', 'type': 'subscript', 'children': ['374', '377']},{'id': '374', 'type': 'attribute', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '376', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '378', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '379', 'type': 'expression_statement', 'children': ['380']},{'id': '380', 'type': 'assignment', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'field_args'},{'id': '382', 'type': 'subscript', 'children': ['383', '388']},{'id': '383', 'type': 'subscript', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '386', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '388', 'type': 'string', 'children': [], 'value': "'args'"},{'id': '389', 'type': 'expression_statement', 'children': ['390']},{'id': '390', 'type': 'assignment', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'field_kwargs'},{'id': '392', 'type': 'subscript', 'children': ['393', '398']},{'id': '393', 'type': 'subscript', 'children': ['394', '397']},{'id': '394', 'type': 'attribute', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '396', 'type': 'identifier', 'children': [], 'value': '_dyn_fields'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'field_cname'},{'id': '398', 'type': 'string', 'children': [], 'value': "'kwargs'"},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'call', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '402', 'type': 'argument_list', 'children': ['403', '404', '405']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '405', 'type': 'call', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'field_type'},{'id': '407', 'type': 'argument_list', 'children': ['408', '409', '412', '414']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'field_label'},{'id': '409', 'type': 'keyword_argument', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'validators'},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'validators'},{'id': '412', 'type': 'list_splat', 'children': ['413']},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'field_args'},{'id': '414', 'type': 'dictionary_splat', 'children': ['415']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'field_kwargs'},{'id': '416', 'type': 'if_statement', 'children': ['417', '420', '427']},{'id': '417', 'type': 'attribute', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'flask_wtf'},{'id': '420', 'type': 'block', 'children': ['421']},{'id': '421', 'type': 'expression_statement', 'children': ['422']},{'id': '422', 'type': 'assignment', 'children': ['423', '424']},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '424', 'type': 'call', 'children': ['425', '426']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '426', 'type': 'argument_list', 'children': []},{'id': '427', 'type': 'else_clause', 'children': ['428']},{'id': '428', 'type': 'block', 'children': ['429']},{'id': '429', 'type': 'expression_statement', 'children': ['430']},{'id': '430', 'type': 'assignment', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '432', 'type': 'call', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '434', 'type': 'argument_list', 'children': ['435']},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'post'},{'id': '436', 'type': 'return_statement', 'children': ['437']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'form'}
def process(self, form, post): if not isinstance(form, FormMeta): raise TypeError('Given form is not a valid WTForm.') re_field_name = re.compile(r'\%([a-zA-Z0-9_]*)\%') class F(form): pass for field, data in post.iteritems(): if field in F(): continue else: if field in self._dyn_fields: field_cname = field current_set_number = None elif (field.split('_')[-1].isdigit() and field[:-(len(field.split('_')[-1]))-1] in self._dyn_fields.keys()): field_cname = field[:-(len(field.split('_')[-1]))-1] current_set_number = str(field.split('_')[-1]) else: continue validators = [] if 'validators' in self._dyn_fields[field_cname]: for validator in self._dyn_fields[field_cname]['validators']: args = [] kwargs = {} if 'args' in self._dyn_fields[field_cname]\ [validator.__name__]: if not current_set_number: args = self._dyn_fields[field_cname]\ [validator.__name__]['args'] else: for arg in self._dyn_fields[field_cname]\ [validator.__name__]['args']: try: arg = re_field_name.sub(r'\1'+'_'+current_set_number, arg) except: pass args.append(arg) if 'kwargs' in self._dyn_fields[field_cname]\ [validator.__name__]: if not current_set_number: kwargs = self._dyn_fields[field_cname]\ [validator.__name__]['kwargs'] else: for key, arg in self.iteritems(self._dyn_fields[field_cname]\ [validator.__name__]['kwargs']): try: arg = re_field_name.sub(r'\1'+'_'+current_set_number, arg) except: pass kwargs[key] = arg validators.append(validator(*args, **kwargs)) field_type = self._dyn_fields[field_cname]['type'] field_label = self._dyn_fields[field_cname]['label'] field_args = self._dyn_fields[field_cname]['args'] field_kwargs = self._dyn_fields[field_cname]['kwargs'] setattr(F, field, field_type(field_label, validators=validators, *field_args, **field_kwargs)) if self.flask_wtf: form = F() else: form = F(post) return form
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'distinct_values'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 't_old'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 't_new'},{'id': '6', 'type': 'block', 'children': ['7', '11', '19', '118']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'list', 'children': ['18'], 'value': "[' -- NOT IN check -- ']"},{'id': '18', 'type': 'string', 'children': [], 'value': "' -- NOT IN check -- '"},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'new_col'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 't_new'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '24', 'type': 'block', 'children': ['25', '35']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'dist_new'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 't_new'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_distinct_values_from_cols'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'list', 'children': ['34'], 'value': '[new_col]'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'new_col'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '40']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'old_col'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 't_old'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'if_statement', 'children': ['42', '45']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '=='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'old_col'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'new_col'},{'id': '45', 'type': 'block', 'children': ['46', '56', '72', '87', '103']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dist_old'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 't_old'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_distinct_values_from_cols'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'list', 'children': ['55'], 'value': '[old_col]'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'old_col'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'not_in_new'},{'id': '59', 'type': 'list_comprehension', 'children': ['60', '61', '66']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'dist_old'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'if_clause', 'children': ['67']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'not'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dist_new'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '!='},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'not_in_new'},{'id': '75', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'res'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'list', 'children': ['84', '85', '86'], 'value': "['Not in New', old_col, not_in_new]"},{'id': '84', 'type': 'string', 'children': [], 'value': "'Not in New'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'old_col'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'not_in_new'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'not_in_old'},{'id': '90', 'type': 'list_comprehension', 'children': ['91', '92', '97']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'dist_new'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'if_clause', 'children': ['98']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'not'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'dist_old'},{'id': '102', 'type': 'integer', 'children': [], 'value': '0'},{'id': '103', 'type': 'if_statement', 'children': ['104', '107']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '!='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'not_in_old'},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'list', 'children': ['115', '116', '117'], 'value': "['Not in Old', new_col, not_in_old]"},{'id': '115', 'type': 'string', 'children': [], 'value': "'Not in Old'"},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'new_col'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'not_in_old'},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'res'}
def distinct_values(t_old, t_new): res = [] res.append([' -- NOT IN check -- ']) for new_col in t_new.header: dist_new = t_new.get_distinct_values_from_cols([new_col]) for old_col in t_old.header: if old_col == new_col: dist_old = t_old.get_distinct_values_from_cols([old_col]) not_in_new = [x for x in dist_old[0] if x not in dist_new[0]] if not_in_new != []: res.append(['Not in New', old_col, not_in_new]) not_in_old = [x for x in dist_new[0] if x not in dist_old[0]] if not_in_old != []: res.append(['Not in Old', new_col, not_in_old]) return sorted(res)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'most_similar_catchments'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'similarity_dist_function'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'records_limit'},{'id': '9', 'type': 'integer', 'children': [], 'value': '500'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'include_subject_catchment'},{'id': '12', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '13', 'type': 'block', 'children': ['14', '34', '111', '119', '185', '199', '211', '215', '219', '242']},{'id': '14', 'type': 'if_statement', 'children': ['15', '21']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'not'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'include_subject_catchment'},{'id': '17', 'type': 'list', 'children': ['18', '19', '20'], 'value': "['auto', 'force', 'exclude']"},{'id': '18', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'force'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'exclude'"},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'raise_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'binary_operator', 'children': ['27', '33'], 'value': '+'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': '"Parameter `include_subject_catchment={}` invalid."'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'include_subject_catchment'},{'id': '33', 'type': 'string', 'children': [], 'value': '"Must be one of `auto`, `force` or `exclude`."'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '37', 'type': '()', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '100']},{'id': '39', 'type': 'attribute', 'children': ['40', '99']},{'id': '40', 'type': 'call', 'children': ['41', '97']},{'id': '41', 'type': 'attribute', 'children': ['42', '96']},{'id': '42', 'type': 'call', 'children': ['43', '67']},{'id': '43', 'type': 'attribute', 'children': ['44', '66']},{'id': '44', 'type': 'call', 'children': ['45', '62']},{'id': '45', 'type': 'attribute', 'children': ['46', '61']},{'id': '46', 'type': 'call', 'children': ['47', '57']},{'id': '47', 'type': 'attribute', 'children': ['48', '56']},{'id': '48', 'type': 'call', 'children': ['49', '54']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'db_session'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'Catchment'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'Catchment'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'descriptors'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Catchment'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'amax_records'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '67', 'type': 'argument_list', 'children': ['68', '75', '78', '91']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': '!='},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'Catchment'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'Catchment'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'is_suitable_for_pooling'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'or_'},{'id': '80', 'type': 'argument_list', 'children': ['81', '86']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '<'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'Descriptors'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'urbext2000'},{'id': '85', 'type': 'float', 'children': [], 'value': '0.03'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': '=='},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'Descriptors'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'urbext2000'},{'id': '90', 'type': 'None', 'children': []},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '95'], 'value': '=='},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'AmaxRecord'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'flag'},{'id': '95', 'type': 'integer', 'children': [], 'value': '0'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'group_by'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'Catchment'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'having'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '110'], 'value': '>='},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'AmaxRecord'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'catchment_id'},{'id': '110', 'type': 'integer', 'children': [], 'value': '10'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'catchments'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'if_statement', 'children': ['120', '123', '141']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '=='},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'include_subject_catchment'},{'id': '122', 'type': 'string', 'children': [], 'value': "'force'"},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'if_statement', 'children': ['125', '133']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '132'], 'value': '>='},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'amax_records'},{'id': '132', 'type': 'integer', 'children': [], 'value': '10'},{'id': '133', 'type': 'block', 'children': ['134']},{'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': 'catchments'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '141', 'type': 'elif_clause', 'children': ['142', '145']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '=='},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'include_subject_catchment'},{'id': '144', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'if_statement', 'children': ['147', '177']},{'id': '147', 'type': 'boolean_operator', 'children': ['148', '160', '161'], 'value': 'and'},{'id': '148', 'type': 'boolean_operator', 'children': ['149', '157'], 'value': 'and'},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '156'], 'value': '>='},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'amax_records'},{'id': '156', 'type': 'integer', 'children': [], 'value': '10'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'is_suitable_for_pooling'},{'id': '160', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '161', 'type': '()', 'children': ['162']},{'id': '162', 'type': 'boolean_operator', 'children': ['163', '170'], 'value': 'or'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '169'], 'value': '<'},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'descriptors'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'urbext2000'},{'id': '169', 'type': 'float', 'children': [], 'value': '0.03'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '176'], 'value': 'is'},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'descriptors'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'urbext2000'},{'id': '176', 'type': 'None', 'children': []},{'id': '177', 'type': 'block', 'children': ['178']},{'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': 'catchments'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '185', 'type': 'for_statement', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'catchment'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'catchments'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'catchment'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'similarity_dist'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'similarity_dist_function'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'subject_catchment'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'catchment'},{'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': 'catchments'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'attrgetter'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'string', 'children': [], 'value': "'similarity_dist'"},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'amax_records_count'},{'id': '214', 'type': 'integer', 'children': [], 'value': '0'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'catchments_limited'},{'id': '218', 'type': 'list', 'children': [], 'value': '[]'},{'id': '219', 'type': 'for_statement', 'children': ['220', '221', '222']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'catchment'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'catchments'},{'id': '222', 'type': 'block', 'children': ['223', '230', '236']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'catchments_limited'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'catchment'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'augmented_assignment', 'children': ['232', '233'], 'value': '+='},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'amax_records_count'},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'catchment'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'record_length'},{'id': '236', 'type': 'if_statement', 'children': ['237', '240']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': '>='},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'amax_records_count'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'records_limit'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'break_statement', 'children': []},{'id': '242', 'type': 'return_statement', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'catchments_limited'}
def most_similar_catchments(self, subject_catchment, similarity_dist_function, records_limit=500, include_subject_catchment='auto'): if include_subject_catchment not in ['auto', 'force', 'exclude']: raise ValueError("Parameter `include_subject_catchment={}` invalid.".format(include_subject_catchment) + "Must be one of `auto`, `force` or `exclude`.") query = (self.db_session.query(Catchment). join(Catchment.descriptors). join(Catchment.amax_records). filter(Catchment.id != subject_catchment.id, Catchment.is_suitable_for_pooling, or_(Descriptors.urbext2000 < 0.03, Descriptors.urbext2000 == None), AmaxRecord.flag == 0). group_by(Catchment). having(func.count(AmaxRecord.catchment_id) >= 10)) catchments = query.all() if include_subject_catchment == 'force': if len(subject_catchment.amax_records) >= 10: catchments.append(subject_catchment) elif include_subject_catchment == 'auto': if len(subject_catchment.amax_records) >= 10 and subject_catchment.is_suitable_for_pooling and \ (subject_catchment.descriptors.urbext2000 < 0.03 or subject_catchment.descriptors.urbext2000 is None): catchments.append(subject_catchment) for catchment in catchments: catchment.similarity_dist = similarity_dist_function(subject_catchment, catchment) catchments.sort(key=attrgetter('similarity_dist')) amax_records_count = 0 catchments_limited = [] for catchment in catchments: catchments_limited.append(catchment) amax_records_count += catchment.record_length if amax_records_count >= records_limit: break return catchments_limited
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'readSAM'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'SAMfile'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '57', '75', '97', '111', '117', '127', '139', '149', '205', '222']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '=='},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '22', '26', '51']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'SAMfile'},{'id': '21', 'type': 'string', 'children': [], 'value': '"r+"'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '33']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'readlines'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '40', '48']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '38', 'type': 'integer', 'children': [], 'value': '0'},{'id': '39', 'type': 'string', 'children': [], 'value': '"@"'},{'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': 'head'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'continue_statement', 'children': []},{'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': 'f'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'read_table'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '69', '72']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'SAMfile'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '68', 'type': 'string', 'children': [], 'value': '"this_gives_one_column"'},{'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'comment'},{'id': '71', 'type': 'string', 'children': [], 'value': '"@"'},{'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '74', 'type': 'None', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '96']},{'id': '84', 'type': 'attribute', 'children': ['85', '95']},{'id': '85', 'type': 'call', 'children': ['86', '93']},{'id': '86', 'type': 'attribute', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '90', 'type': 'integer', 'children': [], 'value': '0'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'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': 'acols'},{'id': '100', 'type': 'list', 'children': ['101', '102', '103', '104', '105', '106', '107', '108', '109', '110'], 'value': '[0,1,2,3,4,5,6,7,8,9]'},{'id': '101', 'type': 'integer', 'children': [], 'value': '0'},{'id': '102', 'type': 'integer', 'children': [], 'value': '1'},{'id': '103', 'type': 'integer', 'children': [], 'value': '2'},{'id': '104', 'type': 'integer', 'children': [], 'value': '3'},{'id': '105', 'type': 'integer', 'children': [], 'value': '4'},{'id': '106', 'type': 'integer', 'children': [], 'value': '5'},{'id': '107', 'type': 'integer', 'children': [], 'value': '6'},{'id': '108', 'type': 'integer', 'children': [], 'value': '7'},{'id': '109', 'type': 'integer', 'children': [], 'value': '8'},{'id': '110', 'type': 'integer', 'children': [], 'value': '9'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'sam_'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'acols'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'samcols'},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'id': '121', 'type': 'attribute', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'bcols'},{'id': '130', 'type': 'list_comprehension', 'children': ['131', '132', '135']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '132', 'type': 'for_in_clause', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'samcols'},{'id': '135', 'type': 'if_clause', 'children': ['136']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'not'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'acols'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '144']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sam_'},{'id': '143', 'type': 'integer', 'children': [], 'value': '10'},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'bcols'},{'id': '148', 'type': 'integer', 'children': [], 'value': '0'},{'id': '149', 'type': 'if_statement', 'children': ['150', '156']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '155'], 'value': '>'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'bcols'},{'id': '155', 'type': 'integer', 'children': [], 'value': '1'},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'for_statement', 'children': ['158', '159', '164']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'bcols'},{'id': '161', 'type': 'slice', 'children': ['162', '163']},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'colon', 'children': []},{'id': '164', 'type': 'block', 'children': ['165', '178', '191']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '170']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'sam_'},{'id': '169', 'type': 'integer', 'children': [], 'value': '10'},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'sam_'},{'id': '174', 'type': 'integer', 'children': [], 'value': '10'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '183']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '183', 'type': 'call', 'children': ['184', '189']},{'id': '184', 'type': 'attribute', 'children': ['185', '188']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '196']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'sam_'},{'id': '195', 'type': 'integer', 'children': [], 'value': '10'},{'id': '196', 'type': 'binary_operator', 'children': ['197', '202'], 'value': '+'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '201'], 'value': '+'},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'sam_'},{'id': '200', 'type': 'integer', 'children': [], 'value': '10'},{'id': '201', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '202', 'type': 'subscript', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'sam_'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '210', 'type': 'list', 'children': ['211', '212', '213', '214', '215', '216', '217', '218', '219', '220', '221'], 'value': "['QNAME','FLAG','RNAME','POS','MAPQ','CIGAR','RNEXT','PNEXT','TLEN','SEQ','QUAL']"},{'id': '211', 'type': 'string', 'children': [], 'value': "'QNAME'"},{'id': '212', 'type': 'string', 'children': [], 'value': "'FLAG'"},{'id': '213', 'type': 'string', 'children': [], 'value': "'RNAME'"},{'id': '214', 'type': 'string', 'children': [], 'value': "'POS'"},{'id': '215', 'type': 'string', 'children': [], 'value': "'MAPQ'"},{'id': '216', 'type': 'string', 'children': [], 'value': "'CIGAR'"},{'id': '217', 'type': 'string', 'children': [], 'value': "'RNEXT'"},{'id': '218', 'type': 'string', 'children': [], 'value': "'PNEXT'"},{'id': '219', 'type': 'string', 'children': [], 'value': "'TLEN'"},{'id': '220', 'type': 'string', 'children': [], 'value': "'SEQ'"},{'id': '221', 'type': 'string', 'children': [], 'value': "'QUAL'"},{'id': '222', 'type': 'if_statement', 'children': ['223', '226', '231']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': '=='},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '225', 'type': 'True', 'children': []},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'return_statement', 'children': ['228']},{'id': '228', 'type': 'expression_list', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'sam_'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '231', 'type': 'else_clause', 'children': ['232']},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'sam_'}
def readSAM(SAMfile,header=False): if header==True: f=open(SAMfile,"r+") head=[] for line in f.readlines(): if line[0]=="@": head.append(line) else: continue f.close() sam=pd.read_table(SAMfile,sep="this_gives_one_column",comment="@",header=None) sam=pd.DataFrame(sam[0].str.split("\t").tolist()) acols=[0,1,2,3,4,5,6,7,8,9] sam_=sam[acols] samcols=sam.columns.tolist() bcols=[ s for s in samcols if s not in acols ] sam_[10]=sam[bcols[0]] if len(bcols) > 1: for c in bcols[1:]: sam_[10]=sam_[10].astype(str) sam[c]=sam[c].astype(str) sam_[10]=sam_[10]+"\t"+sam[c] sam_.columns=['QNAME','FLAG','RNAME','POS','MAPQ','CIGAR','RNEXT','PNEXT','TLEN','SEQ','QUAL'] if header==True: return sam_, head else: return sam_
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'SAMflags'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'block', 'children': ['6', '10', '25', '32', '47', '54', '69', '76', '91', '98', '113', '120', '135', '142', '157', '164', '179', '186', '201', '208', '223', '230', '245', '252', '267', '274']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'if_statement', 'children': ['11', '14', '19']},{'id': '11', 'type': 'binary_operator', 'children': ['12', '13'], 'value': '&'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '18', 'type': 'string', 'children': [], 'value': '"1: Read paired"'},{'id': '19', 'type': 'else_clause', 'children': ['20']},{'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': 'l'},{'id': '24', 'type': 'string', 'children': [], 'value': '"0: Read unpaired"'},{'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': 'flags'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '32', 'type': 'if_statement', 'children': ['33', '36', '41']},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '&'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '35', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'l'},{'id': '40', 'type': 'string', 'children': [], 'value': '"1: Read mapped in proper pair"'},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '46', 'type': 'string', 'children': [], 'value': '"0: Read not mapped in proper pair"'},{'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': 'flags'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '54', 'type': 'if_statement', 'children': ['55', '58', '63']},{'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '&'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '57', 'type': 'integer', 'children': [], 'value': '4'},{'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': 'l'},{'id': '62', 'type': 'string', 'children': [], 'value': '"1: Read unmapped"'},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'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': 'l'},{'id': '68', 'type': 'string', 'children': [], 'value': '"0: Read mapped"'},{'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': 'flags'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '76', 'type': 'if_statement', 'children': ['77', '80', '85']},{'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '&'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '79', 'type': 'integer', 'children': [], 'value': '8'},{'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': 'l'},{'id': '84', 'type': 'string', 'children': [], 'value': '"1: Mate unmapped"'},{'id': '85', 'type': 'else_clause', 'children': ['86']},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '90', 'type': 'string', 'children': [], 'value': '"0: Mate mapped"'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '98', 'type': 'if_statement', 'children': ['99', '102', '107']},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '&'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '101', 'type': 'integer', 'children': [], 'value': '16'},{'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': 'l'},{'id': '106', 'type': 'string', 'children': [], 'value': '"1: Read reverse strand"'},{'id': '107', 'type': 'else_clause', 'children': ['108']},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '112', 'type': 'string', 'children': [], 'value': '"0: Read direct strand"'},{'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': 'flags'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '120', 'type': 'if_statement', 'children': ['121', '124', '129']},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '&'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '123', 'type': 'integer', 'children': [], 'value': '32'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '128', 'type': 'string', 'children': [], 'value': '"1: Mate reverse strand"'},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'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': 'l'},{'id': '134', 'type': 'string', 'children': [], 'value': '"0: Mate direct strand"'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '142', 'type': 'if_statement', 'children': ['143', '146', '151']},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '&'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '145', 'type': 'integer', 'children': [], 'value': '64'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '150', 'type': 'string', 'children': [], 'value': '"1: First in pair"'},{'id': '151', 'type': 'else_clause', 'children': ['152']},{'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': 'l'},{'id': '156', 'type': 'string', 'children': [], 'value': '"0: Second in pair"'},{'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': 'flags'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '164', 'type': 'if_statement', 'children': ['165', '168', '173']},{'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '&'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '167', 'type': 'integer', 'children': [], 'value': '128'},{'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': 'l'},{'id': '172', 'type': 'string', 'children': [], 'value': '"1: Second in pair"'},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '178', 'type': 'string', 'children': [], 'value': '"0: First in pair"'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '186', 'type': 'if_statement', 'children': ['187', '190', '195']},{'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '&'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '189', 'type': 'integer', 'children': [], 'value': '256'},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '194', 'type': 'string', 'children': [], 'value': '"1: Not primary alignment"'},{'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', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '200', 'type': 'string', 'children': [], 'value': '"0: Primary alignment"'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '208', 'type': 'if_statement', 'children': ['209', '212', '217']},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '&'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '211', 'type': 'integer', 'children': [], 'value': '512'},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '216', 'type': 'string', 'children': [], 'value': '"1: Read fails platform/vendor quality checks"'},{'id': '217', 'type': 'else_clause', 'children': ['218']},{'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': 'l'},{'id': '222', 'type': 'string', 'children': [], 'value': '"0: Read passes platform/vendor quality checks"'},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '230', 'type': 'if_statement', 'children': ['231', '234', '239']},{'id': '231', 'type': 'binary_operator', 'children': ['232', '233'], 'value': '&'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '233', 'type': 'integer', 'children': [], 'value': '1024'},{'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': 'l'},{'id': '238', 'type': 'string', 'children': [], 'value': '"1: Read is PCR or optical duplicate"'},{'id': '239', 'type': 'else_clause', 'children': ['240']},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '244', 'type': 'string', 'children': [], 'value': '"0: Read is not PCR or optical duplicate"'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '252', 'type': 'if_statement', 'children': ['253', '256', '261']},{'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '&'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '255', 'type': 'integer', 'children': [], 'value': '2048'},{'id': '256', 'type': 'block', 'children': ['257']},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '260', 'type': 'string', 'children': [], 'value': '"1: Supplementary alignment"'},{'id': '261', 'type': 'else_clause', 'children': ['262']},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '266', 'type': 'string', 'children': [], 'value': '"0: Not supplementary alignment"'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '274', 'type': 'return_statement', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'flags'}
def SAMflags(x): flags=[] if x & 1: l="1: Read paired" else: l="0: Read unpaired" flags.append(l) if x & 2 : l="1: Read mapped in proper pair" else: l="0: Read not mapped in proper pair" flags.append(l) if x & 4 : l="1: Read unmapped" else: l="0: Read mapped" flags.append(l) if x & 8 : l="1: Mate unmapped" else: l="0: Mate mapped" flags.append(l) if x & 16 : l="1: Read reverse strand" else: l="0: Read direct strand" flags.append(l) if x & 32 : l="1: Mate reverse strand" else: l="0: Mate direct strand" flags.append(l) if x & 64 : l="1: First in pair" else: l="0: Second in pair" flags.append(l) if x & 128 : l="1: Second in pair" else: l="0: First in pair" flags.append(l) if x & 256 : l="1: Not primary alignment" else: l="0: Primary alignment" flags.append(l) if x & 512 : l="1: Read fails platform/vendor quality checks" else: l="0: Read passes platform/vendor quality checks" flags.append(l) if x & 1024 : l="1: Read is PCR or optical duplicate" else: l="0: Read is not PCR or optical duplicate" flags.append(l) if x & 2048 : l="1: Supplementary alignment" else: l="0: Not supplementary alignment" flags.append(l) return flags
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '74']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'BLASTquery'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '11', '14', '17', '18', '21', '24', '25', '28', '31', '32', '35', '38', '39', '42', '43', '46', '49', '50', '53', '56', '57', '60', '63', '64', '67', '70', '71']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'program'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'format_type'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'expect'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'nucl_reward'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'nucl_penalty'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'gapcosts'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'hitlist_size'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'descriptions'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '39', 'type': 'default_parameter', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'alignments'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '43', 'type': 'default_parameter', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'ncbi_gi'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'default_parameter', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '50', 'type': 'default_parameter', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'word_size'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'default_parameter', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'composition_based_statistics'},{'id': '55', 'type': 'None', 'children': []},{'id': '56', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '57', 'type': 'default_parameter', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'default_parameter', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '64', 'type': 'default_parameter', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'num_threads'},{'id': '66', 'type': 'None', 'children': []},{'id': '67', 'type': 'default_parameter', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'baseURL'},{'id': '69', 'type': 'string', 'children': [], 'value': '"http://blast.ncbi.nlm.nih.gov"'},{'id': '70', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '71', 'type': 'default_parameter', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '73', 'type': 'False', 'children': []},{'id': '74', 'type': 'block', 'children': ['75', '116', '122', '147', '211', '222', '228', '244', '255', '266', '278', '311']},{'id': '75', 'type': 'if_statement', 'children': ['76', '77', '110']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '77', 'type': 'block', 'children': ['78', '106']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '81', 'type': 'call', 'children': ['82', '103']},{'id': '82', 'type': 'attribute', 'children': ['83', '102']},{'id': '83', 'type': 'call', 'children': ['84', '99']},{'id': '84', 'type': 'attribute', 'children': ['85', '98']},{'id': '85', 'type': 'call', 'children': ['86', '95']},{'id': '86', 'type': 'attribute', 'children': ['87', '94']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': '" "'},{'id': '93', 'type': 'string', 'children': [], 'value': '"%20"'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': '"("'},{'id': '97', 'type': 'string', 'children': [], 'value': '"%28"'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': '")"'},{'id': '101', 'type': 'string', 'children': [], 'value': '"%29"'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'string', 'children': [], 'value': '":"'},{'id': '105', 'type': 'string', 'children': [], 'value': '"%3A"'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'EQ_MENU'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'organism'},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'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': 'EQ_MENU'},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '+'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'baseURL'},{'id': '121', 'type': 'string', 'children': [], 'value': '"/Blast.cgi?"'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '143'], 'value': '+'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '142'], 'value': '+'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '138'], 'value': '+'},{'id': '128', 'type': 'binary_operator', 'children': ['129', '137'], 'value': '+'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '133'], 'value': '+'},{'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '+'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '132', 'type': 'string', 'children': [], 'value': '"QUERY="'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '137', 'type': 'string', 'children': [], 'value': '"&DATABASE="'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'database'},{'id': '142', 'type': 'string', 'children': [], 'value': '"&PROGRAM="'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'program'},{'id': '147', 'type': 'for_statement', 'children': ['148', '151', '192']},{'id': '148', 'type': 'pattern_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'varname'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '153', 'type': 'argument_list', 'children': ['154', '174', '175']},{'id': '154', 'type': 'list', 'children': ['155', '156', '157', '158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173'], 'value': '[filter, format_type, expect, nucl_reward, nucl_penalty,\\\n gapcosts, matrix, hitlist_size, descriptions, alignments,\\\n ncbi_gi, threshold, word_size, composition_based_statistics,\\\n EQ_MENU, num_threads]'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'format_type'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'expect'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'nucl_reward'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'nucl_penalty'},{'id': '160', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'gapcosts'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'hitlist_size'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'descriptions'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'alignments'},{'id': '166', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ncbi_gi'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'word_size'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'composition_based_statistics'},{'id': '171', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'EQ_MENU'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'num_threads'},{'id': '174', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '175', 'type': 'list', 'children': ['176', '177', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191'], 'value': "['FILTER' , 'FORMAT_TYPE', 'EXPECT', 'NUCL_REWARD', 'NUCL_PENALTY',\\\n 'GAPCOSTS', 'MATRIX', 'HITLIST_SIZE', 'DESCRIPTIONS', 'ALIGNMENTS',\\\n 'NCBI_GI', 'THRESHOLD', 'WORD_SIZE', 'COMPOSITION_BASED_STATISTICS',\\\n 'EQ_MENU', 'NUM_THREADS']"},{'id': '176', 'type': 'string', 'children': [], 'value': "'FILTER'"},{'id': '177', 'type': 'string', 'children': [], 'value': "'FORMAT_TYPE'"},{'id': '178', 'type': 'string', 'children': [], 'value': "'EXPECT'"},{'id': '179', 'type': 'string', 'children': [], 'value': "'NUCL_REWARD'"},{'id': '180', 'type': 'string', 'children': [], 'value': "'NUCL_PENALTY'"},{'id': '181', 'type': 'string', 'children': [], 'value': "'GAPCOSTS'"},{'id': '182', 'type': 'string', 'children': [], 'value': "'MATRIX'"},{'id': '183', 'type': 'string', 'children': [], 'value': "'HITLIST_SIZE'"},{'id': '184', 'type': 'string', 'children': [], 'value': "'DESCRIPTIONS'"},{'id': '185', 'type': 'string', 'children': [], 'value': "'ALIGNMENTS'"},{'id': '186', 'type': 'string', 'children': [], 'value': "'NCBI_GI'"},{'id': '187', 'type': 'string', 'children': [], 'value': "'THRESHOLD'"},{'id': '188', 'type': 'string', 'children': [], 'value': "'WORD_SIZE'"},{'id': '189', 'type': 'string', 'children': [], 'value': "'COMPOSITION_BASED_STATISTICS'"},{'id': '190', 'type': 'string', 'children': [], 'value': "'EQ_MENU'"},{'id': '191', 'type': 'string', 'children': [], 'value': "'NUM_THREADS'"},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'if_statement', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '207'], 'value': '+'},{'id': '200', 'type': 'binary_operator', 'children': ['201', '206'], 'value': '+'},{'id': '201', 'type': 'binary_operator', 'children': ['202', '205'], 'value': '+'},{'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '+'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '204', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'varname'},{'id': '206', 'type': 'string', 'children': [], 'value': '"="'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '211', 'type': 'if_statement', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '221'], 'value': '+'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '220', 'type': 'string', 'children': [], 'value': '"&"'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '+'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '227', 'type': 'string', 'children': [], 'value': '"&CMD=Put"'},{'id': '228', 'type': 'if_statement', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '230', 'type': 'block', 'children': ['231', '236']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '243']},{'id': '238', 'type': 'attribute', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '243', 'type': 'argument_list', 'children': []},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'keyword_argument', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '258', 'type': 'call', 'children': ['259', '264']},{'id': '259', 'type': 'attribute', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'RID'},{'id': '269', 'type': 'list_comprehension', 'children': ['270', '271', '274']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '271', 'type': 'for_in_clause', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '274', 'type': 'if_clause', 'children': ['275']},{'id': '275', 'type': 'comparison_operator', 'children': ['276', '277'], 'value': 'in'},{'id': '276', 'type': 'string', 'children': [], 'value': '"RID = "'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '278', 'type': 'if_statement', 'children': ['279', '285', '300']},{'id': '279', 'type': 'comparison_operator', 'children': ['280', '284'], 'value': '>'},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'RID'},{'id': '284', 'type': 'integer', 'children': [], 'value': '0'},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'RID'},{'id': '289', 'type': 'subscript', 'children': ['290', '298']},{'id': '290', 'type': 'call', 'children': ['291', '296']},{'id': '291', 'type': 'attribute', 'children': ['292', '295']},{'id': '292', 'type': 'subscript', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'RID'},{'id': '294', 'type': 'integer', 'children': [], 'value': '0'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'string', 'children': [], 'value': '" "'},{'id': '298', 'type': 'unary_operator', 'children': ['299'], 'value': '-'},{'id': '299', 'type': 'integer', 'children': [], 'value': '1'},{'id': '300', 'type': 'else_clause', 'children': ['301']},{'id': '301', 'type': 'block', 'children': ['302', '307']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '305', 'type': 'argument_list', 'children': ['306']},{'id': '306', 'type': 'string', 'children': [], 'value': '"Could not return an RID for this query."'},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'RID'},{'id': '310', 'type': 'None', 'children': []},{'id': '311', 'type': 'return_statement', 'children': ['312']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'RID'}
def BLASTquery(query,database,program,filter=None,\ format_type=None, expect=None,\ nucl_reward=None, nucl_penalty=None,\ gapcosts=None, matrix=None,\ hitlist_size=None, descriptions=None,\ alignments=None,\ ncbi_gi=None, threshold=None,\ word_size=None, composition_based_statistics=None,\ organism=None, others=None,\ num_threads=None, baseURL="http://blast.ncbi.nlm.nih.gov",\ verbose=False): if organism: organism=organism.replace(" ", "%20").replace("(", "%28").replace(")", "%29").replace(":", "%3A") EQ_MENU=organism else: EQ_MENU=None URL=baseURL+"/Blast.cgi?" URL=URL+"QUERY="+str(query)+"&DATABASE="+str(database)+"&PROGRAM="+str(program) for o,varname in zip([filter, format_type, expect, nucl_reward, nucl_penalty,\ gapcosts, matrix, hitlist_size, descriptions, alignments,\ ncbi_gi, threshold, word_size, composition_based_statistics,\ EQ_MENU, num_threads],\ ['FILTER' , 'FORMAT_TYPE', 'EXPECT', 'NUCL_REWARD', 'NUCL_PENALTY',\ 'GAPCOSTS', 'MATRIX', 'HITLIST_SIZE', 'DESCRIPTIONS', 'ALIGNMENTS',\ 'NCBI_GI', 'THRESHOLD', 'WORD_SIZE', 'COMPOSITION_BASED_STATISTICS',\ 'EQ_MENU', 'NUM_THREADS']): if o: URL=URL+"&"+ varname +"="+str(o) if others: URL=URL+"&"+others URL=URL+"&CMD=Put" if verbose: print(URL) sys.stdout.flush() response=requests.get(url = URL) r=response.content.split("\n") RID=[ s for s in r if "RID = " in s ] if len(RID) > 0: RID=RID[0].split(" ")[-1] else: print("Could not return an RID for this query.") RID=None return RID
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_star'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '8', 'type': 'block', 'children': ['9', '17', '25', '44', '56', '68', '99', '111', '125', '141', '163', '224', '236', '291', '297', '324', '337', '350', '363']},{'id': '9', 'type': 'assert_statement', 'children': ['10']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': 'in'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '13', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '14', 'type': 'tuple', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'starlong'"},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '28', 'type': 'dictionary', 'children': ['29', '34', '39']},{'id': '29', 'type': 'pair', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_1.fastq'"},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'pair', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_2.fastq'"},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'pair', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': "'star_index.tar.gz'"},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '43', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_files_from_filestore'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52', '53']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'docker'},{'id': '55', 'type': 'False', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '59', 'type': 'conditional_expression', 'children': ['60', '61', '67'], 'value': 'if'},{'id': '60', 'type': 'string', 'children': [], 'value': "'.gz'"},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'is_gzipfile'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '66', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_1.fastq'"},{'id': '67', 'type': 'string', 'children': [], 'value': "''"},{'id': '68', 'type': 'if_statement', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '76']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '73', 'type': 'expression_list', 'children': ['74', '75']},{'id': '74', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_1.fastq'"},{'id': '75', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_2.fastq'"},{'id': '76', 'type': 'block', 'children': ['77', '87']},{'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': 'os'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'symlink'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '+'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '94']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '+'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '94', 'type': 'binary_operator', 'children': ['95', '98'], 'value': '+'},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'read_file'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '103', 'type': 'string', 'children': [], 'value': "'star_index'"},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'untargz'},{'id': '106', 'type': 'argument_list', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '109', 'type': 'string', 'children': [], 'value': "'star_index.tar.gz'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'star_fusion_idx'},{'id': '114', 'type': 'call', 'children': ['115', '120']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '120', 'type': 'argument_list', 'children': ['121', '124']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '123', 'type': 'string', 'children': [], 'value': "'star_index'"},{'id': '124', 'type': 'string', 'children': [], 'value': "'ref_genome.fa.star.idx'"},{'id': '125', 'type': 'if_statement', 'children': ['126', '134']},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'star_fusion_idx'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '139', 'type': 'string', 'children': [], 'value': "'star_index'"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'star_fusion_idx'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '144', 'type': 'dictionary_comprehension', 'children': ['145', '154']},{'id': '145', 'type': 'pair', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'docker_path'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '154', 'type': 'for_in_clause', 'children': ['155', '158']},{'id': '155', 'type': 'pattern_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '166', 'type': 'list', 'children': ['167', '168', '174', '175', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '198', '199', '200', '201', '202', '203', '208', '213', '214', '215', '216', '217', '218', '219', '220', '221', '222', '223'], 'value': "['--runThreadN', str(star_options['n']),\n '--genomeDir', input_files['star_index'],\n '--twopassMode', 'Basic',\n '--outReadsUnmapped', 'None',\n '--chimSegmentMin', '12',\n '--chimJunctionOverhangMin', '12',\n '--alignSJDBoverhangMin', '10',\n '--alignMatesGapMax', '200000',\n '--alignIntronMax', '200000',\n '--chimSegmentReadGapMax', 'parameter', '3',\n '--alignSJstitchMismatchNmax', '5', '-1', '5', '5',\n '--outFileNamePrefix', 'rna',\n '--readFilesIn',\n input_files['rna_cutadapt_1.fastq' + gz],\n input_files['rna_cutadapt_2.fastq' + gz],\n '--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD',\n '--outSAMtype', 'BAM', 'Unsorted',\n '--quantMode', 'TranscriptomeSAM']"},{'id': '167', 'type': 'string', 'children': [], 'value': "'--runThreadN'"},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '173', 'type': 'string', 'children': [], 'value': "'n'"},{'id': '174', 'type': 'string', 'children': [], 'value': "'--genomeDir'"},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '177', 'type': 'string', 'children': [], 'value': "'star_index'"},{'id': '178', 'type': 'string', 'children': [], 'value': "'--twopassMode'"},{'id': '179', 'type': 'string', 'children': [], 'value': "'Basic'"},{'id': '180', 'type': 'string', 'children': [], 'value': "'--outReadsUnmapped'"},{'id': '181', 'type': 'string', 'children': [], 'value': "'None'"},{'id': '182', 'type': 'string', 'children': [], 'value': "'--chimSegmentMin'"},{'id': '183', 'type': 'string', 'children': [], 'value': "'12'"},{'id': '184', 'type': 'string', 'children': [], 'value': "'--chimJunctionOverhangMin'"},{'id': '185', 'type': 'string', 'children': [], 'value': "'12'"},{'id': '186', 'type': 'string', 'children': [], 'value': "'--alignSJDBoverhangMin'"},{'id': '187', 'type': 'string', 'children': [], 'value': "'10'"},{'id': '188', 'type': 'string', 'children': [], 'value': "'--alignMatesGapMax'"},{'id': '189', 'type': 'string', 'children': [], 'value': "'200000'"},{'id': '190', 'type': 'string', 'children': [], 'value': "'--alignIntronMax'"},{'id': '191', 'type': 'string', 'children': [], 'value': "'200000'"},{'id': '192', 'type': 'string', 'children': [], 'value': "'--chimSegmentReadGapMax'"},{'id': '193', 'type': 'string', 'children': [], 'value': "'parameter'"},{'id': '194', 'type': 'string', 'children': [], 'value': "'3'"},{'id': '195', 'type': 'string', 'children': [], 'value': "'--alignSJstitchMismatchNmax'"},{'id': '196', 'type': 'string', 'children': [], 'value': "'5'"},{'id': '197', 'type': 'string', 'children': [], 'value': "'-1'"},{'id': '198', 'type': 'string', 'children': [], 'value': "'5'"},{'id': '199', 'type': 'string', 'children': [], 'value': "'5'"},{'id': '200', 'type': 'string', 'children': [], 'value': "'--outFileNamePrefix'"},{'id': '201', 'type': 'string', 'children': [], 'value': "'rna'"},{'id': '202', 'type': 'string', 'children': [], 'value': "'--readFilesIn'"},{'id': '203', 'type': 'subscript', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'},{'id': '206', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_1.fastq'"},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '+'},{'id': '211', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_2.fastq'"},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '213', 'type': 'string', 'children': [], 'value': "'--outSAMattributes'"},{'id': '214', 'type': 'string', 'children': [], 'value': "'NH'"},{'id': '215', 'type': 'string', 'children': [], 'value': "'HI'"},{'id': '216', 'type': 'string', 'children': [], 'value': "'AS'"},{'id': '217', 'type': 'string', 'children': [], 'value': "'NM'"},{'id': '218', 'type': 'string', 'children': [], 'value': "'MD'"},{'id': '219', 'type': 'string', 'children': [], 'value': "'--outSAMtype'"},{'id': '220', 'type': 'string', 'children': [], 'value': "'BAM'"},{'id': '221', 'type': 'string', 'children': [], 'value': "'Unsorted'"},{'id': '222', 'type': 'string', 'children': [], 'value': "'--quantMode'"},{'id': '223', 'type': 'string', 'children': [], 'value': "'TranscriptomeSAM'"},{'id': '224', 'type': 'if_statement', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'gz'},{'id': '226', 'type': 'block', 'children': ['227']},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'list', 'children': ['234', '235'], 'value': "['--readFilesCommand', 'zcat']"},{'id': '234', 'type': 'string', 'children': [], 'value': "'--readFilesCommand'"},{'id': '235', 'type': 'string', 'children': [], 'value': "'zcat'"},{'id': '236', 'type': 'if_statement', 'children': ['237', '242', '266']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '241'], 'value': '=='},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '240', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '241', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'docker_call'},{'id': '246', 'type': 'argument_list', 'children': ['247', '250', '253', '256', '261']},{'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '249', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '253', 'type': 'keyword_argument', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '256', 'type': 'keyword_argument', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '260', 'type': 'string', 'children': [], 'value': "'dockerhub'"},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'tool_version'},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '265', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '266', 'type': 'else_clause', 'children': ['267']},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'docker_call'},{'id': '271', 'type': 'argument_list', 'children': ['272', '275', '278', '281', '286']},{'id': '272', 'type': 'keyword_argument', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '274', 'type': 'string', 'children': [], 'value': "'starlong'"},{'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '285', 'type': 'string', 'children': [], 'value': "'dockerhub'"},{'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'tool_version'},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '290', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '296', 'type': 'argument_list', 'children': []},{'id': '297', 'type': 'for_statement', 'children': ['298', '299', '303']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'id': '299', 'type': 'list', 'children': ['300', '301', '302'], 'value': "['rnaAligned.toTranscriptome.out.bam',\n 'rnaAligned.out.bam',\n 'rnaChimeric.out.junction']"},{'id': '300', 'type': 'string', 'children': [], 'value': "'rnaAligned.toTranscriptome.out.bam'"},{'id': '301', 'type': 'string', 'children': [], 'value': "'rnaAligned.out.bam'"},{'id': '302', 'type': 'string', 'children': [], 'value': "'rnaChimeric.out.junction'"},{'id': '303', 'type': 'block', 'children': ['304']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'assignment', 'children': ['306', '309']},{'id': '306', 'type': 'subscript', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'id': '309', 'type': 'call', 'children': ['310', '315']},{'id': '310', 'type': 'attribute', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'list', 'children': ['322', '323'], 'value': '[work_dir, output_file]'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'export_results'},{'id': '327', 'type': 'argument_list', 'children': ['328', '329', '332', '333', '334']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '329', 'type': 'subscript', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '331', 'type': 'string', 'children': [], 'value': "'rnaAligned.toTranscriptome.out.bam'"},{'id': '332', 'type': 'string', 'children': [], 'value': "'rna_transcriptome.bam'"},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '334', 'type': 'keyword_argument', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'subfolder'},{'id': '336', 'type': 'string', 'children': [], 'value': "'alignments'"},{'id': '337', 'type': 'expression_statement', 'children': ['338']},{'id': '338', 'type': 'call', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'export_results'},{'id': '340', 'type': 'argument_list', 'children': ['341', '342', '345', '346', '347']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '342', 'type': 'subscript', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '344', 'type': 'string', 'children': [], 'value': "'rnaChimeric.out.junction'"},{'id': '345', 'type': 'string', 'children': [], 'value': "'rna_chimeric.junction'"},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '347', 'type': 'keyword_argument', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'subfolder'},{'id': '349', 'type': 'string', 'children': [], 'value': "'mutations/fusions'"},{'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': 'job'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '357', 'type': 'argument_list', 'children': ['358']},{'id': '358', 'type': 'binary_operator', 'children': ['359', '360'], 'value': '%'},{'id': '359', 'type': 'string', 'children': [], 'value': "'Ran STAR on %s successfully'"},{'id': '360', 'type': 'subscript', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '362', 'type': 'string', 'children': [], 'value': "'patient'"},{'id': '363', 'type': 'return_statement', 'children': ['364']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'output_files'}
def run_star(job, fastqs, univ_options, star_options): assert star_options['type'] in ('star', 'starlong') work_dir = os.getcwd() input_files = { 'rna_cutadapt_1.fastq': fastqs[0], 'rna_cutadapt_2.fastq': fastqs[1], 'star_index.tar.gz': star_options['index']} input_files = get_files_from_filestore(job, input_files, work_dir, docker=False) gz = '.gz' if is_gzipfile(input_files['rna_cutadapt_1.fastq']) else '' if gz: for read_file in 'rna_cutadapt_1.fastq', 'rna_cutadapt_2.fastq': os.symlink(read_file, read_file + gz) input_files[read_file + gz] = input_files[read_file] + gz input_files['star_index'] = untargz(input_files['star_index.tar.gz'], work_dir) star_fusion_idx = os.path.join(input_files['star_index'], 'ref_genome.fa.star.idx') if os.path.exists(star_fusion_idx): input_files['star_index'] = star_fusion_idx input_files = {key: docker_path(path, work_dir=work_dir) for key, path in input_files.items()} parameters = ['--runThreadN', str(star_options['n']), '--genomeDir', input_files['star_index'], '--twopassMode', 'Basic', '--outReadsUnmapped', 'None', '--chimSegmentMin', '12', '--chimJunctionOverhangMin', '12', '--alignSJDBoverhangMin', '10', '--alignMatesGapMax', '200000', '--alignIntronMax', '200000', '--chimSegmentReadGapMax', 'parameter', '3', '--alignSJstitchMismatchNmax', '5', '-1', '5', '5', '--outFileNamePrefix', 'rna', '--readFilesIn', input_files['rna_cutadapt_1.fastq' + gz], input_files['rna_cutadapt_2.fastq' + gz], '--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD', '--outSAMtype', 'BAM', 'Unsorted', '--quantMode', 'TranscriptomeSAM'] if gz: parameters.extend(['--readFilesCommand', 'zcat']) if star_options['type'] == 'star': docker_call(tool='star', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub'], tool_version=star_options['version']) else: docker_call(tool='starlong', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub'], tool_version=star_options['version']) output_files = defaultdict() for output_file in ['rnaAligned.toTranscriptome.out.bam', 'rnaAligned.out.bam', 'rnaChimeric.out.junction']: output_files[output_file] = job.fileStore.writeGlobalFile('/'.join([work_dir, output_file])) export_results(job, output_files['rnaAligned.toTranscriptome.out.bam'], 'rna_transcriptome.bam', univ_options, subfolder='alignments') export_results(job, output_files['rnaChimeric.out.junction'], 'rna_chimeric.junction', univ_options, subfolder='mutations/fusions') job.fileStore.logToMaster('Ran STAR on %s successfully' % univ_options['patient']) return output_files
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_and_index_star'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'star_bams'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '8', 'type': 'block', 'children': ['9', '19', '47', '82', '89', '96']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '16']},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'subscript', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '14', 'type': 'string', 'children': [], 'value': "'samtools'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'n'"},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '18', 'type': 'string', 'children': [], 'value': "'n'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '31', '32', '33', '38']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sort_bamfile'},{'id': '28', 'type': 'subscript', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'star_bams'},{'id': '30', 'type': 'string', 'children': [], 'value': "'rnaAligned.out.bam'"},{'id': '31', 'type': 'string', 'children': [], 'value': "'rna'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'samtools_options'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '37', 'type': 'string', 'children': [], 'value': "'samtools'"},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort_disk'},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'star_bams'},{'id': '46', 'type': 'string', 'children': [], 'value': "'rnaAligned.out.bam'"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '61', '62', '63', '68', '71']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'index_bamfile'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'string', 'children': [], 'value': "'rna'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'samtools_options'},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '67', 'type': 'string', 'children': [], 'value': "'samtools'"},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sample_info'},{'id': '70', 'type': 'string', 'children': [], 'value': "'genome_sorted'"},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'index_disk'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '81', 'type': 'argument_list', 'children': []},{'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': 'job'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'dictionary', 'children': ['98', '105', '110']},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'rna_genome'"},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'pair', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': "'rna_transcriptome.bam'"},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'star_bams'},{'id': '109', 'type': 'string', 'children': [], 'value': "'rnaAligned.toTranscriptome.out.bam'"},{'id': '110', 'type': 'pair', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "'rnaChimeric.out.junction'"},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'star_bams'},{'id': '114', 'type': 'string', 'children': [], 'value': "'rnaChimeric.out.junction'"}
def sort_and_index_star(job, star_bams, univ_options, star_options): star_options['samtools']['n'] = star_options['n'] sort = job.wrapJobFn(sort_bamfile, star_bams['rnaAligned.out.bam'], 'rna', univ_options, samtools_options=star_options['samtools'], disk=PromisedRequirement(sort_disk, star_bams['rnaAligned.out.bam'])) index = job.wrapJobFn(index_bamfile, sort.rv(), 'rna', univ_options, samtools_options=star_options['samtools'], sample_info='genome_sorted', disk=PromisedRequirement(index_disk, sort.rv())) job.addChild(sort) sort.addChild(index) return {'rna_genome': index.rv(), 'rna_transcriptome.bam': star_bams['rnaAligned.toTranscriptome.out.bam'], 'rnaChimeric.out.junction': star_bams['rnaChimeric.out.junction']}
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'evaluate'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '67', '84', '88', '191', '204', '212', '229']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ops'},{'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': 'rpn'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '19']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '26', '58']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '26', 'type': 'block', 'children': ['27', '51']},{'id': '27', 'type': 'while_statement', 'children': ['28', '39']},{'id': '28', 'type': 'boolean_operator', 'children': ['29', '33'], 'value': 'and'},{'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': 'ops'},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '<='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '37', 'type': 'unary_operator', 'children': ['38'], 'value': '-'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'rpn'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'},{'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': 'ops'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '50', 'type': 'argument_list', 'children': []},{'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': 'ops'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'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': 'rpn'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '67', 'type': 'while_statement', 'children': ['68', '72']},{'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': 'ops'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'rpn'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ops'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '87', 'type': 'list', 'children': [], 'value': '[]'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'rpn'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'if_statement', 'children': ['93', '98', '182']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '98', 'type': 'block', 'children': ['99', '120', '133', '172']},{'id': '99', 'type': 'if_statement', 'children': ['100', '105']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '=='},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'OPERATOR'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'NOT'},{'id': '105', 'type': 'block', 'children': ['106', '119']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '112']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '110', 'type': 'unary_operator', 'children': ['111'], 'value': '-'},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'IsNot'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '117', 'type': 'unary_operator', 'children': ['118'], 'value': '-'},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'continue_statement', 'children': []},{'id': '120', 'type': 'if_statement', 'children': ['121', '127']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '126'], 'value': '<'},{'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': 'stack'},{'id': '126', 'type': 'integer', 'children': [], 'value': '2'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'raise_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'Unable to build a valid expression. Not enough operands available.'"},{'id': '133', 'type': 'if_statement', 'children': ['134', '139', '155']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '=='},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'OPERATOR'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'OR'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'hc'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'any_of'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'list_splat', 'children': ['149']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '151', 'type': 'slice', 'children': ['152', '154']},{'id': '152', 'type': 'unary_operator', 'children': ['153'], 'value': '-'},{'id': '153', 'type': 'integer', 'children': [], 'value': '2'},{'id': '154', 'type': 'colon', 'children': []},{'id': '155', 'type': 'else_clause', 'children': ['156']},{'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': 'matcher'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'hc'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'all_of'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'list_splat', 'children': ['166']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '168', 'type': 'slice', 'children': ['169', '171']},{'id': '169', 'type': 'unary_operator', 'children': ['170'], 'value': '-'},{'id': '170', 'type': 'integer', 'children': [], 'value': '2'},{'id': '171', 'type': 'colon', 'children': []},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '180']},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '176', 'type': 'slice', 'children': ['177', '179']},{'id': '177', 'type': 'unary_operator', 'children': ['178'], 'value': '-'},{'id': '178', 'type': 'integer', 'children': [], 'value': '2'},{'id': '179', 'type': 'colon', 'children': []},{'id': '180', 'type': 'list', 'children': ['181'], 'value': '[matcher]'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '182', 'type': 'else_clause', 'children': ['183']},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'token'},{'id': '191', 'type': 'if_statement', 'children': ['192', '198']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '197'], 'value': '!='},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '197', 'type': 'integer', 'children': [], 'value': '1'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'raise_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'string', 'children': [], 'value': "'Unable to build a valid expression. The RPN stack should have just one item.'"},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '207', 'type': 'call', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '211', 'type': 'argument_list', 'children': []},{'id': '212', 'type': 'if_statement', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'description'},{'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': 'matcher'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'hc'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'described_as'},{'id': '224', 'type': 'argument_list', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'matcher'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'matcher'}
def evaluate(self): ops = [] rpn = [] for token in self.expr: if isinstance(token, int): while len(ops) and token <= ops[-1]: rpn.append(ops.pop()) ops.append(token) else: rpn.append(token) while len(ops): rpn.append(ops.pop()) stack = [] for token in rpn: if isinstance(token, int): if token == OPERATOR.NOT: stack[-1] = IsNot(stack[-1]) continue if len(stack) < 2: raise RuntimeError('Unable to build a valid expression. Not enough operands available.') if token == OPERATOR.OR: matcher = hc.any_of(*stack[-2:]) else: matcher = hc.all_of(*stack[-2:]) stack[-2:] = [matcher] else: stack.append(token) if len(stack) != 1: raise RuntimeError('Unable to build a valid expression. The RPN stack should have just one item.') matcher = stack.pop() if self.description: matcher = hc.described_as(self.description, matcher) return matcher
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_ensure_patient_group_is_ok'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'patient_object'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'patient_name'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '16', '29', '36', '70']},{'id': '9', 'type': 'import_from_statement', 'children': ['10', '14']},{'id': '10', 'type': 'dotted_name', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'protect'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'addons'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'common'},{'id': '14', 'type': 'dotted_name', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'TCGAToGTEx'},{'id': '16', 'type': 'assert_statement', 'children': ['17', '24']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'patient_object'},{'id': '21', 'type': 'tuple', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '%'},{'id': '25', 'type': 'string', 'children': [], 'value': "'%s,%s'"},{'id': '26', 'type': 'tuple', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'patient_object'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'patient_name'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'patient_object'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40', '51']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'},{'id': '38', 'type': 'string', 'children': [], 'value': "'tumor_type'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'patient_object'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'raise_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'binary_operator', 'children': ['46', '50'], 'value': '+'},{'id': '46', 'type': '()', 'children': ['47']},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'},{'id': '48', 'type': 'string', 'children': [], 'value': "'The patient entry for sample %s '"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'patient_name'},{'id': '50', 'type': 'string', 'children': [], 'value': "'does not contain a Tumor type.'"},{'id': '51', 'type': 'elif_clause', 'children': ['52', '57']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': 'not'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'patient_object'},{'id': '55', 'type': 'string', 'children': [], 'value': "'tumor_type'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'TCGAToGTEx'},{'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': 'ParameterError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '67'], 'value': '+'},{'id': '63', 'type': '()', 'children': ['64']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '%'},{'id': '65', 'type': 'string', 'children': [], 'value': "'The patient entry for sample %s '"},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'patient_name'},{'id': '67', 'type': 'concatenated_string', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'does contains an invalid Tumor type. Please use one of the '"},{'id': '69', 'type': 'string', 'children': [], 'value': "'valid TCGA tumor types.'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '80', '82']},{'id': '71', 'type': 'call', 'children': ['72', '78']},{'id': '72', 'type': 'attribute', 'children': ['73', '77']},{'id': '73', 'type': 'set', 'children': ['74', '75', '76']},{'id': '74', 'type': 'string', 'children': [], 'value': "'tumor_dna_fastq_1'"},{'id': '75', 'type': 'string', 'children': [], 'value': "'normal_dna_fastq_1'"},{'id': '76', 'type': 'string', 'children': [], 'value': "'tumor_rna_fastq_1'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'pass_statement', 'children': []},{'id': '82', 'type': 'else_clause', 'children': ['83']},{'id': '83', 'type': 'block', 'children': ['84', '101', '156', '196']},{'id': '84', 'type': 'if_statement', 'children': ['85', '88']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'not'},{'id': '86', 'type': 'string', 'children': [], 'value': "'hla_haplotype_files'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'raise_statement', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'binary_operator', 'children': ['94', '98'], 'value': '+'},{'id': '94', 'type': '()', 'children': ['95']},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '%'},{'id': '96', 'type': 'string', 'children': [], 'value': "'The patient entry for sample %s '"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'patient_name'},{'id': '98', 'type': 'concatenated_string', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'does not contain a hla_haplotype_files entry.\\nCannot haplotype '"},{'id': '100', 'type': 'string', 'children': [], 'value': "'patient if all the input sequence files are not fastqs.'"},{'id': '101', 'type': 'if_statement', 'children': ['102', '142']},{'id': '102', 'type': '()', 'children': ['103']},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '134'], 'value': 'and'},{'id': '104', 'type': '()', 'children': ['105']},{'id': '105', 'type': 'boolean_operator', 'children': ['106', '120'], 'value': 'or'},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '118'], 'value': '=='},{'id': '107', 'type': 'set_comprehension', 'children': ['108', '115']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': "'tumor_dna_((bam)|(fastq_1)).*'"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '118', 'type': 'set', 'children': ['119']},{'id': '119', 'type': 'None', 'children': []},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '132'], 'value': '=='},{'id': '121', 'type': 'set_comprehension', 'children': ['122', '129']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '126', 'type': 'argument_list', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': "'normal_dna_((bam)|(fastq_1)).*'"},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'for_in_clause', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '132', 'type': 'set', 'children': ['133']},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': '()', 'children': ['135']},{'id': '135', 'type': 'boolean_operator', 'children': ['136', '139'], 'value': 'and'},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'not'},{'id': '137', 'type': 'string', 'children': [], 'value': "'mutation_vcf'"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': 'not'},{'id': '140', 'type': 'string', 'children': [], 'value': "'fusion_bedpe'"},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'raise_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '152'], 'value': '+'},{'id': '148', 'type': '()', 'children': ['149']},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '%'},{'id': '150', 'type': 'string', 'children': [], 'value': "'The patient entry for sample %s '"},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'patient_name'},{'id': '152', 'type': 'concatenated_string', 'children': ['153', '154', '155']},{'id': '153', 'type': 'string', 'children': [], 'value': "'does not contain a mutation_vcf or fusion_bedpe entry. If both '"},{'id': '154', 'type': 'string', 'children': [], 'value': "'tumor and normal DNA sequences (fastqs or bam) are not provided, '"},{'id': '155', 'type': 'string', 'children': [], 'value': "'a pre-computed vcf and/or bedpe must be provided.'"},{'id': '156', 'type': 'if_statement', 'children': ['157', '171']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '169'], 'value': '=='},{'id': '158', 'type': 'set_comprehension', 'children': ['159', '166']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '163', 'type': 'argument_list', 'children': ['164', '165']},{'id': '164', 'type': 'string', 'children': [], 'value': "'tumor_rna_((bam)|(fastq_1)).*'"},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '166', 'type': 'for_in_clause', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '169', 'type': 'set', 'children': ['170']},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'if_statement', 'children': ['173', '180', '182']},{'id': '173', 'type': 'boolean_operator', 'children': ['174', '177'], 'value': 'and'},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': 'not'},{'id': '175', 'type': 'string', 'children': [], 'value': "'mutation_vcf'"},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'in'},{'id': '178', 'type': 'string', 'children': [], 'value': "'fusion_bedpe'"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'pass_statement', 'children': []},{'id': '182', 'type': 'else_clause', 'children': ['183']},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'raise_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '193'], 'value': '+'},{'id': '189', 'type': '()', 'children': ['190']},{'id': '190', 'type': 'binary_operator', 'children': ['191', '192'], 'value': '%'},{'id': '191', 'type': 'string', 'children': [], 'value': "'The patient entry for sample %s '"},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'patient_name'},{'id': '193', 'type': 'concatenated_string', 'children': ['194', '195']},{'id': '194', 'type': 'string', 'children': [], 'value': "'does not contain a tumor rna sequence data entry. We require '"},{'id': '195', 'type': 'string', 'children': [], 'value': "'either tumor_rna_fastq_1 or tumor_rna_bam.'"},{'id': '196', 'type': 'if_statement', 'children': ['197', '204']},{'id': '197', 'type': 'boolean_operator', 'children': ['198', '201'], 'value': 'and'},{'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': 'in'},{'id': '199', 'type': 'string', 'children': [], 'value': "'tumor_rna_bam'"},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'not'},{'id': '202', 'type': 'string', 'children': [], 'value': "'tumor_rna_transcriptome_bam'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'if_statement', 'children': ['206', '209']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': 'not'},{'id': '207', 'type': 'string', 'children': [], 'value': "'expression_files'"},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'test_set'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'raise_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': '()', 'children': ['215']},{'id': '215', 'type': 'binary_operator', 'children': ['216', '219'], 'value': '+'},{'id': '216', 'type': 'binary_operator', 'children': ['217', '218'], 'value': '%'},{'id': '217', 'type': 'string', 'children': [], 'value': "'The patient entry for sample %s '"},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'patient_name'},{'id': '219', 'type': 'concatenated_string', 'children': ['220', '221', '222', '223', '224']},{'id': '220', 'type': 'string', 'children': [], 'value': "'was provided a tumor rna bam with sequences mapped to the '"},{'id': '221', 'type': 'string', 'children': [], 'value': "'genome but was not provided a matching rna bam for the '"},{'id': '222', 'type': 'string', 'children': [], 'value': "'transcriptome or a tar containing expression values. '"},{'id': '223', 'type': 'string', 'children': [], 'value': "'We require either a matching transcriptome bam to estimate'"},{'id': '224', 'type': 'string', 'children': [], 'value': "'expression, or the precomputed expression values.'"}
def _ensure_patient_group_is_ok(patient_object, patient_name=None): from protect.addons.common import TCGAToGTEx assert isinstance(patient_object, (set, dict)), '%s,%s' % (patient_object, patient_name) test_set = set(patient_object) if 'tumor_type' not in patient_object: raise ParameterError(('The patient entry for sample %s ' % patient_name) + 'does not contain a Tumor type.') elif patient_object['tumor_type'] not in TCGAToGTEx: raise ParameterError(('The patient entry for sample %s ' % patient_name) + 'does contains an invalid Tumor type. Please use one of the ' 'valid TCGA tumor types.') if {'tumor_dna_fastq_1', 'normal_dna_fastq_1', 'tumor_rna_fastq_1'}.issubset(test_set): pass else: if 'hla_haplotype_files' not in test_set: raise ParameterError(('The patient entry for sample %s ' % patient_name) + 'does not contain a hla_haplotype_files entry.\nCannot haplotype ' 'patient if all the input sequence files are not fastqs.') if (({re.search('tumor_dna_((bam)|(fastq_1)).*', x) for x in test_set} == {None} or {re.search('normal_dna_((bam)|(fastq_1)).*', x) for x in test_set} == {None}) and ('mutation_vcf' not in test_set and 'fusion_bedpe' not in test_set)): raise ParameterError(('The patient entry for sample %s ' % patient_name) + 'does not contain a mutation_vcf or fusion_bedpe entry. If both ' 'tumor and normal DNA sequences (fastqs or bam) are not provided, ' 'a pre-computed vcf and/or bedpe must be provided.') if {re.search('tumor_rna_((bam)|(fastq_1)).*', x) for x in test_set} == {None}: if 'mutation_vcf' not in test_set and 'fusion_bedpe' in test_set: pass else: raise ParameterError(('The patient entry for sample %s ' % patient_name) + 'does not contain a tumor rna sequence data entry. We require ' 'either tumor_rna_fastq_1 or tumor_rna_bam.') if 'tumor_rna_bam' in test_set and 'tumor_rna_transcriptome_bam' not in test_set: if 'expression_files' not in test_set: raise ParameterError(('The patient entry for sample %s ' % patient_name + 'was provided a tumor rna bam with sequences mapped to the ' 'genome but was not provided a matching rna bam for the ' 'transcriptome or a tar containing expression values. ' 'We require either a matching transcriptome bam to estimate' 'expression, or the precomputed expression values.'))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_default_entries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'input_dict'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'defaults_dict'},{'id': '6', 'type': 'block', 'children': ['7', '93']},{'id': '7', 'type': 'for_statement', 'children': ['8', '11', '16']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'defaults_dict'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'block', 'children': ['17', '28']},{'id': '17', 'type': 'if_statement', 'children': ['18', '21']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'string', 'children': [], 'value': "'patients'"},{'id': '21', 'type': 'block', 'children': ['22', '27']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'string', 'children': [], 'value': "'Cannot default `patients`.'"},{'id': '27', 'type': 'continue_statement', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '34', '74']},{'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': 'value'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'if_statement', 'children': ['36', '45', '52']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '40'], 'value': 'or'},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'input_dict'},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': 'is'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'input_dict'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'block', 'children': ['46']},{'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': 'input_dict'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '52', 'type': 'else_clause', 'children': ['53']},{'id': '53', 'type': 'block', 'children': ['54', '68']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_add_default_entries'},{'id': '59', 'type': 'argument_list', 'children': ['60', '67']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'input_dict'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '66', 'type': 'dictionary', 'children': []},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '73']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'input_dict'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '74', 'type': 'else_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'if_statement', 'children': ['77', '86']},{'id': '77', 'type': 'boolean_operator', 'children': ['78', '81'], 'value': 'or'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'not'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'input_dict'},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': 'is'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'input_dict'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '85', 'type': 'None', 'children': []},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '92']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'input_dict'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'input_dict'}
def _add_default_entries(input_dict, defaults_dict): for key, value in defaults_dict.iteritems(): if key == 'patients': print('Cannot default `patients`.') continue if isinstance(value, dict): if key not in input_dict or input_dict[key] is None: input_dict[key] = value else: r = _add_default_entries(input_dict.get(key, {}), value) input_dict[key] = r else: if key not in input_dict or input_dict[key] is None: input_dict[key] = value return input_dict
{'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', '24', '35', '56', '78', '105', '115', '250']},{'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': ['13', '16', '19']},{'id': '13', 'type': 'keyword_argument', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'prog'},{'id': '15', 'type': 'string', 'children': [], 'value': "'ProTECT'"},{'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '18', 'type': 'string', 'children': [], 'value': "'Prediction of T-Cell Epitopes for Cancer Therapy'"},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'epilog'},{'id': '21', 'type': 'concatenated_string', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'Contact Arjun Rao ([email protected]) if you encounter '"},{'id': '23', 'type': 'string', 'children': [], 'value': "'any problems while running ProTECT'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'add_mutually_exclusive_group'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '34', 'type': 'True', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'inputs'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42', '45', '50', '53']},{'id': '41', 'type': 'string', 'children': [], 'value': "'--config_file'"},{'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '44', 'type': 'string', 'children': [], 'value': "'config_file'"},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '47', 'type': 'concatenated_string', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'Config file to be used in the '"},{'id': '49', 'type': 'string', 'children': [], 'value': "'run.'"},{'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '55', 'type': 'None', 'children': []},{'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': 'inputs'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63', '66', '72', '75']},{'id': '62', 'type': 'string', 'children': [], 'value': "'--generate_config'"},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '65', 'type': 'string', 'children': [], 'value': "'generate_config'"},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '68', 'type': 'concatenated_string', 'children': ['69', '70', '71']},{'id': '69', 'type': 'string', 'children': [], 'value': "'Generate a config file '"},{'id': '70', 'type': 'string', 'children': [], 'value': "'in the current directory that is pre-filled with references and flags for '"},{'id': '71', 'type': 'string', 'children': [], 'value': "'an hg19 run.'"},{'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': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '77', 'type': 'False', 'children': []},{'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': 'parser'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85', '88', '96', '99', '102']},{'id': '84', 'type': 'string', 'children': [], 'value': "'--max-cores-per-job'"},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '87', 'type': 'string', 'children': [], 'value': "'max_cores'"},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '90', 'type': 'concatenated_string', 'children': ['91', '92', '93', '94', '95']},{'id': '91', 'type': 'string', 'children': [], 'value': "'Maximum cores to use per '"},{'id': '92', 'type': 'string', 'children': [], 'value': "'job. Aligners and Haplotypers ask for cores dependent on the machine that '"},{'id': '93', 'type': 'string', 'children': [], 'value': "'the launchpad gets assigned to -- In a heterogeneous cluster, this can '"},{'id': '94', 'type': 'string', 'children': [], 'value': "'lead to problems. This value should be set to the number of cpus on the '"},{'id': '95', 'type': 'string', 'children': [], 'value': "'smallest node in a cluster.'"},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '101', 'type': 'False', 'children': []},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'pattern_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'others'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'parse_known_args'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'if_statement', 'children': ['116', '119', '124']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'generate_config'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'generate_config_file'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'else_clause', 'children': ['125']},{'id': '125', 'type': 'block', 'children': ['126', '135', '143', '158', '225', '240']},{'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': 'Job'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'Runner'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'addToilOptions'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '148', 'type': 'call', 'children': ['149', '154']},{'id': '149', 'type': 'attribute', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '158', 'type': 'if_statement', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'maxCores'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'if_statement', 'children': ['164', '168', '180']},{'id': '164', 'type': 'not_operator', 'children': ['165']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'max_cores'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'max_cores'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'maxCores'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'if_statement', 'children': ['183', '193']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '187'], 'value': '>'},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'max_cores'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'maxCores'},{'id': '193', 'type': 'block', 'children': ['194', '214']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '197', 'type': 'argument_list', 'children': ['198', '209']},{'id': '198', 'type': 'binary_operator', 'children': ['199', '202'], 'value': '%'},{'id': '199', 'type': 'concatenated_string', 'children': ['200', '201']},{'id': '200', 'type': 'string', 'children': [], 'value': '"The value provided to max-cores-per-job (%s) was greater than that "'},{'id': '201', 'type': 'string', 'children': [], 'value': '"provided to maxCores (%s). Setting max-cores-per-job = maxCores."'},{'id': '202', 'type': 'tuple', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'max_cores'},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'maxCores'},{'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'max_cores'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'maxCores'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'Job'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234', '237']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'parse_config_file'},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'max_cores'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'Job'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'Runner'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'startToil'},{'id': '247', 'type': 'argument_list', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '250', 'type': 'return_statement', 'children': ['251']},{'id': '251', 'type': 'None', 'children': []}
def main(): parser = argparse.ArgumentParser(prog='ProTECT', description='Prediction of T-Cell Epitopes for Cancer Therapy', epilog='Contact Arjun Rao ([email protected]) if you encounter ' 'any problems while running ProTECT') inputs = parser.add_mutually_exclusive_group(required=True) inputs.add_argument('--config_file', dest='config_file', help='Config file to be used in the ' 'run.', type=str, default=None) inputs.add_argument('--generate_config', dest='generate_config', help='Generate a config file ' 'in the current directory that is pre-filled with references and flags for ' 'an hg19 run.', action='store_true', default=False) parser.add_argument('--max-cores-per-job', dest='max_cores', help='Maximum cores to use per ' 'job. Aligners and Haplotypers ask for cores dependent on the machine that ' 'the launchpad gets assigned to -- In a heterogeneous cluster, this can ' 'lead to problems. This value should be set to the number of cpus on the ' 'smallest node in a cluster.', type=int, required=False, default=None) params, others = parser.parse_known_args() if params.generate_config: generate_config_file() else: Job.Runner.addToilOptions(parser) params = parser.parse_args() params.config_file = os.path.abspath(params.config_file) if params.maxCores: if not params.max_cores: params.max_cores = int(params.maxCores) else: if params.max_cores > int(params.maxCores): print("The value provided to max-cores-per-job (%s) was greater than that " "provided to maxCores (%s). Setting max-cores-per-job = maxCores." % (params.max_cores, params.maxCores), file=sys.stderr) params.max_cores = int(params.maxCores) start = Job.wrapJobFn(parse_config_file, params.config_file, params.max_cores) Job.Runner.startToil(start, params) return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'align_dna'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '9', 'type': 'block', 'children': ['10', '43', '78', '113', '148', '183', '221', '228', '235', '242', '249', '256', '263']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'bwa'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20', '21', '22', '23', '33', '38']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'run_bwa'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'bwa_disk'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '32', 'type': 'string', 'children': [], 'value': "'index'"},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '37', 'type': 'string', 'children': [], 'value': "'java_Xmx'"},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cores'},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '42', 'type': 'string', 'children': [], 'value': "'n'"},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sam2bam'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '57', '58', '59', '62', '73']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'bam_conversion'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'bwa'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '61', 'type': 'string', 'children': [], 'value': "'samtools'"},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '66', 'type': 'argument_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sam2bam_disk'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'bwa'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '77', 'type': 'string', 'children': [], 'value': "'java_Xmx'"},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'reheader'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87', '92', '93', '94', '97', '108']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'fix_bam_header'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sam2bam'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '96', 'type': 'string', 'children': [], 'value': "'samtools'"},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'sam2bam_disk'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'bwa'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '107', 'type': 'argument_list', 'children': []},{'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '112', 'type': 'string', 'children': [], 'value': "'java_Xmx'"},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'regroup'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '127', '128', '129', '132', '143']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'add_readgroups'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'reheader'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '131', 'type': 'string', 'children': [], 'value': "'picard'"},{'id': '132', 'type': 'keyword_argument', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'regroup_disk'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'reheader'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '147', 'type': 'string', 'children': [], 'value': "'java_Xmx'"},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'mkdup'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157', '162', '163', '164', '167', '178']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'mark_duplicates'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'regroup'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '166', 'type': 'string', 'children': [], 'value': "'picard'"},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'mkdup_disk'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'regroup'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '177', 'type': 'argument_list', 'children': []},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '182', 'type': 'string', 'children': [], 'value': "'java_Xmx'"},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192', '197', '198', '199', '202', '205', '216']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'index_bamfile'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'mkdup'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '196', 'type': 'argument_list', 'children': []},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '201', 'type': 'string', 'children': [], 'value': "'samtools'"},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'sample_info'},{'id': '204', 'type': 'string', 'children': [], 'value': "'fix_pg_sorted'"},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '209', 'type': 'argument_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'index_disk'},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'mkdup'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '215', 'type': 'argument_list', 'children': []},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '220', 'type': 'string', 'children': [], 'value': "'java_Xmx'"},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'bwa'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'bwa'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'sam2bam'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'sam2bam'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'reheader'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'reheader'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'regroup'},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'regroup'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'mkdup'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'mkdup'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '263', 'type': 'return_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '268', 'type': 'argument_list', 'children': []}
def align_dna(job, fastqs, sample_type, univ_options, bwa_options): bwa = job.wrapJobFn(run_bwa, fastqs, sample_type, univ_options, bwa_options, disk=PromisedRequirement(bwa_disk, fastqs, bwa_options['index']), memory=univ_options['java_Xmx'], cores=bwa_options['n']) sam2bam = job.wrapJobFn(bam_conversion, bwa.rv(), sample_type, univ_options, bwa_options['samtools'], disk=PromisedRequirement(sam2bam_disk, bwa.rv()), memory=univ_options['java_Xmx']) reheader = job.wrapJobFn(fix_bam_header, sam2bam.rv(), sample_type, univ_options, bwa_options['samtools'], disk=PromisedRequirement(sam2bam_disk, bwa.rv()), memory=univ_options['java_Xmx']) regroup = job.wrapJobFn(add_readgroups, reheader.rv(), sample_type, univ_options, bwa_options['picard'], disk=PromisedRequirement(regroup_disk, reheader.rv()), memory=univ_options['java_Xmx']) mkdup = job.wrapJobFn(mark_duplicates, regroup.rv(), sample_type, univ_options, bwa_options['picard'], disk=PromisedRequirement(mkdup_disk, regroup.rv()), memory=univ_options['java_Xmx']) index = job.wrapJobFn(index_bamfile, mkdup.rv(), sample_type, univ_options, bwa_options['samtools'], sample_info='fix_pg_sorted', disk=PromisedRequirement(index_disk, mkdup.rv()), memory=univ_options['java_Xmx']) job.addChild(bwa) bwa.addChild(sam2bam) sam2bam.addChild(reheader) reheader.addChild(regroup) regroup.addChild(mkdup) mkdup.addChild(index) return index.rv()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '6', 'type': 'block', 'children': ['7', '73', '80', '104', '119']},{'id': '7', 'type': 'try_statement', 'children': ['8', '16', '40']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '16', 'type': 'except_clause', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '18', 'type': 'block', 'children': ['19', '23', '35']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '29']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'mod_path'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cls_name'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'rpartition'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '35', 'type': 'if_statement', 'children': ['36', '38']},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'mod_path'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'raise_statement', 'children': []},{'id': '40', 'type': 'else_clause', 'children': ['41']},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'try_statement', 'children': ['43', '50', '59']},{'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': 'entry'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'default_bot'},{'id': '50', 'type': 'except_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "f'{entry}.Bot'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '67']},{'id': '63', 'type': 'pattern_list', 'children': ['64', '65', '66']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'mod_path'},{'id': '65', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'cls_name'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'rpartition'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'mod_path'},{'id': '80', 'type': 'try_statement', 'children': ['81', '90']},{'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': 'bot_cls'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'cls_name'},{'id': '90', 'type': 'except_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '92', 'type': 'block', 'children': ['93', '103']},{'id': '93', 'type': 'if_statement', 'children': ['94', '97']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'is'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '96', 'type': 'None', 'children': []},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'import_module'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '103', 'type': 'raise_statement', 'children': []},{'id': '104', 'type': 'if_statement', 'children': ['105', '111']},{'id': '105', 'type': 'not_operator', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'bot_cls'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'Bot'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'raise_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ImproperlyConfigured'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'},{'id': '117', 'type': 'string', 'children': [], 'value': '"\'%s\' isn\'t a subclass of Bot."'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'bot_cls'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'label'}
def create(cls, entry): try: module = import_module(entry) except ImportError: module = None mod_path, _, cls_name = entry.rpartition('.') if not mod_path: raise else: try: entry = module.default_bot except AttributeError: return cls(f'{entry}.Bot', module) else: mod_path, _, cls_name = entry.rpartition('.') mod = import_module(mod_path) try: bot_cls = getattr(mod, cls_name) except AttributeError: if module is None: import_module(entry) raise if not issubclass(bot_cls, Bot): raise ImproperlyConfigured( "'%s' isn't a subclass of Bot." % entry) return cls(entry, mod, bot_cls.label)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'populate'},{'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': 'installed_bots'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '15']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ready'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': []},{'id': '15', 'type': 'with_statement', 'children': ['16', '21']},{'id': '16', 'type': 'with_clause', 'children': ['17']},{'id': '17', 'type': 'with_item', 'children': ['18']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_lock'},{'id': '21', 'type': 'block', 'children': ['22', '28', '38', '44', '121', '139', '157', '174', '180', '196', '202']},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ready'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'return_statement', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'loading'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': '"populate() isn\'t re-entrant"'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'loading'},{'id': '43', 'type': 'True', 'children': []},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '49']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '46', 'type': 'boolean_operator', 'children': ['47', '48'], 'value': 'or'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'installed_bots'},{'id': '48', 'type': 'dictionary', 'children': []},{'id': '49', 'type': 'block', 'children': ['50', '76', '85', '105', '115']},{'id': '50', 'type': 'if_statement', 'children': ['51', '56']},{'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': 'entry'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'Bot'},{'id': '56', 'type': 'block', 'children': ['57', '61']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'entry'},{'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', '73'], 'value': '[cls.__module__, cls.__name__]'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '72', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'bot_reg'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'BotRegistry'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'create'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '85', 'type': 'if_statement', 'children': ['86', '93']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': 'in'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'bot_reg'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'bots'},{'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': 'ImproperlyConfigured'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'binary_operator', 'children': ['99', '102'], 'value': '%'},{'id': '99', 'type': 'concatenated_string', 'children': ['100', '101']},{'id': '100', 'type': 'string', 'children': [], 'value': '"Bot labels aren\'t unique, "'},{'id': '101', 'type': 'string', 'children': [], 'value': '"duplicates: %s"'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'bot_reg'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '114']},{'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': 'bots'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'bot_reg'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'label'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'bot_reg'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'bot_reg'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'bots'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Counter'},{'id': '126', 'type': 'generator_expression', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'bot_reg'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '130', 'type': 'for_in_clause', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'bot_reg'},{'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': 'bots'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'duplicates'},{'id': '142', 'type': 'list_comprehension', 'children': ['143', '144', '153']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '144', 'type': 'for_in_clause', 'children': ['145', '148']},{'id': '145', 'type': 'pattern_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'most_common'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'if_clause', 'children': ['154']},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '>'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '156', 'type': 'integer', 'children': [], 'value': '1'},{'id': '157', 'type': 'if_statement', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'duplicates'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'raise_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ImproperlyConfigured'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '168'], 'value': '%'},{'id': '165', 'type': 'concatenated_string', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': '"Bot names aren\'t unique, "'},{'id': '167', 'type': 'string', 'children': [], 'value': '"duplicates: %s"'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'string', 'children': [], 'value': '", "'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'duplicates'},{'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': 'bots_ready'},{'id': '179', 'type': 'True', 'children': []},{'id': '180', 'type': 'for_statement', 'children': ['181', '182', '189']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'bot'},{'id': '182', 'type': 'call', 'children': ['183', '188']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'bots'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '188', 'type': 'argument_list', 'children': []},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'bot'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'import_configs'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'configs_ready'},{'id': '201', 'type': 'True', 'children': []},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'ready'},{'id': '207', 'type': 'True', 'children': []}
def populate(self, installed_bots=None): if self.ready: return with self._lock: if self.ready: return if self.loading: raise RuntimeError("populate() isn't re-entrant") self.loading = True for entry in installed_bots or {}: if isinstance(entry, Bot): cls = entry entry = '.'.join([cls.__module__, cls.__name__]) bot_reg = BotRegistry.create(entry) if bot_reg.label in self.bots: raise ImproperlyConfigured( "Bot labels aren't unique, " "duplicates: %s" % bot_reg.label) self.bots[bot_reg.label] = bot_reg bot_reg.bots = self counts = Counter( bot_reg.name for bot_reg in self.bots.values()) duplicates = [ name for name, count in counts.most_common() if count > 1] if duplicates: raise ImproperlyConfigured( "Bot names aren't unique, " "duplicates: %s" % ", ".join(duplicates)) self.bots_ready = True for bot in self.bots.values(): bot.import_configs() self.configs_ready = True self.ready = True
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_initkwargs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'form_list'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'initial_dict'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'instance_dict'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'condition_dict'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'list_splat_pattern', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '17', 'type': 'dictionary_splat_pattern', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '19', 'type': 'block', 'children': ['20', '42', '48', '56', '98', '150', '156']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'dictionary', 'children': ['27', '32', '37']},{'id': '27', 'type': 'pair', 'children': ['28', '29']},{'id': '28', 'type': 'string', 'children': [], 'value': "'initial_dict'"},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '31'], 'value': 'or'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'initial_dict'},{'id': '31', 'type': 'dictionary', 'children': []},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'instance_dict'"},{'id': '34', 'type': 'boolean_operator', 'children': ['35', '36'], 'value': 'or'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'instance_dict'},{'id': '36', 'type': 'dictionary', 'children': []},{'id': '37', 'type': 'pair', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'condition_dict'"},{'id': '39', 'type': 'boolean_operator', 'children': ['40', '41'], 'value': 'or'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'condition_dict'},{'id': '41', 'type': 'dictionary', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'init_form_list'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'SortedDict'},{'id': '47', 'type': 'argument_list', 'children': []},{'id': '48', 'type': 'assert_statement', 'children': ['49', '55']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '54'], 'value': '>'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'form_list'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'string', 'children': [], 'value': "'at least one form is needed'"},{'id': '56', 'type': 'for_statement', 'children': ['57', '60', '64']},{'id': '57', 'type': 'pattern_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'form_list'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'if_statement', 'children': ['66', '73', '87']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '70', 'type': 'tuple', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '84']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'init_form_list'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'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', '97']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'init_form_list'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '98', 'type': 'for_statement', 'children': ['99', '100', '105']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'init_form_list'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'itervalues'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'block', 'children': ['106', '121']},{'id': '106', 'type': 'if_statement', 'children': ['107', '114']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'formsets'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'BaseFormSet'},{'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': 'form'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '121', 'type': 'for_statement', 'children': ['122', '123', '130']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'form'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'base_fields'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'itervalues'},{'id': '129', 'type': 'argument_list', 'children': []},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'if_statement', 'children': ['132', '147']},{'id': '132', 'type': '()', 'children': ['133']},{'id': '133', 'type': 'boolean_operator', 'children': ['134', '141'], 'value': 'and'},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'forms'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'FileField'},{'id': '141', 'type': 'not_operator', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '146', 'type': 'string', 'children': [], 'value': "'file_storage'"},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'raise_statement', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'NoFileStorageConfigured'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '154', 'type': 'string', 'children': [], 'value': "'form_list'"},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'init_form_list'},{'id': '156', 'type': 'return_statement', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def get_initkwargs(cls, form_list, initial_dict=None, instance_dict=None, condition_dict=None, *args, **kwargs): kwargs.update({ 'initial_dict': initial_dict or {}, 'instance_dict': instance_dict or {}, 'condition_dict': condition_dict or {}, }) init_form_list = SortedDict() assert len(form_list) > 0, 'at least one form is needed' for i, form in enumerate(form_list): if isinstance(form, (list, tuple)): init_form_list[unicode(form[0])] = form[1] else: init_form_list[unicode(i)] = form for form in init_form_list.itervalues(): if issubclass(form, formsets.BaseFormSet): form = form.form for field in form.base_fields.itervalues(): if (isinstance(field, forms.FileField) and not hasattr(cls, 'file_storage')): raise NoFileStorageConfigured kwargs['form_list'] = init_form_list return kwargs
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'post'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '24', '86', '102', '115', '123', '149', '171', '247']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'wizard_prev_step'},{'id': '13', 'type': 'call', 'children': ['14', '21']},{'id': '14', 'type': 'attribute', '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': 'request'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'POST'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '21', 'type': 'argument_list', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': "'wizard_prev_step'"},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'if_statement', 'children': ['25', '34']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '27'], 'value': 'and'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'wizard_prev_step'},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'wizard_prev_step'},{'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_form_list'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '43', '79']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'current_step'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'wizard_prev_step'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_form'},{'id': '50', 'type': 'argument_list', 'children': ['51', '65']},{'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '53', 'type': 'call', 'children': ['54', '59']},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'get_step_data'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '67', 'type': 'call', 'children': ['68', '73']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'get_step_files'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'attribute', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '79', 'type': 'return_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'management_form'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ManagementForm'},{'id': '91', 'type': 'argument_list', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'POST'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '102', 'type': 'if_statement', 'children': ['103', '109']},{'id': '103', 'type': 'not_operator', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'management_form'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'is_valid'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'raise_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ValidationError'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'string', 'children': [], 'value': "'ManagementForm data is missing or has been tampered.'"},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'form_current_step'},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'management_form'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'cleaned_data'},{'id': '122', 'type': 'string', 'children': [], 'value': "'current_step'"},{'id': '123', 'type': 'if_statement', 'children': ['124', '140']},{'id': '124', 'type': '()', 'children': ['125']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '133'], 'value': 'and'},{'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '!='},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'form_current_step'},{'id': '128', 'type': 'attribute', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '139'], 'value': 'is'},{'id': '134', 'type': 'attribute', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'current_step'},{'id': '139', 'type': 'None', 'children': []},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', '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': 'storage'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'current_step'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'form_current_step'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'get_form'},{'id': '156', 'type': 'argument_list', 'children': ['157', '164']},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'data'},{'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': 'request'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'POST'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'files'},{'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': 'request'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'FILES'},{'id': '171', 'type': 'if_statement', 'children': ['172', '177']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'is_valid'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'block', 'children': ['178', '197', '216']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '185']},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'set_step_data'},{'id': '185', 'type': 'argument_list', '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': 'steps'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'process_step'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'storage'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'set_step_files'},{'id': '204', 'type': 'argument_list', 'children': ['205', '210']},{'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': 'steps'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'process_step_files'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '216', 'type': 'if_statement', 'children': ['217', '228', '238']},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '223'], 'value': '=='},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '223', 'type': 'attribute', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'steps'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'render_done'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '236', 'type': 'dictionary_splat', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '238', 'type': 'else_clause', 'children': ['239']},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'render_next_step'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'form'},{'id': '247', 'type': 'return_statement', 'children': ['248']},{'id': '248', 'type': 'call', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'form'}
def post(self, *args, **kwargs): wizard_prev_step = self.request.POST.get('wizard_prev_step', None) if wizard_prev_step and wizard_prev_step in self.get_form_list(): self.storage.current_step = wizard_prev_step form = self.get_form( data=self.storage.get_step_data(self.steps.current), files=self.storage.get_step_files(self.steps.current)) return self.render(form) management_form = ManagementForm(self.request.POST, prefix=self.prefix) if not management_form.is_valid(): raise ValidationError( 'ManagementForm data is missing or has been tampered.') form_current_step = management_form.cleaned_data['current_step'] if (form_current_step != self.steps.current and self.storage.current_step is not None): self.storage.current_step = form_current_step form = self.get_form(data=self.request.POST, files=self.request.FILES) if form.is_valid(): self.storage.set_step_data(self.steps.current, self.process_step(form)) self.storage.set_step_files(self.steps.current, self.process_step_files(form)) if self.steps.current == self.steps.last: return self.render_done(form, **kwargs) else: return self.render_next_step(form) return self.render(form)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_config_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '6', 'type': 'block', 'children': ['7', '16', '27', '45', '51', '57', '63', '229', '244', '260', '280', '300']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'Parsing config file'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '27', 'type': 'if_statement', 'children': ['28', '37']},{'id': '28', 'type': 'not_operator', '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': 'os'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'raise_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'},{'id': '43', 'type': 'string', 'children': [], 'value': "'The config file was not found at specified location. Please verify '"},{'id': '44', 'type': 'string', 'children': [], 'value': "'and retry.'"},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'sample_set'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'tool_options'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'with_statement', 'children': ['64', '74']},{'id': '64', 'type': 'with_clause', 'children': ['65']},{'id': '65', 'type': 'with_item', 'children': ['66']},{'id': '66', 'type': 'as_pattern', 'children': ['67', '72']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'config_file'},{'id': '71', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '72', 'type': 'as_pattern_target', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '74', 'type': 'block', 'children': ['75', '102']},{'id': '75', 'type': 'for_statement', 'children': ['76', '77', '78']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '78', 'type': 'block', 'children': ['79', '87']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'if_statement', 'children': ['88', '91', '100']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '91', 'type': 'ERROR', 'children': ['92', '93', '94']},{'id': '92', 'type': 'ERROR', 'children': []},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'continue'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'BEGIN'"},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'break_statement', 'children': []},{'id': '102', 'type': 'for_statement', 'children': ['103', '106', '111']},{'id': '103', 'type': 'pattern_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'group_params'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'tool_specific_param_generator'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'if_statement', 'children': ['113', '116', '139', '221']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '=='},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '115', 'type': 'string', 'children': [], 'value': "'patient'"},{'id': '116', 'type': 'block', 'children': ['117', '131']},{'id': '117', 'type': 'if_statement', 'children': ['118', '125']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'not'},{'id': '119', 'type': 'string', 'children': [], 'value': "'patient_id'"},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'group_params'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'raise_statement', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': "'A patient group is missing the patient_id flag.'"},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '138']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sample_set'},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'group_params'},{'id': '137', 'type': 'string', 'children': [], 'value': "'patient_id'"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'group_params'},{'id': '139', 'type': 'elif_clause', 'children': ['140', '143']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '=='},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '142', 'type': 'string', 'children': [], 'value': "'Universal_Options'"},{'id': '143', 'type': 'block', 'children': ['144', '148', '155', '171', '193']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'group_params'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'required_options'},{'id': '151', 'type': 'set', 'children': ['152', '153', '154']},{'id': '152', 'type': 'string', 'children': [], 'value': "'java_Xmx'"},{'id': '153', 'type': 'string', 'children': [], 'value': "'output_folder'"},{'id': '154', 'type': 'string', 'children': [], 'value': "'storage_location'"},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'missing_opts'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'required_options'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '170', 'type': 'argument_list', 'children': []},{'id': '171', 'type': 'if_statement', 'children': ['172', '178']},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '177'], 'value': '>'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'missing_opts'},{'id': '177', 'type': 'integer', 'children': [], 'value': '0'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'raise_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'binary_operator', 'children': ['184', '187'], 'value': '+'},{'id': '184', 'type': 'concatenated_string', 'children': ['185', '186']},{'id': '185', 'type': 'string', 'children': [], 'value': "' The following options have no arguments in the config '"},{'id': '186', 'type': 'string', 'children': [], 'value': "'file :\\n'"},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'missing_opts'},{'id': '193', 'type': 'if_statement', 'children': ['194', '197']},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '196', 'type': 'string', 'children': [], 'value': "'sse_key_is_master'"},{'id': '197', 'type': 'block', 'children': ['198', '208']},{'id': '198', 'type': 'assert_statement', 'children': ['199']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '203'], 'value': 'in'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '202', 'type': 'string', 'children': [], 'value': "'sse_key_is_master'"},{'id': '203', 'type': 'tuple', 'children': ['204', '205', '206', '207']},{'id': '204', 'type': 'string', 'children': [], 'value': "'True'"},{'id': '205', 'type': 'string', 'children': [], 'value': "'true'"},{'id': '206', 'type': 'string', 'children': [], 'value': "'False'"},{'id': '207', 'type': 'string', 'children': [], 'value': "'false'"},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '213', '214']},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '212', 'type': 'string', 'children': [], 'value': "'sse_key_is_master'"},{'id': '213', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '218'], 'value': 'in'},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '217', 'type': 'string', 'children': [], 'value': "'sse_key_is_master'"},{'id': '218', 'type': 'tuple', 'children': ['219', '220']},{'id': '219', 'type': 'string', 'children': [], 'value': "'True'"},{'id': '220', 'type': 'string', 'children': [], 'value': "'true'"},{'id': '221', 'type': 'else_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '228']},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'tool_options'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'groupname'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'group_params'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'required_tools'},{'id': '232', 'type': 'set', 'children': ['233', '234', '235', '236', '237', '238', '239', '240', '241', '242', '243']},{'id': '233', 'type': 'string', 'children': [], 'value': "'cutadapt'"},{'id': '234', 'type': 'string', 'children': [], 'value': "'bwa'"},{'id': '235', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '236', 'type': 'string', 'children': [], 'value': "'phlat'"},{'id': '237', 'type': 'string', 'children': [], 'value': "'transgene'"},{'id': '238', 'type': 'string', 'children': [], 'value': "'mut_callers'"},{'id': '239', 'type': 'string', 'children': [], 'value': "'rsem'"},{'id': '240', 'type': 'string', 'children': [], 'value': "'mhci'"},{'id': '241', 'type': 'string', 'children': [], 'value': "'mhcii'"},{'id': '242', 'type': 'string', 'children': [], 'value': "'snpeff'"},{'id': '243', 'type': 'string', 'children': [], 'value': "'rank_boost'"},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'missing_tools'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'required_tools'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'tool_options'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '259', 'type': 'argument_list', 'children': []},{'id': '260', 'type': 'if_statement', 'children': ['261', '267']},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '266'], 'value': '>'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'missing_tools'},{'id': '266', 'type': 'integer', 'children': [], 'value': '0'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'raise_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '+'},{'id': '273', 'type': 'string', 'children': [], 'value': "' The following tools have no arguments in the config file : \\n'"},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'missing_tools'},{'id': '280', 'type': 'for_statement', 'children': ['281', '282', '287']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'patient_id'},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'sample_set'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '286', 'type': 'argument_list', 'children': []},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'addFollowOnJobFn'},{'id': '293', 'type': 'argument_list', 'children': ['294', '295', '298', '299']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'pipeline_launchpad'},{'id': '295', 'type': 'subscript', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'sample_set'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'patient_id'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'tool_options'},{'id': '300', 'type': 'return_statement', 'children': ['301']},{'id': '301', 'type': 'None', 'children': []}
def parse_config_file(job, config_file): job.fileStore.logToMaster('Parsing config file') config_file = os.path.abspath(config_file) if not os.path.exists(config_file): raise ParameterError('The config file was not found at specified location. Please verify ' + 'and retry.') sample_set = defaultdict() univ_options = defaultdict() tool_options = defaultdict() with open(config_file, 'r') as conf: for line in conf: line = line.strip() if line.startswith(' continue if line.startswith('BEGIN'): break for groupname, group_params in tool_specific_param_generator(job, conf): if groupname == 'patient': if 'patient_id' not in group_params.keys(): raise ParameterError('A patient group is missing the patient_id flag.') sample_set[group_params['patient_id']] = group_params elif groupname == 'Universal_Options': univ_options = group_params required_options = {'java_Xmx', 'output_folder', 'storage_location'} missing_opts = required_options.difference(set(univ_options.keys())) if len(missing_opts) > 0: raise ParameterError(' The following options have no arguments in the config ' 'file :\n' + '\n'.join(missing_opts)) if univ_options['sse_key_is_master']: assert univ_options['sse_key_is_master'] in ('True', 'true', 'False', 'false') univ_options['sse_key_is_master'] = \ univ_options['sse_key_is_master'] in ('True', 'true') else: tool_options[groupname] = group_params required_tools = {'cutadapt', 'bwa', 'star', 'phlat', 'transgene', 'mut_callers', 'rsem', 'mhci', 'mhcii', 'snpeff', 'rank_boost'} missing_tools = required_tools.difference(set(tool_options.keys())) if len(missing_tools) > 0: raise ParameterError(' The following tools have no arguments in the config file : \n' + '\n'.join(missing_tools)) for patient_id in sample_set.keys(): job.addFollowOnJobFn(pipeline_launchpad, sample_set[patient_id], univ_options, tool_options) return None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_star'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '8', 'type': 'block', 'children': ['9', '17', '30', '40', '59', '71', '108', '153', '159', '185', '196', '207', '224', '231', '241']},{'id': '9', 'type': 'assert_statement', 'children': ['10']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': 'in'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '13', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '14', 'type': 'tuple', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'starlong'"},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '24']},{'id': '19', 'type': 'attribute', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'},{'id': '26', 'type': 'string', 'children': [], 'value': "'Running STAR on %s'"},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '29', 'type': 'string', 'children': [], 'value': "'patient'"},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '33', 'type': 'call', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '43', 'type': 'dictionary', 'children': ['44', '49', '54']},{'id': '44', 'type': 'pair', 'children': ['45', '46']},{'id': '45', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_1.fastq'"},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '48', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_1.fastq'"},{'id': '49', 'type': 'pair', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_2.fastq'"},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '53', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_2.fastq'"},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'star_index.tar.gz'"},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '58', 'type': 'string', 'children': [], 'value': "'index_tar'"},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get_files_from_filestore'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67', '68']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'docker'},{'id': '70', 'type': 'True', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '74', 'type': 'list', 'children': ['75', '76', '82', '83', '86', '87', '88', '89', '92', '95', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107'], 'value': "['--runThreadN', str(star_options['n']),\n '--genomeDir', input_files['star_index'],\n '--outFileNamePrefix', 'rna',\n '--readFilesIn',\n input_files['rna_cutadapt_1.fastq'],\n input_files['rna_cutadapt_2.fastq'],\n '--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD',\n '--outSAMtype', 'BAM', 'SortedByCoordinate',\n '--quantMode', 'TranscriptomeSAM',\n '--outSAMunmapped', 'Within']"},{'id': '75', 'type': 'string', 'children': [], 'value': "'--runThreadN'"},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '81', 'type': 'string', 'children': [], 'value': "'n'"},{'id': '82', 'type': 'string', 'children': [], 'value': "'--genomeDir'"},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '85', 'type': 'string', 'children': [], 'value': "'star_index'"},{'id': '86', 'type': 'string', 'children': [], 'value': "'--outFileNamePrefix'"},{'id': '87', 'type': 'string', 'children': [], 'value': "'rna'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'--readFilesIn'"},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '91', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_1.fastq'"},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '94', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_2.fastq'"},{'id': '95', 'type': 'string', 'children': [], 'value': "'--outSAMattributes'"},{'id': '96', 'type': 'string', 'children': [], 'value': "'NH'"},{'id': '97', 'type': 'string', 'children': [], 'value': "'HI'"},{'id': '98', 'type': 'string', 'children': [], 'value': "'AS'"},{'id': '99', 'type': 'string', 'children': [], 'value': "'NM'"},{'id': '100', 'type': 'string', 'children': [], 'value': "'MD'"},{'id': '101', 'type': 'string', 'children': [], 'value': "'--outSAMtype'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'BAM'"},{'id': '103', 'type': 'string', 'children': [], 'value': "'SortedByCoordinate'"},{'id': '104', 'type': 'string', 'children': [], 'value': "'--quantMode'"},{'id': '105', 'type': 'string', 'children': [], 'value': "'TranscriptomeSAM'"},{'id': '106', 'type': 'string', 'children': [], 'value': "'--outSAMunmapped'"},{'id': '107', 'type': 'string', 'children': [], 'value': "'Within'"},{'id': '108', 'type': 'if_statement', 'children': ['109', '114', '133']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '=='},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'star_options'},{'id': '112', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '113', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'docker_call'},{'id': '118', 'type': 'argument_list', 'children': ['119', '122', '125', '128']},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '121', 'type': 'string', 'children': [], 'value': "'star'"},{'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '132', 'type': 'string', 'children': [], 'value': "'dockerhub'"},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'docker_call'},{'id': '138', 'type': 'argument_list', 'children': ['139', '142', '145', '148']},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '141', 'type': 'string', 'children': [], 'value': "'starlong'"},{'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '152', 'type': 'string', 'children': [], 'value': "'dockerhub'"},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'for_statement', 'children': ['160', '161', '164']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'bam_file'},{'id': '161', 'type': 'list', 'children': ['162', '163'], 'value': "['rnaAligned.toTranscriptome.out.bam',\n 'rnaAligned.sortedByCoord.out.bam']"},{'id': '162', 'type': 'string', 'children': [], 'value': "'rnaAligned.toTranscriptome.out.bam'"},{'id': '163', 'type': 'string', 'children': [], 'value': "'rnaAligned.sortedByCoord.out.bam'"},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '170']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'bam_file'},{'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': 'job'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'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': "'/'"},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'list', 'children': ['183', '184'], 'value': '[\n work_dir, bam_file]'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'bam_file'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'deleteGlobalFile'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '195', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_1.fastq'"},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '203']},{'id': '198', 'type': 'attribute', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'deleteGlobalFile'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '206', 'type': 'string', 'children': [], 'value': "'rna_cutadapt_2.fastq'"},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'index_star'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216', '219', '220', '221']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'index_bamfile'},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '218', 'type': 'string', 'children': [], 'value': "'rnaAligned.sortedByCoord.out.bam'"},{'id': '219', 'type': 'string', 'children': [], 'value': "'rna'"},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '223', 'type': 'string', 'children': [], 'value': "'120G'"},{'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': 'job'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'index_star'},{'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': 'output_files'},{'id': '235', 'type': 'string', 'children': [], 'value': "'rnaAligned.sortedByCoord.out.bam'"},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'index_star'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'return_statement', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'output_files'}
def run_star(job, fastqs, univ_options, star_options): assert star_options['type'] in ('star', 'starlong') job.fileStore.logToMaster('Running STAR on %s' %univ_options['patient']) work_dir = job.fileStore.getLocalTempDir() input_files = { 'rna_cutadapt_1.fastq': fastqs['rna_cutadapt_1.fastq'], 'rna_cutadapt_2.fastq': fastqs['rna_cutadapt_2.fastq'], 'star_index.tar.gz': star_options['index_tar']} input_files = get_files_from_filestore(job, input_files, work_dir, docker=True) parameters = ['--runThreadN', str(star_options['n']), '--genomeDir', input_files['star_index'], '--outFileNamePrefix', 'rna', '--readFilesIn', input_files['rna_cutadapt_1.fastq'], input_files['rna_cutadapt_2.fastq'], '--outSAMattributes', 'NH', 'HI', 'AS', 'NM', 'MD', '--outSAMtype', 'BAM', 'SortedByCoordinate', '--quantMode', 'TranscriptomeSAM', '--outSAMunmapped', 'Within'] if star_options['type'] == 'star': docker_call(tool='star', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub']) else: docker_call(tool='starlong', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub']) output_files = defaultdict() for bam_file in ['rnaAligned.toTranscriptome.out.bam', 'rnaAligned.sortedByCoord.out.bam']: output_files[bam_file] = job.fileStore.writeGlobalFile('/'.join([ work_dir, bam_file])) job.fileStore.deleteGlobalFile(fastqs['rna_cutadapt_1.fastq']) job.fileStore.deleteGlobalFile(fastqs['rna_cutadapt_2.fastq']) index_star = job.wrapJobFn(index_bamfile, output_files['rnaAligned.sortedByCoord.out.bam'], 'rna', univ_options, disk='120G') job.addChild(index_star) output_files['rnaAligned.sortedByCoord.out.bam'] = index_star.rv() return output_files
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_bwa'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '9', 'type': 'block', 'children': ['10', '25', '35', '44', '71', '83', '113', '155', '168', '183', '190']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '17']},{'id': '12', 'type': 'attribute', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'},{'id': '19', 'type': 'string', 'children': [], 'value': "'Running bwa on %s:%s'"},{'id': '20', 'type': 'tuple', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '23', 'type': 'string', 'children': [], 'value': "'patient'"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fq_extn'},{'id': '38', 'type': 'conditional_expression', 'children': ['39', '40', '43'], 'value': 'if'},{'id': '39', 'type': 'string', 'children': [], 'value': "'.gz'"},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '42', 'type': 'string', 'children': [], 'value': "'gzipped'"},{'id': '43', 'type': 'string', 'children': [], 'value': "''"},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '47', 'type': 'dictionary', 'children': ['48', '57', '66']},{'id': '48', 'type': 'pair', 'children': ['49', '52']},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'},{'id': '50', 'type': 'string', 'children': [], 'value': "'dna_1.fastq'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'fq_extn'},{'id': '52', 'type': 'subscript', 'children': ['53', '56']},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'pair', 'children': ['58', '61']},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '+'},{'id': '59', 'type': 'string', 'children': [], 'value': "'dna_2.fastq'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'fq_extn'},{'id': '61', 'type': 'subscript', 'children': ['62', '65']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'fastqs'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'pair', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "'bwa_index.tar.gz'"},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '70', 'type': 'string', 'children': [], 'value': "'index_tar'"},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get_files_from_filestore'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79', '80']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'docker'},{'id': '82', 'type': 'True', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '86', 'type': 'list', 'children': ['87', '88', '89', '95', '96', '97', '107', '110'], 'value': "['mem',\n '-t', str(bwa_options['n']),\n '-v', '1',\n '/'.join([input_files['bwa_index'], 'hg19.fa']),\n input_files['dna_1.fastq'],\n input_files['dna_2.fastq']]"},{'id': '87', 'type': 'string', 'children': [], 'value': "'mem'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'-t'"},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'bwa_options'},{'id': '94', 'type': 'string', 'children': [], 'value': "'n'"},{'id': '95', 'type': 'string', 'children': [], 'value': "'-v'"},{'id': '96', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'list', 'children': ['103', '106'], 'value': "[input_files['bwa_index'], 'hg19.fa']"},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '105', 'type': 'string', 'children': [], 'value': "'bwa_index'"},{'id': '106', 'type': 'string', 'children': [], 'value': "'hg19.fa'"},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '109', 'type': 'string', 'children': [], 'value': "'dna_1.fastq'"},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '112', 'type': 'string', 'children': [], 'value': "'dna_2.fastq'"},{'id': '113', 'type': 'with_statement', 'children': ['114', '133']},{'id': '114', 'type': 'with_clause', 'children': ['115']},{'id': '115', 'type': 'with_item', 'children': ['116']},{'id': '116', 'type': 'as_pattern', 'children': ['117', '131']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '119', 'type': 'argument_list', 'children': ['120', '130']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "''"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'list', 'children': ['126', '127', '128', '129'], 'value': "[work_dir, '/', sample_type, '_aligned.sam']"},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '127', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '129', 'type': 'string', 'children': [], 'value': "'_aligned.sam'"},{'id': '130', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '131', 'type': 'as_pattern_target', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'docker_call'},{'id': '137', 'type': 'argument_list', 'children': ['138', '141', '144', '147', '152']},{'id': '138', 'type': 'keyword_argument', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '140', 'type': 'string', 'children': [], 'value': "'bwa'"},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '151', 'type': 'string', 'children': [], 'value': "'dockerhub'"},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'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': 'job'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'samfile'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'samfile_processing'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'wrapJobFn'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177', '178', '179', '180']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'bam_conversion'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '182', 'type': 'string', 'children': [], 'value': "'60G'"},{'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': 'job'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'addChild'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'samfile_processing'},{'id': '190', 'type': 'return_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'samfile_processing'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '195', 'type': 'argument_list', 'children': []}
def run_bwa(job, fastqs, sample_type, univ_options, bwa_options): job.fileStore.logToMaster('Running bwa on %s:%s' % (univ_options['patient'], sample_type)) work_dir = job.fileStore.getLocalTempDir() fq_extn = '.gz' if fastqs['gzipped'] else '' input_files = { 'dna_1.fastq' + fq_extn: fastqs[sample_type][0], 'dna_2.fastq' + fq_extn: fastqs[sample_type][1], 'bwa_index.tar.gz': bwa_options['index_tar']} input_files = get_files_from_filestore(job, input_files, work_dir, docker=True) parameters = ['mem', '-t', str(bwa_options['n']), '-v', '1', '/'.join([input_files['bwa_index'], 'hg19.fa']), input_files['dna_1.fastq'], input_files['dna_2.fastq']] with open(''.join([work_dir, '/', sample_type, '_aligned.sam']), 'w') as samfile: docker_call(tool='bwa', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub'], outfile=samfile) output_file = job.fileStore.writeGlobalFile(samfile.name) samfile_processing = job.wrapJobFn(bam_conversion, output_file, sample_type, univ_options, disk='60G') job.addChild(samfile_processing) return samfile_processing.rv()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_radia'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'perchrom_rvs'},{'id': '6', 'type': 'block', 'children': ['7', '16', '26', '49', '61', '87', '233', '270', '276', '306']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'Running merge_radia'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '29', 'type': 'dictionary_comprehension', 'children': ['30', '33', '40']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'jsid'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'perchrom_files'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'perchrom_rvs'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '44']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'jsid'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'perchrom_files'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_files_from_filestore'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57', '58']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'docker'},{'id': '60', 'type': 'False', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'chromosomes'},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '76']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "''"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'list', 'children': ['71', '72'], 'value': "['chr', str(x)]"},{'id': '71', 'type': 'string', 'children': [], 'value': "'chr'"},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '84'], 'value': '+'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'integer', 'children': [], 'value': '23'},{'id': '84', 'type': 'list', 'children': ['85', '86'], 'value': "['X', 'Y']"},{'id': '85', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '86', 'type': 'string', 'children': [], 'value': "'Y'"},{'id': '87', 'type': 'with_statement', 'children': ['88', '122']},{'id': '88', 'type': 'with_clause', 'children': ['89', '105', '106']},{'id': '89', 'type': 'with_item', 'children': ['90']},{'id': '90', 'type': 'as_pattern', 'children': ['91', '103']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '93', 'type': 'argument_list', 'children': ['94', '102']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'list', 'children': ['100', '101'], 'value': "[work_dir, 'radia_calls.vcf']"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '101', 'type': 'string', 'children': [], 'value': "'radia_calls.vcf'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '103', 'type': 'as_pattern_target', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'radfile'},{'id': '105', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '106', 'type': 'with_item', 'children': ['107']},{'id': '107', 'type': 'as_pattern', 'children': ['108', '120']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '110', 'type': 'argument_list', 'children': ['111', '119']},{'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': 'list', 'children': ['117', '118'], 'value': "[work_dir, 'radia_filter_passing_calls.vcf']"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '118', 'type': 'string', 'children': [], 'value': "'radia_filter_passing_calls.vcf'"},{'id': '119', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '120', 'type': 'as_pattern_target', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'radpassfile'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'chromosomes'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'with_statement', 'children': ['128', '148']},{'id': '128', 'type': 'with_clause', 'children': ['129']},{'id': '129', 'type': 'with_item', 'children': ['130']},{'id': '130', 'type': 'as_pattern', 'children': ['131', '146']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '133', 'type': 'argument_list', 'children': ['134', '145']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'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': 'list', 'children': ['142', '143', '144'], 'value': "['radia_filtered_', chrom, '.vcf']"},{'id': '142', 'type': 'string', 'children': [], 'value': "'radia_filtered_'"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '144', 'type': 'string', 'children': [], 'value': "'.vcf'"},{'id': '145', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '146', 'type': 'as_pattern_target', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'filtradfile'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'for_statement', 'children': ['150', '151', '152']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'filtradfile'},{'id': '152', 'type': 'block', 'children': ['153', '161', '186', '187', '198', '207']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '160', 'type': 'argument_list', 'children': []},{'id': '161', 'type': 'if_statement', 'children': ['162', '165', '169']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '165', 'type': 'ERROR', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': "'\n if chrom == '"},{'id': '167', 'type': 'ERROR', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'chr1'},{'id': '169', 'type': 'block', 'children': ['170', '178']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '175', 'type': 'keyword_argument', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'radfile'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'radpassfile'},{'id': '186', 'type': 'continue_statement', 'children': []},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'else'},{'id': '190', 'type': 'type', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'radfile'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '207', 'type': 'if_statement', 'children': ['208', '219']},{'id': '208', 'type': 'boolean_operator', 'children': ['209', '214'], 'value': 'and'},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '213'], 'value': '=='},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '212', 'type': 'integer', 'children': [], 'value': '6'},{'id': '213', 'type': 'string', 'children': [], 'value': "'PASS'"},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'not'},{'id': '215', 'type': 'string', 'children': [], 'value': "'MT=GERM'"},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '218', 'type': 'integer', 'children': [], 'value': '7'},{'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': 'print'},{'id': '223', 'type': 'argument_list', 'children': ['224', '230']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'radpassfile'},{'id': '233', 'type': 'with_statement', 'children': ['234', '263']},{'id': '234', 'type': 'with_clause', 'children': ['235', '246', '247']},{'id': '235', 'type': 'with_item', 'children': ['236']},{'id': '236', 'type': 'as_pattern', 'children': ['237', '244']},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '239', 'type': 'argument_list', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'radpassfile'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '243', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '244', 'type': 'as_pattern_target', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'radpassfile'},{'id': '246', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '247', 'type': 'with_item', 'children': ['248']},{'id': '248', 'type': 'as_pattern', 'children': ['249', '261']},{'id': '249', 'type': 'call', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '251', 'type': 'argument_list', 'children': ['252', '260']},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'list', 'children': ['258', '259'], 'value': "[work_dir, 'radia_parsed_filter_passing_calls.vcf']"},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '259', 'type': 'string', 'children': [], 'value': "'radia_parsed_filter_passing_calls.vcf'"},{'id': '260', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '261', 'type': 'as_pattern_target', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'parsedradfile'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'call', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'parse_radia_multi_alt'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'radpassfile'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'parsedradfile'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '275', 'type': 'argument_list', 'children': []},{'id': '276', 'type': 'for_statement', 'children': ['277', '278', '285']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'radia_file'},{'id': '278', 'type': 'list', 'children': ['279', '282'], 'value': '[radfile.name, parsedradfile.name]'},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'radfile'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'parsedradfile'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '285', 'type': 'block', 'children': ['286']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '298']},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '290', 'type': 'call', 'children': ['291', '296']},{'id': '291', 'type': 'attribute', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'radia_file'},{'id': '298', 'type': 'call', 'children': ['299', '304']},{'id': '299', 'type': 'attribute', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'radia_file'},{'id': '306', 'type': 'return_statement', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'output_files'}
def merge_radia(job, perchrom_rvs): job.fileStore.logToMaster('Running merge_radia') work_dir = job.fileStore.getLocalTempDir() input_files = {filename: jsid for perchrom_files in perchrom_rvs.values() for filename, jsid in perchrom_files.items()} input_files = get_files_from_filestore(job, input_files, work_dir, docker=False) chromosomes = [''.join(['chr', str(x)]) for x in range(1, 23) + ['X', 'Y']] with open('/'.join([work_dir, 'radia_calls.vcf']), 'w') as radfile, \ open('/'.join([work_dir, 'radia_filter_passing_calls.vcf']), 'w') as radpassfile: for chrom in chromosomes: with open(input_files[''.join(['radia_filtered_', chrom, '.vcf'])], 'r') as filtradfile: for line in filtradfile: line = line.strip() if line.startswith(' if chrom == 'chr1': print(line, file=radfile) print(line, file=radpassfile) continue else: print(line, file=radfile) line = line.split('\t') if line[6] == 'PASS' and 'MT=GERM' not in line[7]: print('\t'.join(line), file=radpassfile) with open(radpassfile.name, 'r') as radpassfile, \ open('/'.join([work_dir, 'radia_parsed_filter_passing_calls.vcf']), 'w') as parsedradfile: parse_radia_multi_alt(radpassfile, parsedradfile) output_files = defaultdict() for radia_file in [radfile.name, parsedradfile.name]: output_files[os.path.basename(radia_file)] = job.fileStore.writeGlobalFile(radia_file) return output_files
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_mutect'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'perchrom_rvs'},{'id': '6', 'type': 'block', 'children': ['7', '16', '26', '49', '61', '87', '328', '341']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': "'Running merge_mutect'"},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '25', 'type': 'argument_list', 'children': []},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '29', 'type': 'dictionary_comprehension', 'children': ['30', '33', '40']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'jsid'},{'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'perchrom_files'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'perchrom_rvs'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'for_in_clause', 'children': ['41', '44']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'jsid'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'perchrom_files'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_files_from_filestore'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57', '58']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'docker'},{'id': '60', 'type': 'False', 'children': []},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'chromosomes'},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '76']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'string', 'children': [], 'value': "''"},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'list', 'children': ['71', '72'], 'value': "['chr', str(x)]"},{'id': '71', 'type': 'string', 'children': [], 'value': "'chr'"},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '84'], 'value': '+'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'integer', 'children': [], 'value': '23'},{'id': '84', 'type': 'list', 'children': ['85', '86'], 'value': "['X', 'Y']"},{'id': '85', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '86', 'type': 'string', 'children': [], 'value': "'Y'"},{'id': '87', 'type': 'with_statement', 'children': ['88', '139']},{'id': '88', 'type': 'with_clause', 'children': ['89', '105', '106', '122', '123']},{'id': '89', 'type': 'with_item', 'children': ['90']},{'id': '90', 'type': 'as_pattern', 'children': ['91', '103']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '93', 'type': 'argument_list', 'children': ['94', '102']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'list', 'children': ['100', '101'], 'value': "[work_dir, 'mutect_calls.vcf']"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '101', 'type': 'string', 'children': [], 'value': "'mutect_calls.vcf'"},{'id': '102', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '103', 'type': 'as_pattern_target', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'mutvcf'},{'id': '105', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '106', 'type': 'with_item', 'children': ['107']},{'id': '107', 'type': 'as_pattern', 'children': ['108', '120']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '110', 'type': 'argument_list', 'children': ['111', '119']},{'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': 'list', 'children': ['117', '118'], 'value': "[work_dir, 'mutect_calls.out']"},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '118', 'type': 'string', 'children': [], 'value': "'mutect_calls.out'"},{'id': '119', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '120', 'type': 'as_pattern_target', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'mutout'},{'id': '122', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '123', 'type': 'with_item', 'children': ['124']},{'id': '124', 'type': 'as_pattern', 'children': ['125', '137']},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '127', 'type': 'argument_list', 'children': ['128', '136']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'list', 'children': ['134', '135'], 'value': "[work_dir, 'mutect_passing_calls.vcf']"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '135', 'type': 'string', 'children': [], 'value': "'mutect_passing_calls.vcf'"},{'id': '136', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '137', 'type': 'as_pattern_target', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'mutpassvcf'},{'id': '139', 'type': 'block', 'children': ['140', '144']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'out_header_not_printed'},{'id': '143', 'type': 'True', 'children': []},{'id': '144', 'type': 'for_statement', 'children': ['145', '146', '147']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'chromosomes'},{'id': '147', 'type': 'block', 'children': ['148', '248']},{'id': '148', 'type': 'with_statement', 'children': ['149', '169']},{'id': '149', 'type': 'with_clause', 'children': ['150']},{'id': '150', 'type': 'with_item', 'children': ['151']},{'id': '151', 'type': 'as_pattern', 'children': ['152', '167']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '154', 'type': 'argument_list', 'children': ['155', '166']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'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': 'list', 'children': ['163', '164', '165'], 'value': "['mutect_', chrom, '.vcf']"},{'id': '163', 'type': 'string', 'children': [], 'value': "'mutect_'"},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '165', 'type': 'string', 'children': [], 'value': "'.vcf'"},{'id': '166', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '167', 'type': 'as_pattern_target', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'mutfile'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'for_statement', 'children': ['171', '172', '173']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'mutfile'},{'id': '173', 'type': 'block', 'children': ['174', '182', '207', '208', '219', '228']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '181', 'type': 'argument_list', 'children': []},{'id': '182', 'type': 'if_statement', 'children': ['183', '186', '190']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '186', 'type': 'ERROR', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': "'\n if chrom == '"},{'id': '188', 'type': 'ERROR', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'chr1'},{'id': '190', 'type': 'block', 'children': ['191', '199']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '194', 'type': 'argument_list', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '196', 'type': 'keyword_argument', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'mutvcf'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'mutpassvcf'},{'id': '207', 'type': 'continue_statement', 'children': []},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'else'},{'id': '211', 'type': 'type', 'children': ['212']},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'mutvcf'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '228', 'type': 'if_statement', 'children': ['229', '234']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '233'], 'value': '!='},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '232', 'type': 'integer', 'children': [], 'value': '6'},{'id': '233', 'type': 'string', 'children': [], 'value': "'REJECT'"},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '238', 'type': 'argument_list', 'children': ['239', '245']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'mutpassvcf'},{'id': '248', 'type': 'with_statement', 'children': ['249', '269']},{'id': '249', 'type': 'with_clause', 'children': ['250']},{'id': '250', 'type': 'with_item', 'children': ['251']},{'id': '251', 'type': 'as_pattern', 'children': ['252', '267']},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '254', 'type': 'argument_list', 'children': ['255', '266']},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': "''"},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'list', 'children': ['263', '264', '265'], 'value': "['mutect_', chrom,\n '.out']"},{'id': '263', 'type': 'string', 'children': [], 'value': "'mutect_'"},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '265', 'type': 'string', 'children': [], 'value': "'.out'"},{'id': '266', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '267', 'type': 'as_pattern_target', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'mutfile'},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'for_statement', 'children': ['271', '272', '273']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'mutfile'},{'id': '273', 'type': 'block', 'children': ['274', '282', '299', '300', '302', '313', '317']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'assignment', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '281', 'type': 'argument_list', 'children': []},{'id': '282', 'type': 'if_statement', 'children': ['283', '286', '290']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '286', 'type': 'ERROR', 'children': ['287', '288']},{'id': '287', 'type': 'string', 'children': [], 'value': "'\n if chrom == '"},{'id': '288', 'type': 'ERROR', 'children': ['289']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'chr1'},{'id': '290', 'type': 'block', 'children': ['291']},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '294', 'type': 'argument_list', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'mutout'},{'id': '299', 'type': 'continue_statement', 'children': []},{'id': '300', 'type': 'ERROR', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'elif'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'out_header_not_printed'},{'id': '305', 'type': 'type', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '308', 'type': 'argument_list', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '310', 'type': 'keyword_argument', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'mutout'},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'assignment', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'out_header_not_printed'},{'id': '316', 'type': 'False', 'children': []},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'assignment', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'else'},{'id': '320', 'type': 'type', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'mutout'},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'id': '331', 'type': 'call', 'children': ['332', '337']},{'id': '332', 'type': 'attribute', 'children': ['333', '336']},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'mutpassvcf'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '341', 'type': 'return_statement', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'output_file'}
def merge_mutect(job, perchrom_rvs): job.fileStore.logToMaster('Running merge_mutect') work_dir = job.fileStore.getLocalTempDir() input_files = {filename: jsid for perchrom_files in perchrom_rvs.values() for filename, jsid in perchrom_files.items()} input_files = get_files_from_filestore(job, input_files, work_dir, docker=False) chromosomes = [''.join(['chr', str(x)]) for x in range(1, 23) + ['X', 'Y']] with open('/'.join([work_dir, 'mutect_calls.vcf']), 'w') as mutvcf, \ open('/'.join([work_dir, 'mutect_calls.out']), 'w') as mutout, \ open('/'.join([work_dir, 'mutect_passing_calls.vcf']), 'w') as mutpassvcf: out_header_not_printed = True for chrom in chromosomes: with open(input_files[''.join(['mutect_', chrom, '.vcf'])], 'r') as mutfile: for line in mutfile: line = line.strip() if line.startswith(' if chrom == 'chr1': print(line, file=mutvcf) print(line, file=mutpassvcf) continue else: print(line, file=mutvcf) line = line.split('\t') if line[6] != 'REJECT': print('\t'.join(line), file=mutpassvcf) with open(input_files[''.join(['mutect_', chrom, '.out'])], 'r') as mutfile: for line in mutfile: line = line.strip() if line.startswith(' if chrom == 'chr1': print(line, file=mutout) continue elif out_header_not_printed: print(line, file=mutout) out_header_not_printed = False else: print(line, file=mutout) output_file = job.fileStore.writeGlobalFile(mutpassvcf.name) return output_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_mutation_aggregator'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fusion_output'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'radia_output'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'mutect_output'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'indel_output'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '10', 'type': 'block', 'children': ['11', '24', '34', '52', '64', '71', '78', '84', '92', '208', '216', '224', '237']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '%'},{'id': '20', 'type': 'string', 'children': [], 'value': "'Aggregating mutations for %s'"},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '23', 'type': 'string', 'children': [], 'value': "'patient'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'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': 'job'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'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': 'input_files'},{'id': '37', 'type': 'dictionary', 'children': ['38', '41', '46', '49']},{'id': '38', 'type': 'pair', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'mutect.vcf'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'mutect_output'},{'id': '41', 'type': 'pair', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'radia.vcf'"},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'radia_output'},{'id': '45', 'type': 'string', 'children': [], 'value': "'radia_parsed_filter_passing_calls.vcf'"},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'indel.vcf'"},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'indel_output'},{'id': '49', 'type': 'pair', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'fusion.vcf'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'fusion_output'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'get_files_from_filestore'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59', '60', '61']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'docker'},{'id': '63', 'type': 'False', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'string', 'children': [], 'value': "'indel.vcf'"},{'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': 'input_files'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': "'fusion.vcf'"},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'mutcallers'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'with_statement', 'children': ['93', '114']},{'id': '93', 'type': 'with_clause', 'children': ['94']},{'id': '94', 'type': 'with_item', 'children': ['95']},{'id': '95', 'type': 'as_pattern', 'children': ['96', '112']},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '98', 'type': 'argument_list', 'children': ['99', '111']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "''"},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'list', 'children': ['105', '106', '107', '110'], 'value': "[work_dir, '/', univ_options['patient'], '_merged_mutations.vcf']"},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '106', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '109', 'type': 'string', 'children': [], 'value': "'patient'"},{'id': '110', 'type': 'string', 'children': [], 'value': "'_merged_mutations.vcf'"},{'id': '111', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '112', 'type': 'as_pattern_target', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'merged_mut_file'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'for_statement', 'children': ['116', '117', '118']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'mut_caller'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'mutcallers'},{'id': '118', 'type': 'block', 'children': ['119', '128', '136']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'mut_caller'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'string', 'children': [], 'value': "'.vcf'"},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '135', 'type': 'argument_list', 'children': []},{'id': '136', 'type': 'with_statement', 'children': ['137', '149']},{'id': '137', 'type': 'with_clause', 'children': ['138']},{'id': '138', 'type': 'with_item', 'children': ['139']},{'id': '139', 'type': 'as_pattern', 'children': ['140', '147']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '142', 'type': 'argument_list', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'mut_caller'},{'id': '146', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '147', 'type': 'as_pattern_target', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'mutfile'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '153']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'mutfile'},{'id': '153', 'type': 'block', 'children': ['154', '175', '176', '188']},{'id': '154', 'type': 'if_statement', 'children': ['155', '158', '162']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '158', 'type': 'ERROR', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': "'\n if caller == '"},{'id': '160', 'type': 'ERROR', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'radia'},{'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', '172']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '171', 'type': 'argument_list', 'children': []},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'merged_mut_file'},{'id': '175', 'type': 'continue_statement', 'children': []},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '179', 'type': 'call', 'children': ['180', '187']},{'id': '180', 'type': 'attribute', 'children': ['181', '186']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '187', 'type': 'argument_list', 'children': []},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '207']},{'id': '190', 'type': 'subscript', 'children': ['191', '194']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '194', 'type': 'tuple', 'children': ['195', '198', '201', '204']},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '197', 'type': 'integer', 'children': [], 'value': '0'},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '203', 'type': 'integer', 'children': [], 'value': '3'},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '206', 'type': 'integer', 'children': [], 'value': '4'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'merge_vcfs'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'merged_mut_file'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'export_results'},{'id': '219', 'type': 'argument_list', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'merged_mut_file'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'output_file'},{'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': 'job'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'merged_mut_file'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'output_file'}
def run_mutation_aggregator(job, fusion_output, radia_output, mutect_output, indel_output, univ_options): job.fileStore.logToMaster('Aggregating mutations for %s' % univ_options['patient']) work_dir = job.fileStore.getLocalTempDir() input_files = { 'mutect.vcf': mutect_output, 'radia.vcf': radia_output['radia_parsed_filter_passing_calls.vcf'], 'indel.vcf': indel_output, 'fusion.vcf': fusion_output} input_files = get_files_from_filestore(job, input_files, work_dir, docker=False) input_files.pop('indel.vcf') input_files.pop('fusion.vcf') vcf_file = defaultdict() mutcallers = input_files.keys() with open(''.join([work_dir, '/', univ_options['patient'], '_merged_mutations.vcf']), 'w') as merged_mut_file: for mut_caller in mutcallers: caller = mut_caller.rstrip('.vcf') vcf_file[caller] = defaultdict() with open(input_files[mut_caller], 'r') as mutfile: for line in mutfile: if line.startswith(' if caller == 'radia': print(line.strip(), file=merged_mut_file) continue line = line.strip().split() vcf_file[caller][(line[0], line[1], line[3], line[4])] = line merge_vcfs(vcf_file, merged_mut_file.name) export_results(merged_mut_file.name, univ_options) output_file = job.fileStore.writeGlobalFile(merged_mut_file.name) return output_file
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_phlat_calls'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tumor_phlat'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'normal_phlat'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'rna_phlat'},{'id': '8', 'type': 'block', 'children': ['9', '18', '28', '41', '50', '131', '285', '291', '318']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '16']},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'string', 'children': [], 'value': "'Merging Phlat calls'"},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '21', 'type': 'call', 'children': ['22', '27']},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '31', 'type': 'dictionary', 'children': ['32', '35', '38']},{'id': '32', 'type': 'pair', 'children': ['33', '34']},{'id': '33', 'type': 'string', 'children': [], 'value': "'tumor_dna'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'tumor_phlat'},{'id': '35', 'type': 'pair', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'normal_dna'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'normal_phlat'},{'id': '38', 'type': 'pair', 'children': ['39', '40']},{'id': '39', 'type': 'string', 'children': [], 'value': "'tumor_rna'"},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'rna_phlat'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_files_from_filestore'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48', '49']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '50', 'type': 'with_statement', 'children': ['51', '87']},{'id': '51', 'type': 'with_clause', 'children': ['52', '63', '64', '75', '76']},{'id': '52', 'type': 'with_item', 'children': ['53']},{'id': '53', 'type': 'as_pattern', 'children': ['54', '61']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '56', 'type': 'argument_list', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '59', 'type': 'string', 'children': [], 'value': "'tumor_dna'"},{'id': '60', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '61', 'type': 'as_pattern_target', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'td_file'},{'id': '63', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '64', 'type': 'with_item', 'children': ['65']},{'id': '65', 'type': 'as_pattern', 'children': ['66', '73']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '68', 'type': 'argument_list', 'children': ['69', '72']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '71', 'type': 'string', 'children': [], 'value': "'normal_dna'"},{'id': '72', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '73', 'type': 'as_pattern_target', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'nd_file'},{'id': '75', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '76', 'type': 'with_item', 'children': ['77']},{'id': '77', 'type': 'as_pattern', 'children': ['78', '85']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '80', 'type': 'argument_list', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '83', 'type': 'string', 'children': [], 'value': "'tumor_rna'"},{'id': '84', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '85', 'type': 'as_pattern_target', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tr_file'},{'id': '87', 'type': 'block', 'children': ['88', '116']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'mhc_alleles'},{'id': '91', 'type': 'dictionary', 'children': ['92', '95', '98', '101', '104', '107', '110', '113']},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'HLA_A'"},{'id': '94', 'type': 'list', 'children': [], 'value': '[]'},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'HLA_B'"},{'id': '97', 'type': 'list', 'children': [], 'value': '[]'},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'HLA_C'"},{'id': '100', 'type': 'list', 'children': [], 'value': '[]'},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'HLA_DPA'"},{'id': '103', 'type': 'list', 'children': [], 'value': '[]'},{'id': '104', 'type': 'pair', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'HLA_DQA'"},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'pair', 'children': ['108', '109']},{'id': '108', 'type': 'string', 'children': [], 'value': "'HLA_DPB'"},{'id': '109', 'type': 'list', 'children': [], 'value': '[]'},{'id': '110', 'type': 'pair', 'children': ['111', '112']},{'id': '111', 'type': 'string', 'children': [], 'value': "'HLA_DQB'"},{'id': '112', 'type': 'list', 'children': [], 'value': '[]'},{'id': '113', 'type': 'pair', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': "'HLA_DRB'"},{'id': '115', 'type': 'list', 'children': [], 'value': '[]'},{'id': '116', 'type': 'for_statement', 'children': ['117', '118', '122']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'phlatfile'},{'id': '118', 'type': 'expression_list', 'children': ['119', '120', '121']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'td_file'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'nd_file'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tr_file'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'mhc_alleles'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'parse_phlat_file'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'phlatfile'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'mhc_alleles'},{'id': '131', 'type': 'with_statement', 'children': ['132', '168']},{'id': '132', 'type': 'with_clause', 'children': ['133', '150', '151']},{'id': '133', 'type': 'with_item', 'children': ['134']},{'id': '134', 'type': 'as_pattern', 'children': ['135', '148']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '137', 'type': 'argument_list', 'children': ['138', '147']},{'id': '138', 'type': 'call', 'children': ['139', '144']},{'id': '139', 'type': 'attribute', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '146', 'type': 'string', 'children': [], 'value': "'mhci_alleles.list'"},{'id': '147', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '148', 'type': 'as_pattern_target', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'mhci_file'},{'id': '150', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '151', 'type': 'with_item', 'children': ['152']},{'id': '152', 'type': 'as_pattern', 'children': ['153', '166']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '155', 'type': 'argument_list', 'children': ['156', '165']},{'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': 'os'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '162', 'type': 'argument_list', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '164', 'type': 'string', 'children': [], 'value': "'mhcii_alleles.list'"},{'id': '165', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '166', 'type': 'as_pattern_target', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'mhcii_file'},{'id': '168', 'type': 'block', 'children': ['169', '209', '218', '242', '251', '260']},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '175']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'mhci_group'},{'id': '171', 'type': 'list', 'children': ['172', '173', '174'], 'value': "['HLA_A', 'HLA_B', 'HLA_C']"},{'id': '172', 'type': 'string', 'children': [], 'value': "'HLA_A'"},{'id': '173', 'type': 'string', 'children': [], 'value': "'HLA_B'"},{'id': '174', 'type': 'string', 'children': [], 'value': "'HLA_C'"},{'id': '175', 'type': 'block', 'children': ['176', '185']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'mpa'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'most_probable_alleles'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'mhc_alleles'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'mhci_group'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '188', 'type': 'argument_list', 'children': ['189', '206']},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'list_comprehension', 'children': ['195', '203']},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': "''"},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'list', 'children': ['201', '202'], 'value': "['HLA-', x]"},{'id': '201', 'type': 'string', 'children': [], 'value': "'HLA-'"},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '203', 'type': 'for_in_clause', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'mpa'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'mhci_file'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'drb_mpa'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'most_probable_alleles'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'mhc_alleles'},{'id': '217', 'type': 'string', 'children': [], 'value': "'HLA_DRB'"},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '221', 'type': 'argument_list', 'children': ['222', '239']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'list_comprehension', 'children': ['228', '236']},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'string', 'children': [], 'value': "''"},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'list', 'children': ['234', '235'], 'value': "['HLA-', x]"},{'id': '234', 'type': 'string', 'children': [], 'value': "'HLA-'"},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '236', 'type': 'for_in_clause', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'drb_mpa'},{'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'mhcii_file'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'dqa_mpa'},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'most_probable_alleles'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'mhc_alleles'},{'id': '250', 'type': 'string', 'children': [], 'value': "'HLA_DQA'"},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'dqb_mpa'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'most_probable_alleles'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'subscript', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'mhc_alleles'},{'id': '259', 'type': 'string', 'children': [], 'value': "'HLA_DQB'"},{'id': '260', 'type': 'for_statement', 'children': ['261', '262', '263']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'dqa_allele'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'dqa_mpa'},{'id': '263', 'type': 'block', 'children': ['264']},{'id': '264', 'type': 'for_statement', 'children': ['265', '266', '267']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'dqb_allele'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'dqb_mpa'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '271', 'type': 'argument_list', 'children': ['272', '282']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'string', 'children': [], 'value': "''"},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'list', 'children': ['278', '279', '280', '281'], 'value': "['HLA-', dqa_allele, '/', dqb_allele]"},{'id': '278', 'type': 'string', 'children': [], 'value': "'HLA-'"},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'dqa_allele'},{'id': '280', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'dqb_allele'},{'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'mhcii_file'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '290', 'type': 'argument_list', 'children': []},{'id': '291', 'type': 'for_statement', 'children': ['292', '293', '296']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'allele_file'},{'id': '293', 'type': 'list', 'children': ['294', '295'], 'value': "['mhci_alleles.list', 'mhcii_alleles.list']"},{'id': '294', 'type': 'string', 'children': [], 'value': "'mhci_alleles.list'"},{'id': '295', 'type': 'string', 'children': [], 'value': "'mhcii_alleles.list'"},{'id': '296', 'type': 'block', 'children': ['297']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'assignment', 'children': ['299', '302']},{'id': '299', 'type': 'subscript', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'allele_file'},{'id': '302', 'type': 'call', 'children': ['303', '308']},{'id': '303', 'type': 'attribute', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '315']},{'id': '310', 'type': 'attribute', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '315', 'type': 'argument_list', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'allele_file'},{'id': '318', 'type': 'return_statement', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'output_files'}
def merge_phlat_calls(job, tumor_phlat, normal_phlat, rna_phlat): job.fileStore.logToMaster('Merging Phlat calls') work_dir = job.fileStore.getLocalTempDir() input_files = { 'tumor_dna': tumor_phlat, 'normal_dna': normal_phlat, 'tumor_rna': rna_phlat} input_files = get_files_from_filestore(job, input_files, work_dir) with open(input_files['tumor_dna'], 'r') as td_file, \ open(input_files['normal_dna'], 'r') as nd_file, \ open(input_files['tumor_rna'], 'r') as tr_file: mhc_alleles = {'HLA_A': [], 'HLA_B': [], 'HLA_C': [], 'HLA_DPA': [], 'HLA_DQA': [], 'HLA_DPB': [], 'HLA_DQB': [], 'HLA_DRB': []} for phlatfile in td_file, nd_file, tr_file: mhc_alleles = parse_phlat_file(phlatfile, mhc_alleles) with open(os.path.join(work_dir, 'mhci_alleles.list'), 'w') as mhci_file, \ open(os.path.join(work_dir, 'mhcii_alleles.list'), 'w') as mhcii_file: for mhci_group in ['HLA_A', 'HLA_B', 'HLA_C']: mpa = most_probable_alleles(mhc_alleles[mhci_group]) print('\n'.join([''.join(['HLA-', x]) for x in mpa]), file=mhci_file) drb_mpa = most_probable_alleles(mhc_alleles['HLA_DRB']) print('\n'.join([''.join(['HLA-', x]) for x in drb_mpa]), file=mhcii_file) dqa_mpa = most_probable_alleles(mhc_alleles['HLA_DQA']) dqb_mpa = most_probable_alleles(mhc_alleles['HLA_DQB']) for dqa_allele in dqa_mpa: for dqb_allele in dqb_mpa: print(''.join(['HLA-', dqa_allele, '/', dqb_allele]), file=mhcii_file) output_files = defaultdict() for allele_file in ['mhci_alleles.list', 'mhcii_alleles.list']: output_files[allele_file] = job.fileStore.writeGlobalFile(os.path.join(work_dir, allele_file)) return output_files
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'docker_call'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'java_opts'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '15', 'type': 'string', 'children': [], 'value': "'aarjunrao'"},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '18', 'type': 'False', 'children': []},{'id': '19', 'type': 'block', 'children': ['20', '47', '60', '91', '97', '106', '139', '207', '245', '258']},{'id': '20', 'type': 'if_statement', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '22', 'type': 'block', 'children': ['23', '30', '41']},{'id': '23', 'type': 'assert_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': 'outfile'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '29', 'type': 'string', 'children': [], 'value': "'outfile was not passsed a file'"},{'id': '30', 'type': 'assert_statement', 'children': ['31', '40']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': 'in'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '35', 'type': 'list', 'children': ['36', '37', '38', '39'], 'value': "['w', 'a', 'wb', 'ab']"},{'id': '36', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '37', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'wb'"},{'id': '39', 'type': 'string', 'children': [], 'value': "'ab'"},{'id': '40', 'type': 'string', 'children': [], 'value': "'outfile not writeable'"},{'id': '41', 'type': 'assert_statement', 'children': ['42', '46']},{'id': '42', 'type': 'not_operator', 'children': ['43']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'closed'},{'id': '46', 'type': 'string', 'children': [], 'value': "'outfile is closed'"},{'id': '47', 'type': 'if_statement', 'children': ['48', '49', '54']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '53', 'type': 'string', 'children': [], 'value': "'-i'"},{'id': '54', 'type': 'else_clause', 'children': ['55']},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '59', 'type': 'string', 'children': [], 'value': "''"},{'id': '60', 'type': 'if_statement', 'children': ['61', '64', '76']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'},{'id': '62', 'type': 'string', 'children': [], 'value': "':'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'tool'},{'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': 'docker_tool'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'list', 'children': ['74', '75'], 'value': '[dockerhub, tool]'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'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': 'docker_tool'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "''"},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'list', 'children': ['87', '88', '89', '90'], 'value': "[dockerhub, '/', tool, ':latest']"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '88', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '90', 'type': 'string', 'children': [], 'value': "':latest'"},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '94', 'type': 'list', 'children': ['95', '96'], 'value': "['docker', 'images']"},{'id': '95', 'type': 'string', 'children': [], 'value': "'docker'"},{'id': '96', 'type': 'string', 'children': [], 'value': "'images'"},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'dimg_rv'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'check_output'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'existing_images'},{'id': '109', 'type': 'list_comprehension', 'children': ['110', '125', '132']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "':'"},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'subscript', 'children': ['116', '121']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'slice', 'children': ['122', '123', '124']},{'id': '122', 'type': 'integer', 'children': [], 'value': '0'},{'id': '123', 'type': 'colon', 'children': []},{'id': '124', 'type': 'integer', 'children': [], 'value': '2'},{'id': '125', 'type': 'for_in_clause', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'dimg_rv'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'splitlines'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'if_clause', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '139', 'type': 'if_statement', 'children': ['140', '143']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'not'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'docker_tool'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'existing_images'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'try_statement', 'children': ['145', '169', '197']},{'id': '145', 'type': 'block', 'children': ['146', '162']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '149', 'type': 'call', 'children': ['150', '161']},{'id': '150', 'type': 'attribute', 'children': ['151', '160']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'string', 'children': [], 'value': "' '"},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'list', 'children': ['157', '158', '159'], 'value': "['docker', 'pull', docker_tool]"},{'id': '157', 'type': 'string', 'children': [], 'value': "'docker'"},{'id': '158', 'type': 'string', 'children': [], 'value': "'pull'"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'docker_tool'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '161', 'type': 'argument_list', 'children': []},{'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': 'subprocess'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '169', 'type': 'except_clause', 'children': ['170', '176']},{'id': '170', 'type': 'as_pattern', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'CalledProcessError'},{'id': '174', 'type': 'as_pattern_target', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'err'},{'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': 'RuntimeError'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'binary_operator', 'children': ['182', '189'], 'value': '+'},{'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '+'},{'id': '183', 'type': 'string', 'children': [], 'value': "'docker command returned a non-zero exit status '"},{'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '%'},{'id': '185', 'type': 'string', 'children': [], 'value': "'(%s)'"},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '%'},{'id': '190', 'type': 'string', 'children': [], 'value': '\'for command \\"%s\\"\''},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'string', 'children': [], 'value': "' '"},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '197', 'type': 'except_clause', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'raise_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '+'},{'id': '205', 'type': 'string', 'children': [], 'value': "'docker not found on system. Install on all'"},{'id': '206', 'type': 'string', 'children': [], 'value': "' nodes.'"},{'id': '207', 'type': 'if_statement', 'children': ['208', '209', '230']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'java_opts'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'base_docker_call'},{'id': '213', 'type': 'binary_operator', 'children': ['214', '229'], 'value': '+'},{'id': '214', 'type': 'binary_operator', 'children': ['215', '223'], 'value': '+'},{'id': '215', 'type': 'binary_operator', 'children': ['216', '222'], 'value': '+'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'string', 'children': [], 'value': "' docker run -e JAVA_OPTS=-Xmx{} '"},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'java_opts'},{'id': '222', 'type': 'string', 'children': [], 'value': "'--rm=true '"},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'string', 'children': [], 'value': "'-v {}:/data --log-driver=none '"},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '230', 'type': 'else_clause', 'children': ['231']},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'base_docker_call'},{'id': '235', 'type': 'binary_operator', 'children': ['236', '244'], 'value': '+'},{'id': '236', 'type': 'binary_operator', 'children': ['237', '243'], 'value': '+'},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'string', 'children': [], 'value': "' docker run --rm=true -v {}:/data '"},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '243', 'type': 'string', 'children': [], 'value': "'--log-driver=none '"},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'interactive'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '257'], 'value': '+'},{'id': '249', 'type': 'binary_operator', 'children': ['250', '255'], 'value': '+'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'base_docker_call'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '254', 'type': 'argument_list', 'children': []},{'id': '255', 'type': 'list', 'children': ['256'], 'value': '[docker_tool]'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'docker_tool'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '258', 'type': 'try_statement', 'children': ['259', '270', '296']},{'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': 'subprocess'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '270', 'type': 'except_clause', 'children': ['271', '277']},{'id': '271', 'type': 'as_pattern', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'CalledProcessError'},{'id': '275', 'type': 'as_pattern_target', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'raise_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'binary_operator', 'children': ['283', '288'], 'value': '+'},{'id': '283', 'type': 'binary_operator', 'children': ['284', '285'], 'value': '%'},{'id': '284', 'type': 'string', 'children': [], 'value': "'docker command returned a non-zero exit status (%s)'"},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'returncode'},{'id': '288', 'type': 'binary_operator', 'children': ['289', '290'], 'value': '%'},{'id': '289', 'type': 'string', 'children': [], 'value': '\'for command \\"%s\\"\''},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'string', 'children': [], 'value': "' '"},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '296', 'type': 'except_clause', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'raise_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'string', 'children': [], 'value': "'docker not found on system. Install on all nodes.'"}
def docker_call(tool, tool_parameters, work_dir, java_opts=None, outfile=None, dockerhub='aarjunrao', interactive=False): if outfile: assert isinstance(outfile, file), 'outfile was not passsed a file' assert outfile.mode in ['w', 'a', 'wb', 'ab'], 'outfile not writeable' assert not outfile.closed, 'outfile is closed' if interactive: interactive = '-i' else: interactive = '' if ':' in tool: docker_tool = '/'.join([dockerhub, tool]) else: docker_tool = ''.join([dockerhub, '/', tool, ':latest']) call = ['docker', 'images'] dimg_rv = subprocess.check_output(call) existing_images = [':'.join(x.split()[0:2]) for x in dimg_rv.splitlines() if x.startswith(dockerhub)] if docker_tool not in existing_images: try: call = ' '.join(['docker', 'pull', docker_tool]).split() subprocess.check_call(call) except subprocess.CalledProcessError as err: raise RuntimeError('docker command returned a non-zero exit status ' + '(%s)' % err.returncode + 'for command \"%s\"' % ' '.join(call),) except OSError: raise RuntimeError('docker not found on system. Install on all' + ' nodes.') if java_opts: base_docker_call = ' docker run -e JAVA_OPTS=-Xmx{} '.format(java_opts) + '--rm=true ' + \ '-v {}:/data --log-driver=none '.format(work_dir) + interactive else: base_docker_call = ' docker run --rm=true -v {}:/data '.format(work_dir) + \ '--log-driver=none ' + interactive call = base_docker_call.split() + [docker_tool] + tool_parameters try: subprocess.check_call(call, stdout=outfile) except subprocess.CalledProcessError as err: raise RuntimeError('docker command returned a non-zero exit status (%s)' % err.returncode + 'for command \"%s\"' % ' '.join(call),) except OSError: raise RuntimeError('docker not found on system. Install on all nodes.')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_file_from_gdc'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'gdc_url'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'gdc_download_token'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'write_to_jobstore'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '21', '28', '37', '50', '58', '65', '94', '103', '132', '219', '237']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '14', 'type': 'call', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'getLocalTempDir'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'gdc_url'},{'id': '28', 'type': 'assert_statement', 'children': ['29', '34']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': '=='},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '33', 'type': 'string', 'children': [], 'value': "'gdc'"},{'id': '34', 'type': 'binary_operator', 'children': ['35', '36'], 'value': '%'},{'id': '35', 'type': 'string', 'children': [], 'value': "'Unexpected url scheme: %s'"},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'gdc_url'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'file_dir'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'list', 'children': ['46', '47'], 'value': '[work_dir, parsed_url.netloc]'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'netloc'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'currwd'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '57', 'type': 'argument_list', 'children': []},{'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': 'os'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '65', 'type': 'try_statement', 'children': ['66', '85']},{'id': '66', 'type': 'block', 'children': ['67', '78']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'download_call'},{'id': '70', 'type': 'list', 'children': ['71', '72', '73', '74', '75'], 'value': "['gdc-client', 'download', '-t', gdc_download_token, parsed_url.netloc]"},{'id': '71', 'type': 'string', 'children': [], 'value': "'gdc-client'"},{'id': '72', 'type': 'string', 'children': [], 'value': "'download'"},{'id': '73', 'type': 'string', 'children': [], 'value': "'-t'"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'gdc_download_token'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'parsed_url'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'netloc'},{'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': 'subprocess'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'check_call'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'download_call'},{'id': '85', 'type': 'finally_clause', 'children': ['86']},{'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': 'os'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'chdir'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'currwd'},{'id': '94', 'type': 'assert_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '101']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'file_dir'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '106', 'type': 'list_comprehension', 'children': ['107', '116', '124']},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'file_dir'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'file_dir'},{'id': '124', 'type': 'if_clause', 'children': ['125']},{'id': '125', 'type': 'not_operator', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': "'logs'"},{'id': '132', 'type': 'if_statement', 'children': ['133', '139', '149']},{'id': '133', 'type': 'comparison_operator', 'children': ['134', '138'], 'value': '=='},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '138', 'type': 'integer', 'children': [], 'value': '1'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'assert_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '147']},{'id': '142', 'type': 'attribute', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': "'vcf'"},{'id': '149', 'type': 'else_clause', 'children': ['150']},{'id': '150', 'type': 'block', 'children': ['151', '177', '194']},{'id': '151', 'type': 'if_statement', 'children': ['152', '171']},{'id': '152', 'type': 'not_operator', 'children': ['153']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '168'], 'value': '>='},{'id': '154', 'type': 'set_comprehension', 'children': ['155', '165']},{'id': '155', 'type': 'subscript', 'children': ['156', '164']},{'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': 'os'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '164', 'type': 'integer', 'children': [], 'value': '1'},{'id': '165', 'type': 'for_in_clause', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '168', 'type': 'set', 'children': ['169', '170']},{'id': '169', 'type': 'string', 'children': [], 'value': "'.bam'"},{'id': '170', 'type': 'string', 'children': [], 'value': "'.bai'"},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'raise_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ParameterError'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': "'Can currently only handle pre-indexed GDC bams.'"},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '180', 'type': 'list_comprehension', 'children': ['181', '182', '185']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '182', 'type': 'for_in_clause', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '185', 'type': 'if_clause', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'tuple', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': "'bam'"},{'id': '193', 'type': 'string', 'children': [], 'value': "'bai'"},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201', '216']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '203', 'type': 'lambda', 'children': ['204', '206']},{'id': '204', 'type': 'lambda_parameters', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '206', 'type': 'subscript', 'children': ['207', '215']},{'id': '207', 'type': 'call', 'children': ['208', '213']},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '215', 'type': 'integer', 'children': [], 'value': '1'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '218', 'type': 'True', 'children': []},{'id': '219', 'type': 'if_statement', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'write_to_jobstore'},{'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': 'output_files'},{'id': '225', 'type': 'list_comprehension', 'children': ['226', '234']},{'id': '226', 'type': 'call', 'children': ['227', '232']},{'id': '227', 'type': 'attribute', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '234', 'type': 'for_in_clause', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'output_files'},{'id': '237', 'type': 'return_statement', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'output_files'}
def get_file_from_gdc(job, gdc_url, gdc_download_token, write_to_jobstore=True): work_dir = job.fileStore.getLocalTempDir() parsed_url = urlparse(gdc_url) assert parsed_url.scheme == 'gdc', 'Unexpected url scheme: %s' % gdc_url file_dir = '/'.join([work_dir, parsed_url.netloc]) currwd = os.getcwd() os.chdir(work_dir) try: download_call = ['gdc-client', 'download', '-t', gdc_download_token, parsed_url.netloc] subprocess.check_call(download_call) finally: os.chdir(currwd) assert os.path.exists(file_dir) output_files = [os.path.join(file_dir, x) for x in os.listdir(file_dir) if not x.endswith('logs')] if len(output_files) == 1: assert output_files[0].endswith('vcf') else: if not {os.path.splitext(x)[1] for x in output_files} >= {'.bam', '.bai'}: raise ParameterError('Can currently only handle pre-indexed GDC bams.') output_files = [x for x in output_files if x.endswith(('bam', 'bai'))] output_files = sorted(output_files, key=lambda x: os.path.splitext(x)[1], reverse=True) if write_to_jobstore: output_files = [job.fileStore.writeGlobalFile(f) for f in output_files] return output_files
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_key_hippie'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'typed'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '19', '32', '46', '67', '102']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '12', 'type': 'conditional_expression', 'children': ['13', '14', '15'], 'value': 'if'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'typed'},{'id': '15', 'type': 'lambda', 'children': ['16', '18']},{'id': '16', 'type': 'lambda_parameters', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'if_statement', 'children': ['20', '24']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'is_hashable'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'expression_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '32', 'type': 'if_statement', 'children': ['33', '38']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'obj'},{'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': 'obj'},{'id': '51', 'type': 'tuple', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'return_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '58', 'type': 'generator_expression', 'children': ['59', '64']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'make_key_hippie'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'typed'},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '67', 'type': 'if_statement', 'children': ['68', '73']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'generator_expression', 'children': ['82', '93']},{'id': '82', 'type': 'tuple', 'children': ['83', '88']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'make_key_hippie'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'typed'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'make_key_hippie'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'typed'},{'id': '93', 'type': 'for_in_clause', 'children': ['94', '97']},{'id': '94', 'type': 'pattern_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'raise_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '%'},{'id': '107', 'type': 'string', 'children': [], 'value': '"%r can not be hashed. Try providing a custom key function."'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'obj'}
def make_key_hippie(obj, typed=True): ftype = type if typed else lambda o: None if is_hashable(obj): return obj, ftype(obj) if isinstance(obj, set): obj = sorted(obj) if isinstance(obj, (list, tuple)): return tuple(make_key_hippie(e, typed) for e in obj) if isinstance(obj, dict): return tuple(sorted(((make_key_hippie(k, typed), make_key_hippie(v, typed)) for k, v in obj.items()))) raise ValueError( "%r can not be hashed. Try providing a custom key function." % obj)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_radia'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tumor_bam'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'normal_bam'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'radia_options'},{'id': '10', 'type': 'block', 'children': ['11', '48', '82', '105', '111', '198', '211']},{'id': '11', 'type': 'if_statement', 'children': ['12', '19', '26', '41']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'in'},{'id': '13', 'type': 'string', 'children': [], 'value': "'rna_genome'"},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '25', 'type': 'string', 'children': [], 'value': "'rna_genome'"},{'id': '26', 'type': 'elif_clause', 'children': ['27', '39']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '36'], 'value': '=='},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'set', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'rna_genome_sorted.bam'"},{'id': '38', 'type': 'string', 'children': [], 'value': "'rna_genome_sorted.bam.bai'"},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'pass_statement', 'children': []},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'raise_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': "'An improperly formatted dict was passed to rna_bam.'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'bams'},{'id': '51', 'type': 'dictionary', 'children': ['52', '57', '62', '67', '72', '77']},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'tumor_rna'"},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '56', 'type': 'string', 'children': [], 'value': "'rna_genome_sorted.bam'"},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'tumor_rnai'"},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '61', 'type': 'string', 'children': [], 'value': "'rna_genome_sorted.bam.bai'"},{'id': '62', 'type': 'pair', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'tumor_dna'"},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'tumor_bam'},{'id': '66', 'type': 'string', 'children': [], 'value': "'tumor_dna_fix_pg_sorted.bam'"},{'id': '67', 'type': 'pair', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'tumor_dnai'"},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'tumor_bam'},{'id': '71', 'type': 'string', 'children': [], 'value': "'tumor_dna_fix_pg_sorted.bam.bai'"},{'id': '72', 'type': 'pair', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "'normal_dna'"},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'normal_bam'},{'id': '76', 'type': 'string', 'children': [], 'value': "'normal_dna_fix_pg_sorted.bam'"},{'id': '77', 'type': 'pair', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'normal_dnai'"},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'normal_bam'},{'id': '81', 'type': 'string', 'children': [], 'value': "'normal_dna_fix_pg_sorted.bam.bai'"},{'id': '82', 'type': 'if_statement', 'children': ['83', '86', '93']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'radia_options'},{'id': '85', 'type': 'string', 'children': [], 'value': "'chromosomes'"},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'chromosomes'},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'radia_options'},{'id': '92', 'type': 'string', 'children': [], 'value': "'chromosomes'"},{'id': '93', 'type': 'else_clause', 'children': ['94']},{'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': 'chromosomes'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'sample_chromosomes'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'radia_options'},{'id': '104', 'type': 'string', 'children': [], 'value': "'genome_fai'"},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'perchrom_radia'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'for_statement', 'children': ['112', '113', '114']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'chromosomes'},{'id': '114', 'type': 'block', 'children': ['115', '149', '188']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'radia'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125', '126', '127', '128', '131']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'run_radia_perchrom'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'bams'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'radia_options'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '130', 'type': 'string', 'children': [], 'value': "'6G'"},{'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137', '140', '143', '146']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'radia_disk'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'tumor_bam'},{'id': '139', 'type': 'string', 'children': [], 'value': "'tumor_dna_fix_pg_sorted.bam'"},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'normal_bam'},{'id': '142', 'type': 'string', 'children': [], 'value': "'normal_dna_fix_pg_sorted.bam'"},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '145', 'type': 'string', 'children': [], 'value': "'rna_genome_sorted.bam'"},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'radia_options'},{'id': '148', 'type': 'string', 'children': [], 'value': "'genome_fasta'"},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'filter_radia'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'radia'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'addChildJobFn'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159', '164', '165', '166', '167', '170']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'run_filter_radia'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'bams'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'radia'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'radia_options'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'memory'},{'id': '169', 'type': 'string', 'children': [], 'value': "'6G'"},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'disk'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'PromisedRequirement'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176', '179', '182', '185']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'radia_disk'},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'tumor_bam'},{'id': '178', 'type': 'string', 'children': [], 'value': "'tumor_dna_fix_pg_sorted.bam'"},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'normal_bam'},{'id': '181', 'type': 'string', 'children': [], 'value': "'normal_dna_fix_pg_sorted.bam'"},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'rna_bam'},{'id': '184', 'type': 'string', 'children': [], 'value': "'rna_genome_sorted.bam'"},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'radia_options'},{'id': '187', 'type': 'string', 'children': [], 'value': "'genome_fasta'"},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '193']},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'perchrom_radia'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'filter_radia'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'rv'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '205']},{'id': '200', 'type': 'attribute', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '%'},{'id': '207', 'type': 'string', 'children': [], 'value': "'Ran spawn_radia on %s successfully'"},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '210', 'type': 'string', 'children': [], 'value': "'patient'"},{'id': '211', 'type': 'return_statement', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'perchrom_radia'}
def run_radia(job, rna_bam, tumor_bam, normal_bam, univ_options, radia_options): if 'rna_genome' in rna_bam.keys(): rna_bam = rna_bam['rna_genome'] elif set(rna_bam.keys()) == {'rna_genome_sorted.bam', 'rna_genome_sorted.bam.bai'}: pass else: raise RuntimeError('An improperly formatted dict was passed to rna_bam.') bams = {'tumor_rna': rna_bam['rna_genome_sorted.bam'], 'tumor_rnai': rna_bam['rna_genome_sorted.bam.bai'], 'tumor_dna': tumor_bam['tumor_dna_fix_pg_sorted.bam'], 'tumor_dnai': tumor_bam['tumor_dna_fix_pg_sorted.bam.bai'], 'normal_dna': normal_bam['normal_dna_fix_pg_sorted.bam'], 'normal_dnai': normal_bam['normal_dna_fix_pg_sorted.bam.bai']} if radia_options['chromosomes']: chromosomes = radia_options['chromosomes'] else: chromosomes = sample_chromosomes(job, radia_options['genome_fai']) perchrom_radia = defaultdict() for chrom in chromosomes: radia = job.addChildJobFn(run_radia_perchrom, bams, univ_options, radia_options, chrom, memory='6G', disk=PromisedRequirement( radia_disk, tumor_bam['tumor_dna_fix_pg_sorted.bam'], normal_bam['normal_dna_fix_pg_sorted.bam'], rna_bam['rna_genome_sorted.bam'], radia_options['genome_fasta'])) filter_radia = radia.addChildJobFn(run_filter_radia, bams, radia.rv(), univ_options, radia_options, chrom, memory='6G', disk=PromisedRequirement( radia_disk, tumor_bam['tumor_dna_fix_pg_sorted.bam'], normal_bam['normal_dna_fix_pg_sorted.bam'], rna_bam['rna_genome_sorted.bam'], radia_options['genome_fasta'])) perchrom_radia[chrom] = filter_radia.rv() job.fileStore.logToMaster('Ran spawn_radia on %s successfully' % univ_options['patient']) return perchrom_radia
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_bamfile'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'bamfile'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'samtools_options'},{'id': '9', 'type': 'block', 'children': ['10', '18', '29', '40', '47', '59', '83', '106', '115', '130']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'in_bamfile'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': "''"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'list', 'children': ['27', '28'], 'value': "[sample_type, '.bam']"},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '28', 'type': 'string', 'children': [], 'value': "'.bam'"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'out_bamfile'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'list', 'children': ['38', '39'], 'value': "[sample_type, 'sorted.bam']"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '39', 'type': 'string', 'children': [], 'value': "'sorted.bam'"},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '43', 'type': 'dictionary', 'children': ['44']},{'id': '44', 'type': 'pair', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'in_bamfile'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'bamfile'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_files_from_filestore'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '56']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'docker'},{'id': '58', 'type': 'True', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '62', 'type': 'list', 'children': ['63', '64', '65', '69', '70', '71', '72', '73', '74', '80'], 'value': "['sort',\n '-o', docker_path(out_bamfile),\n '-O', 'bam',\n '-T', 'temp_sorted',\n '-@', str(samtools_options['n']),\n input_files[in_bamfile]]"},{'id': '63', 'type': 'string', 'children': [], 'value': "'sort'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'-o'"},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'docker_path'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'out_bamfile'},{'id': '69', 'type': 'string', 'children': [], 'value': "'-O'"},{'id': '70', 'type': 'string', 'children': [], 'value': "'bam'"},{'id': '71', 'type': 'string', 'children': [], 'value': "'-T'"},{'id': '72', 'type': 'string', 'children': [], 'value': "'temp_sorted'"},{'id': '73', 'type': 'string', 'children': [], 'value': "'-@'"},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'samtools_options'},{'id': '79', 'type': 'string', 'children': [], 'value': "'n'"},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'input_files'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'in_bamfile'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'docker_call'},{'id': '86', 'type': 'argument_list', 'children': ['87', '90', '93', '96', '101']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'tool'},{'id': '89', 'type': 'string', 'children': [], 'value': "'samtools'"},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'tool_parameters'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'dockerhub'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '100', 'type': 'string', 'children': [], 'value': "'dockerhub'"},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'tool_version'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'samtools_options'},{'id': '105', 'type': 'string', 'children': [], 'value': "'version'"},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'deleteGlobalFile'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'bamfile'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '122']},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'logToMaster'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '%'},{'id': '124', 'type': 'string', 'children': [], 'value': "'Ran samtools-sort on %s:%s successfully'"},{'id': '125', 'type': 'tuple', 'children': ['126', '129']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '128', 'type': 'string', 'children': [], 'value': "'patient'"},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sample_type'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'out_bamfile'}
def sort_bamfile(job, bamfile, sample_type, univ_options, samtools_options): work_dir = os.getcwd() in_bamfile = ''.join([sample_type, '.bam']) out_bamfile = '_'.join([sample_type, 'sorted.bam']) input_files = { in_bamfile: bamfile} input_files = get_files_from_filestore(job, input_files, work_dir, docker=True) parameters = ['sort', '-o', docker_path(out_bamfile), '-O', 'bam', '-T', 'temp_sorted', '-@', str(samtools_options['n']), input_files[in_bamfile]] docker_call(tool='samtools', tool_parameters=parameters, work_dir=work_dir, dockerhub=univ_options['dockerhub'], tool_version=samtools_options['version']) job.fileStore.deleteGlobalFile(bamfile) job.fileStore.logToMaster('Ran samtools-sort on %s:%s successfully' % (univ_options['patient'], sample_type)) return job.fileStore.writeGlobalFile(out_bamfile)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'recursive_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '5', 'type': 'block', 'children': ['6', '175']},{'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': 'data_structure'},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_primitive_types'},{'id': '13', 'type': 'block', 'children': ['14', '22', '30', '77', '82', '94']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'is_meta'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Meta'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'was_dict'},{'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': 'data_structure'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'WasDict'},{'id': '30', 'type': 'if_statement', 'children': ['31', '36']},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': '()', 'children': ['33']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'or'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'is_meta'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'was_dict'},{'id': '36', 'type': 'block', 'children': ['37', '45', '64']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'was_dict'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '45', 'type': 'if_statement', 'children': ['46', '48']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'was_dict'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'try_statement', 'children': ['50', '61']},{'id': '50', 'type': 'block', 'children': ['51', '57']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'was_dict'},{'id': '60', 'type': 'True', 'children': []},{'id': '61', 'type': 'except_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'pass_statement', 'children': []},{'id': '64', 'type': 'try_statement', 'children': ['65', '74']},{'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': 'data_structure'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'except_clause', 'children': ['75']},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'pass_statement', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'tlen'},{'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'try_statement', 'children': ['83', '91']},{'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': 'tlen'},{'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': 'data_structure'},{'id': '91', 'type': 'except_clause', 'children': ['92']},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'pass_statement', 'children': []},{'id': '94', 'type': 'if_statement', 'children': ['95', '99']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '!='},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'tlen'},{'id': '97', 'type': 'unary_operator', 'children': ['98'], 'value': '-'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'try_statement', 'children': ['101', '172']},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'if_statement', 'children': ['103', '104', '132', '152']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'was_dict'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '111', 'type': 'argument_list', 'children': ['112', '129']},{'id': '112', 'type': 'list_comprehension', 'children': ['113', '126']},{'id': '113', 'type': 'tuple', 'children': ['114', '120']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'recursive_sort'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '119', 'type': 'integer', 'children': [], 'value': '0'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'recursive_sort'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '125', 'type': 'integer', 'children': [], 'value': '1'},{'id': '126', 'type': 'for_in_clause', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'TraversalBasedReprCompare'},{'id': '132', 'type': 'elif_clause', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'is_meta'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'binary_operator', 'children': ['137', '144'], 'value': '+'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '139', 'type': 'slice', 'children': ['140', '141', '142']},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'colon', 'children': []},{'id': '142', 'type': 'unary_operator', 'children': ['143'], 'value': '-'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'list', 'children': ['145'], 'value': '[\n recursive_sort(\n data_structure[-1]\n )\n ]'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'recursive_sort'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '150', 'type': 'unary_operator', 'children': ['151'], 'value': '-'},{'id': '151', 'type': 'integer', 'children': [], 'value': '1'},{'id': '152', 'type': 'else_clause', 'children': ['153']},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'return_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '160', 'type': 'argument_list', 'children': ['161', '169']},{'id': '161', 'type': 'list_comprehension', 'children': ['162', '166']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'recursive_sort'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '166', 'type': 'for_in_clause', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'data_structure'},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'TraversalBasedReprCompare'},{'id': '172', 'type': 'except_clause', 'children': ['173']},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'pass_statement', 'children': []},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'data_structure'}
def recursive_sort(data_structure): if not isinstance(data_structure, _primitive_types): is_meta = isinstance(data_structure, Meta) was_dict = isinstance(data_structure, WasDict) if not (is_meta or was_dict): was_dict = isinstance(data_structure, dict) if not was_dict: try: data_structure = data_structure.__dict__ was_dict = True except: pass try: data_structure = data_structure.items() except: pass tlen = -1 try: tlen = len(data_structure) except: pass if tlen != -1: try: if was_dict: return tuple(sorted( [ ( recursive_sort(x[0]), recursive_sort(x[1]), ) for x in data_structure ], key=TraversalBasedReprCompare )) elif is_meta: return data_structure[0:-1] + [ recursive_sort( data_structure[-1] ) ] else: return tuple(sorted( [recursive_sort( x, ) for x in data_structure], key=TraversalBasedReprCompare, )) except: pass return data_structure
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tree_diff'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '8', 'type': 'integer', 'children': [], 'value': '5'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '20', '27', '87']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '27', 'type': 'if_statement', 'children': ['28', '30', '55']},{'id': '28', 'type': 'not_operator', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '30', 'type': 'block', 'children': ['31', '43']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '34', 'type': 'call', 'children': ['35', '41']},{'id': '35', 'type': 'attribute', 'children': ['36', '40']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'vformat'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '46', 'type': 'call', 'children': ['47', '53']},{'id': '47', 'type': 'attribute', 'children': ['48', '52']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'vformat'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '55', 'type': 'else_clause', 'children': ['56']},{'id': '56', 'type': 'block', 'children': ['57', '72']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '60', 'type': 'call', 'children': ['61', '70']},{'id': '61', 'type': 'attribute', 'children': ['62', '69']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'vformat'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'recursive_sort'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '75', 'type': 'call', 'children': ['76', '85']},{'id': '76', 'type': 'attribute', 'children': ['77', '84']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'vformat'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'recursive_sort'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'difflib'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'unified_diff'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99', '100', '103']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'lineterm'},{'id': '105', 'type': 'string', 'children': [], 'value': '""'}
def tree_diff(a, b, n=5, sort=False): a = dump(a) b = dump(b) if not sort: a = vformat(a).split("\n") b = vformat(b).split("\n") else: a = vformat(recursive_sort(a)).split("\n") b = vformat(recursive_sort(b)).split("\n") return "\n".join(difflib.unified_diff(a, b, n=n, lineterm=""))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_perchrom_mutations'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '8', 'type': 'block', 'children': ['9', '17', '24', '31', '38', '45', '52', '59', '69', '79', '107', '117', '124', '305', '401', '414', '427']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'import_from_statement', 'children': ['18', '22']},{'id': '18', 'type': 'dotted_name', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'protect'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'mutation_calling'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'muse'},{'id': '22', 'type': 'dotted_name', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'process_muse_vcf'},{'id': '24', 'type': 'import_from_statement', 'children': ['25', '29']},{'id': '25', 'type': 'dotted_name', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'protect'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'mutation_calling'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'mutect'},{'id': '29', 'type': 'dotted_name', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'process_mutect_vcf'},{'id': '31', 'type': 'import_from_statement', 'children': ['32', '36']},{'id': '32', 'type': 'dotted_name', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'protect'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'mutation_calling'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'radia'},{'id': '36', 'type': 'dotted_name', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'process_radia_vcf'},{'id': '38', 'type': 'import_from_statement', 'children': ['39', '43']},{'id': '39', 'type': 'dotted_name', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'protect'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mutation_calling'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'somaticsniper'},{'id': '43', 'type': 'dotted_name', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'process_somaticsniper_vcf'},{'id': '45', 'type': 'import_from_statement', 'children': ['46', '50']},{'id': '46', 'type': 'dotted_name', 'children': ['47', '48', '49']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'protect'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'mutation_calling'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'strelka'},{'id': '50', 'type': 'dotted_name', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'process_strelka_vcf'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'string', 'children': [], 'value': "'indels'"},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '63', 'type': 'string', 'children': [], 'value': "'strelka_indels'"},{'id': '64', 'type': 'subscript', 'children': ['65', '68']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '67', 'type': 'string', 'children': [], 'value': "'strelka'"},{'id': '68', 'type': 'string', 'children': [], 'value': "'indels'"},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '73', 'type': 'string', 'children': [], 'value': "'strelka_snvs'"},{'id': '74', 'type': 'subscript', 'children': ['75', '78']},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '77', 'type': 'string', 'children': [], 'value': "'strelka'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'snvs'"},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'vcf_processor'},{'id': '82', 'type': 'dictionary', 'children': ['83', '101']},{'id': '83', 'type': 'pair', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'snvs'"},{'id': '85', 'type': 'dictionary', 'children': ['86', '89', '92', '95', '98']},{'id': '86', 'type': 'pair', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': "'mutect'"},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'process_mutect_vcf'},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': "'muse'"},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'process_muse_vcf'},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'radia'"},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'process_radia_vcf'},{'id': '95', 'type': 'pair', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': "'somaticsniper'"},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'process_somaticsniper_vcf'},{'id': '98', 'type': 'pair', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'strelka_snvs'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'process_strelka_vcf'},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'indels'"},{'id': '103', 'type': 'dictionary', 'children': ['104']},{'id': '104', 'type': 'pair', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'strelka_indels'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'process_strelka_vcf'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'majority'},{'id': '110', 'type': 'dictionary', 'children': ['111', '114']},{'id': '111', 'type': 'pair', 'children': ['112', '113']},{'id': '112', 'type': 'string', 'children': [], 'value': "'snvs'"},{'id': '113', 'type': 'integer', 'children': [], 'value': '2'},{'id': '114', 'type': 'pair', 'children': ['115', '116']},{'id': '115', 'type': 'string', 'children': [], 'value': "'indels'"},{'id': '116', 'type': 'integer', 'children': [], 'value': '1'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'accepted_hits'},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '124', 'type': 'for_statement', 'children': ['125', '126', '131']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'mut_type'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'vcf_processor'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '130', 'type': 'argument_list', 'children': []},{'id': '131', 'type': 'block', 'children': ['132', '158', '168', '177', '196', '216']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'perchrom_mutations'},{'id': '135', 'type': 'dictionary_comprehension', 'children': ['136', '153']},{'id': '136', 'type': 'pair', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '138', 'type': 'call', 'children': ['139', '144']},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'vcf_processor'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mut_type'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146', '151', '152']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '146', 'type': 'subscript', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'mutations'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '153', 'type': 'for_in_clause', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'vcf_processor'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'mut_type'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '163']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'perchrom_mutations'},{'id': '162', 'type': 'string', 'children': [], 'value': "'strelka'"},{'id': '163', 'type': 'subscript', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'perchrom_mutations'},{'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '+'},{'id': '166', 'type': 'string', 'children': [], 'value': "'strelka_'"},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'mut_type'},{'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': 'perchrom_mutations'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '+'},{'id': '175', 'type': 'string', 'children': [], 'value': "'strelka_'"},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'mut_type'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'vcf_lists'},{'id': '180', 'type': 'dictionary_comprehension', 'children': ['181', '187']},{'id': '181', 'type': 'pair', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'read_vcf'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '187', 'type': 'for_in_clause', 'children': ['188', '191']},{'id': '188', 'type': 'pattern_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'vcf_file'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'perchrom_mutations'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '195', 'type': 'argument_list', 'children': []},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'all_positions'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'list_splat', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'vcf_lists'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '215', 'type': 'argument_list', 'children': []},{'id': '216', 'type': 'for_statement', 'children': ['217', '218', '222']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'all_positions'},{'id': '222', 'type': 'block', 'children': ['223', '241']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '226', 'type': 'dictionary_comprehension', 'children': ['227', '234']},{'id': '227', 'type': 'pair', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '231'], 'value': 'in'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'vcf_lists'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '234', 'type': 'for_in_clause', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'perchrom_mutations'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'if_statement', 'children': ['242', '254']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '251'], 'value': '>='},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '250', 'type': 'argument_list', 'children': []},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'majority'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'mut_type'},{'id': '254', 'type': 'block', 'children': ['255', '276', '286']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'callers'},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'string', 'children': [], 'value': "','"},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'list_comprehension', 'children': ['264', '265', '274']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '265', 'type': 'for_in_clause', 'children': ['266', '269']},{'id': '266', 'type': 'pattern_list', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'caller'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'if_clause', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '276', 'type': 'assert_statement', 'children': ['277']},{'id': '277', 'type': 'comparison_operator', 'children': ['278', '281'], 'value': 'not'},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '280', 'type': 'integer', 'children': [], 'value': '1'},{'id': '281', 'type': 'subscript', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'accepted_hits'},{'id': '283', 'type': 'subscript', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '285', 'type': 'integer', 'children': [], 'value': '0'},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '297']},{'id': '288', 'type': 'subscript', 'children': ['289', '294']},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'accepted_hits'},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '293', 'type': 'integer', 'children': [], 'value': '0'},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '296', 'type': 'integer', 'children': [], 'value': '1'},{'id': '297', 'type': 'tuple', 'children': ['298', '301', '304']},{'id': '298', 'type': 'subscript', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '300', 'type': 'integer', 'children': [], 'value': '2'},{'id': '301', 'type': 'subscript', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '303', 'type': 'integer', 'children': [], 'value': '3'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'callers'},{'id': '305', 'type': 'with_statement', 'children': ['306', '325']},{'id': '306', 'type': 'with_clause', 'children': ['307']},{'id': '307', 'type': 'with_item', 'children': ['308']},{'id': '308', 'type': 'as_pattern', 'children': ['309', '323']},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '311', 'type': 'argument_list', 'children': ['312', '322']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'string', 'children': [], 'value': "''"},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'list', 'children': ['318', '319', '320', '321'], 'value': "[work_dir, '/', chrom, '.vcf']"},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'work_dir'},{'id': '319', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '321', 'type': 'string', 'children': [], 'value': "'.vcf'"},{'id': '322', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '323', 'type': 'as_pattern_target', 'children': ['324']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '325', 'type': 'block', 'children': ['326', '334']},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'call', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '329', 'type': 'argument_list', 'children': ['330', '331']},{'id': '330', 'type': 'string', 'children': [], 'value': "'\n print('"},{'id': '331', 'type': 'ERROR', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '337', '350', '352']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '337', 'type': 'ERROR', 'children': ['338', '340']},{'id': '338', 'type': 'ERROR', 'children': ['339']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '340', 'type': 'comparison_operator', 'children': ['341', '342'], 'value': 'in'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'chrom_sorted'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'accepted_hits'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '349', 'type': 'argument_list', 'children': []},{'id': '350', 'type': 'ERROR', 'children': ['351']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '352', 'type': 'type', 'children': ['353']},{'id': '353', 'type': 'constrained_type', 'children': ['354', '363']},{'id': '354', 'type': 'type', 'children': ['355']},{'id': '355', 'type': 'comparison_operator', 'children': ['356', '357'], 'value': 'in'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '357', 'type': 'call', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '359', 'type': 'argument_list', 'children': ['360']},{'id': '360', 'type': 'subscript', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'accepted_hits'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '363', 'type': 'type', 'children': ['364']},{'id': '364', 'type': 'call', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '366', 'type': 'argument_list', 'children': ['367', '368', '369', '370', '377', '384', '385', '386', '395', '398']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '369', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '370', 'type': 'subscript', 'children': ['371', '376']},{'id': '371', 'type': 'subscript', 'children': ['372', '375']},{'id': '372', 'type': 'subscript', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'accepted_hits'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '376', 'type': 'integer', 'children': [], 'value': '0'},{'id': '377', 'type': 'subscript', 'children': ['378', '383']},{'id': '378', 'type': 'subscript', 'children': ['379', '382']},{'id': '379', 'type': 'subscript', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'accepted_hits'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '383', 'type': 'integer', 'children': [], 'value': '1'},{'id': '384', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '385', 'type': 'string', 'children': [], 'value': "'PASS'"},{'id': '386', 'type': 'binary_operator', 'children': ['387', '388'], 'value': '+'},{'id': '387', 'type': 'string', 'children': [], 'value': "'callers='"},{'id': '388', 'type': 'subscript', 'children': ['389', '394']},{'id': '389', 'type': 'subscript', 'children': ['390', '393']},{'id': '390', 'type': 'subscript', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'accepted_hits'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '394', 'type': 'integer', 'children': [], 'value': '2'},{'id': '395', 'type': 'keyword_argument', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '397', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '398', 'type': 'keyword_argument', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '401', 'type': 'expression_statement', 'children': ['402']},{'id': '402', 'type': 'assignment', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'fsid'},{'id': '404', 'type': 'call', 'children': ['405', '410']},{'id': '405', 'type': 'attribute', 'children': ['406', '409']},{'id': '406', 'type': 'attribute', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'fileStore'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'writeGlobalFile'},{'id': '410', 'type': 'argument_list', 'children': ['411']},{'id': '411', 'type': 'attribute', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '414', 'type': 'expression_statement', 'children': ['415']},{'id': '415', 'type': 'call', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'export_results'},{'id': '417', 'type': 'argument_list', 'children': ['418', '419', '420', '423', '424']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'fsid'},{'id': '420', 'type': 'attribute', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'univ_options'},{'id': '424', 'type': 'keyword_argument', 'children': ['425', '426']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'subfolder'},{'id': '426', 'type': 'string', 'children': [], 'value': "'mutations/merged'"},{'id': '427', 'type': 'return_statement', 'children': ['428']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'fsid'}
def merge_perchrom_mutations(job, chrom, mutations, univ_options): work_dir = os.getcwd() from protect.mutation_calling.muse import process_muse_vcf from protect.mutation_calling.mutect import process_mutect_vcf from protect.mutation_calling.radia import process_radia_vcf from protect.mutation_calling.somaticsniper import process_somaticsniper_vcf from protect.mutation_calling.strelka import process_strelka_vcf mutations.pop('indels') mutations['strelka_indels'] = mutations['strelka']['indels'] mutations['strelka_snvs'] = mutations['strelka']['snvs'] vcf_processor = {'snvs': {'mutect': process_mutect_vcf, 'muse': process_muse_vcf, 'radia': process_radia_vcf, 'somaticsniper': process_somaticsniper_vcf, 'strelka_snvs': process_strelka_vcf }, 'indels': {'strelka_indels': process_strelka_vcf } } majority = {'snvs': 2, 'indels': 1} accepted_hits = defaultdict(dict) for mut_type in vcf_processor.keys(): perchrom_mutations = {caller: vcf_processor[mut_type][caller](job, mutations[caller][chrom], work_dir, univ_options) for caller in vcf_processor[mut_type]} perchrom_mutations['strelka'] = perchrom_mutations['strelka_' + mut_type] perchrom_mutations.pop('strelka_' + mut_type) vcf_lists = {caller: read_vcf(vcf_file) for caller, vcf_file in perchrom_mutations.items()} all_positions = list(set(itertools.chain(*vcf_lists.values()))) for position in sorted(all_positions): hits = {caller: position in vcf_lists[caller] for caller in perchrom_mutations.keys()} if sum(hits.values()) >= majority[mut_type]: callers = ','.join([caller for caller, hit in hits.items() if hit]) assert position[1] not in accepted_hits[position[0]] accepted_hits[position[0]][position[1]] = (position[2], position[3], callers) with open(''.join([work_dir, '/', chrom, '.vcf']), 'w') as outfile: print(' print(' file=outfile) print(' for chrom in chrom_sorted(accepted_hits.keys()): for position in sorted(accepted_hits[chrom]): print(chrom, position, '.', accepted_hits[chrom][position][0], accepted_hits[chrom][position][1], '.', 'PASS', 'callers=' + accepted_hits[chrom][position][2], sep='\t', file=outfile) fsid = job.fileStore.writeGlobalFile(outfile.name) export_results(job, fsid, outfile.name, univ_options, subfolder='mutations/merged') return fsid
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '9', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '10', 'type': 'block', 'children': ['11', '30', '49', '68', '87']},{'id': '11', 'type': 'if_statement', 'children': ['12', '19']},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '16'], 'value': 'or'},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': '=='},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '15', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'},{'id': '17', 'type': 'string', 'children': [], 'value': "'dns_txt'"},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '27']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'check_dns_txt'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'True', 'children': []},{'id': '30', 'type': 'if_statement', 'children': ['31', '38']},{'id': '31', 'type': 'boolean_operator', 'children': ['32', '35'], 'value': 'or'},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': '=='},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '34', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'},{'id': '36', 'type': 'string', 'children': [], 'value': "'dns_cname'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'if_statement', 'children': ['40', '46']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'check_dns_cname'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'True', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '57']},{'id': '50', 'type': 'boolean_operator', 'children': ['51', '54'], 'value': 'or'},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '53', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'},{'id': '55', 'type': 'string', 'children': [], 'value': "'meta_tag'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'if_statement', 'children': ['59', '65']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'check_meta_tag'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'True', 'children': []},{'id': '68', 'type': 'if_statement', 'children': ['69', '76']},{'id': '69', 'type': 'boolean_operator', 'children': ['70', '73'], 'value': 'or'},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '=='},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '72', 'type': 'string', 'children': [], 'value': "'*'"},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'},{'id': '74', 'type': 'string', 'children': [], 'value': "'html_file'"},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'strategies'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '84']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'check_html_file'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'True', 'children': []},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'False', 'children': []}
def check(domain, prefix, code, strategies='*'): if strategies == '*' or 'dns_txt' in strategies: if check_dns_txt(domain, prefix, code): return True if strategies == '*' or 'dns_cname' in strategies: if check_dns_cname(domain, prefix, code): return True if strategies == '*' or 'meta_tag' in strategies: if check_meta_tag(domain, prefix, code): return True if strategies == '*' or 'html_file' in strategies: if check_html_file(domain, prefix, code): return True return False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'register_cache_buster'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '28', '32', '36', '45', '159', '168', '181', '194', '221', '251', '259']},{'id': '10', 'type': 'if_statement', 'children': ['11', '22']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': '()', 'children': ['13']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '17'], 'value': 'or'},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': '"`config` must be an instance of dict or None"'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'bust_map'},{'id': '31', 'type': 'dictionary', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'unbust_map'},{'id': '35', 'type': 'dictionary', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'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': 'app'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'Starting computing hashes for static assets'"},{'id': '45', 'type': 'for_statement', 'children': ['46', '50', '58']},{'id': '46', 'type': 'pattern_list', 'children': ['47', '48', '49']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'dirpath'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'dirnames'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'walk'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'static_folder'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '62', 'type': 'block', 'children': ['63', '75', '85', '94', '129', '143', '147', '153']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'rooted_filename'},{'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': 'join'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'dirpath'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '75', 'type': 'if_statement', 'children': ['76', '83']},{'id': '76', 'type': 'not_operator', 'children': ['77']},{'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': '__is_file_to_be_busted'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'rooted_filename'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'continue_statement', 'children': []},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "f'Computing hashes for {rooted_filename}'"},{'id': '94', 'type': 'with_statement', 'children': ['95', '105']},{'id': '95', 'type': 'with_clause', 'children': ['96']},{'id': '96', 'type': 'with_item', 'children': ['97']},{'id': '97', 'type': 'as_pattern', 'children': ['98', '103']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'rooted_filename'},{'id': '102', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '103', 'type': 'as_pattern_target', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '109', 'type': 'subscript', 'children': ['110', '124']},{'id': '110', 'type': 'call', 'children': ['111', '123']},{'id': '111', 'type': 'attribute', 'children': ['112', '122']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'md5'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'slice', 'children': ['125', '126']},{'id': '125', 'type': 'colon', 'children': []},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'hash_size'},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'unbusted'},{'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': 'os'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'rooted_filename'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'static_folder'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'busted'},{'id': '146', 'type': 'string', 'children': [], 'value': 'f"{unbusted}?q={version}"'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'bust_map'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'unbusted'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'busted'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '158']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'unbust_map'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'busted'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'unbusted'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '166']},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "'Finished Starting computing hashes for static assets'"},{'id': '168', 'type': 'function_definition', 'children': ['169', '170', '172']},{'id': '169', 'type': 'function_name', 'children': [], 'value': 'bust_filename'},{'id': '170', 'type': 'parameters', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'bust_map'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '181', 'type': 'function_definition', 'children': ['182', '183', '185']},{'id': '182', 'type': 'function_name', 'children': [], 'value': 'unbust_filename'},{'id': '183', 'type': 'parameters', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'return_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'unbust_map'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '194', 'type': 'decorated_definition', 'children': ['195', '199']},{'id': '195', 'type': 'decorator', 'children': ['196']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'url_defaults'},{'id': '199', 'type': 'function_definition', 'children': ['200', '201', '204']},{'id': '200', 'type': 'function_name', 'children': [], 'value': 'reverse_to_cache_busted_url'},{'id': '201', 'type': 'parameters', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'if_statement', 'children': ['206', '209']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '=='},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '208', 'type': 'string', 'children': [], 'value': "'static'"},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '215']},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '214', 'type': 'string', 'children': [], 'value': "'filename'"},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'bust_filename'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'subscript', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '220', 'type': 'string', 'children': [], 'value': "'filename'"},{'id': '221', 'type': 'function_definition', 'children': ['222', '223', '228']},{'id': '222', 'type': 'function_name', 'children': [], 'value': 'debusting_static_view'},{'id': '223', 'type': 'parameters', 'children': ['224', '226']},{'id': '224', 'type': 'list_splat_pattern', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '226', 'type': 'dictionary_splat_pattern', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '228', 'type': 'block', 'children': ['229', '243']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '234']},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '233', 'type': 'string', 'children': [], 'value': "'filename'"},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'unbust_filename'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'string', 'children': [], 'value': "'filename'"},{'id': '243', 'type': 'return_statement', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'original_static_view'},{'id': '246', 'type': 'argument_list', 'children': ['247', '249']},{'id': '247', 'type': 'list_splat', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '249', 'type': 'dictionary_splat', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'original_static_view'},{'id': '254', 'type': 'subscript', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'view_functions'},{'id': '258', 'type': 'string', 'children': [], 'value': "'static'"},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '266']},{'id': '261', 'type': 'subscript', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'view_functions'},{'id': '265', 'type': 'string', 'children': [], 'value': "'static'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'debusting_static_view'}
def register_cache_buster(self, app, config=None): if not (config is None or isinstance(config, dict)): raise ValueError("`config` must be an instance of dict or None") bust_map = {} unbust_map = {} app.logger.debug('Starting computing hashes for static assets') for dirpath, dirnames, filenames in os.walk(app.static_folder): for filename in filenames: rooted_filename = os.path.join(dirpath, filename) if not self.__is_file_to_be_busted(rooted_filename): continue app.logger.debug(f'Computing hashes for {rooted_filename}') with open(rooted_filename, 'rb') as f: version = hashlib.md5( f.read() ).hexdigest()[:self.hash_size] unbusted = os.path.relpath(rooted_filename, app.static_folder) busted = f"{unbusted}?q={version}" bust_map[unbusted] = busted unbust_map[busted] = unbusted app.logger.debug('Finished Starting computing hashes for static assets') def bust_filename(file): return bust_map.get(file, file) def unbust_filename(file): return unbust_map.get(file, file) @app.url_defaults def reverse_to_cache_busted_url(endpoint, values): if endpoint == 'static': values['filename'] = bust_filename(values['filename']) def debusting_static_view(*args, **kwargs): kwargs['filename'] = unbust_filename(kwargs.get('filename')) return original_static_view(*args, **kwargs) original_static_view = app.view_functions['static'] app.view_functions['static'] = debusting_static_view
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_inventory'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '27', '34', '38', '42', '100', '113', '132', '145', '164', '177', '191', '204', '218', '231', '249']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'udi'},{'id': '11', 'type': 'dictionary', 'children': ['12', '15', '18', '21', '24']},{'id': '12', 'type': 'pair', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': '"name"'},{'id': '14', 'type': 'string', 'children': [], 'value': '""'},{'id': '15', 'type': 'pair', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': '"description"'},{'id': '17', 'type': 'string', 'children': [], 'value': '""'},{'id': '18', 'type': 'pair', 'children': ['19', '20']},{'id': '19', 'type': 'string', 'children': [], 'value': '"pid"'},{'id': '20', 'type': 'string', 'children': [], 'value': '""'},{'id': '21', 'type': 'pair', 'children': ['22', '23']},{'id': '22', 'type': 'string', 'children': [], 'value': '"vid"'},{'id': '23', 'type': 'string', 'children': [], 'value': '""'},{'id': '24', 'type': 'pair', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': '"sn"'},{'id': '26', 'type': 'string', 'children': [], 'value': '""'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'udi'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'capture_next'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'chassis_udi_text'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '50']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '50', 'type': 'block', 'children': ['51', '59', '88']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lc_line'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'if_statement', 'children': ['60', '78']},{'id': '60', 'type': 'boolean_operator', 'children': ['61', '77'], 'value': 'and'},{'id': '61', 'type': 'boolean_operator', 'children': ['62', '74'], 'value': 'and'},{'id': '62', 'type': '()', 'children': ['63']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '71'], 'value': 'or'},{'id': '64', 'type': 'boolean_operator', 'children': ['65', '68'], 'value': 'or'},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'},{'id': '66', 'type': 'string', 'children': [], 'value': "'chassis'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'lc_line'},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'},{'id': '69', 'type': 'string', 'children': [], 'value': "'switch system'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'lc_line'},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'in'},{'id': '72', 'type': 'string', 'children': [], 'value': "'rack'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'lc_line'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'in'},{'id': '75', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'lc_line'},{'id': '77', 'type': 'string', 'children': [], 'value': "'descr'"},{'id': '78', 'type': 'block', 'children': ['79', '83', '87']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'capture_next'},{'id': '82', 'type': 'True', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'chassis_udi_text'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '87', 'type': 'continue_statement', 'children': []},{'id': '88', 'type': 'if_statement', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'capture_next'},{'id': '90', 'type': 'block', 'children': ['91', '99']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '94', 'type': 'binary_operator', 'children': ['95', '98'], 'value': '+'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '+'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'chassis_udi_text'},{'id': '97', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '99', 'type': 'break_statement', 'children': []},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109', '110']},{'id': '108', 'type': 'string', 'children': [], 'value': 'r"(?i)NAME: (?P<name>.*?),? (?i)DESCR"'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'MULTILINE'},{'id': '113', 'type': 'if_statement', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'udi'},{'id': '120', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '121', 'type': 'call', 'children': ['122', '130']},{'id': '122', 'type': 'attribute', 'children': ['123', '129']},{'id': '123', 'type': 'call', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': '\'" ,\''},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141', '142']},{'id': '140', 'type': 'string', 'children': [], 'value': 'r"(?i)DESCR: (?P<description>.*)"'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'MULTILINE'},{'id': '145', 'type': 'if_statement', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '153']},{'id': '150', 'type': 'subscript', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'udi'},{'id': '152', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '153', 'type': 'call', 'children': ['154', '162']},{'id': '154', 'type': 'attribute', 'children': ['155', '161']},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': '\'" \''},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '171', 'type': 'argument_list', 'children': ['172', '173', '174']},{'id': '172', 'type': 'string', 'children': [], 'value': 'r"(?i)PID: (?P<pid>.*?),? "'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'MULTILINE'},{'id': '177', 'type': 'if_statement', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'udi'},{'id': '184', 'type': 'string', 'children': [], 'value': "'pid'"},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'string', 'children': [], 'value': "'pid'"},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200', '201']},{'id': '199', 'type': 'string', 'children': [], 'value': 'r"(?i)VID: (?P<vid>.*?),? "'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'MULTILINE'},{'id': '204', 'type': 'if_statement', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'udi'},{'id': '211', 'type': 'string', 'children': [], 'value': "'vid'"},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'string', 'children': [], 'value': "'vid'"},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227', '228']},{'id': '226', 'type': 'string', 'children': [], 'value': 'r"(?i)SN: (?P<sn>.*)"'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'inventory_output'},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'MULTILINE'},{'id': '231', 'type': 'if_statement', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'udi'},{'id': '238', 'type': 'string', 'children': [], 'value': "'sn'"},{'id': '239', 'type': 'call', 'children': ['240', '248']},{'id': '240', 'type': 'attribute', 'children': ['241', '247']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'string', 'children': [], 'value': "'sn'"},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'return_statement', 'children': ['250']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'udi'}
def parse_inventory(inventory_output=None): udi = { "name": "", "description": "", "pid": "", "vid": "", "sn": "" } if inventory_output is None: return udi capture_next = False chassis_udi_text = None for line in inventory_output.split('\n'): lc_line = line.lower() if ('chassis' in lc_line or 'switch system' in lc_line or 'rack' in lc_line) and 'name' in lc_line and 'descr': capture_next = True chassis_udi_text = line continue if capture_next: inventory_output = chassis_udi_text + "\n" + line break match = re.search(r"(?i)NAME: (?P<name>.*?),? (?i)DESCR", inventory_output, re.MULTILINE) if match: udi['name'] = match.group('name').strip('" ,') match = re.search(r"(?i)DESCR: (?P<description>.*)", inventory_output, re.MULTILINE) if match: udi['description'] = match.group('description').strip('" ') match = re.search(r"(?i)PID: (?P<pid>.*?),? ", inventory_output, re.MULTILINE) if match: udi['pid'] = match.group('pid') match = re.search(r"(?i)VID: (?P<vid>.*?),? ", inventory_output, re.MULTILINE) if match: udi['vid'] = match.group('vid') match = re.search(r"(?i)SN: (?P<sn>.*)", inventory_output, re.MULTILINE) if match: udi['sn'] = match.group('sn').strip() return udi
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'yaml_file_to_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '46', '102', '118', '132', '153', '160', '189', '212', '240']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'load_yaml'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'file_path'},{'id': '13', 'type': 'block', 'children': ['14', '44']},{'id': '14', 'type': 'with_statement', 'children': ['15', '25']},{'id': '15', 'type': 'with_clause', 'children': ['16']},{'id': '16', 'type': 'with_item', 'children': ['17']},{'id': '17', 'type': 'as_pattern', 'children': ['18', '23']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'file_path'},{'id': '22', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '23', 'type': 'as_pattern_target', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'yamlfile'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'try_statement', 'children': ['27', '37']},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'yaml'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'yamlfile'},{'id': '37', 'type': 'except_clause', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'yaml'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'YAMLError'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'dictionary', 'children': []},{'id': '44', 'type': 'return_statement', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'dictionary'},{'id': '46', 'type': 'function_definition', 'children': ['47', '48', '51']},{'id': '47', 'type': 'function_name', 'children': [], 'value': 'merge'},{'id': '48', 'type': 'parameters', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '51', 'type': 'block', 'children': ['52', '100']},{'id': '52', 'type': 'if_statement', 'children': ['53', '64']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '59'], 'value': 'and'},{'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': 'user'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'for_statement', 'children': ['66', '69', '74']},{'id': '66', 'type': 'pattern_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'if_statement', 'children': ['76', '79', '86']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'not'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '95', 'type': 'argument_list', 'children': ['96', '99']},{'id': '96', 'type': 'subscript', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '100', 'type': 'return_statement', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '105', 'type': 'None', 'children': []},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'os'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'config_file_path'},{'id': '121', 'type': 'call', 'children': ['122', '127']},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '127', 'type': 'argument_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '+'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '131', 'type': 'string', 'children': [], 'value': "'.yaml'"},{'id': '132', 'type': 'if_statement', 'children': ['133', '142']},{'id': '133', 'type': 'not_operator', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'config_file_path'},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'raise_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'string', 'children': [], 'value': "'Config file does not exist: {}'"},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'config_file_path'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'default_dict'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'load_yaml'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'config_file_path'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'user_config_file_path'},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '169', 'type': 'argument_list', 'children': ['170', '178', '179']},{'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': 'os'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '178', 'type': 'string', 'children': [], 'value': "'.condoor'"},{'id': '179', 'type': 'binary_operator', 'children': ['180', '188'], 'value': '+'},{'id': '180', 'type': 'call', 'children': ['181', '186']},{'id': '181', 'type': 'attribute', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '188', 'type': 'string', 'children': [], 'value': "'.yaml'"},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'user_config_file_path'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'getenv'},{'id': '196', 'type': 'argument_list', 'children': ['197', '211']},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '+'},{'id': '198', 'type': 'string', 'children': [], 'value': "'CONDOOR_'"},{'id': '199', 'type': 'call', 'children': ['200', '210']},{'id': '200', 'type': 'attribute', 'children': ['201', '209']},{'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': 'os'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '210', 'type': 'argument_list', 'children': []},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'user_config_file_path'},{'id': '212', 'type': 'if_statement', 'children': ['213', '221']},{'id': '213', 'type': 'call', 'children': ['214', '219']},{'id': '214', 'type': 'attribute', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'user_config_file_path'},{'id': '221', 'type': 'block', 'children': ['222', '229']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'user_dict'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'load_yaml'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'user_config_file_path'},{'id': '229', 'type': 'if_statement', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'user_dict'},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'default_dict'},{'id': '235', 'type': 'call', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'user_dict'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'default_dict'},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'default_dict'}
def yaml_file_to_dict(script_name, path=None): def load_yaml(file_path): with open(file_path, 'r') as yamlfile: try: dictionary = yaml.load(yamlfile) except yaml.YAMLError: return {} return dictionary def merge(user, default): if isinstance(user, dict) and isinstance(default, dict): for k, v in default.iteritems(): if k not in user: user[k] = v else: user[k] = merge(user[k], v) return user if path is None: path = os.path.abspath('.') config_file_path = os.path.join(path, script_name + '.yaml') if not os.path.exists(config_file_path): raise RuntimeError('Config file does not exist: {}'.format(config_file_path)) default_dict = load_yaml(config_file_path) user_config_file_path = os.path.join(os.path.expanduser('~'), '.condoor', os.path.basename(script_name) + '.yaml') user_config_file_path = os.getenv('CONDOOR_' + os.path.basename(script_name).upper(), user_config_file_path) if os.path.exists(user_config_file_path): user_dict = load_yaml(user_config_file_path) if user_dict: default_dict = merge(user_dict, default_dict) return default_dict
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_hop_info_from_url'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'verify_reachability'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '16', '32', '48', '70', '91', '100']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '19', 'type': 'conditional_expression', 'children': ['20', '21', '26'], 'value': 'if'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': 'is'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'unquote'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '35', 'type': 'conditional_expression', 'children': ['36', '37', '42'], 'value': 'if'},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': 'is'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'unquote'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '48', 'type': 'try_statement', 'children': ['49', '63']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'enable_password'},{'id': '53', 'type': 'subscript', 'children': ['54', '62']},{'id': '54', 'type': 'subscript', 'children': ['55', '61']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'parse_qs'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '61', 'type': 'string', 'children': [], 'value': '"enable_password"'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'except_clause', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'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': 'enable_password'},{'id': '69', 'type': 'None', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hop_info'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'HopInfo'},{'id': '75', 'type': 'argument_list', 'children': ['76', '79', '82', '83', '84', '87', '88']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'hostname'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'parsed'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'enable_password'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'verify_reachability'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'verify_reachability'},{'id': '91', 'type': 'if_statement', 'children': ['92', '97']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'hop_info'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'is_valid'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'hop_info'},{'id': '100', 'type': 'raise_statement', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'InvalidHopInfoError'}
def make_hop_info_from_url(url, verify_reachability=None): parsed = urlparse(url) username = None if parsed.username is None else unquote(parsed.username) password = None if parsed.password is None else unquote(parsed.password) try: enable_password = parse_qs(parsed.query)["enable_password"][0] except KeyError: enable_password = None hop_info = HopInfo( parsed.scheme, parsed.hostname, username, password, parsed.port, enable_password, verify_reachability=verify_reachability ) if hop_info.is_valid(): return hop_info raise InvalidHopInfoError
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sendmail'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sender'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'mail_options'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rcpt_options'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '27', '36', '45', '52', '79', '88', '92', '120', '136', '144']},{'id': '15', 'type': 'if_statement', 'children': ['16', '21']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'},{'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': 'recipients'},{'id': '25', 'type': 'list', 'children': ['26'], 'value': '[recipients]'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'mail_options'},{'id': '30', 'type': 'None', 'children': []},{'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': 'mail_options'},{'id': '35', 'type': 'list', 'children': [], 'value': '[]'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'rcpt_options'},{'id': '39', 'type': 'None', 'children': []},{'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': 'rcpt_options'},{'id': '44', 'type': 'list', 'children': [], 'value': '[]'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'await', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ehlo_or_helo_if_needed'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'supports_esmtp'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '63']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'},{'id': '59', 'type': 'string', 'children': [], 'value': '"size"'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'esmtp_extensions'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'mail_options'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': '"size={}"'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'await', 'children': ['81']},{'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': 'mail'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sender'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'mail_options'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '91', 'type': 'list', 'children': [], 'value': '[]'},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'recipient'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'recipients'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'try_statement', 'children': ['97', '107']},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'await', 'children': ['100']},{'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': 'rcpt'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'recipient'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'rcpt_options'},{'id': '107', 'type': 'except_clause', 'children': ['108', '112']},{'id': '108', 'type': 'as_pattern', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'SMTPCommandFailedError'},{'id': '110', 'type': 'as_pattern_target', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '112', 'type': 'block', 'children': ['113']},{'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': 'errors'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '120', 'type': 'if_statement', 'children': ['121', '130']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '126'], 'value': '=='},{'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': 'recipients'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'raise_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'SMTPNoRecipientError'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'await', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'errors'}
async def sendmail( self, sender, recipients, message, mail_options=None, rcpt_options=None ): if isinstance(recipients, str): recipients = [recipients] if mail_options is None: mail_options = [] if rcpt_options is None: rcpt_options = [] await self.ehlo_or_helo_if_needed() if self.supports_esmtp: if "size" in self.esmtp_extensions: mail_options.append("size={}".format(len(message))) await self.mail(sender, mail_options) errors = [] for recipient in recipients: try: await self.rcpt(recipient, rcpt_options) except SMTPCommandFailedError as e: errors.append(e) if len(recipients) == len(errors): raise SMTPNoRecipientError(errors) await self.data(message) return errors
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_fsm'},{'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': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'transitions'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'max_transitions'},{'id': '12', 'type': 'integer', 'children': [], 'value': '20'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '23']},{'id': '16', 'type': 'attribute', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_chain'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'target_device'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'run_fsm'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25', '26', '27', '28', '29']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'transitions'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'max_transitions'}
def run_fsm(self, name, command, events, transitions, timeout, max_transitions=20): return self._chain.target_device.run_fsm(name, command, events, transitions, timeout, max_transitions)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_view_details'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '8', 'type': 'string', 'children': [], 'value': "''"},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'urlpatterns'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'if_statement', 'children': ['15', '22', '218']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '19', 'type': 'tuple', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'URLPattern'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'RegexURLPattern'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'try_statement', 'children': ['24', '214']},{'id': '24', 'type': 'block', 'children': ['25', '32', '40', '44', '48', '52', '79', '90', '109']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'describe_pattern'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'docstr'},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'expected_json_response'},{'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': 'expected_url'},{'id': '51', 'type': 'string', 'children': [], 'value': "''"},{'id': '52', 'type': 'if_statement', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'docstr'},{'id': '54', 'type': 'block', 'children': ['55', '70']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65']},{'id': '63', 'type': 'string', 'children': [], 'value': "r'URL: (.*)'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'docstr'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'DOTALL'},{'id': '70', 'type': 'if_statement', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'expected_url'},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'id': '79', 'type': 'if_statement', 'children': ['80', '88']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'not'},{'id': '81', 'type': 'string', 'children': [], 'value': "'view_class'"},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'continue_statement', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'possible_methods'},{'id': '93', 'type': 'list_comprehension', 'children': ['94', '95', '105']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'view_class'},{'id': '105', 'type': 'if_clause', 'children': ['106']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'in'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'METHODS'},{'id': '109', 'type': 'for_statement', 'children': ['110', '111', '112']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'possible_methods'},{'id': '112', 'type': 'block', 'children': ['113', '127']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'view_method_docstr'},{'id': '116', 'type': 'attribute', 'children': ['117', '126']},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '119', 'type': 'argument_list', 'children': ['120', '125']},{'id': '120', 'type': 'attribute', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'view_class'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '126', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '127', 'type': 'if_statement', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'view_method_docstr'},{'id': '129', 'type': 'block', 'children': ['130', '154', '169']},{'id': '130', 'type': 'if_statement', 'children': ['131', '137']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'in'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '133', 'type': 'list', 'children': ['134', '135', '136'], 'value': "['put', 'patch', 'delete']"},{'id': '134', 'type': 'string', 'children': [], 'value': "'put'"},{'id': '135', 'type': 'string', 'children': [], 'value': "'patch'"},{'id': '136', 'type': 'string', 'children': [], 'value': "'delete'"},{'id': '137', 'type': 'block', 'children': ['138', '153']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'url_details'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'dictionary', 'children': ['147', '150']},{'id': '147', 'type': 'pair', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'expected_url'},{'id': '150', 'type': 'pair', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '153', 'type': 'continue_statement', 'children': []},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163', '164']},{'id': '162', 'type': 'string', 'children': [], 'value': "r'```(.*)```'"},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'view_method_docstr'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'DOTALL'},{'id': '169', 'type': 'if_statement', 'children': ['170', '173']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'is'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '172', 'type': 'None', 'children': []},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'for_statement', 'children': ['175', '176', '177']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '177', 'type': 'block', 'children': ['178', '186']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'expected_json_response'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '185', 'type': 'argument_list', 'children': []},{'id': '186', 'type': 'if_statement', 'children': ['187', '194']},{'id': '187', 'type': 'boolean_operator', 'children': ['188', '193'], 'value': 'and'},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '192'], 'value': 'and'},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'is'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '191', 'type': 'None', 'children': []},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'expected_json_response'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'expected_url'},{'id': '194', 'type': 'block', 'children': ['195', '213']},{'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': 'url_details'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'dictionary', 'children': ['204', '207', '210']},{'id': '204', 'type': 'pair', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'expected_url'},{'id': '207', 'type': 'pair', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '210', 'type': 'pair', 'children': ['211', '212']},{'id': '211', 'type': 'string', 'children': [], 'value': "'response'"},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'expected_json_response'},{'id': '213', 'type': 'continue_statement', 'children': []},{'id': '214', 'type': 'except_clause', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ViewDoesNotExist'},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'pass_statement', 'children': []},{'id': '218', 'type': 'elif_clause', 'children': ['219', '226']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '223', 'type': 'tuple', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'URLResolver'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'RegexURLResolver'},{'id': '226', 'type': 'block', 'children': ['227', '239', '246', '252']},{'id': '227', 'type': 'try_statement', 'children': ['228', '235']},{'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': 'patterns'},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'url_patterns'},{'id': '235', 'type': 'except_clause', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ImportError'},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'continue_statement', 'children': []},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'describe_pattern'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'current_full_url'},{'id': '249', 'type': 'binary_operator', 'children': ['250', '251'], 'value': '+'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '256', 'type': 'identifier', 'children': [], 'value': '_get_view_details'},{'id': '257', 'type': 'argument_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'current_full_url'}
def _get_view_details(self, urlpatterns, parent=''): for pattern in urlpatterns: if isinstance(pattern, (URLPattern, RegexURLPattern)): try: d = describe_pattern(pattern) docstr = pattern.callback.__doc__ method = None expected_json_response = '' expected_url = '' if docstr: u = re.findall(r'URL: (.*)', docstr, flags=re.DOTALL) if u: expected_url = u[0] if 'view_class' not in dir(pattern.callback): continue possible_methods = [m for m in dir(pattern.callback.view_class) if m in METHODS] for method in possible_methods: view_method_docstr = getattr(pattern.callback.view_class, method).__doc__ if view_method_docstr: if method in ['put', 'patch', 'delete']: self.url_details.append({ 'url': expected_url, 'method': method }) continue j = re.findall(r'```(.*)```', view_method_docstr, flags=re.DOTALL) if j is not None: for match in j: expected_json_response = match.strip() if method is not None and expected_json_response and expected_url: self.url_details.append({ 'url': expected_url, 'method': method, 'response': expected_json_response }) continue except ViewDoesNotExist: pass elif isinstance(pattern, (URLResolver, RegexURLResolver)): try: patterns = pattern.url_patterns except ImportError: continue d = describe_pattern(pattern) current_full_url = parent + d self._get_view_details(patterns, current_full_url)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'scan_module'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'modpath'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '7', 'type': 'block', 'children': ['8', '22', '89', '184', '230', '261', '267', '273', '313']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'used_origins'},{'id': '11', 'type': 'call', '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': 'map'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'modpath'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'function_definition', 'children': ['23', '24', '27']},{'id': '23', 'type': 'function_name', 'children': [], 'value': 'get_origins'},{'id': '24', 'type': 'parameters', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'modpath'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '27', 'type': 'block', 'children': ['28', '34', '81', '87']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'origins'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'function_definition', 'children': ['35', '36', '39']},{'id': '35', 'type': 'function_name', 'children': [], 'value': 'walk_origins'},{'id': '36', 'type': 'parameters', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'modpath'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '51']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '42', 'type': 'call', 'children': ['43', '48']},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'import_map'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get_origins'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'modpath'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'if_statement', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'not'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'origins'},{'id': '56', 'type': 'block', 'children': ['57', '64']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'origins'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '64', 'type': 'if_statement', 'children': ['65', '68']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'in'},{'id': '66', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'walk_origins'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'list_splat', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '78', 'type': 'argument_list', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'walk_origins'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'modpath'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'origins'},{'id': '89', 'type': 'function_definition', 'children': ['90', '91', '93']},{'id': '90', 'type': 'function_name', 'children': [], 'value': 'get_origins_for_node'},{'id': '91', 'type': 'parameters', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '93', 'type': 'block', 'children': ['94', '128', '180']},{'id': '94', 'type': 'if_statement', 'children': ['95', '110']},{'id': '95', 'type': 'boolean_operator', 'children': ['96', '102'], 'value': 'and'},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '101'], 'value': '=='},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '101', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '109'], 'value': '=='},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '109', 'type': 'string', 'children': [], 'value': "'Load'"},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'binary_operator', 'children': ['113', '121'], 'value': '|'},{'id': '113', 'type': 'set', 'children': ['114']},{'id': '114', 'type': 'binary_operator', 'children': ['115', '118'], 'value': '+'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'modpath'},{'id': '117', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'get_origins'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'modpath'},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '128', 'type': 'if_statement', 'children': ['129', '144']},{'id': '129', 'type': 'boolean_operator', 'children': ['130', '136'], 'value': 'and'},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '135'], 'value': '=='},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '135', 'type': 'string', 'children': [], 'value': "'Attribute'"},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '143'], 'value': '=='},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '143', 'type': 'string', 'children': [], 'value': "'Load'"},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'return_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '150', 'type': 'argument_list', 'children': ['151', '154']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'list_splat', 'children': ['155']},{'id': '155', 'type': 'list_comprehension', 'children': ['156', '172']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '165'], 'value': '|'},{'id': '157', 'type': 'set', 'children': ['158']},{'id': '158', 'type': 'binary_operator', 'children': ['159', '162'], 'value': '+'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '+'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '161', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'get_origins'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '172', 'type': 'for_in_clause', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'get_origins_for_node'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '180', 'type': 'return_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '183', 'type': 'argument_list', 'children': []},{'id': '184', 'type': 'function_definition', 'children': ['185', '186', '188']},{'id': '185', 'type': 'function_name', 'children': [], 'value': 'get_origins_used_by_node'},{'id': '186', 'type': 'parameters', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '188', 'type': 'block', 'children': ['189', '202', '226']},{'id': '189', 'type': 'if_statement', 'children': ['190', '196']},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '195'], 'value': '=='},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '195', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'return_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'get_origins_for_node'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '202', 'type': 'if_statement', 'children': ['203', '209']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '208'], 'value': '=='},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '208', 'type': 'string', 'children': [], 'value': "'Attribute'"},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'return_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '215', 'type': 'argument_list', 'children': ['216', '222']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'get_origins_used_by_node'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '222', 'type': 'call', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'get_origins_for_node'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '226', 'type': 'return_statement', 'children': ['227']},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '229', 'type': 'argument_list', 'children': []},{'id': '230', 'type': 'function_definition', 'children': ['231', '232', '234']},{'id': '231', 'type': 'function_name', 'children': [], 'value': 'scan_loads'},{'id': '232', 'type': 'parameters', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '234', 'type': 'block', 'children': ['235', '255']},{'id': '235', 'type': 'if_statement', 'children': ['236', '244']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '241'], 'value': 'in'},{'id': '237', 'type': 'call', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'node_type'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '241', 'type': 'list', 'children': ['242', '243'], 'value': "['Name', 'Attribute']"},{'id': '242', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '243', 'type': 'string', 'children': [], 'value': "'Attribute'"},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'used_origins'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'get_origins_used_by_node'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'for_each_child'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'scan_loads'},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'for_each_child'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'scan_loads'},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'intermediate_origins'},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '272', 'type': 'argument_list', 'children': []},{'id': '273', 'type': 'for_statement', 'children': ['274', '275', '276']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'used_origins'},{'id': '276', 'type': 'block', 'children': ['277', '286']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '286', 'type': 'for_statement', 'children': ['287', '288', '296']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292']},{'id': '291', 'type': 'integer', 'children': [], 'value': '1'},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '296', 'type': 'block', 'children': ['297']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'intermediate_origins'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'subscript', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '310', 'type': 'slice', 'children': ['311', '312']},{'id': '311', 'type': 'colon', 'children': []},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'used_origins'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'intermediate_origins'}
def scan_module(self, modpath, node): used_origins = self.map.setdefault(modpath, set()) def get_origins(modpath, name): origins = set() def walk_origins(modpath, name): for origin in self.import_map.get_origins(modpath, name): if origin not in origins: origins.add(origin) if '.' in origin: walk_origins(*origin.rsplit('.', 1)) walk_origins(modpath, name) return origins def get_origins_for_node(node): if node_type(node) == 'Name' and node_type(node.ctx) == 'Load': return {modpath + '.' + node.id} | get_origins(modpath, node.id) if node_type(node) == 'Attribute' and node_type(node.ctx) == 'Load': return set.union(set(), *[ {parent + '.' + node.attr} | get_origins(parent, node.attr) for parent in get_origins_for_node(node.value)]) return set() def get_origins_used_by_node(node): if node_type(node) == 'Name': return get_origins_for_node(node) if node_type(node) == 'Attribute': return set.union(get_origins_used_by_node(node.value), get_origins_for_node(node)) return set() def scan_loads(node): if node_type(node) in ['Name', 'Attribute']: used_origins.update(get_origins_used_by_node(node)) for_each_child(node, scan_loads) for_each_child(node, scan_loads) intermediate_origins = set() for origin in used_origins: parts = origin.split('.') for i in range(1, len(parts)): intermediate_origins.add('.'.join(parts[:i])) used_origins.update(intermediate_origins)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'operations'},{'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': 'op_types'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '22']},{'id': '9', 'type': 'if_statement', 'children': ['10', '12']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '16', 'type': 'list', 'children': ['17', '18', '19', '20', '21'], 'value': "['message', 'action', 'sync', 'viewlock', 'savedchapter']"},{'id': '17', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'sync'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'viewlock'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'savedchapter'"},{'id': '22', 'type': 'while_statement', 'children': ['23', '34']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '31'], 'value': '<'},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_handle'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_eof'},{'id': '34', 'type': 'block', 'children': ['35', '50', '77', '133', '157', '172', '193', '216', '236']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'current_time'},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'mgz'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'convert_to_timestamp'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'binary_operator', 'children': ['46', '49'], 'value': '/'},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '_time'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '50', 'type': 'try_statement', 'children': ['51', '67']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '55', 'type': 'call', 'children': ['56', '63']},{'id': '56', 'type': 'attribute', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'mgz'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'parse_stream'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_handle'},{'id': '67', 'type': 'except_clause', 'children': ['68', '71']},{'id': '68', 'type': 'tuple', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ConstructError'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'raise_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'MgzError'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'string', 'children': [], 'value': "'failed to parse body operation'"},{'id': '77', 'type': 'if_statement', 'children': ['78', '83']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '=='},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '82', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'if_statement', 'children': ['85', '92', '117']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '91'], 'value': 'in'},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ACTIONS_WITH_PLAYER_ID'},{'id': '92', 'type': 'block', 'children': ['93', '105']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'counter'},{'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': '_actions_by_player'},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'player_id'},{'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': 'counter'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'list', 'children': ['112'], 'value': '[operation.action.type]'},{'id': '112', 'type': 'attribute', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '117', 'type': 'else_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '126']},{'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': '_actions_without_player'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'list', 'children': ['128'], 'value': '[operation.action.type]'},{'id': '128', 'type': 'attribute', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '133', 'type': 'if_statement', 'children': ['134', '149']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '140'], 'value': 'and'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': '=='},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '139', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '142', 'type': 'argument_list', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '157', 'type': 'if_statement', 'children': ['158', '163']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '=='},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '162', 'type': 'string', 'children': [], 'value': "'sync'"},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'augmented_assignment', 'children': ['166', '169'], 'value': '+='},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': '_time'},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'time_increment'},{'id': '172', 'type': 'if_statement', 'children': ['173', '186']},{'id': '173', 'type': 'boolean_operator', 'children': ['174', '179'], 'value': 'and'},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': '=='},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '178', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '185'], 'value': '=='},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '185', 'type': 'string', 'children': [], 'value': "'postgame'"},{'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': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': '_postgame'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '193', 'type': 'if_statement', 'children': ['194', '199']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '198'], 'value': '=='},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '198', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '199', 'type': 'block', 'children': ['200', '208']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '203', 'type': 'call', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'current_time'},{'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': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': '_parse_action'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'current_time'},{'id': '216', 'type': 'if_statement', 'children': ['217', '222']},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '221'], 'value': '=='},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '221', 'type': 'string', 'children': [], 'value': "'savedchapter'"},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '227', 'type': 'identifier', 'children': [], 'value': '_parse_lobby_chat'},{'id': '228', 'type': 'argument_list', 'children': ['229', '234', '235']},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'lobby'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'messages'},{'id': '234', 'type': 'string', 'children': [], 'value': "'save'"},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'current_time'},{'id': '236', 'type': 'if_statement', 'children': ['237', '242', '256', '285']},{'id': '237', 'type': 'comparison_operator', 'children': ['238', '241'], 'value': '=='},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '241', 'type': 'string', 'children': [], 'value': "'viewlock'"},{'id': '242', 'type': 'block', 'children': ['243']},{'id': '243', 'type': 'if_statement', 'children': ['244', '249']},{'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': 'in'},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'yield', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'Viewlock'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '256', 'type': 'elif_clause', 'children': ['257', '270']},{'id': '257', 'type': 'boolean_operator', 'children': ['258', '263'], 'value': 'and'},{'id': '258', 'type': 'comparison_operator', 'children': ['259', '262'], 'value': '=='},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '262', 'type': 'string', 'children': [], 'value': "'action'"},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '269'], 'value': '!='},{'id': '264', 'type': 'attribute', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '269', 'type': 'string', 'children': [], 'value': "'postgame'"},{'id': '270', 'type': 'block', 'children': ['271']},{'id': '271', 'type': 'if_statement', 'children': ['272', '277']},{'id': '272', 'type': 'comparison_operator', 'children': ['273', '276'], 'value': 'in'},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'yield', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'current_time'},{'id': '285', 'type': 'elif_clause', 'children': ['286', '305']},{'id': '286', 'type': '()', 'children': ['287']},{'id': '287', 'type': 'boolean_operator', 'children': ['288', '300'], 'value': 'and'},{'id': '288', 'type': '()', 'children': ['289']},{'id': '289', 'type': 'boolean_operator', 'children': ['290', '295'], 'value': 'or'},{'id': '290', 'type': 'comparison_operator', 'children': ['291', '294'], 'value': '=='},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '294', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '295', 'type': 'comparison_operator', 'children': ['296', '299'], 'value': '=='},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '299', 'type': 'string', 'children': [], 'value': "'embedded'"},{'id': '300', 'type': 'comparison_operator', 'children': ['301', '304'], 'value': '=='},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'subtype'},{'id': '304', 'type': 'string', 'children': [], 'value': "'chat'"},{'id': '305', 'type': 'block', 'children': ['306', '329', '336']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'chat'},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'ChatMessage'},{'id': '311', 'type': 'argument_list', 'children': ['312', '317', '318', '323', '328']},{'id': '312', 'type': 'attribute', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'current_time'},{'id': '318', 'type': 'call', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '321', 'type': 'identifier', 'children': [], 'value': '_players'},{'id': '322', 'type': 'argument_list', 'children': []},{'id': '323', 'type': 'subscript', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '326', 'type': 'identifier', 'children': [], 'value': '_diplomacy'},{'id': '327', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '328', 'type': 'string', 'children': [], 'value': "'game'"},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '333', 'type': 'identifier', 'children': [], 'value': '_parse_chat'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'chat'},{'id': '336', 'type': 'if_statement', 'children': ['337', '342']},{'id': '337', 'type': 'comparison_operator', 'children': ['338', '341'], 'value': 'in'},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'op_types'},{'id': '342', 'type': 'block', 'children': ['343']},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'yield', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'chat'}
def operations(self, op_types=None): if not op_types: op_types = ['message', 'action', 'sync', 'viewlock', 'savedchapter'] while self._handle.tell() < self._eof: current_time = mgz.util.convert_to_timestamp(self._time / 1000) try: operation = mgz.body.operation.parse_stream(self._handle) except (ConstructError, ValueError): raise MgzError('failed to parse body operation') if operation.type == 'action': if operation.action.type in ACTIONS_WITH_PLAYER_ID: counter = self._actions_by_player[operation.action.player_id] counter.update([operation.action.type]) else: self._actions_without_player.update([operation.action.type]) if operation.type == 'action' and isinstance(operation.action.type, int): print(operation.action) if operation.type == 'sync': self._time += operation.time_increment if operation.type == 'action' and operation.action.type == 'postgame': self._postgame = operation if operation.type == 'action': action = Action(operation, current_time) self._parse_action(action, current_time) if operation.type == 'savedchapter': self._parse_lobby_chat(operation.lobby.messages, 'save', current_time) if operation.type == 'viewlock': if operation.type in op_types: yield Viewlock(operation) elif operation.type == 'action' and operation.action.type != 'postgame': if operation.type in op_types: yield Action(operation, current_time) elif ((operation.type == 'message' or operation.type == 'embedded') and operation.subtype == 'chat'): chat = ChatMessage(operation.data.text, current_time, self._players(), self._diplomacy['type'], 'game') self._parse_chat(chat) if operation.type in op_types: yield chat
{'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', '20', '24', '30', '44', '402', '409']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'FSM'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'Context'},{'id': '13', 'type': 'argument_list', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'transition_counter'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'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': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'log'},{'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': '"{} Start"'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '44', 'type': 'while_statement', 'children': ['45', '50']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'transition_counter'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'max_transitions'},{'id': '50', 'type': 'block', 'children': ['51', '55', '370']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'augmented_assignment', 'children': ['53', '54'], 'value': '+='},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'transition_counter'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'try_statement', 'children': ['56', '357']},{'id': '56', 'type': 'block', 'children': ['57', '63', '148', '156', '166', '178']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'if_statement', 'children': ['64', '69', '93']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '68'], 'value': 'is'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'init_pattern'},{'id': '68', 'type': 'None', 'children': []},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'event'},{'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': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ctrl'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'expect'},{'id': '81', 'type': 'argument_list', 'children': ['82', '85', '90']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'searchwindowsize'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'searchwindowsize'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '93', 'type': 'else_clause', 'children': ['94']},{'id': '94', 'type': 'block', 'children': ['95', '112']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': '"INIT_PATTERN={}"'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'pattern_to_str'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'init_pattern'},{'id': '112', 'type': 'try_statement', 'children': ['113', '129', '140']},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'event'},{'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': 'events'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'init_pattern'},{'id': '129', 'type': 'except_clause', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '131', 'type': 'block', 'children': ['132', '139']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'string', 'children': [], 'value': '"INIT_PATTERN unknown."'},{'id': '139', 'type': 'continue_statement', 'children': []},{'id': '140', 'type': 'finally_clause', 'children': ['141']},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'assignment', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'init_pattern'},{'id': '147', 'type': 'None', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'finish_time'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '155'], 'value': '-'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'start_time'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '159', 'type': 'tuple', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'state'},{'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': 'ctx'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '171', 'type': 'subscript', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '178', 'type': 'if_statement', 'children': ['179', '184', '337']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'in'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'transition_table'},{'id': '184', 'type': 'block', 'children': ['185', '193', '200', '219', '309', '318', '324']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'transition'},{'id': '188', 'type': 'subscript', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'transition_table'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '199']},{'id': '195', 'type': 'pattern_list', 'children': ['196', '197', '198']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'next_state'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'next_timeout'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'transition'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': '"E={},S={},T={},RT={:.2f}"'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '210', 'type': 'argument_list', 'children': ['211', '214', '217', '218']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'finish_time'},{'id': '219', 'type': 'if_statement', 'children': ['220', '230', '254', '275', '287']},{'id': '220', 'type': 'boolean_operator', 'children': ['221', '225'], 'value': 'and'},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '225', 'type': 'not_operator', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'if_statement', 'children': ['232', '237']},{'id': '232', 'type': 'not_operator', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '237', 'type': 'block', 'children': ['238', '252']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'string', 'children': [], 'value': '"Error: {}"'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '252', 'type': 'return_statement', 'children': ['253']},{'id': '253', 'type': 'False', 'children': []},{'id': '254', 'type': 'elif_clause', 'children': ['255', '260']},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '257', 'type': 'argument_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '260', 'type': 'block', 'children': ['261', '273']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'log'},{'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': '"A=Exception {}"'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '273', 'type': 'raise_statement', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '275', 'type': 'elif_clause', 'children': ['276', '279']},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '278'], 'value': 'is'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '278', 'type': 'None', 'children': []},{'id': '279', 'type': 'block', 'children': ['280']},{'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': 'self'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'string', 'children': [], 'value': '"A=None"'},{'id': '287', 'type': 'else_clause', 'children': ['288']},{'id': '288', 'type': 'block', 'children': ['289', '304']},{'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': 'self'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'string', 'children': [], 'value': '"FSM Action is not callable: {}"'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'action_instance'},{'id': '304', 'type': 'raise_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'RuntimeWarning'},{'id': '307', 'type': 'argument_list', 'children': ['308']},{'id': '308', 'type': 'string', 'children': [], 'value': '"FSM Action is not callable"'},{'id': '309', 'type': 'if_statement', 'children': ['310', '313']},{'id': '310', 'type': 'comparison_operator', 'children': ['311', '312'], 'value': '!='},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'next_timeout'},{'id': '312', 'type': 'integer', 'children': [], 'value': '0'},{'id': '313', 'type': 'block', 'children': ['314']},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'next_timeout'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'next_state'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'string', 'children': [], 'value': '"NS={},NT={}"'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '334', 'type': 'argument_list', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'next_state'},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '337', 'type': 'else_clause', 'children': ['338']},{'id': '338', 'type': 'block', 'children': ['339', '356']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'string', 'children': [], 'value': '"Unknown transition: EVENT={},STATE={}"'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '349', 'type': 'argument_list', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '356', 'type': 'continue_statement', 'children': []},{'id': '357', 'type': 'except_clause', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'EOF'},{'id': '359', 'type': 'block', 'children': ['360']},{'id': '360', 'type': 'raise_statement', 'children': ['361']},{'id': '361', 'type': 'call', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '363', 'type': 'argument_list', 'children': ['364', '365']},{'id': '364', 'type': 'string', 'children': [], 'value': '"Session closed unexpectedly"'},{'id': '365', 'type': 'attribute', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'ctrl'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'hostname'},{'id': '370', 'type': 'if_statement', 'children': ['371', '379']},{'id': '371', 'type': 'boolean_operator', 'children': ['372', '375'], 'value': 'or'},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'finished'},{'id': '375', 'type': 'comparison_operator', 'children': ['376', '377'], 'value': '=='},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'next_state'},{'id': '377', 'type': 'unary_operator', 'children': ['378'], 'value': '-'},{'id': '378', 'type': 'integer', 'children': [], 'value': '1'},{'id': '379', 'type': 'block', 'children': ['380', '400']},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'call', 'children': ['387', '390']},{'id': '387', 'type': 'attribute', 'children': ['388', '389']},{'id': '388', 'type': 'string', 'children': [], 'value': '"{} Stop at E={},S={}"'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '390', 'type': 'argument_list', 'children': ['391', '394', '397']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '394', 'type': 'attribute', 'children': ['395', '396']},{'id': '395', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '397', 'type': 'attribute', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '400', 'type': 'return_statement', 'children': ['401']},{'id': '401', 'type': 'True', 'children': []},{'id': '402', 'type': 'expression_statement', 'children': ['403']},{'id': '403', 'type': 'call', 'children': ['404', '407']},{'id': '404', 'type': 'attribute', 'children': ['405', '406']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '407', 'type': 'argument_list', 'children': ['408']},{'id': '408', 'type': 'string', 'children': [], 'value': '"FSM looped. Exiting"'},{'id': '409', 'type': 'return_statement', 'children': ['410']},{'id': '410', 'type': 'False', 'children': []}
def run(self): ctx = FSM.Context(self.name, self.device) transition_counter = 0 timeout = self.timeout self.log("{} Start".format(self.name)) while transition_counter < self.max_transitions: transition_counter += 1 try: start_time = time() if self.init_pattern is None: ctx.event = self.ctrl.expect(self.events, searchwindowsize=self.searchwindowsize, timeout=timeout) else: self.log("INIT_PATTERN={}".format(pattern_to_str(self.init_pattern))) try: ctx.event = self.events.index(self.init_pattern) except ValueError: self.log("INIT_PATTERN unknown.") continue finally: self.init_pattern = None finish_time = time() - start_time key = (ctx.event, ctx.state) ctx.pattern = self.events[ctx.event] if key in self.transition_table: transition = self.transition_table[key] next_state, action_instance, next_timeout = transition self.log("E={},S={},T={},RT={:.2f}".format(ctx.event, ctx.state, timeout, finish_time)) if callable(action_instance) and not isclass(action_instance): if not action_instance(ctx): self.log("Error: {}".format(ctx.msg)) return False elif isinstance(action_instance, Exception): self.log("A=Exception {}".format(action_instance)) raise action_instance elif action_instance is None: self.log("A=None") else: self.log("FSM Action is not callable: {}".format(str(action_instance))) raise RuntimeWarning("FSM Action is not callable") if next_timeout != 0: timeout = next_timeout ctx.state = next_state self.log("NS={},NT={}".format(next_state, timeout)) else: self.log("Unknown transition: EVENT={},STATE={}".format(ctx.event, ctx.state)) continue except EOF: raise ConnectionError("Session closed unexpectedly", self.ctrl.hostname) if ctx.finished or next_state == -1: self.log("{} Stop at E={},S={}".format(self.name, ctx.event, ctx.state)) return True self.log("FSM looped. Exiting") return False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '6', 'type': 'integer', 'children': [], 'value': '8000'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'fixtures'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '17', '27', '33', '39', '46', '55', '67', '77', '81', '85', '447', '456', '462', '472']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'extractor'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'Extractor'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Parser'},{'id': '22', 'type': 'argument_list', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'extractor'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'url_details'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'fixtures'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'url_details'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_store'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'get_store'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'url_details'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': '_store'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'Variable'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66']},{'id': '64', 'type': 'string', 'children': [], 'value': "'let'"},{'id': '65', 'type': 'string', 'children': [], 'value': "'store'"},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'store'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'functions'},{'id': '70', 'type': 'binary_operator', 'children': ['71', '76'], 'value': '+'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '75'], 'value': '+'},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '+'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'DATA_FINDER'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'GET_HANDLER'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'MODIFY_HANDLER'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'POST_HANDLER'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '80', 'type': 'list', 'children': [], 'value': '[]'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'endpoint_uris'},{'id': '84', 'type': 'list', 'children': [], 'value': '[]'},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '90']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '90', 'type': 'block', 'children': ['91', '97', '126', '136', '157', '221']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'Endpoint'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'if_statement', 'children': ['98', '109', '120']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '106'], 'value': 'in'},{'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': 'u'},{'id': '103', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'list', 'children': ['107', '108'], 'value': "['get', 'post']"},{'id': '107', 'type': 'string', 'children': [], 'value': "'get'"},{'id': '108', 'type': 'string', 'children': [], 'value': "'post'"},{'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': 'method'},{'id': '113', 'type': 'call', 'children': ['114', '119']},{'id': '114', 'type': 'attribute', 'children': ['115', '118']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '117', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '119', 'type': 'argument_list', 'children': []},{'id': '120', 'type': 'else_clause', 'children': ['121']},{'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': 'method'},{'id': '125', 'type': 'string', 'children': [], 'value': "'modify'"},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ResponseBody'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '143']},{'id': '138', 'type': 'pattern_list', 'children': ['139', '142']},{'id': '139', 'type': 'subscript', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '141', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'list_url'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'clean_url'},{'id': '145', 'type': 'argument_list', 'children': ['146', '149', '150']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '148', 'type': 'string', 'children': [], 'value': "'full_url'"},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_store'},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '154', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '156', 'type': 'argument_list', 'children': []},{'id': '157', 'type': 'if_statement', 'children': ['158', '171']},{'id': '158', 'type': 'boolean_operator', 'children': ['159', '162'], 'value': 'and'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'is'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'list_url'},{'id': '161', 'type': 'None', 'children': []},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '170'], 'value': '=='},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '167', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'string', 'children': [], 'value': "'get'"},{'id': '171', 'type': 'block', 'children': ['172', '178', '187', '205']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'list_endpoint'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'Endpoint'},{'id': '177', 'type': 'argument_list', 'children': []},{'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': 'list_endpoint'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'construct'},{'id': '183', 'type': 'argument_list', 'children': ['184', '185', '186']},{'id': '184', 'type': 'string', 'children': [], 'value': "'get'"},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'list_url'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '187', 'type': 'if_statement', 'children': ['188', '194']},{'id': '188', 'type': 'comparison_operator', 'children': ['189', '193'], 'value': 'not'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'list_endpoint'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'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': 'endpoints'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'list_endpoint'},{'id': '205', 'type': 'if_statement', 'children': ['206', '211']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '210'], 'value': 'not'},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'list_endpoint'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'endpoint_uris'},{'id': '211', 'type': 'block', 'children': ['212']},{'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': 'endpoint_uris'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'list_endpoint'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '221', 'type': 'if_statement', 'children': ['222', '225', '398']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '=='},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '224', 'type': 'string', 'children': [], 'value': "'modify'"},{'id': '225', 'type': 'block', 'children': ['226', '239']},{'id': '226', 'type': 'expression_statement', 'children': ['227']},{'id': '227', 'type': 'assignment', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'without_prefix'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '233', 'type': 'argument_list', 'children': ['234', '235', '236']},{'id': '234', 'type': 'string', 'children': [], 'value': "r'\\/(\\w+)\\_\\_'"},{'id': '235', 'type': 'string', 'children': [], 'value': "''"},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '238', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '239', 'type': 'for_statement', 'children': ['240', '243', '248']},{'id': '240', 'type': 'pattern_list', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': '_store'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '247', 'type': 'argument_list', 'children': []},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'if_statement', 'children': ['250', '253']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': 'in'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'without_prefix'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '253', 'type': 'block', 'children': ['254', '264', '273', '277', '292']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "'options'"},{'id': '263', 'type': 'string', 'children': [], 'value': "'{}'"},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'ast'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'literal_eval'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '276', 'type': 'list', 'children': [], 'value': '[]'},{'id': '277', 'type': 'if_statement', 'children': ['278', '281']},{'id': '278', 'type': 'comparison_operator', 'children': ['279', '280'], 'value': 'is'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '280', 'type': 'None', 'children': []},{'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': 'modifiers'},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '289', 'type': 'argument_list', 'children': ['290', '291']},{'id': '290', 'type': 'string', 'children': [], 'value': "'modifiers'"},{'id': '291', 'type': 'list', 'children': [], 'value': '[]'},{'id': '292', 'type': 'if_statement', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'for_statement', 'children': ['296', '297', '298']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'modifiers'},{'id': '298', 'type': 'block', 'children': ['299']},{'id': '299', 'type': 'if_statement', 'children': ['300', '309']},{'id': '300', 'type': 'comparison_operator', 'children': ['301', '308'], 'value': '=='},{'id': '301', 'type': 'call', 'children': ['302', '307']},{'id': '302', 'type': 'attribute', 'children': ['303', '306']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '305', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '307', 'type': 'argument_list', 'children': []},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'mod'},{'id': '309', 'type': 'block', 'children': ['310', '316', '320', '349', '364', '382']},{'id': '310', 'type': 'expression_statement', 'children': ['311']},{'id': '311', 'type': 'assignment', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'mod_endpoint'},{'id': '313', 'type': 'call', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'Endpoint'},{'id': '315', 'type': 'argument_list', 'children': []},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'assignment', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'without_prefix'},{'id': '320', 'type': 'if_statement', 'children': ['321', '335']},{'id': '321', 'type': 'boolean_operator', 'children': ['322', '330'], 'value': 'and'},{'id': '322', 'type': 'comparison_operator', 'children': ['323', '329'], 'value': 'is'},{'id': '323', 'type': 'call', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'string', 'children': [], 'value': "'position'"},{'id': '329', 'type': 'None', 'children': []},{'id': '330', 'type': 'comparison_operator', 'children': ['331', '334'], 'value': '=='},{'id': '331', 'type': 'subscript', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '333', 'type': 'string', 'children': [], 'value': "'position'"},{'id': '334', 'type': 'string', 'children': [], 'value': "'url'"},{'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': 'uri'},{'id': '339', 'type': 'call', 'children': ['340', '343']},{'id': '340', 'type': 'attribute', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '343', 'type': 'argument_list', 'children': ['344', '345', '346']},{'id': '344', 'type': 'string', 'children': [], 'value': "r'\\/?\\_\\_key'"},{'id': '345', 'type': 'string', 'children': [], 'value': "'/:id'"},{'id': '346', 'type': 'subscript', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '348', 'type': 'string', 'children': [], 'value': "'full_url'"},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '354']},{'id': '351', 'type': 'attribute', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'mod_endpoint'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'construct'},{'id': '354', 'type': 'argument_list', 'children': ['355', '362', '363']},{'id': '355', 'type': 'call', 'children': ['356', '361']},{'id': '356', 'type': 'attribute', 'children': ['357', '360']},{'id': '357', 'type': 'subscript', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '359', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '361', 'type': 'argument_list', 'children': []},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '364', 'type': 'if_statement', 'children': ['365', '371']},{'id': '365', 'type': 'comparison_operator', 'children': ['366', '370'], 'value': 'not'},{'id': '366', 'type': 'call', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '368', 'type': 'argument_list', 'children': ['369']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'mod_endpoint'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '371', 'type': 'block', 'children': ['372']},{'id': '372', 'type': 'expression_statement', 'children': ['373']},{'id': '373', 'type': 'call', 'children': ['374', '377']},{'id': '374', 'type': 'attribute', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '377', 'type': 'argument_list', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'mod_endpoint'},{'id': '382', 'type': 'if_statement', 'children': ['383', '388']},{'id': '383', 'type': 'comparison_operator', 'children': ['384', '387'], 'value': 'not'},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'mod_endpoint'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'endpoint_uris'},{'id': '388', 'type': 'block', 'children': ['389']},{'id': '389', 'type': 'expression_statement', 'children': ['390']},{'id': '390', 'type': 'call', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'endpoint_uris'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '394', 'type': 'argument_list', 'children': ['395']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'mod_endpoint'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '398', 'type': 'else_clause', 'children': ['399']},{'id': '399', 'type': 'block', 'children': ['400', '413', '431']},{'id': '400', 'type': 'expression_statement', 'children': ['401']},{'id': '401', 'type': 'call', 'children': ['402', '405']},{'id': '402', 'type': 'attribute', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'construct'},{'id': '405', 'type': 'argument_list', 'children': ['406', '409', '412']},{'id': '406', 'type': 'subscript', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '408', 'type': 'string', 'children': [], 'value': "'method'"},{'id': '409', 'type': 'subscript', 'children': ['410', '411']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '411', 'type': 'string', 'children': [], 'value': "'url'"},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '413', 'type': 'if_statement', 'children': ['414', '420']},{'id': '414', 'type': 'comparison_operator', 'children': ['415', '419'], 'value': 'not'},{'id': '415', 'type': 'call', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '417', 'type': 'argument_list', 'children': ['418']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '420', 'type': 'block', 'children': ['421']},{'id': '421', 'type': 'expression_statement', 'children': ['422']},{'id': '422', 'type': 'call', 'children': ['423', '426']},{'id': '423', 'type': 'attribute', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '426', 'type': 'argument_list', 'children': ['427']},{'id': '427', 'type': 'call', 'children': ['428', '429']},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '429', 'type': 'argument_list', 'children': ['430']},{'id': '430', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '431', 'type': 'if_statement', 'children': ['432', '437']},{'id': '432', 'type': 'comparison_operator', 'children': ['433', '436'], 'value': 'not'},{'id': '433', 'type': 'attribute', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'endpoint_uris'},{'id': '437', 'type': 'block', 'children': ['438']},{'id': '438', 'type': 'expression_statement', 'children': ['439']},{'id': '439', 'type': 'call', 'children': ['440', '443']},{'id': '440', 'type': 'attribute', 'children': ['441', '442']},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'endpoint_uris'},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '443', 'type': 'argument_list', 'children': ['444']},{'id': '444', 'type': 'attribute', 'children': ['445', '446']},{'id': '445', 'type': 'identifier', 'children': [], 'value': 'endpoint'},{'id': '446', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '447', 'type': 'expression_statement', 'children': ['448']},{'id': '448', 'type': 'assignment', 'children': ['449', '450']},{'id': '449', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '450', 'type': 'call', 'children': ['451', '454']},{'id': '451', 'type': 'attribute', 'children': ['452', '453']},{'id': '452', 'type': 'string', 'children': [], 'value': "''"},{'id': '453', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '454', 'type': 'argument_list', 'children': ['455']},{'id': '455', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '456', 'type': 'expression_statement', 'children': ['457']},{'id': '457', 'type': 'assignment', 'children': ['458', '459']},{'id': '458', 'type': 'identifier', 'children': [], 'value': 'express'},{'id': '459', 'type': 'call', 'children': ['460', '461']},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'ExpressServer'},{'id': '461', 'type': 'argument_list', 'children': []},{'id': '462', 'type': 'expression_statement', 'children': ['463']},{'id': '463', 'type': 'call', 'children': ['464', '467']},{'id': '464', 'type': 'attribute', 'children': ['465', '466']},{'id': '465', 'type': 'identifier', 'children': [], 'value': 'express'},{'id': '466', 'type': 'identifier', 'children': [], 'value': 'construct'},{'id': '467', 'type': 'argument_list', 'children': ['468', '469', '470', '471']},{'id': '468', 'type': 'identifier', 'children': [], 'value': 'variables'},{'id': '469', 'type': 'identifier', 'children': [], 'value': 'functions'},{'id': '470', 'type': 'identifier', 'children': [], 'value': 'endpoints'},{'id': '471', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '472', 'type': 'return_statement', 'children': ['473']},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'express'}
def build(port=8000, fixtures=None): extractor = Extractor() parser = Parser(extractor.url_details, fixtures) parser.parse() url_details = parser.results _store = get_store(url_details) store = json.dumps(_store) variables = str(Variable('let', 'store', store)) functions = DATA_FINDER + GET_HANDLER + MODIFY_HANDLER + POST_HANDLER endpoints = [] endpoint_uris = [] for u in parser.results: endpoint = Endpoint() if u['method'].lower() in ['get', 'post']: method = u['method'].lower() else: method = 'modify' response = str(ResponseBody(method)) u['url'], list_url = clean_url(u['full_url'], _store, u['method'].lower()) if list_url is not None and u['method'].lower() == 'get': list_endpoint = Endpoint() list_endpoint.construct('get', list_url, response) if str(list_endpoint) not in endpoints: endpoints.append(str(list_endpoint)) if list_endpoint.uri not in endpoint_uris: endpoint_uris.append(list_endpoint.uri) if method == 'modify': without_prefix = re.sub(r'\/(\w+)\_\_', '', u['url']) for k, v in _store.items(): if without_prefix in k: options = v.get('options', '{}') options = ast.literal_eval(options) modifiers = [] if options is not None: modifiers = options.get('modifiers', []) if modifiers: for mod in modifiers: if u['method'].lower() == mod: mod_endpoint = Endpoint() uri = without_prefix if v.get('position') is not None and v['position'] == 'url': uri = re.sub(r'\/?\_\_key', '/:id', u['full_url']) mod_endpoint.construct(u['method'].lower(), uri, response) if str(mod_endpoint) not in endpoints: endpoints.append(str(mod_endpoint)) if mod_endpoint.uri not in endpoint_uris: endpoint_uris.append(mod_endpoint.uri) else: endpoint.construct(u['method'], u['url'], response) if str(endpoint) not in endpoints: endpoints.append(str(endpoint)) if endpoint.uri not in endpoint_uris: endpoint_uris.append(endpoint.uri) endpoints = ''.join(endpoints) express = ExpressServer() express.construct(variables, functions, endpoints, port) return express
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gpg_decrypt'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'gpg_config'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '217', '304']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': 'decrypt'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '13', 'type': 'block', 'children': ['14', '215']},{'id': '14', 'type': 'if_statement', 'children': ['15', '20', '41', '136']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '20', 'type': 'block', 'children': ['21', '25', '39']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'res_v'},{'id': '24', 'type': 'list', 'children': [], 'value': '[]'},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'obj'},{'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': 'res_v'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'decrypt'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'res_v'},{'id': '41', 'type': 'elif_clause', 'children': ['42', '47']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'if_statement', 'children': ['49', '52', '115']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'in'},{'id': '50', 'type': 'string', 'children': [], 'value': "'_gpg'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'try_statement', 'children': ['54', '101']},{'id': '54', 'type': 'block', 'children': ['55', '66']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'decrypted'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'gpg'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'decrypt'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '65', 'type': 'string', 'children': [], 'value': "'_gpg'"},{'id': '66', 'type': 'if_statement', 'children': ['67', '70', '89']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'decrypted'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '88']},{'id': '78', 'type': 'attribute', 'children': ['79', '87']},{'id': '79', 'type': 'call', 'children': ['80', '85']},{'id': '80', 'type': 'attribute', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'decrypted'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'else_clause', 'children': ['90']},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'string', 'children': [], 'value': '"gpg error unpacking secrets %s"'},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'decrypted'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '101', 'type': 'except_clause', 'children': ['102', '106']},{'id': '102', 'type': 'as_pattern', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '104', 'type': 'as_pattern_target', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'string', 'children': [], 'value': '"error unpacking secrets %s"'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'for_statement', 'children': ['118', '121', '126']},{'id': '118', 'type': 'pattern_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '125', 'type': 'argument_list', 'children': []},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'decrypt'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '136', 'type': 'else_clause', 'children': ['137']},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'try_statement', 'children': ['139', '205']},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'if_statement', 'children': ['141', '144']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': 'in'},{'id': '142', 'type': 'string', 'children': [], 'value': "'BEGIN PGP'"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'try_statement', 'children': ['146', '191']},{'id': '146', 'type': 'block', 'children': ['147', '156']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'decrypted'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'gpg'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'decrypt'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '156', 'type': 'if_statement', 'children': ['157', '160', '179']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'decrypted'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'ok'},{'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': 'obj'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '178']},{'id': '168', 'type': 'attribute', 'children': ['169', '177']},{'id': '169', 'type': 'call', 'children': ['170', '175']},{'id': '170', 'type': 'attribute', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'decrypted'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'else_clause', 'children': ['180']},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': '"gpg error unpacking secrets %s"'},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'decrypted'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '191', 'type': 'except_clause', 'children': ['192', '196']},{'id': '192', 'type': 'as_pattern', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '194', 'type': 'as_pattern_target', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '196', 'type': 'block', 'children': ['197']},{'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': 'log'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204']},{'id': '203', 'type': 'string', 'children': [], 'value': '"error unpacking secrets %s"'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '205', 'type': 'except_clause', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'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': 'log'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'string', 'children': [], 'value': "'Pass on decryption. Only decrypt strings'"},{'id': '215', 'type': 'return_statement', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '217', 'type': 'if_statement', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'GPG_IMPORTED'},{'id': '219', 'type': 'block', 'children': ['220', '275', '299']},{'id': '220', 'type': 'if_statement', 'children': ['221', '223']},{'id': '221', 'type': 'not_operator', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'gpg_config'},{'id': '223', 'type': 'block', 'children': ['224', '228', '235', '248']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'gpg_config'},{'id': '227', 'type': 'dictionary', 'children': []},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '231', 'type': 'dictionary', 'children': ['232']},{'id': '232', 'type': 'pair', 'children': ['233', '234']},{'id': '233', 'type': 'string', 'children': [], 'value': "'homedir'"},{'id': '234', 'type': 'string', 'children': [], 'value': "'~/.gnupg/'"},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'env_fields'},{'id': '238', 'type': 'dictionary', 'children': ['239', '242', '245']},{'id': '239', 'type': 'pair', 'children': ['240', '241']},{'id': '240', 'type': 'string', 'children': [], 'value': "'homedir'"},{'id': '241', 'type': 'string', 'children': [], 'value': "'FIGGYPY_GPG_HOMEDIR'"},{'id': '242', 'type': 'pair', 'children': ['243', '244']},{'id': '243', 'type': 'string', 'children': [], 'value': "'binary'"},{'id': '244', 'type': 'string', 'children': [], 'value': "'FIGGYPY_GPG_BINARY'"},{'id': '245', 'type': 'pair', 'children': ['246', '247']},{'id': '246', 'type': 'string', 'children': [], 'value': "'keyring'"},{'id': '247', 'type': 'string', 'children': [], 'value': "'FIGGYPY_GPG_KEYRING'"},{'id': '248', 'type': 'for_statement', 'children': ['249', '252', '257']},{'id': '249', 'type': 'pattern_list', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'env_fields'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '256', 'type': 'argument_list', 'children': []},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '263']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'gpg_config'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'env_or_default'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '267', 'type': 'conditional_expression', 'children': ['268', '271', '274'], 'value': 'if'},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '273'], 'value': 'in'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'defaults'},{'id': '274', 'type': 'None', 'children': []},{'id': '275', 'type': 'try_statement', 'children': ['276', '287']},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'gpg'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'gnupg'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'GPG'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'dictionary_splat', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'gpg_config'},{'id': '287', 'type': 'except_clause', 'children': ['288', '291']},{'id': '288', 'type': 'tuple', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'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': 'log'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '297', 'type': 'argument_list', 'children': ['298']},{'id': '298', 'type': 'string', 'children': [], 'value': "'Failed to configure gpg. Will be unable to decrypt secrets.'"},{'id': '299', 'type': 'return_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'decrypt'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'cfg'},{'id': '304', 'type': 'return_statement', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'cfg'}
def gpg_decrypt(cfg, gpg_config=None): def decrypt(obj): if isinstance(obj, list): res_v = [] for item in obj: res_v.append(decrypt(item)) return res_v elif isinstance(obj, dict): if '_gpg' in obj: try: decrypted = gpg.decrypt(obj['_gpg']) if decrypted.ok: obj = n(decrypted.data.decode('utf-8').encode()) else: log.error("gpg error unpacking secrets %s", decrypted.stderr) except Exception as err: log.error("error unpacking secrets %s", err) else: for k, v in obj.items(): obj[k] = decrypt(v) else: try: if 'BEGIN PGP' in obj: try: decrypted = gpg.decrypt(obj) if decrypted.ok: obj = n(decrypted.data.decode('utf-8').encode()) else: log.error("gpg error unpacking secrets %s", decrypted.stderr) except Exception as err: log.error("error unpacking secrets %s", err) except TypeError: log.debug('Pass on decryption. Only decrypt strings') return obj if GPG_IMPORTED: if not gpg_config: gpg_config = {} defaults = {'homedir': '~/.gnupg/'} env_fields = {'homedir': 'FIGGYPY_GPG_HOMEDIR', 'binary': 'FIGGYPY_GPG_BINARY', 'keyring': 'FIGGYPY_GPG_KEYRING'} for k, v in env_fields.items(): gpg_config[k] = env_or_default(v, defaults[k] if k in defaults else None) try: gpg = gnupg.GPG(**gpg_config) except (OSError, RuntimeError): log.exception('Failed to configure gpg. Will be unable to decrypt secrets.') return decrypt(cfg) return cfg
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_teams'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '19', '23', '192', '200']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'subscript', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '11', 'type': 'string', 'children': [], 'value': "'teams'"},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'subscript', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '18', 'type': 'string', 'children': [], 'value': "'teams'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'teams'},{'id': '22', 'type': 'list', 'children': [], 'value': '[]'},{'id': '23', 'type': 'for_statement', 'children': ['24', '27', '37']},{'id': '24', 'type': 'pattern_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'player'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '36']},{'id': '31', 'type': 'attribute', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'players'},{'id': '37', 'type': 'block', 'children': ['38', '42', '176']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'added'},{'id': '41', 'type': 'False', 'children': []},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '58']},{'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', '48']},{'id': '47', 'type': 'integer', 'children': [], 'value': '0'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'attribute', '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': '_header'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'players'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'if_statement', 'children': ['60', '69']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '68'], 'value': '=='},{'id': '61', 'type': 'subscript', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'player'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'my_diplomacy'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '68', 'type': 'string', 'children': [], 'value': "'ally'"},{'id': '69', 'type': 'block', 'children': ['70', '74', '78', '82', '132', '144', '158', '172']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'inner_team'},{'id': '73', 'type': 'False', 'children': []},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'outer_team'},{'id': '77', 'type': 'False', 'children': []},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'new_team'},{'id': '81', 'type': 'True', 'children': []},{'id': '82', 'type': 'for_statement', 'children': ['83', '86', '90']},{'id': '83', 'type': 'pattern_list', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tl'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'teams'},{'id': '90', 'type': 'block', 'children': ['91', '104', '118']},{'id': '91', 'type': 'if_statement', 'children': ['92', '99']},{'id': '92', 'type': 'boolean_operator', 'children': ['93', '96'], 'value': 'or'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'in'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'tl'},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'in'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'tl'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'new_team'},{'id': '103', 'type': 'False', 'children': []},{'id': '104', 'type': 'if_statement', 'children': ['105', '112']},{'id': '105', 'type': 'boolean_operator', 'children': ['106', '109'], 'value': 'and'},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'in'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'tl'},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'not'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tl'},{'id': '112', 'type': 'block', 'children': ['113', '117']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'inner_team'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '117', 'type': 'break_statement', 'children': []},{'id': '118', 'type': 'if_statement', 'children': ['119', '126']},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '123'], 'value': 'and'},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'not'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'tl'},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'in'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'tl'},{'id': '126', 'type': 'block', 'children': ['127', '131']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'outer_team'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '131', 'type': 'break_statement', 'children': []},{'id': '132', 'type': 'if_statement', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'new_team'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'teams'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'list', 'children': ['142', '143'], 'value': '[i, j]'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'inner_team'},{'id': '147', 'type': 'False', 'children': []},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'teams'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'inner_team'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '158', 'type': 'if_statement', 'children': ['159', '162']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'is'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'outer_team'},{'id': '161', 'type': 'False', 'children': []},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '170']},{'id': '165', 'type': 'attribute', 'children': ['166', '169']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'teams'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'outer_team'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'added'},{'id': '175', 'type': 'True', 'children': []},{'id': '176', 'type': 'if_statement', 'children': ['177', '183']},{'id': '177', 'type': 'boolean_operator', 'children': ['178', '180'], 'value': 'and'},{'id': '178', 'type': 'not_operator', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'added'},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '!='},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'teams'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'list', 'children': ['191'], 'value': '[j]'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '199']},{'id': '194', 'type': 'subscript', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '198', 'type': 'string', 'children': [], 'value': "'teams'"},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'teams'},{'id': '200', 'type': 'return_statement', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'teams'}
def get_teams(self): if self._cache['teams']: return self._cache['teams'] teams = [] for j, player in enumerate(self._header.initial.players): added = False for i in range(0, len(self._header.initial.players)): if player.attributes.my_diplomacy[i] == 'ally': inner_team = False outer_team = False new_team = True for t, tl in enumerate(teams): if j in tl or i in tl: new_team = False if j in tl and i not in tl: inner_team = t break if j not in tl and i in tl: outer_team = t break if new_team: teams.append([i, j]) if inner_team is not False: teams[inner_team].append(i) if outer_team is not False: teams[outer_team].append(j) added = True if not added and j != 0: teams.append([j]) self._cache['teams'] = teams return teams
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_settings'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_postgame'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'dictionary', 'children': ['16', '33', '54', '65', '82', '108', '117', '126', '141', '156', '171', '180', '188', '196']},{'id': '16', 'type': 'pair', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '18', 'type': 'tuple', 'children': ['19', '26']},{'id': '19', 'type': 'attribute', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'lobby'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'game_type_id'},{'id': '26', 'type': 'attribute', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lobby'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'game_type'},{'id': '33', 'type': 'pair', 'children': ['34', '35']},{'id': '34', 'type': 'string', 'children': [], 'value': "'difficulty'"},{'id': '35', 'type': 'tuple', 'children': ['36', '45']},{'id': '36', 'type': 'attribute', 'children': ['37', '44']},{'id': '37', 'type': 'attribute', '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': '_header'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'scenario'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'game_settings'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'difficulty_id'},{'id': '45', 'type': 'attribute', 'children': ['46', '53']},{'id': '46', 'type': 'attribute', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'scenario'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'game_settings'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'difficulty'},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'population_limit'"},{'id': '56', 'type': 'binary_operator', 'children': ['57', '64'], 'value': '*'},{'id': '57', 'type': 'attribute', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'lobby'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'population_limit'},{'id': '64', 'type': 'integer', 'children': [], 'value': '25'},{'id': '65', 'type': 'pair', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'map_reveal_choice'"},{'id': '67', 'type': 'tuple', 'children': ['68', '75']},{'id': '68', 'type': 'attribute', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'lobby'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'reveal_map_id'},{'id': '75', 'type': 'attribute', 'children': ['76', '81']},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'lobby'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'reveal_map'},{'id': '82', 'type': 'pair', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'speed'"},{'id': '84', 'type': 'tuple', 'children': ['85', '92']},{'id': '85', 'type': 'attribute', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'replay'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'game_speed_id'},{'id': '92', 'type': 'call', 'children': ['93', '100']},{'id': '93', 'type': 'attribute', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'mgz'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'SPEEDS'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'attribute', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'replay'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'game_speed_id'},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'cheats'"},{'id': '110', 'type': 'attribute', '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': '_header'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'replay'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'cheats_enabled'},{'id': '117', 'type': 'pair', 'children': ['118', '119']},{'id': '118', 'type': 'string', 'children': [], 'value': "'lock_teams'"},{'id': '119', 'type': 'attribute', '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': '_header'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'lobby'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'lock_teams'},{'id': '126', 'type': 'pair', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': "'starting_resources'"},{'id': '128', 'type': 'tuple', 'children': ['129', '135']},{'id': '129', 'type': 'conditional_expression', 'children': ['130', '133', '134'], 'value': 'if'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'resource_level_id'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '134', 'type': 'None', 'children': []},{'id': '135', 'type': 'conditional_expression', 'children': ['136', '139', '140'], 'value': 'if'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'resource_level'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'pair', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': "'starting_age'"},{'id': '143', 'type': 'tuple', 'children': ['144', '150']},{'id': '144', 'type': 'conditional_expression', 'children': ['145', '148', '149'], 'value': 'if'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'starting_age_id'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '149', 'type': 'None', 'children': []},{'id': '150', 'type': 'conditional_expression', 'children': ['151', '154', '155'], 'value': 'if'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'starting_age'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '155', 'type': 'None', 'children': []},{'id': '156', 'type': 'pair', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': "'victory_condition'"},{'id': '158', 'type': 'tuple', 'children': ['159', '165']},{'id': '159', 'type': 'conditional_expression', 'children': ['160', '163', '164'], 'value': 'if'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'victory_type_id'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '164', 'type': 'None', 'children': []},{'id': '165', 'type': 'conditional_expression', 'children': ['166', '169', '170'], 'value': 'if'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'victory_type'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '170', 'type': 'None', 'children': []},{'id': '171', 'type': 'pair', 'children': ['172', '173']},{'id': '172', 'type': 'string', 'children': [], 'value': "'team_together'"},{'id': '173', 'type': 'conditional_expression', 'children': ['174', '178', '179'], 'value': 'if'},{'id': '174', 'type': 'not_operator', 'children': ['175']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'team_together'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '179', 'type': 'None', 'children': []},{'id': '180', 'type': 'pair', 'children': ['181', '182']},{'id': '181', 'type': 'string', 'children': [], 'value': "'all_technologies'"},{'id': '182', 'type': 'conditional_expression', 'children': ['183', '186', '187'], 'value': 'if'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'all_techs'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '187', 'type': 'None', 'children': []},{'id': '188', 'type': 'pair', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': "'lock_speed'"},{'id': '190', 'type': 'conditional_expression', 'children': ['191', '194', '195'], 'value': 'if'},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'lock_speed'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'postgame'},{'id': '195', 'type': 'None', 'children': []},{'id': '196', 'type': 'pair', 'children': ['197', '198']},{'id': '197', 'type': 'string', 'children': [], 'value': "'multiqueue'"},{'id': '198', 'type': 'None', 'children': []}
def get_settings(self): postgame = self.get_postgame() return { 'type': ( self._header.lobby.game_type_id, self._header.lobby.game_type ), 'difficulty': ( self._header.scenario.game_settings.difficulty_id, self._header.scenario.game_settings.difficulty ), 'population_limit': self._header.lobby.population_limit * 25, 'map_reveal_choice': ( self._header.lobby.reveal_map_id, self._header.lobby.reveal_map ), 'speed': ( self._header.replay.game_speed_id, mgz.const.SPEEDS.get(self._header.replay.game_speed_id) ), 'cheats': self._header.replay.cheats_enabled, 'lock_teams': self._header.lobby.lock_teams, 'starting_resources': ( postgame.resource_level_id if postgame else None, postgame.resource_level if postgame else None, ), 'starting_age': ( postgame.starting_age_id if postgame else None, postgame.starting_age if postgame else None ), 'victory_condition': ( postgame.victory_type_id if postgame else None, postgame.victory_type if postgame else None ), 'team_together': not postgame.team_together if postgame else None, 'all_technologies': postgame.all_techs if postgame else None, 'lock_speed': postgame.lock_speed if postgame else None, 'multiqueue': None }
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_map'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '19', '31', '43', '62', '72', '76', '80', '84', '88', '166', '205', '213', '221', '254', '264', '268', '283', '292', '296', '320', '344', '389']},{'id': '6', 'type': 'if_statement', 'children': ['7', '12']},{'id': '7', 'type': 'subscript', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '11', 'type': 'string', 'children': [], 'value': "'map'"},{'id': '12', 'type': 'block', 'children': ['13']},{'id': '13', 'type': 'return_statement', 'children': ['14']},{'id': '14', 'type': 'subscript', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '18', 'type': 'string', 'children': [], 'value': "'map'"},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'map_id'},{'id': '22', 'type': 'attribute', 'children': ['23', '30']},{'id': '23', 'type': 'attribute', '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': '_header'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'scenario'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'game_settings'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'map_id'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'instructions'},{'id': '34', 'type': 'attribute', 'children': ['35', '42']},{'id': '35', 'type': 'attribute', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'scenario'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'messages'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'instructions'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '46', 'type': 'call', 'children': ['47', '54']},{'id': '47', 'type': 'attribute', 'children': ['48', '53']},{'id': '48', 'type': 'attribute', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'mgz'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'MAP_SIZES'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'attribute', 'children': ['56', '61']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'map_info'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'size_x'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'dimension'},{'id': '65', 'type': 'attribute', 'children': ['66', '71']},{'id': '66', 'type': 'attribute', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': '_header'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'map_info'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'size_x'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'custom'},{'id': '75', 'type': 'True', 'children': []},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '79', 'type': 'string', 'children': [], 'value': "'Unknown'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '83', 'type': 'None', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '87', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'ENCODING_MARKERS'},{'id': '91', 'type': 'block', 'children': ['92', '98', '104', '113']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'test_encoding'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'e_m'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'test_encoding'},{'id': '113', 'type': 'for_statement', 'children': ['114', '115', '121']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'instructions'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "b'\\n'"},{'id': '121', 'type': 'block', 'children': ['122', '131']},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'e_m'},{'id': '131', 'type': 'if_statement', 'children': ['132', '136']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': '>'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '134', 'type': 'unary_operator', 'children': ['135'], 'value': '-'},{'id': '135', 'type': 'integer', 'children': [], 'value': '1'},{'id': '136', 'type': 'block', 'children': ['137', '141', '159', '165']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'test_encoding'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '144', 'type': 'call', 'children': ['145', '157']},{'id': '145', 'type': 'attribute', 'children': ['146', '156']},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '148', 'type': 'slice', 'children': ['149', '155']},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '+'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'e_m'},{'id': '155', 'type': 'colon', 'children': []},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '164', 'type': 'integer', 'children': [], 'value': '2'},{'id': '165', 'type': 'break_statement', 'children': []},{'id': '166', 'type': 'if_statement', 'children': ['167', '169']},{'id': '167', 'type': 'not_operator', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '169', 'type': 'block', 'children': ['170', '174']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '173', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '174', 'type': 'for_statement', 'children': ['175', '176', '177']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'LANGUAGE_MARKERS'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'if_statement', 'children': ['179', '197']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '195'], 'value': '>'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'instructions'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'subscript', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '194', 'type': 'integer', 'children': [], 'value': '1'},{'id': '195', 'type': 'unary_operator', 'children': ['196'], 'value': '-'},{'id': '196', 'type': 'integer', 'children': [], 'value': '1'},{'id': '197', 'type': 'block', 'children': ['198', '204']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '203', 'type': 'integer', 'children': [], 'value': '2'},{'id': '204', 'type': 'break_statement', 'children': []},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '212']},{'id': '207', 'type': 'subscript', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '210', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '211', 'type': 'string', 'children': [], 'value': "'encoding'"},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '220']},{'id': '215', 'type': 'subscript', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '218', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '219', 'type': 'string', 'children': [], 'value': "'language'"},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'language'},{'id': '221', 'type': 'if_statement', 'children': ['222', '225']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '!='},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'map_id'},{'id': '224', 'type': 'integer', 'children': [], 'value': '44'},{'id': '225', 'type': 'block', 'children': ['226', '240', '250']},{'id': '226', 'type': 'if_statement', 'children': ['227', '234']},{'id': '227', 'type': 'comparison_operator', 'children': ['228', '229'], 'value': 'not'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'map_id'},{'id': '229', 'type': 'attribute', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'mgz'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'MAP_NAMES'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'raise_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'string', 'children': [], 'value': "'unspecified builtin map'"},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '243', 'type': 'subscript', 'children': ['244', '249']},{'id': '244', 'type': 'attribute', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'mgz'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'MAP_NAMES'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'map_id'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'custom'},{'id': '253', 'type': 'False', 'children': []},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263']},{'id': '262', 'type': 'string', 'children': [], 'value': "b'\\x00.*? (\\-?[0-9]+)\\x00.*?\\.rms'"},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'instructions'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '267', 'type': 'None', 'children': []},{'id': '268', 'type': 'if_statement', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '270', 'type': 'block', 'children': ['271']},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'integer', 'children': [], 'value': '1'},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'has_modes'},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'string', 'children': [], 'value': "': !'"},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'mode_string'},{'id': '295', 'type': 'string', 'children': [], 'value': "''"},{'id': '296', 'type': 'if_statement', 'children': ['297', '301']},{'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': '>'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'has_modes'},{'id': '299', 'type': 'unary_operator', 'children': ['300'], 'value': '-'},{'id': '300', 'type': 'integer', 'children': [], 'value': '1'},{'id': '301', 'type': 'block', 'children': ['302', '312']},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'mode_string'},{'id': '305', 'type': 'subscript', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '307', 'type': 'slice', 'children': ['308', '311']},{'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '+'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'has_modes'},{'id': '310', 'type': 'integer', 'children': [], 'value': '3'},{'id': '311', 'type': 'colon', 'children': []},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '315', 'type': 'subscript', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '317', 'type': 'slice', 'children': ['318', '319']},{'id': '318', 'type': 'colon', 'children': []},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'has_modes'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'modes'},{'id': '323', 'type': 'dictionary', 'children': ['324', '329', '334', '339']},{'id': '324', 'type': 'pair', 'children': ['325', '326']},{'id': '325', 'type': 'string', 'children': [], 'value': "'direct_placement'"},{'id': '326', 'type': 'comparison_operator', 'children': ['327', '328'], 'value': 'in'},{'id': '327', 'type': 'string', 'children': [], 'value': "'P'"},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'mode_string'},{'id': '329', 'type': 'pair', 'children': ['330', '331']},{'id': '330', 'type': 'string', 'children': [], 'value': "'effect_quantity'"},{'id': '331', 'type': 'comparison_operator', 'children': ['332', '333'], 'value': 'in'},{'id': '332', 'type': 'string', 'children': [], 'value': "'C'"},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'mode_string'},{'id': '334', 'type': 'pair', 'children': ['335', '336']},{'id': '335', 'type': 'string', 'children': [], 'value': "'guard_state'"},{'id': '336', 'type': 'comparison_operator', 'children': ['337', '338'], 'value': 'in'},{'id': '337', 'type': 'string', 'children': [], 'value': "'G'"},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'mode_string'},{'id': '339', 'type': 'pair', 'children': ['340', '341']},{'id': '340', 'type': 'string', 'children': [], 'value': "'fixed_positions'"},{'id': '341', 'type': 'comparison_operator', 'children': ['342', '343'], 'value': 'in'},{'id': '342', 'type': 'string', 'children': [], 'value': "'F'"},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'mode_string'},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'assignment', 'children': ['346', '351']},{'id': '346', 'type': 'subscript', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '349', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '350', 'type': 'string', 'children': [], 'value': "'map'"},{'id': '351', 'type': 'dictionary', 'children': ['352', '359', '366', '369', '372', '375', '378', '381']},{'id': '352', 'type': 'pair', 'children': ['353', '354']},{'id': '353', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '354', 'type': 'conditional_expression', 'children': ['355', '356', '358'], 'value': 'if'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'map_id'},{'id': '356', 'type': 'not_operator', 'children': ['357']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'custom'},{'id': '358', 'type': 'None', 'children': []},{'id': '359', 'type': 'pair', 'children': ['360', '361']},{'id': '360', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '361', 'type': 'call', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '365', 'type': 'argument_list', 'children': []},{'id': '366', 'type': 'pair', 'children': ['367', '368']},{'id': '367', 'type': 'string', 'children': [], 'value': "'size'"},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '369', 'type': 'pair', 'children': ['370', '371']},{'id': '370', 'type': 'string', 'children': [], 'value': "'dimension'"},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'dimension'},{'id': '372', 'type': 'pair', 'children': ['373', '374']},{'id': '373', 'type': 'string', 'children': [], 'value': "'seed'"},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'seed'},{'id': '375', 'type': 'pair', 'children': ['376', '377']},{'id': '376', 'type': 'string', 'children': [], 'value': "'modes'"},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'modes'},{'id': '378', 'type': 'pair', 'children': ['379', '380']},{'id': '379', 'type': 'string', 'children': [], 'value': "'custom'"},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'custom'},{'id': '381', 'type': 'pair', 'children': ['382', '383']},{'id': '382', 'type': 'string', 'children': [], 'value': "'zr'"},{'id': '383', 'type': 'call', 'children': ['384', '387']},{'id': '384', 'type': 'attribute', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '387', 'type': 'argument_list', 'children': ['388']},{'id': '388', 'type': 'string', 'children': [], 'value': "'ZR@'"},{'id': '389', 'type': 'return_statement', 'children': ['390']},{'id': '390', 'type': 'subscript', 'children': ['391', '394']},{'id': '391', 'type': 'attribute', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '393', 'type': 'identifier', 'children': [], 'value': '_cache'},{'id': '394', 'type': 'string', 'children': [], 'value': "'map'"}
def get_map(self): if self._cache['map']: return self._cache['map'] map_id = self._header.scenario.game_settings.map_id instructions = self._header.scenario.messages.instructions size = mgz.const.MAP_SIZES.get(self._header.map_info.size_x) dimension = self._header.map_info.size_x custom = True name = 'Unknown' language = None encoding = 'unknown' for pair in ENCODING_MARKERS: marker = pair[0] test_encoding = pair[1] e_m = marker.encode(test_encoding) for line in instructions.split(b'\n'): pos = line.find(e_m) if pos > -1: encoding = test_encoding name = line[pos+len(e_m):].decode(encoding) language = pair[2] break if not language: language = 'unknown' for pair in LANGUAGE_MARKERS: if instructions.find(pair[0].encode(pair[1])) > -1: language = pair[2] break self._cache['encoding'] = encoding self._cache['language'] = language if map_id != 44: if map_id not in mgz.const.MAP_NAMES: raise ValueError('unspecified builtin map') name = mgz.const.MAP_NAMES[map_id] custom = False match = re.search(b'\x00.*? (\-?[0-9]+)\x00.*?\.rms', instructions) seed = None if match: seed = int(match.group(1)) has_modes = name.find(': !') mode_string = '' if has_modes > -1: mode_string = name[has_modes + 3:] name = name[:has_modes] modes = { 'direct_placement': 'P' in mode_string, 'effect_quantity': 'C' in mode_string, 'guard_state': 'G' in mode_string, 'fixed_positions': 'F' in mode_string } self._cache['map'] = { 'id': map_id if not custom else None, 'name': name.strip(), 'size': size, 'dimension': dimension, 'seed': seed, 'modes': modes, 'custom': custom, 'zr': name.startswith('ZR@') } return self._cache['map']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '7', 'type': 'typed_default_parameter', 'children': ['8', '9', '11']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'follow_symlinks'},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'typed_default_parameter', 'children': ['13', '14', '16']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'maximum_depth'},{'id': '14', 'type': 'type', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '16', 'type': 'integer', 'children': [], 'value': '20'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '21', 'type': 'block', 'children': ['22', '60', '67']},{'id': '22', 'type': 'if_statement', 'children': ['23', '30']},{'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': 'source'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '30', 'type': 'block', 'children': ['31', '45', '59']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '44']},{'id': '33', 'type': 'subscript', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'path_map'},{'id': '37', 'type': 'attribute', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '58']},{'id': '47', 'type': 'subscript', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'class_cache'},{'id': '51', 'type': 'attribute', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '59', 'type': 'continue_statement', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '67', 'type': 'if_statement', 'children': ['68', '80', '109']},{'id': '68', 'type': 'call', 'children': ['69', '76']},{'id': '69', 'type': 'attribute', 'children': ['70', '75']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'tuple', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'.zip'"},{'id': '79', 'type': 'string', 'children': [], 'value': "'.jar'"},{'id': '80', 'type': 'block', 'children': ['81', '89']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'zf'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ZipFile'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '88', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'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': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'path_map'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '99', 'type': 'argument_list', 'children': ['100', '105']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'zf'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'namelist'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'zf'},{'id': '109', 'type': 'elif_clause', 'children': ['110', '118']},{'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': 'os'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '118', 'type': 'block', 'children': ['119', '132']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': '_walk'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126', '129']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'follow_links'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'follow_symlinks'},{'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'maximum_depth'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'maximum_depth'},{'id': '132', 'type': 'for_statement', 'children': ['133', '137', '138']},{'id': '133', 'type': 'pattern_list', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'walker'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'for_statement', 'children': ['140', '141', '142']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'file_'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '142', 'type': 'block', 'children': ['143', '155', '167']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'path_full'},{'id': '146', 'type': 'call', 'children': ['147', '152']},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '152', 'type': 'argument_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'file_'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'path_suffix'},{'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': 'os'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'relpath'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'path_full'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'source'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '174']},{'id': '169', 'type': 'subscript', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'path_map'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'path_suffix'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'path_full'}
def update(self, *sources, follow_symlinks: bool=False, maximum_depth: int=20): for source in sources: if isinstance(source, self.klass): self.path_map[source.this.name.value] = source self.class_cache[source.this.name.value] = source continue source = str(source) if source.lower().endswith(('.zip', '.jar')): zf = ZipFile(source, 'r') self.path_map.update(zip(zf.namelist(), repeat(zf))) elif os.path.isdir(source): walker = _walk( source, follow_links=follow_symlinks, maximum_depth=maximum_depth ) for root, dirs, files in walker: for file_ in files: path_full = os.path.join(root, file_) path_suffix = os.path.relpath(path_full, source) self.path_map[path_suffix] = path_full
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'error_view'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'template_dir'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '16', '22', '212']},{'id': '8', 'type': 'if_statement', 'children': ['9', '11']},{'id': '9', 'type': 'not_operator', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'template_dir'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'template_dir'},{'id': '15', 'type': 'string', 'children': [], 'value': '"Pylot/Error"'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'template_page'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '%'},{'id': '20', 'type': 'string', 'children': [], 'value': '"%s/index.html"'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'template_dir'},{'id': '22', 'type': 'class_definition', 'children': ['23', '24', '26']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Error'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'Pylot'},{'id': '26', 'type': 'block', 'children': ['27', '177']},{'id': '27', 'type': 'decorated_definition', 'children': ['28', '30']},{'id': '28', 'type': 'decorator', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'classmethod'},{'id': '30', 'type': 'function_definition', 'children': ['31', '32', '37']},{'id': '31', 'type': 'function_name', 'children': [], 'value': 'register'},{'id': '32', 'type': 'parameters', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '35', 'type': 'dictionary_splat_pattern', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '37', 'type': 'block', 'children': ['38', '51', '72', '93', '114', '135', '156']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '47']},{'id': '40', 'type': 'attribute', 'children': ['41', '46']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '49', 'type': 'dictionary_splat', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '51', 'type': 'decorated_definition', 'children': ['52', '59']},{'id': '52', 'type': 'decorator', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'errorhandler'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'integer', 'children': [], 'value': '400'},{'id': '59', 'type': 'function_definition', 'children': ['60', '61', '63']},{'id': '60', 'type': 'function_name', 'children': [], 'value': 'error_400'},{'id': '61', 'type': 'parameters', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '71', 'type': 'integer', 'children': [], 'value': '400'},{'id': '72', 'type': 'decorated_definition', 'children': ['73', '80']},{'id': '73', 'type': 'decorator', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'errorhandler'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'integer', 'children': [], 'value': '401'},{'id': '80', 'type': 'function_definition', 'children': ['81', '82', '84']},{'id': '81', 'type': 'function_name', 'children': [], 'value': 'error_401'},{'id': '82', 'type': 'parameters', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'return_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '92', 'type': 'integer', 'children': [], 'value': '401'},{'id': '93', 'type': 'decorated_definition', 'children': ['94', '101']},{'id': '94', 'type': 'decorator', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'errorhandler'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'integer', 'children': [], 'value': '403'},{'id': '101', 'type': 'function_definition', 'children': ['102', '103', '105']},{'id': '102', 'type': 'function_name', 'children': [], 'value': 'error_403'},{'id': '103', 'type': 'parameters', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'return_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '113', 'type': 'integer', 'children': [], 'value': '403'},{'id': '114', 'type': 'decorated_definition', 'children': ['115', '122']},{'id': '115', 'type': 'decorator', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'errorhandler'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'integer', 'children': [], 'value': '404'},{'id': '122', 'type': 'function_definition', 'children': ['123', '124', '126']},{'id': '123', 'type': 'function_name', 'children': [], 'value': 'error_404'},{'id': '124', 'type': 'parameters', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '134', 'type': 'integer', 'children': [], 'value': '404'},{'id': '135', 'type': 'decorated_definition', 'children': ['136', '143']},{'id': '136', 'type': 'decorator', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'errorhandler'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'integer', 'children': [], 'value': '500'},{'id': '143', 'type': 'function_definition', 'children': ['144', '145', '147']},{'id': '144', 'type': 'function_name', 'children': [], 'value': 'error_500'},{'id': '145', 'type': 'parameters', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '153', 'type': 'argument_list', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '155', 'type': 'integer', 'children': [], 'value': '500'},{'id': '156', 'type': 'decorated_definition', 'children': ['157', '164']},{'id': '157', 'type': 'decorator', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'errorhandler'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'integer', 'children': [], 'value': '503'},{'id': '164', 'type': 'function_definition', 'children': ['165', '166', '168']},{'id': '165', 'type': 'function_name', 'children': [], 'value': 'error_503'},{'id': '166', 'type': 'parameters', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '168', 'type': 'block', 'children': ['169']},{'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': 'cls'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '176', 'type': 'integer', 'children': [], 'value': '503'},{'id': '177', 'type': 'decorated_definition', 'children': ['178', '180']},{'id': '178', 'type': 'decorator', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'classmethod'},{'id': '180', 'type': 'function_definition', 'children': ['181', '182', '186']},{'id': '181', 'type': 'function_name', 'children': [], 'value': 'index'},{'id': '182', 'type': 'parameters', 'children': ['183', '184', '185']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '186', 'type': 'block', 'children': ['187', '198']},{'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': 'cls'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'meta_'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '%'},{'id': '196', 'type': 'string', 'children': [], 'value': '"Error %s"'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '198', 'type': 'return_statement', 'children': ['199']},{'id': '199', 'type': 'expression_list', 'children': ['200', '211']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'render'},{'id': '204', 'type': 'argument_list', 'children': ['205', '208']},{'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'view_template'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'template_page'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '212', 'type': 'return_statement', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'Error'}
def error_view(template_dir=None): if not template_dir: template_dir = "Pylot/Error" template_page = "%s/index.html" % template_dir class Error(Pylot): @classmethod def register(cls, app, **kwargs): super(cls, cls).register(app, **kwargs) @app.errorhandler(400) def error_400(error): return cls.index(error, 400) @app.errorhandler(401) def error_401(error): return cls.index(error, 401) @app.errorhandler(403) def error_403(error): return cls.index(error, 403) @app.errorhandler(404) def error_404(error): return cls.index(error, 404) @app.errorhandler(500) def error_500(error): return cls.index(error, 500) @app.errorhandler(503) def error_503(error): return cls.index(error, 503) @classmethod def index(cls, error, code): cls.meta_(title="Error %s" % code) return cls.render(error=error, view_template=template_page), code return Error
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_device_list'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '6', 'type': 'block', 'children': ['7', '20', '24', '28', '32', '217', '262']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'is'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '19']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': "'Error updating Emby devices.'"},{'id': '19', 'type': 'return_statement', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'new_devices'},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'active_devices'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'dev_update'},{'id': '31', 'type': 'False', 'children': []},{'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sessions'},{'id': '35', 'type': 'block', 'children': ['36', '50', '74', '81']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'{}.{}'"},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '43', 'type': 'argument_list', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '46', 'type': 'string', 'children': [], 'value': "'DeviceId'"},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '49', 'type': 'string', 'children': [], 'value': "'Client'"},{'id': '50', 'type': 'try_statement', 'children': ['51', '70']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': '_LOGGER'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59', '60', '65']},{'id': '58', 'type': 'string', 'children': [], 'value': "'Session msg on %s of type: %s, themeflag: %s'"},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '63', 'type': 'string', 'children': [], 'value': "'NowPlayingItem'"},{'id': '64', 'type': 'string', 'children': [], 'value': "'Type'"},{'id': '65', 'type': 'subscript', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '68', 'type': 'string', 'children': [], 'value': "'NowPlayingItem'"},{'id': '69', 'type': 'string', 'children': [], 'value': "'IsThemeMedia'"},{'id': '70', 'type': 'except_clause', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'pass_statement', 'children': []},{'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': 'active_devices'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '81', 'type': 'if_statement', 'children': ['82', '99', '131']},{'id': '82', 'type': 'boolean_operator', 'children': ['83', '88', '89'], 'value': 'and'},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'not'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_devices'},{'id': '88', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '!='},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '92', 'type': 'string', 'children': [], 'value': "'DeviceId'"},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_api_id'},{'id': '99', 'type': 'block', 'children': ['100', '108', '116', '124']},{'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': '_LOGGER'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'string', 'children': [], 'value': "'New Emby DeviceID: %s. Adding to device list.'"},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'EmbyDevice'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '123']},{'id': '118', 'type': 'subscript', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_devices'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'new_devices'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'new'},{'id': '131', 'type': 'elif_clause', 'children': ['132', '142']},{'id': '132', 'type': 'comparison_operator', 'children': ['133', '136'], 'value': '!='},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '135', 'type': 'string', 'children': [], 'value': "'DeviceId'"},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_api_id'},{'id': '142', 'type': 'block', 'children': ['143', '157', '171', '182', '193', '207']},{'id': '143', 'type': 'if_statement', 'children': ['144', '152']},{'id': '144', 'type': 'not_operator', 'children': ['145']},{'id': '145', 'type': 'attribute', 'children': ['146', '151']},{'id': '146', 'type': 'subscript', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'identifier', 'children': [], 'value': '_devices'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'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': 'dev_update'},{'id': '156', 'type': 'True', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'do_update'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'update_check'},{'id': '164', 'type': 'argument_list', 'children': ['165', '170']},{'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': '_devices'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '180']},{'id': '173', 'type': 'attribute', 'children': ['174', '179']},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_devices'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'update_data'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'device'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '191']},{'id': '184', 'type': 'attribute', 'children': ['185', '190']},{'id': '185', 'type': 'subscript', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': '_devices'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'set_active'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'True', 'children': []},{'id': '193', 'type': 'if_statement', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'dev_update'},{'id': '195', 'type': 'block', 'children': ['196', '203']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': '_do_new_devices_callback'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'integer', 'children': [], 'value': '0'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'dev_update'},{'id': '206', 'type': 'False', 'children': []},{'id': '207', 'type': 'if_statement', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'do_update'},{'id': '209', 'type': 'block', 'children': ['210']},{'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': '_do_update_callback'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'dev_name'},{'id': '217', 'type': 'for_statement', 'children': ['218', '219', '222']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'dev_id'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': '_devices'},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'if_statement', 'children': ['224', '227']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': 'not'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'dev_id'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'active_devices'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'if_statement', 'children': ['229', '236']},{'id': '229', 'type': 'attribute', 'children': ['230', '235']},{'id': '230', 'type': 'subscript', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': '_devices'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'dev_id'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'is_active'},{'id': '236', 'type': 'block', 'children': ['237', '248', '255']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '246']},{'id': '239', 'type': 'attribute', 'children': ['240', '245']},{'id': '240', 'type': 'subscript', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_devices'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'dev_id'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'set_active'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'False', 'children': []},{'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': 'self'},{'id': '252', 'type': 'identifier', 'children': [], 'value': '_do_update_callback'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'dev_id'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'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': '_do_stale_devices_callback'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'dev_id'},{'id': '262', 'type': 'if_statement', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'new_devices'},{'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': 'self'},{'id': '269', 'type': 'identifier', 'children': [], 'value': '_do_new_devices_callback'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'integer', 'children': [], 'value': '0'}
def update_device_list(self, sessions): if sessions is None: _LOGGER.error('Error updating Emby devices.') return new_devices = [] active_devices = [] dev_update = False for device in sessions: dev_name = '{}.{}'.format(device['DeviceId'], device['Client']) try: _LOGGER.debug('Session msg on %s of type: %s, themeflag: %s', dev_name, device['NowPlayingItem']['Type'], device['NowPlayingItem']['IsThemeMedia']) except KeyError: pass active_devices.append(dev_name) if dev_name not in self._devices and \ device['DeviceId'] != str(self._api_id): _LOGGER.debug('New Emby DeviceID: %s. Adding to device list.', dev_name) new = EmbyDevice(device, self) self._devices[dev_name] = new new_devices.append(new) elif device['DeviceId'] != str(self._api_id): if not self._devices[dev_name].is_active: dev_update = True do_update = self.update_check( self._devices[dev_name], device) self._devices[dev_name].update_data(device) self._devices[dev_name].set_active(True) if dev_update: self._do_new_devices_callback(0) dev_update = False if do_update: self._do_update_callback(dev_name) for dev_id in self._devices: if dev_id not in active_devices: if self._devices[dev_id].is_active: self._devices[dev_id].set_active(False) self._do_update_callback(dev_id) self._do_stale_devices_callback(dev_id) if new_devices: self._do_new_devices_callback(0)
{'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', '11', '19', '25', '33', '43', '53', '140', '181', '194', '200', '296', '327', '338', '353']},{'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', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'get_parser'},{'id': '10', 'type': 'argument_list', 'children': []},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'args'},{'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': 'parse_args'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ARCHIVE'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'archive_path'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'archive'},{'id': '28', 'type': '()', 'children': ['29']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'no_archive'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '40']},{'id': '35', 'type': 'subscript', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '39', 'type': 'string', 'children': [], 'value': "'F2FORMAT_VERSION'"},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'python'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '50']},{'id': '45', 'type': 'subscript', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '49', 'type': 'string', 'children': [], 'value': "'F2FORMAT_ENCODING'"},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '53', 'type': 'function_definition', 'children': ['54', '55', '57']},{'id': '54', 'type': 'function_name', 'children': [], 'value': 'find'},{'id': '55', 'type': 'parameters', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '57', 'type': 'block', 'children': ['58', '64', '73', '137']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'flst'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'temp'},{'id': '76', 'type': 'block', 'children': ['77', '89']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'root'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '89', 'type': 'if_statement', 'children': ['90', '98', '109', '126']},{'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': 'isdir'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'flst'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '109', 'type': 'elif_clause', 'children': ['110', '118']},{'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': 'os'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'flst'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '126', 'type': 'elif_clause', 'children': ['127', '135']},{'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': 'os'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'islink'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'continue_statement', 'children': []},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'yield', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'flst'},{'id': '140', 'type': 'function_definition', 'children': ['141', '142', '144']},{'id': '141', 'type': 'function_name', 'children': [], 'value': 'rename'},{'id': '142', 'type': 'parameters', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '144', 'type': 'block', 'children': ['145', '158', '171']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '150']},{'id': '147', 'type': 'pattern_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '150', 'type': 'call', 'children': ['151', '156']},{'id': '151', 'type': 'attribute', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '%'},{'id': '162', 'type': 'string', 'children': [], 'value': "'%s-%s%s'"},{'id': '163', 'type': 'tuple', 'children': ['164', '165', '170']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'stem'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'uuid'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'uuid4'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '171', 'type': 'return_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '178']},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'ARCHIVE'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '181', 'type': 'if_statement', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'archive'},{'id': '183', 'type': 'block', 'children': ['184']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '189', 'type': 'argument_list', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'ARCHIVE'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'exist_ok'},{'id': '193', 'type': 'True', 'children': []},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'filelist'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '209']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '202', 'type': 'subscript', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'argv'},{'id': '206', 'type': 'slice', 'children': ['207', '208']},{'id': '207', 'type': 'integer', 'children': [], 'value': '1'},{'id': '208', 'type': 'colon', 'children': []},{'id': '209', 'type': 'block', 'children': ['210', '262']},{'id': '210', 'type': 'if_statement', 'children': ['211', '219']},{'id': '211', 'type': 'call', 'children': ['212', '217']},{'id': '212', 'type': 'attribute', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '219', 'type': 'block', 'children': ['220', '255']},{'id': '220', 'type': 'if_statement', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'archive'},{'id': '222', 'type': 'block', 'children': ['223', '230', '247']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '226', 'type': 'call', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'rename'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'makedirs'},{'id': '235', 'type': 'argument_list', 'children': ['236', '244']},{'id': '236', 'type': 'call', 'children': ['237', '242']},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'exist_ok'},{'id': '246', 'type': 'True', 'children': []},{'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': 'shutil'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '252', 'type': 'argument_list', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'filelist'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '262', 'type': 'if_statement', 'children': ['263', '271']},{'id': '263', 'type': 'call', 'children': ['264', '269']},{'id': '264', 'type': 'attribute', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '271', 'type': 'block', 'children': ['272', '286']},{'id': '272', 'type': 'if_statement', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'archive'},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'shutil'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'copytree'},{'id': '280', 'type': 'argument_list', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'rename'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'filelist'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '296', 'type': 'function_definition', 'children': ['297', '298', '300']},{'id': '297', 'type': 'function_name', 'children': [], 'value': 'ispy'},{'id': '298', 'type': 'parameters', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '300', 'type': 'block', 'children': ['301']},{'id': '301', 'type': 'return_statement', 'children': ['302']},{'id': '302', 'type': '()', 'children': ['303']},{'id': '303', 'type': 'boolean_operator', 'children': ['304', '312'], 'value': 'and'},{'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': 'os'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '312', 'type': '()', 'children': ['313']},{'id': '313', 'type': 'comparison_operator', 'children': ['314', '324'], 'value': 'in'},{'id': '314', 'type': 'subscript', 'children': ['315', '323']},{'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': 'os'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '323', 'type': 'integer', 'children': [], 'value': '1'},{'id': '324', 'type': 'tuple', 'children': ['325', '326']},{'id': '325', 'type': 'string', 'children': [], 'value': "'.py'"},{'id': '326', 'type': 'string', 'children': [], 'value': "'.pyw'"},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'assignment', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'filelist'},{'id': '330', 'type': 'call', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '332', 'type': 'argument_list', 'children': ['333']},{'id': '333', 'type': 'call', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '335', 'type': 'argument_list', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'ispy'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'filelist'},{'id': '338', 'type': 'if_statement', 'children': ['339', '345']},{'id': '339', 'type': 'comparison_operator', 'children': ['340', '344'], 'value': '=='},{'id': '340', 'type': 'call', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'filelist'},{'id': '344', 'type': 'integer', 'children': [], 'value': '0'},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'string', 'children': [], 'value': "'argument PATH: no valid source file found'"},{'id': '353', 'type': 'if_statement', 'children': ['354', '361', '371']},{'id': '354', 'type': 'boolean_operator', 'children': ['355', '358'], 'value': 'or'},{'id': '355', 'type': 'comparison_operator', 'children': ['356', '357'], 'value': 'is'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'mp'},{'id': '357', 'type': 'None', 'children': []},{'id': '358', 'type': 'comparison_operator', 'children': ['359', '360'], 'value': '<='},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'CPU_CNT'},{'id': '360', 'type': 'integer', 'children': [], 'value': '1'},{'id': '361', 'type': 'block', 'children': ['362']},{'id': '362', 'type': 'expression_statement', 'children': ['363']},{'id': '363', 'type': 'list_comprehension', 'children': ['364', '368']},{'id': '364', 'type': 'call', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'f2format'},{'id': '366', 'type': 'argument_list', 'children': ['367']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '368', 'type': 'for_in_clause', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'filelist'},{'id': '371', 'type': 'else_clause', 'children': ['372']},{'id': '372', 'type': 'block', 'children': ['373']},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '385']},{'id': '375', 'type': 'attribute', 'children': ['376', '384']},{'id': '376', 'type': 'call', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'mp'},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'Pool'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'keyword_argument', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'processes'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'CPU_CNT'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '385', 'type': 'argument_list', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'f2format'},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'filelist'}
def main(): parser = get_parser() args = parser.parse_args() ARCHIVE = args.archive_path archive = (not args.no_archive) os.environ['F2FORMAT_VERSION'] = args.python os.environ['F2FORMAT_ENCODING'] = args.encoding def find(root): flst = list() temp = os.listdir(root) for file in temp: path = os.path.join(root, file) if os.path.isdir(path): flst.extend(find(path)) elif os.path.isfile(path): flst.append(path) elif os.path.islink(path): continue yield from flst def rename(path): stem, ext = os.path.splitext(path) name = '%s-%s%s' % (stem, uuid.uuid4(), ext) return os.path.join(ARCHIVE, name) if archive: os.makedirs(ARCHIVE, exist_ok=True) filelist = list() for path in sys.argv[1:]: if os.path.isfile(path): if archive: dest = rename(path) os.makedirs(os.path.dirname(dest), exist_ok=True) shutil.copy(path, dest) filelist.append(path) if os.path.isdir(path): if archive: shutil.copytree(path, rename(path)) filelist.extend(find(path)) def ispy(file): return (os.path.isfile(file) and (os.path.splitext(file)[1] in ('.py', '.pyw'))) filelist = sorted(filter(ispy, filelist)) if len(filelist) == 0: parser.error('argument PATH: no valid source file found') if mp is None or CPU_CNT <= 1: [f2format(filename) for filename in filelist] else: mp.Pool(processes=CPU_CNT).map(f2format, filelist)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'random_useragent'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '6', 'type': 'True', 'children': []},{'id': '7', 'type': 'block', 'children': ['8', '11', '17', '35', '47', '90', '205']},{'id': '8', 'type': 'import_statement', 'children': ['9']},{'id': '9', 'type': 'dotted_name', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'default_ua'},{'id': '14', 'type': 'binary_operator', 'children': ['15', '16'], 'value': '%'},{'id': '15', 'type': 'string', 'children': [], 'value': "'urlfetch/%s'"},{'id': '16', 'type': 'identifier', 'children': [], 'value': '__version__'},{'id': '17', 'type': 'if_statement', 'children': ['18', '23', '29']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '27', 'type': 'list', 'children': ['28'], 'value': '[filename]'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '29', 'type': 'else_clause', 'children': ['30']},{'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': 'filenames'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '38'], 'value': 'and'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'UAFILE'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'UAFILE'},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '50', '86']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'filenames'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'try_statement', 'children': ['52', '83']},{'id': '52', 'type': 'block', 'children': ['53', '62']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '62', 'type': 'if_statement', 'children': ['63', '81']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '72'], 'value': 'and'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'S_ISREG'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'st_mode'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'access'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'R_OK'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'break_statement', 'children': []},{'id': '83', 'type': 'except_clause', 'children': ['84']},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'pass_statement', 'children': []},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'default_ua'},{'id': '90', 'type': 'with_statement', 'children': ['91', '101']},{'id': '91', 'type': 'with_clause', 'children': ['92']},{'id': '92', 'type': 'with_item', 'children': ['93']},{'id': '93', 'type': 'as_pattern', 'children': ['94', '99']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '96', 'type': 'argument_list', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '98', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '99', 'type': 'as_pattern_target', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '101', 'type': 'block', 'children': ['102', '108', '112', '120']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'filesize'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'st'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'st_size'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '111', 'type': 'integer', 'children': [], 'value': '0'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'Random'},{'id': '119', 'type': 'argument_list', 'children': []},{'id': '120', 'type': 'for_statement', 'children': ['121', '122', '126']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'integer', 'children': [], 'value': '3'},{'id': '126', 'type': 'block', 'children': ['127', '137', '141', '148', '154', '162', '190', '198']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'augmented_assignment', 'children': ['129', '130'], 'value': '+='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'randint'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136']},{'id': '135', 'type': 'integer', 'children': [], 'value': '0'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'filesize'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'augmented_assignment', 'children': ['139', '140'], 'value': '%='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'filesize'},{'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': 'f'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'pos'},{'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': 'f'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'if_statement', 'children': ['163', '165']},{'id': '163', 'type': 'not_operator', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'if_statement', 'children': ['167', '174']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '173'], 'value': '=='},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'filesize'},{'id': '174', 'type': 'block', 'children': ['175', '182']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '189', 'type': 'argument_list', 'children': []},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'ERROR', 'children': ['199', '200', '203', '204']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '202', 'type': 'integer', 'children': [], 'value': '0'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'return'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '205', 'type': 'return_statement', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'default_ua'}
def random_useragent(filename=True): import random default_ua = 'urlfetch/%s' % __version__ if isinstance(filename, basestring): filenames = [filename] else: filenames = [] if filename and UAFILE: filenames.append(UAFILE) for filename in filenames: try: st = os.stat(filename) if stat.S_ISREG(st.st_mode) and os.access(filename, os.R_OK): break except: pass else: return default_ua with open(filename, 'rb') as f: filesize = st.st_size pos = 0 r = random.Random() for i in range(3): pos += r.randint(0, filesize) pos %= filesize f.seek(pos) f.readline() line = f.readline() if not line: if f.tell() == filesize: f.seek(0) line = f.readline() line = line.strip() if line and line[0] != ' return line return default_ua
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'encode_multipart'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '28', '39', '153', '329', '343', '349']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'BytesIO'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'boundary'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'choose_boundary'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'part_boundary'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'},{'id': '26', 'type': 'string', 'children': [], 'value': "'--%s\\r\\n'"},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'boundary'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '31', 'type': 'subscript', 'children': ['32', '38']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'codecs'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'lookup'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '38', 'type': 'integer', 'children': [], 'value': '3'},{'id': '39', 'type': 'if_statement', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'for_statement', 'children': ['47', '50', '55']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'block', 'children': ['56', '72']},{'id': '56', 'type': 'if_statement', 'children': ['57', '66']},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'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': 'values'},{'id': '62', 'type': 'tuple', 'children': ['63', '64', '65']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '70', 'type': 'tuple', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '75', 'type': 'block', 'children': ['76', '83', '97', '104', '118', '146']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'part_boundary'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '91']},{'id': '85', 'type': 'attribute', 'children': ['86', '90']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'binary_operator', 'children': ['93', '96'], 'value': '%'},{'id': '93', 'type': 'concatenated_string', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "'Content-Disposition: form-data; '"},{'id': '95', 'type': 'string', 'children': [], 'value': '\'name="%s"\\r\\n\''},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'string', 'children': [], 'value': "b'Content-Type: text/plain\\r\\n\\r\\n'"},{'id': '104', 'type': 'if_statement', 'children': ['105', '110']},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '107', 'type': 'argument_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '118', 'type': 'if_statement', 'children': ['119', '126', '137']},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '121'], 'value': 'and'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'py3k'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '135']},{'id': '129', 'type': 'attribute', 'children': ['130', '134']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '137', 'type': 'else_clause', 'children': ['138']},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'string', 'children': [], 'value': "b'\\r\\n'"},{'id': '153', 'type': 'for_statement', 'children': ['154', '157', '162']},{'id': '154', 'type': 'pattern_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'fieldname'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'block', 'children': ['163', '203', '238', '245', '294', '322']},{'id': '163', 'type': 'if_statement', 'children': ['164', '169', '176', '192']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '175']},{'id': '172', 'type': 'pattern_list', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '176', 'type': 'elif_clause', 'children': ['177', '182']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '179', 'type': 'argument_list', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '181', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'id': '193', 'type': 'block', 'children': ['194', '198']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '197', 'type': 'None', 'children': []},{'id': '198', 'type': 'raise_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'UrlfetchException'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'string', 'children': [], 'value': '"file must has filename"'},{'id': '203', 'type': 'if_statement', 'children': ['204', '209', '218', '229']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '208', 'type': 'string', 'children': [], 'value': "'read'"},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'elif_clause', 'children': ['219', '224']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '229', 'type': 'else_clause', 'children': ['230']},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'call', 'children': ['240', '243']},{'id': '240', 'type': 'attribute', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'part_boundary'},{'id': '245', 'type': 'if_statement', 'children': ['246', '247', '271']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '247', 'type': 'block', 'children': ['248', '264']},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '256']},{'id': '250', 'type': 'attribute', 'children': ['251', '255']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'binary_operator', 'children': ['258', '261'], 'value': '%'},{'id': '258', 'type': 'concatenated_string', 'children': ['259', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': '\'Content-Disposition: form-data; name="%s"; \''},{'id': '260', 'type': 'string', 'children': [], 'value': '\'filename="%s"\\r\\n\''},{'id': '261', 'type': 'tuple', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'fieldname'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'filename'},{'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': 'body'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'string', 'children': [], 'value': "b'Content-Type: application/octet-stream\\r\\n\\r\\n'"},{'id': '271', 'type': 'else_clause', 'children': ['272']},{'id': '272', 'type': 'block', 'children': ['273', '287']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '281']},{'id': '275', 'type': 'attribute', 'children': ['276', '280']},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'binary_operator', 'children': ['283', '286'], 'value': '%'},{'id': '283', 'type': 'concatenated_string', 'children': ['284', '285']},{'id': '284', 'type': 'string', 'children': [], 'value': '\'Content-Disposition: form-data; name="%s"\''},{'id': '285', 'type': 'string', 'children': [], 'value': "'\\r\\n'"},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'name'},{'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': 'body'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'string', 'children': [], 'value': "b'Content-Type: text/plain\\r\\n\\r\\n'"},{'id': '294', 'type': 'if_statement', 'children': ['295', '302', '313']},{'id': '295', 'type': 'boolean_operator', 'children': ['296', '297'], 'value': 'and'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'py3k'},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '299', 'type': 'argument_list', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '302', 'type': 'block', 'children': ['303']},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '311']},{'id': '305', 'type': 'attribute', 'children': ['306', '310']},{'id': '306', 'type': 'call', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '313', 'type': 'else_clause', 'children': ['314']},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'call', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'string', 'children': [], 'value': "b'\\r\\n'"},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'call', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'binary_operator', 'children': ['339', '342'], 'value': '+'},{'id': '339', 'type': 'binary_operator', 'children': ['340', '341'], 'value': '+'},{'id': '340', 'type': 'string', 'children': [], 'value': "'--'"},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'boundary'},{'id': '342', 'type': 'string', 'children': [], 'value': "'--\\r\\n'"},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'assignment', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'content_type'},{'id': '346', 'type': 'binary_operator', 'children': ['347', '348'], 'value': '%'},{'id': '347', 'type': 'string', 'children': [], 'value': "'multipart/form-data; boundary=%s'"},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'boundary'},{'id': '349', 'type': 'return_statement', 'children': ['350']},{'id': '350', 'type': 'expression_list', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'content_type'},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'body'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'getvalue'},{'id': '356', 'type': 'argument_list', 'children': []}
def encode_multipart(data, files): body = BytesIO() boundary = choose_boundary() part_boundary = b('--%s\r\n' % boundary) writer = codecs.lookup('utf-8')[3] if isinstance(data, dict): for name, values in data.items(): if not isinstance(values, (list, tuple, set)): values = (values, ) for value in values: body.write(part_boundary) writer(body).write('Content-Disposition: form-data; ' 'name="%s"\r\n' % name) body.write(b'Content-Type: text/plain\r\n\r\n') if isinstance(value, int): value = str(value) if py3k and isinstance(value, str): writer(body).write(value) else: body.write(value) body.write(b'\r\n') for fieldname, f in files.items(): if isinstance(f, tuple): filename, f = f elif hasattr(f, 'name'): filename = basename(f.name) else: filename = None raise UrlfetchException("file must has filename") if hasattr(f, 'read'): value = f.read() elif isinstance(f, basestring): value = f else: value = str(f) body.write(part_boundary) if filename: writer(body).write('Content-Disposition: form-data; name="%s"; ' 'filename="%s"\r\n' % (fieldname, filename)) body.write(b'Content-Type: application/octet-stream\r\n\r\n') else: writer(body).write('Content-Disposition: form-data; name="%s"' '\r\n' % name) body.write(b'Content-Type: text/plain\r\n\r\n') if py3k and isinstance(value, str): writer(body).write(value) else: body.write(value) body.write(b'\r\n') body.write(b('--' + boundary + '--\r\n')) content_type = 'multipart/form-data; boundary=%s' % boundary return content_type, body.getvalue()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'assemble'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '5', 'type': 'block', 'children': ['6', '10', '158', '162', '166', '195', '199']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '13', 'type': 'block', 'children': ['14', '29', '43', '51', '55', '145']},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Label'},{'id': '20', 'type': 'block', 'children': ['21', '28']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '28', 'type': 'continue_statement', 'children': []},{'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': 'mnemonic'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '34', 'type': 'expression_list', 'children': ['35', '38']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '37', 'type': 'integer', 'children': [], 'value': '0'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '40', 'type': 'slice', 'children': ['41', '42']},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'colon', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'operand_fmts'},{'id': '46', 'type': 'subscript', 'children': ['47', '50']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'opcode_table'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'mnemonic'},{'id': '50', 'type': 'string', 'children': [], 'value': "'operands'"},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '54', 'type': 'list', 'children': [], 'value': '[]'},{'id': '55', 'type': 'for_statement', 'children': ['56', '59', '63']},{'id': '56', 'type': 'pattern_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'if_statement', 'children': ['65', '70', '78', '100', '114', '128']},{'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': 'operand'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '70', 'type': 'block', 'children': ['71']},{'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': 'final_operands'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '78', 'type': 'elif_clause', 'children': ['79', '84']},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '81', 'type': 'argument_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'Constant'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '93', 'type': 'argument_list', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'OperandTypes'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'CONSTANT_INDEX'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '100', 'type': 'elif_clause', 'children': ['101', '106']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '114', 'type': 'elif_clause', 'children': ['115', '120']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'Label'},{'id': '120', 'type': 'block', 'children': ['121']},{'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': 'final_operands'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '128', 'type': 'else_clause', 'children': ['129']},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '138', 'type': 'argument_list', 'children': ['139', '144']},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'operand_fmts'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'operand'},{'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': 'final'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'Instruction'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'create'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'mnemonic'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'label_pcs'},{'id': '161', 'type': 'dictionary', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'for_statement', 'children': ['167', '168', '169']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '169', 'type': 'block', 'children': ['170', '186']},{'id': '170', 'type': 'if_statement', 'children': ['171', '176']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'Label'},{'id': '176', 'type': 'block', 'children': ['177', '185']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '184']},{'id': '179', 'type': 'subscript', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'label_pcs'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '185', 'type': 'continue_statement', 'children': []},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'augmented_assignment', 'children': ['188', '189'], 'value': '+='},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'size_on_disk'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '198', 'type': 'integer', 'children': [], 'value': '0'},{'id': '199', 'type': 'for_statement', 'children': ['200', '201', '202']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'final'},{'id': '202', 'type': 'block', 'children': ['203', '211', '287', '296']},{'id': '203', 'type': 'if_statement', 'children': ['204', '209']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'Label'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'continue_statement', 'children': []},{'id': '211', 'type': 'for_statement', 'children': ['212', '215', '221']},{'id': '212', 'type': 'pattern_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'if_statement', 'children': ['223', '228', '262']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'for_statement', 'children': ['230', '233', '238']},{'id': '230', 'type': 'pattern_list', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '237', 'type': 'argument_list', 'children': []},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'if_statement', 'children': ['240', '245']},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '242', 'type': 'argument_list', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'Label'},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '251']},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255']},{'id': '254', 'type': 'integer', 'children': [], 'value': '40'},{'id': '255', 'type': 'binary_operator', 'children': ['256', '261'], 'value': '-'},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'label_pcs'},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '262', 'type': 'elif_clause', 'children': ['263', '268']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'Label'},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '276']},{'id': '271', 'type': 'subscript', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '276', 'type': 'call', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '278', 'type': 'argument_list', 'children': ['279', '280']},{'id': '279', 'type': 'integer', 'children': [], 'value': '40'},{'id': '280', 'type': 'binary_operator', 'children': ['281', '286'], 'value': '-'},{'id': '281', 'type': 'subscript', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'label_pcs'},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'operand'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'augmented_assignment', 'children': ['289', '290'], 'value': '+='},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'size_on_disk'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'current_pc'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'yield', 'children': ['298']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'ins'}
def assemble(code): final = [] for line in code: if isinstance(line, Label): final.append(line) continue mnemonic, operands = line[0], line[1:] operand_fmts = opcode_table[mnemonic]['operands'] final_operands = [] for i, operand in enumerate(operands): if isinstance(operand, Operand): final_operands.append(operand) elif isinstance(operand, Constant): final_operands.append(Operand( OperandTypes.CONSTANT_INDEX, operand.index )) elif isinstance(operand, dict): final_operands.append(operand) elif isinstance(operand, Label): final_operands.append(operand) else: final_operands.append(Operand( operand_fmts[i][1], operand )) final.append(Instruction.create(mnemonic, final_operands)) label_pcs = {} current_pc = 0 for ins in final: if isinstance(ins, Label): label_pcs[ins.name] = current_pc continue current_pc += ins.size_on_disk(current_pc) current_pc = 0 for ins in final: if isinstance(ins, Label): continue for i, operand in enumerate(ins.operands): if isinstance(operand, dict): for k, v in operand.items(): if isinstance(v, Label): operand[k] = Operand(40, label_pcs[v.name] - current_pc) elif isinstance(operand, Label): ins.operands[i] = Operand( 40, label_pcs[operand.name] - current_pc ) current_pc += ins.size_on_disk(current_pc) yield ins
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_add_new'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'host_object'},{'id': '6', 'type': 'block', 'children': ['7', '16', '43']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_get_insertion_point'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'host_object'},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '23']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'listed'},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'slice', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '22', 'type': 'colon', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '34']},{'id': '24', 'type': 'if_statement', 'children': ['25', '32']},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'listed'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'is_subdomain'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'host_object'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'break_statement', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '41']},{'id': '36', 'type': 'attribute', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'hosts'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'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': 'hosts'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'host_object'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'to_unicode'},{'id': '56', 'type': 'argument_list', 'children': []}
def _add_new(self, host_object): i = self._get_insertion_point(host_object) for listed in self[i:]: if not listed.is_subdomain(host_object): break self.hosts.pop(i) self.hosts.insert(i, host_object.to_unicode())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_instruction'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_pos'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '7', 'type': 'block', 'children': ['8', '20', '28']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '13']},{'id': '10', 'type': 'pattern_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '13', 'type': 'expression_list', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'fmt_operands'},{'id': '23', 'type': 'subscript', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'opcode_table'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '27', 'type': 'string', 'children': [], 'value': "'operands'"},{'id': '28', 'type': 'if_statement', 'children': ['29', '32', '90', '133', '229', '312']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'wide'},{'id': '32', 'type': 'block', 'children': ['33', '44', '55', '70']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'string', 'children': [], 'value': "'>B'"},{'id': '43', 'type': 'integer', 'children': [], 'value': '0xC4'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'>B'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'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': 'fout'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65']},{'id': '64', 'type': 'string', 'children': [], 'value': "'>H'"},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '68', 'type': 'integer', 'children': [], 'value': '0'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '70', 'type': 'if_statement', 'children': ['71', '74']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '=='},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '73', 'type': 'integer', 'children': [], 'value': '0x84'},{'id': '74', 'type': 'block', 'children': ['75']},{'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': 'fout'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '83', 'type': 'argument_list', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'>h'"},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '90', 'type': 'elif_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'fmt_operands'},{'id': '92', 'type': 'block', 'children': ['93', '104']},{'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': 'fout'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'>B'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '104', 'type': 'for_statement', 'children': ['105', '110', '114']},{'id': '105', 'type': 'pattern_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '107', 'type': 'tuple_pattern', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'fmt_operands'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '127']},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'attribute', 'children': ['129', '132']},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '133', 'type': 'elif_clause', 'children': ['134', '137']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '=='},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '136', 'type': 'integer', 'children': [], 'value': '0xAB'},{'id': '137', 'type': 'block', 'children': ['138', '149', '160', '169', '179', '200']},{'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': 'fout'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': "'>B'"},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '-'},{'id': '153', 'type': 'integer', 'children': [], 'value': '4'},{'id': '154', 'type': 'binary_operator', 'children': ['155', '159'], 'value': '%'},{'id': '155', 'type': '()', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '+'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'start_pos'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'integer', 'children': [], 'value': '4'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '163', 'type': 'conditional_expression', 'children': ['164', '165', '168'], 'value': 'if'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '!='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '167', 'type': 'integer', 'children': [], 'value': '4'},{'id': '168', 'type': 'integer', 'children': [], 'value': '0'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'string', 'children': [], 'value': "f'{padding}x'"},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189', '194']},{'id': '188', 'type': 'string', 'children': [], 'value': "'>ii'"},{'id': '189', 'type': 'attribute', 'children': ['190', '193']},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '199', 'type': 'integer', 'children': [], 'value': '0'},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '212']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '211']},{'id': '206', 'type': 'attribute', 'children': ['207', '210']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '209', 'type': 'integer', 'children': [], 'value': '0'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '211', 'type': 'argument_list', 'children': []},{'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': 'fout'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '221', 'type': 'argument_list', 'children': ['222', '223', '224']},{'id': '222', 'type': 'string', 'children': [], 'value': "'>ii'"},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '224', 'type': 'subscript', 'children': ['225', '228']},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '227', 'type': 'integer', 'children': [], 'value': '0'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '229', 'type': 'elif_clause', 'children': ['230', '233']},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': '=='},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '232', 'type': 'integer', 'children': [], 'value': '0xAA'},{'id': '233', 'type': 'block', 'children': ['234', '245', '256', '265', '275']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '242', 'type': 'argument_list', 'children': ['243', '244']},{'id': '243', 'type': 'string', 'children': [], 'value': "'>B'"},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'opcode'},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '-'},{'id': '249', 'type': 'integer', 'children': [], 'value': '4'},{'id': '250', 'type': 'binary_operator', 'children': ['251', '255'], 'value': '%'},{'id': '251', 'type': '()', 'children': ['252']},{'id': '252', 'type': 'binary_operator', 'children': ['253', '254'], 'value': '+'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'start_pos'},{'id': '254', 'type': 'integer', 'children': [], 'value': '1'},{'id': '255', 'type': 'integer', 'children': [], 'value': '4'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '259', 'type': 'conditional_expression', 'children': ['260', '261', '264'], 'value': 'if'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '261', 'type': 'comparison_operator', 'children': ['262', '263'], 'value': '!='},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '263', 'type': 'integer', 'children': [], 'value': '4'},{'id': '264', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'fout'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'string', 'children': [], 'value': "f'{padding}x'"},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'call', 'children': ['277', '280']},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '283', 'type': 'argument_list', 'children': ['284', '285', '290', '295', '300']},{'id': '284', 'type': 'string', 'children': [], 'value': "f'>iii{len(operands) - 3}i'"},{'id': '285', 'type': 'attribute', 'children': ['286', '289']},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '288', 'type': 'integer', 'children': [], 'value': '0'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '290', 'type': 'attribute', 'children': ['291', '294']},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '293', 'type': 'integer', 'children': [], 'value': '1'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '295', 'type': 'attribute', 'children': ['296', '299']},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '298', 'type': 'integer', 'children': [], 'value': '2'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '300', 'type': 'list_splat', 'children': ['301']},{'id': '301', 'type': 'generator_expression', 'children': ['302', '305']},{'id': '302', 'type': 'attribute', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '305', 'type': 'for_in_clause', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '307', 'type': 'subscript', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '309', 'type': 'slice', 'children': ['310', '311']},{'id': '310', 'type': 'integer', 'children': [], 'value': '3'},{'id': '311', 'type': 'colon', 'children': []},{'id': '312', 'type': 'else_clause', 'children': ['313']},{'id': '313', 'type': 'block', 'children': ['314']},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'fout'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'pack'},{'id': '322', 'type': 'argument_list', 'children': ['323', '324']},{'id': '323', 'type': 'string', 'children': [], 'value': "'>B'"},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'opcode'}
def write_instruction(fout, start_pos, ins): opcode, operands = ins.opcode, ins.operands fmt_operands = opcode_table[opcode]['operands'] if ins.wide: fout.write(pack('>B', 0xC4)) fout.write(pack('>B', opcode)) fout.write(pack('>H', operands[0].value)) if opcode == 0x84: fout.write(pack('>h', operands[1].value)) elif fmt_operands: fout.write(pack('>B', opcode)) for i, (fmt, _) in enumerate(fmt_operands): fout.write(fmt.value.pack(operands[i].value)) elif opcode == 0xAB: fout.write(pack('>B', opcode)) padding = 4 - (start_pos + 1) % 4 padding = padding if padding != 4 else 0 fout.write(pack(f'{padding}x')) fout.write(pack('>ii', operands[1].value, len(operands[0]))) for key in sorted(operands[0].keys()): fout.write(pack('>ii', key, operands[0][key])) elif opcode == 0xAA: fout.write(pack('>B', opcode)) padding = 4 - (start_pos + 1) % 4 padding = padding if padding != 4 else 0 fout.write(pack(f'{padding}x')) fout.write(pack( f'>iii{len(operands) - 3}i', operands[0].value, operands[1].value, operands[2].value, *(o.value for o in operands[3:]) )) else: fout.write(pack('>B', opcode))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_instruction'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_pos'},{'id': '6', 'type': 'block', 'children': ['7', '16', '22', '29', '35', '41', '47', '51', '401']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'integer', 'children': [], 'value': '1'},{'id': '16', 'type': 'if_statement', 'children': ['17', '19']},{'id': '17', 'type': 'not_operator', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ord'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'opcode_table'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '40', 'type': 'string', 'children': [], 'value': "'operands'"},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '46', 'type': 'string', 'children': [], 'value': "'mnemonic'"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '50', 'type': 'list', 'children': [], 'value': '[]'},{'id': '51', 'type': 'if_statement', 'children': ['52', '53', '89', '189', '316']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'operands'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'for_statement', 'children': ['55', '58', '59']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'operands'},{'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': 'final_operands'},{'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': 'Operand'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '70', 'type': 'subscript', 'children': ['71', '88']},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'attribute', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'elif_clause', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '92', 'type': 'integer', 'children': [], 'value': '0xAB'},{'id': '93', 'type': 'block', 'children': ['94', '105', '114', '121', '136', '140', '169', '176']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '-'},{'id': '98', 'type': 'integer', 'children': [], 'value': '4'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '104'], 'value': '%'},{'id': '100', 'type': '()', 'children': ['101']},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'start_pos'},{'id': '103', 'type': 'integer', 'children': [], 'value': '1'},{'id': '104', 'type': 'integer', 'children': [], 'value': '4'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '108', 'type': 'conditional_expression', 'children': ['109', '110', '113'], 'value': 'if'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '!='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '112', 'type': 'integer', 'children': [], 'value': '4'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'fio'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '126']},{'id': '123', 'type': 'pattern_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'npairs'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': "'>ii'"},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'integer', 'children': [], 'value': '8'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'id': '139', 'type': 'dictionary', 'children': []},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '147']},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '142', 'type': 'call', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'None', 'children': []},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'npairs'},{'id': '147', 'type': 'block', 'children': ['148', '163']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '153']},{'id': '150', 'type': 'pattern_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': "'>ii'"},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'integer', 'children': [], 'value': '8'},{'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': 'pairs'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'pairs'},{'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': 'final_operands'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '184', 'type': 'argument_list', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'OperandTypes'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'BRANCH'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '189', 'type': 'elif_clause', 'children': ['190', '193']},{'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '=='},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '192', 'type': 'integer', 'children': [], 'value': '0xAA'},{'id': '193', 'type': 'block', 'children': ['194', '205', '214', '221', '237', '250', '263', '276']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '-'},{'id': '198', 'type': 'integer', 'children': [], 'value': '4'},{'id': '199', 'type': 'binary_operator', 'children': ['200', '204'], 'value': '%'},{'id': '200', 'type': '()', 'children': ['201']},{'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '+'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'start_pos'},{'id': '203', 'type': 'integer', 'children': [], 'value': '1'},{'id': '204', 'type': 'integer', 'children': [], 'value': '4'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '208', 'type': 'conditional_expression', 'children': ['209', '210', '213'], 'value': 'if'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': '!='},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '212', 'type': 'integer', 'children': [], 'value': '4'},{'id': '213', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'fio'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'padding'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '227']},{'id': '223', 'type': 'pattern_list', 'children': ['224', '225', '226']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'string', 'children': [], 'value': "'>iii'"},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'integer', 'children': [], 'value': '12'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '245', 'type': 'argument_list', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'OperandTypes'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'BRANCH'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '258', 'type': 'argument_list', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'OperandTypes'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'LITERAL'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '271', 'type': 'argument_list', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'OperandTypes'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'LITERAL'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '276', 'type': 'for_statement', 'children': ['277', '278', '287']},{'id': '277', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '278', 'type': 'call', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '280', 'type': 'argument_list', 'children': ['281', '282']},{'id': '281', 'type': 'None', 'children': []},{'id': '282', 'type': 'binary_operator', 'children': ['283', '286'], 'value': '+'},{'id': '283', 'type': 'binary_operator', 'children': ['284', '285'], 'value': '-'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'high'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'low'},{'id': '286', 'type': 'integer', 'children': [], 'value': '1'},{'id': '287', 'type': 'block', 'children': ['288', '303']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '291', 'type': 'subscript', 'children': ['292', '302']},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '294', 'type': 'argument_list', 'children': ['295', '296']},{'id': '295', 'type': 'string', 'children': [], 'value': "'>i'"},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'integer', 'children': [], 'value': '4'},{'id': '302', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'final_operands'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '308', 'type': 'argument_list', 'children': ['309']},{'id': '309', 'type': 'call', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '311', 'type': 'argument_list', 'children': ['312', '315']},{'id': '312', 'type': 'attribute', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'OperandTypes'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'BRANCH'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '316', 'type': 'elif_clause', 'children': ['317', '320']},{'id': '317', 'type': 'comparison_operator', 'children': ['318', '319'], 'value': '=='},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '319', 'type': 'integer', 'children': [], 'value': '0xC4'},{'id': '320', 'type': 'block', 'children': ['321', '336', '342', '348', '372']},{'id': '321', 'type': 'expression_statement', 'children': ['322']},{'id': '322', 'type': 'assignment', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'real_op'},{'id': '324', 'type': 'subscript', 'children': ['325', '335']},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '327', 'type': 'argument_list', 'children': ['328', '329']},{'id': '328', 'type': 'string', 'children': [], 'value': "'>B'"},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '333', 'type': 'argument_list', 'children': ['334']},{'id': '334', 'type': 'integer', 'children': [], 'value': '1'},{'id': '335', 'type': 'integer', 'children': [], 'value': '0'},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'assignment', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '339', 'type': 'subscript', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'opcode_table'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'real_op'},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'assignment', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '345', 'type': 'subscript', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'ins'},{'id': '347', 'type': 'string', 'children': [], 'value': "'mnemonic'"},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'call', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '353', 'type': 'argument_list', 'children': ['354']},{'id': '354', 'type': 'call', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '356', 'type': 'argument_list', 'children': ['357', '360']},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'OperandTypes'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'LOCAL_INDEX'},{'id': '360', 'type': 'subscript', 'children': ['361', '371']},{'id': '361', 'type': 'call', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '363', 'type': 'argument_list', 'children': ['364', '365']},{'id': '364', 'type': 'string', 'children': [], 'value': "'>H'"},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'integer', 'children': [], 'value': '2'},{'id': '371', 'type': 'integer', 'children': [], 'value': '0'},{'id': '372', 'type': 'if_statement', 'children': ['373', '376']},{'id': '373', 'type': 'comparison_operator', 'children': ['374', '375'], 'value': '=='},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'real_op'},{'id': '375', 'type': 'integer', 'children': [], 'value': '0x84'},{'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': 'final_operands'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '382', 'type': 'argument_list', 'children': ['383']},{'id': '383', 'type': 'call', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'Operand'},{'id': '385', 'type': 'argument_list', 'children': ['386', '389']},{'id': '386', 'type': 'attribute', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'OperandTypes'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'LITERAL'},{'id': '389', 'type': 'subscript', 'children': ['390', '400']},{'id': '390', 'type': 'call', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'unpack'},{'id': '392', 'type': 'argument_list', 'children': ['393', '394']},{'id': '393', 'type': 'string', 'children': [], 'value': "'>H'"},{'id': '394', 'type': 'call', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'fio'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '398', 'type': 'argument_list', 'children': ['399']},{'id': '399', 'type': 'integer', 'children': [], 'value': '2'},{'id': '400', 'type': 'integer', 'children': [], 'value': '0'},{'id': '401', 'type': 'return_statement', 'children': ['402']},{'id': '402', 'type': 'call', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'Instruction'},{'id': '404', 'type': 'argument_list', 'children': ['405', '406', '407', '408']},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'final_operands'},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'start_pos'}
def read_instruction(fio, start_pos): op = fio.read(1) if not op: return None op = ord(op) ins = opcode_table[op] operands = ins['operands'] name = ins['mnemonic'] final_operands = [] if operands: for fmt, type_ in operands: final_operands.append( Operand( type_, fmt.value.unpack(fio.read(fmt.value.size))[0] ) ) elif op == 0xAB: padding = 4 - (start_pos + 1) % 4 padding = padding if padding != 4 else 0 fio.read(padding) default, npairs = unpack('>ii', fio.read(8)) pairs = {} for _ in repeat(None, npairs): match, offset = unpack('>ii', fio.read(8)) pairs[match] = offset final_operands.append(pairs) final_operands.append(Operand(OperandTypes.BRANCH, default)) elif op == 0xAA: padding = 4 - (start_pos + 1) % 4 padding = padding if padding != 4 else 0 fio.read(padding) default, low, high = unpack('>iii', fio.read(12)) final_operands.append(Operand(OperandTypes.BRANCH, default)) final_operands.append(Operand(OperandTypes.LITERAL, low)) final_operands.append(Operand(OperandTypes.LITERAL, high)) for _ in repeat(None, high - low + 1): offset = unpack('>i', fio.read(4))[0] final_operands.append(Operand(OperandTypes.BRANCH, offset)) elif op == 0xC4: real_op = unpack('>B', fio.read(1))[0] ins = opcode_table[real_op] name = ins['mnemonic'] final_operands.append(Operand( OperandTypes.LOCAL_INDEX, unpack('>H', fio.read(2))[0] )) if real_op == 0x84: final_operands.append(Operand( OperandTypes.LITERAL, unpack('>H', fio.read(2))[0] )) return Instruction(name, op, final_operands, start_pos)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_type'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_list'},{'id': '5', 'type': 'block', 'children': ['6', '13', '45']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'ret_dict'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'file_list'},{'id': '16', 'type': 'block', 'children': ['17', '30']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '22']},{'id': '19', 'type': 'pattern_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '22', 'type': 'call', 'children': ['23', '28']},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '43']},{'id': '32', 'type': 'attribute', 'children': ['33', '42']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ret_dict'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ext'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '41', 'type': 'string', 'children': [], 'value': "''"},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filepath'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ret_dict'}
def sort_by_type(file_list): ret_dict = defaultdict(list) for filepath in file_list: _, ext = os.path.splitext(filepath) ret_dict[ext.replace('.', '')].append(filepath) return ret_dict
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_triple'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'triple'},{'id': '6', 'type': 'block', 'children': ['7', '14', '40', '44', '53', '62', '83', '95', '114', '146', '155', '169', '181', '188', '199', '211', '223', '235', '246', '253']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '13']},{'id': '9', 'type': 'pattern_list', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'triple'},{'id': '14', 'type': 'if_statement', 'children': ['15', '21']},{'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': '_should_ignore_predicate'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '21', 'type': 'block', 'children': ['22', '39']},{'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': 'log'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'info'},{'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': '"Ignoring triple with predicate \'{}\'"'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_field_name_from_uri'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '39', 'type': 'return_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '43', 'type': 'list', 'children': [], 'value': '[]'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '%'},{'id': '51', 'type': 'string', 'children': [], 'value': '"Possible member %s found"'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_expand_qname'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '62', 'type': 'if_statement', 'children': ['63', '73']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '70'], 'value': 'not'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_namespace_from_uri'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'allowed_namespaces'},{'id': '73', 'type': 'block', 'children': ['74', '82']},{'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': 'log'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': '"Member %s does not use an allowed namespace"'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '82', 'type': 'return_statement', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_is_instance'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'tuple', 'children': ['92', '93', '94']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '95', 'type': 'if_statement', 'children': ['96', '104']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '101'], 'value': '=='},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'rt'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'URIRef'},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'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': '_expand_qname'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '114', 'type': 'if_statement', 'children': ['115', '130']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '123', '124'], 'value': 'and'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '118', 'type': 'argument_list', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'schema_def'},{'id': '122', 'type': 'string', 'children': [], 'value': '"attributes_by_class"'},{'id': '123', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '124', 'type': 'not_operator', 'children': ['125']},{'id': '125', 'type': 'attribute', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'schema_def'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'attributes_by_class'},{'id': '130', 'type': 'block', 'children': ['131', '138']},{'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': 'log'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': '"Parsed ontology not found. Parsing..."'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '145']},{'id': '140', 'type': 'attribute', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'schema_def'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'parse_ontology'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'class_invalid'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_validate_class'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '155', 'type': 'if_statement', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'class_invalid'},{'id': '157', 'type': 'block', 'children': ['158', '167']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '%'},{'id': '165', 'type': 'string', 'children': [], 'value': '"Invalid class %s"'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'class_invalid'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_superclasses_for_subject'},{'id': '176', 'type': 'argument_list', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'member_invalid'},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': '_validate_member'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197', '198']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '199', 'type': 'if_statement', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'member_invalid'},{'id': '201', 'type': 'block', 'children': ['202', '209']},{'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': 'log'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'string', 'children': [], 'value': '"Invalid member of class"'},{'id': '209', 'type': 'return_statement', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'member_invalid'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'dupe_invalid'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': '_validate_duplication'},{'id': '218', 'type': 'argument_list', 'children': ['219', '222']},{'id': '219', 'type': 'tuple', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'instanceof'},{'id': '223', 'type': 'if_statement', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'dupe_invalid'},{'id': '225', 'type': 'block', 'children': ['226', '233']},{'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': 'log'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'string', 'children': [], 'value': '"Duplication found"'},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'dupe_invalid'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '242']},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'checked_attributes'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'tuple', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'string', 'children': [], 'value': '"successfully validated triple, no errors"'},{'id': '253', 'type': 'return_statement', 'children': []}
def _check_triple(self, triple): subj, pred, obj = triple if self._should_ignore_predicate(pred): log.info("Ignoring triple with predicate '{}'" .format(self._field_name_from_uri(pred))) return classes = [] log.warning("Possible member %s found" % pred) pred = self._expand_qname(pred) if self._namespace_from_uri(pred) not in self.allowed_namespaces: log.info("Member %s does not use an allowed namespace", pred) return instanceof = self._is_instance((subj, pred, obj)) if type(instanceof) == rt.URIRef: instanceof = self._expand_qname(instanceof) if hasattr(self.schema_def, "attributes_by_class") and \ not self.schema_def.attributes_by_class: log.info("Parsed ontology not found. Parsing...") self.schema_def.parse_ontology() class_invalid = self._validate_class(instanceof) if class_invalid: log.warning("Invalid class %s" % instanceof) return class_invalid classes = self._superclasses_for_subject(self.graph, instanceof) classes.append(instanceof) member_invalid = self._validate_member(pred, classes, instanceof) if member_invalid: log.warning("Invalid member of class") return member_invalid dupe_invalid = self._validate_duplication((subj, pred), instanceof) if dupe_invalid: log.warning("Duplication found") return dupe_invalid self.checked_attributes.append((subj, pred)) log.warning("successfully validated triple, no errors") return
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_ontology'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '14', '27', '159', '172']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '13', 'type': 'argument_list', 'children': []},{'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': 'log'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '%'},{'id': '21', 'type': 'string', 'children': [], 'value': '"Parsing ontology file for %s"'},{'id': '22', 'type': 'attribute', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '27', 'type': 'for_statement', 'children': ['28', '32', '37']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_schema_nodes'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '81', '89', '112']},{'id': '38', 'type': 'if_statement', 'children': ['39', '44']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'not'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'attributes_by_class'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'if_statement', 'children': ['46', '72']},{'id': '46', 'type': 'boolean_operator', 'children': ['47', '59', '60'], 'value': 'and'},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'rt'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'URIRef'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'subscript', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'lexicon'},{'id': '58', 'type': 'string', 'children': [], 'value': "'class'"},{'id': '59', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '=='},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'rt'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'URIRef'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'subscript', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'lexicon'},{'id': '71', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '80']},{'id': '75', 'type': 'subscript', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'attributes_by_class'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '80', 'type': 'list', 'children': [], 'value': '[]'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '84', 'type': 'list', 'children': ['85'], 'value': '[(subj, pred, obj)]'},{'id': '85', 'type': 'tuple', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '89', 'type': 'if_statement', 'children': ['90', '98']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '95'], 'value': '=='},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'rt'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'BNode'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'deepest_node'},{'id': '104', 'type': 'argument_list', 'children': ['105', '109']},{'id': '105', 'type': 'tuple', 'children': ['106', '107', '108']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '112', 'type': 'for_statement', 'children': ['113', '117', '118']},{'id': '113', 'type': 'pattern_list', 'children': ['114', '115', '116']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'leaves'},{'id': '118', 'type': 'block', 'children': ['119', '134']},{'id': '119', 'type': 'if_statement', 'children': ['120', '125']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'not'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'attributes_by_class'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '133']},{'id': '128', 'type': 'subscript', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'attributes_by_class'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '133', 'type': 'list', 'children': [], 'value': '[]'},{'id': '134', 'type': 'if_statement', 'children': ['135', '147']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '=='},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pred'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'rt'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'URIRef'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'subscript', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'lexicon'},{'id': '146', 'type': 'string', 'children': [], 'value': "'domain'"},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '157']},{'id': '150', 'type': 'attribute', 'children': ['151', '156']},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'attributes_by_class'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'o'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'subj'},{'id': '159', 'type': 'if_statement', 'children': ['160', '164']},{'id': '160', 'type': 'not_operator', 'children': ['161']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'attributes_by_class'},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'string', 'children': [], 'value': '"No nodes found in ontology"'},{'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': 'log'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'string', 'children': [], 'value': '"Ontology parsing complete in {}"'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'binary_operator', 'children': ['184', '192'], 'value': '*'},{'id': '184', 'type': '()', 'children': ['185']},{'id': '185', 'type': 'binary_operator', 'children': ['186', '191'], 'value': '-'},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'clock'},{'id': '190', 'type': 'argument_list', 'children': []},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1000'}
def parse_ontology(self): start = time.clock() log.info("Parsing ontology file for %s" % self.__class__.__name__) for subj, pred, obj in self._schema_nodes(): if subj not in self.attributes_by_class: if obj == rt.URIRef(self.lexicon['class']) and \ pred == rt.URIRef(self.lexicon['type']): self.attributes_by_class[subj] = [] leaves = [(subj, pred, obj)] if type(obj) == rt.BNode: leaves = deepest_node((subj, pred, obj), self.graph) for s, p, o in leaves: if o not in self.attributes_by_class: self.attributes_by_class[o] = [] if pred == rt.URIRef(self.lexicon['domain']): self.attributes_by_class[o].append(subj) if not self.attributes_by_class: log.info("No nodes found in ontology") log.info("Ontology parsing complete in {}".format( (time.clock() - start) * 1000))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'new_frame_event'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '25', '29', '106', '195']},{'id': '6', 'type': 'for_statement', 'children': ['7', '8', '15']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'out_pool'},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'outframe_pool'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '23']},{'id': '17', 'type': 'not_operator', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'out_pool'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'available'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '28', 'type': 'dictionary', 'children': []},{'id': '29', 'type': 'for_statement', 'children': ['30', '31', '38']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'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': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'input_buffer'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'block', 'children': ['39', '48', '56', '65']},{'id': '39', 'type': 'if_statement', 'children': ['40', '46']},{'id': '40', 'type': 'not_operator', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'available'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': []},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'in_frame'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'peek'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'if_statement', 'children': ['57', '60']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'in_frame'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'raise_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'if_statement', 'children': ['66', '71', '80']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '70'], 'value': '>='},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'in_frame'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'frame_no'},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '77']},{'id': '74', 'type': 'subscript', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'in_frame'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'frame_no'},{'id': '80', 'type': 'else_clause', 'children': ['81']},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'while_statement', 'children': ['83', '99']},{'id': '83', 'type': 'boolean_operator', 'children': ['84', '91'], 'value': 'and'},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '90'], 'value': '>'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'available'},{'id': '89', 'type': 'argument_list', 'children': []},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '98'], 'value': 'is'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'peek'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'block', 'children': ['100']},{'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': 'in_buff'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'if_statement', 'children': ['107', '113']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '112'], 'value': '>'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '112', 'type': 'integer', 'children': [], 'value': '1'},{'id': '113', 'type': 'block', 'children': ['114', '125', '175']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'frame_no'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '124', 'type': 'argument_list', 'children': []},{'id': '125', 'type': 'for_statement', 'children': ['126', '127', '128']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'while_statement', 'children': ['130', '143']},{'id': '130', 'type': 'boolean_operator', 'children': ['131', '136'], 'value': 'and'},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '<'},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'frame_no'},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '142'], 'value': '>'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'available'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'block', 'children': ['144', '150', '158', '167']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '149', 'type': 'argument_list', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'in_frame'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'peek'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'if_statement', 'children': ['159', '162']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'is'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'in_frame'},{'id': '161', 'type': 'None', 'children': []},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'raise_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'in_buff'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'in_frame'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'frame_no'},{'id': '175', 'type': 'if_statement', 'children': ['176', '193']},{'id': '176', 'type': 'comparison_operator', 'children': ['177', '185'], 'value': '!='},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '184', 'type': 'argument_list', 'children': []},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'frame_nos'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'return_statement', 'children': []},{'id': '195', 'type': 'try_statement', 'children': ['196', '203', '207']},{'id': '196', 'type': 'block', 'children': ['197']},{'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': 'process_frame'},{'id': '202', 'type': 'argument_list', 'children': []},{'id': '203', 'type': 'except_clause', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'raise_statement', 'children': []},{'id': '207', 'type': 'except_clause', 'children': ['208', '212']},{'id': '208', 'type': 'as_pattern', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '210', 'type': 'as_pattern_target', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '212', 'type': 'block', 'children': ['213', '222']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '220']},{'id': '215', 'type': 'attribute', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'exception'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '222', 'type': 'raise_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '225', 'type': 'argument_list', 'children': []}
def new_frame_event(self): for out_pool in self.outframe_pool.values(): if not out_pool.available(): return frame_nos = {} for in_buff in self.input_buffer.values(): if not in_buff.available(): return in_frame = in_buff.peek() if in_frame is None: raise StopIteration() if in_frame.frame_no >= 0: frame_nos[in_buff] = in_frame.frame_no else: while in_buff.available() > 1 and in_buff.peek(1) is not None: in_buff.get() if len(frame_nos) > 1: frame_no = max(frame_nos.values()) for in_buff in frame_nos: while frame_nos[in_buff] < frame_no and in_buff.available() > 1: in_buff.get() in_frame = in_buff.peek() if in_frame is None: raise StopIteration() frame_nos[in_buff] = in_frame.frame_no if min(frame_nos.values()) != max(frame_nos.values()): return try: self.process_frame() except StopIteration: raise except Exception as ex: self.logger.exception(ex) raise StopIteration()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GaussianFilterCore'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x_sigma'},{'id': '6', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'y_sigma'},{'id': '9', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '10', 'type': 'block', 'children': ['11', '137', '145', '153', '160', '167', '192', '228', '234', '240', '246', '257', '261', '273', '285', '295']},{'id': '11', 'type': 'function_definition', 'children': ['12', '13', '15']},{'id': '12', 'type': 'function_name', 'children': [], 'value': 'filter_1D'},{'id': '13', 'type': 'parameters', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '15', 'type': 'block', 'children': ['16', '32', '36', '40', '74', '83', '102', '127', '135']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '/'},{'id': '20', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '21', 'type': '()', 'children': ['22']},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '*'},{'id': '23', 'type': 'float', 'children': [], 'value': '2.0'},{'id': '24', 'type': '()', 'children': ['25']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '31'], 'value': '**'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sigma'},{'id': '30', 'type': 'float', 'children': [], 'value': '0.0001'},{'id': '31', 'type': 'float', 'children': [], 'value': '2.0'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'coefs'},{'id': '35', 'type': 'list', 'children': [], 'value': '[]'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '39', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '40', 'type': 'while_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '>'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '43', 'type': 'float', 'children': [], 'value': '0.0001'},{'id': '44', 'type': 'block', 'children': ['45', '52']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'coefs'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'unary_operator', 'children': ['61'], 'value': '-'},{'id': '61', 'type': '()', 'children': ['62']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '*'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '64', 'type': '()', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'binary_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': 'coefs'},{'id': '73', 'type': 'integer', 'children': [], 'value': '2'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'fil_dim'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '82'], 'value': '-'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'coefs'},{'id': '82', 'type': 'integer', 'children': [], 'value': '1'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '90', 'type': 'argument_list', 'children': ['91', '97']},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '+'},{'id': '92', 'type': 'integer', 'children': [], 'value': '1'},{'id': '93', 'type': '()', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '*'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'fil_dim'},{'id': '96', 'type': 'integer', 'children': [], 'value': '2'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '102', 'type': 'for_statement', 'children': ['103', '106', '110']},{'id': '103', 'type': 'pattern_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'coefs'},{'id': '110', 'type': 'block', 'children': ['111', '119']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '118']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '-'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'fil_dim'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '126']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '+'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fil_dim'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'coef'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'augmented_assignment', 'children': ['129', '130'], 'value': '/='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'return_statement', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'x_sigma'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'x_sigma'},{'id': '144', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'y_sigma'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'y_sigma'},{'id': '152', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'x_fil'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'filter_1D'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'x_sigma'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'y_fil'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'filter_1D'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'y_sigma'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '174', 'type': 'argument_list', 'children': ['175', '187']},{'id': '175', 'type': 'list', 'children': ['176', '181', '186'], 'value': '[y_fil.shape[0], x_fil.shape[0], 1]'},{'id': '176', 'type': 'subscript', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'y_fil'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '180', 'type': 'integer', 'children': [], 'value': '0'},{'id': '181', 'type': 'subscript', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'x_fil'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '185', 'type': 'integer', 'children': [], 'value': '0'},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '192', 'type': 'for_statement', 'children': ['193', '194', '202']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '194', 'type': 'call', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'subscript', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'y_fil'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '201', 'type': 'integer', 'children': [], 'value': '0'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'for_statement', 'children': ['204', '205', '213']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'subscript', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'x_fil'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '212', 'type': 'integer', 'children': [], 'value': '0'},{'id': '213', 'type': 'block', 'children': ['214']},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '221']},{'id': '216', 'type': 'subscript', 'children': ['217', '218', '219', '220']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '220', 'type': 'integer', 'children': [], 'value': '0'},{'id': '221', 'type': 'binary_operator', 'children': ['222', '225'], 'value': '*'},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'x_fil'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'y_fil'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'out_frame'},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'Frame'},{'id': '233', 'type': 'argument_list', 'children': []},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'assignment', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'out_frame'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'out_frame'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '245', 'type': 'string', 'children': [], 'value': "'fil'"},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'audit'},{'id': '249', 'type': 'call', 'children': ['250', '255']},{'id': '250', 'type': 'attribute', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'out_frame'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'string', 'children': [], 'value': "'audit'"},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'augmented_assignment', 'children': ['259', '260'], 'value': '+='},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'audit'},{'id': '260', 'type': 'string', 'children': [], 'value': "'data = GaussianFilter()\\n'"},{'id': '261', 'type': 'if_statement', 'children': ['262', '265']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': '!='},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'x_sigma'},{'id': '264', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'augmented_assignment', 'children': ['268', '269'], 'value': '+='},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'audit'},{'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '%'},{'id': '270', 'type': 'string', 'children': [], 'value': "' x_sigma: %g\\n'"},{'id': '271', 'type': '()', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'x_sigma'},{'id': '273', 'type': 'if_statement', 'children': ['274', '277']},{'id': '274', 'type': 'comparison_operator', 'children': ['275', '276'], 'value': '!='},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'y_sigma'},{'id': '276', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'augmented_assignment', 'children': ['280', '281'], 'value': '+='},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'audit'},{'id': '281', 'type': 'binary_operator', 'children': ['282', '283'], 'value': '%'},{'id': '282', 'type': 'string', 'children': [], 'value': "' y_sigma: %g\\n'"},{'id': '283', 'type': '()', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'y_sigma'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '292']},{'id': '287', 'type': 'attribute', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'out_frame'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'metadata'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'string', 'children': [], 'value': "'audit'"},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'audit'},{'id': '295', 'type': 'return_statement', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'out_frame'}
def GaussianFilterCore(x_sigma=0.0, y_sigma=0.0): def filter_1D(sigma): alpha = 1.0 / (2.0 * (max(sigma, 0.0001) ** 2.0)) coefs = [] coef = 1.0 while coef > 0.0001: coefs.append(coef) coef = math.exp(-(alpha * (float(len(coefs) ** 2)))) fil_dim = len(coefs) - 1 result = numpy.zeros(1 + (fil_dim * 2), dtype=numpy.float32) for n, coef in enumerate(coefs): result[fil_dim - n] = coef result[fil_dim + n] = coef result /= result.sum() return result x_sigma = max(x_sigma, 0.0) y_sigma = max(y_sigma, 0.0) x_fil = filter_1D(x_sigma) y_fil = filter_1D(y_sigma) result = numpy.empty( [y_fil.shape[0], x_fil.shape[0], 1], dtype=numpy.float32) for y in range(y_fil.shape[0]): for x in range(x_fil.shape[0]): result[y, x, 0] = x_fil[x] * y_fil[y] out_frame = Frame() out_frame.data = result out_frame.type = 'fil' audit = out_frame.metadata.get('audit') audit += 'data = GaussianFilter()\n' if x_sigma != 0.0: audit += ' x_sigma: %g\n' % (x_sigma) if y_sigma != 0.0: audit += ' y_sigma: %g\n' % (y_sigma) out_frame.metadata.set('audit', audit) return out_frame
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'either'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'if_statement', 'children': ['7', '13', '22']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'string', 'children': [], 'value': "'children'"},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Either'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Required'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '22', 'type': 'else_clause', 'children': ['23']},{'id': '23', 'type': 'block', 'children': ['24', '28', '34', '262']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '31', 'type': 'list', 'children': ['32'], 'value': '[[self]]'},{'id': '32', 'type': 'list', 'children': ['33'], 'value': '[self]'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'while_statement', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '36', 'type': 'block', 'children': ['37', '46', '57']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'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': 'types'},{'id': '49', 'type': 'list_comprehension', 'children': ['50', '54']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '57', 'type': 'if_statement', 'children': ['58', '61', '107', '155', '203', '253']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'in'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'Either'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '61', 'type': 'block', 'children': ['62', '79', '91']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'either'},{'id': '65', 'type': 'subscript', 'children': ['66', '78']},{'id': '66', 'type': 'list_comprehension', 'children': ['67', '68', '71']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '71', 'type': 'if_clause', 'children': ['72']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '77'], 'value': 'is'},{'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': 'c'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'Either'},{'id': '78', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'children'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'either'},{'id': '91', 'type': 'for_statement', 'children': ['92', '93', '96']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'either'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'binary_operator', 'children': ['104', '106'], 'value': '+'},{'id': '104', 'type': 'list', 'children': ['105'], 'value': '[c]'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '107', 'type': 'elif_clause', 'children': ['108', '111']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Required'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '111', 'type': 'block', 'children': ['112', '129', '141']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '115', 'type': 'subscript', 'children': ['116', '128']},{'id': '116', 'type': 'list_comprehension', 'children': ['117', '118', '121']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '118', 'type': 'for_in_clause', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '121', 'type': 'if_clause', 'children': ['122']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '127'], 'value': 'is'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'Required'},{'id': '128', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'children'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'required'},{'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': 'groups'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '154'], 'value': '+'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '155', 'type': 'elif_clause', 'children': ['156', '159']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'in'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '159', 'type': 'block', 'children': ['160', '177', '189']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'optional'},{'id': '163', 'type': 'subscript', 'children': ['164', '176']},{'id': '164', 'type': 'list_comprehension', 'children': ['165', '166', '169']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '166', 'type': 'for_in_clause', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '169', 'type': 'if_clause', 'children': ['170']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '175'], 'value': 'is'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'Optional'},{'id': '176', 'type': 'integer', 'children': [], 'value': '0'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'optional'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'binary_operator', 'children': ['196', '202'], 'value': '+'},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'optional'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '203', 'type': 'elif_clause', 'children': ['204', '207']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'in'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'OneOrMore'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '207', 'type': 'block', 'children': ['208', '225', '237']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'oneormore'},{'id': '211', 'type': 'subscript', 'children': ['212', '224']},{'id': '212', 'type': 'list_comprehension', 'children': ['213', '214', '217']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '214', 'type': 'for_in_clause', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '217', 'type': 'if_clause', 'children': ['218']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '223'], 'value': 'is'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'OneOrMore'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'oneormore'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'binary_operator', 'children': ['244', '252'], 'value': '+'},{'id': '244', 'type': 'binary_operator', 'children': ['245', '251'], 'value': '*'},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'oneormore'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '251', 'type': 'integer', 'children': [], 'value': '2'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '253', 'type': 'else_clause', 'children': ['254']},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '262', 'type': 'return_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'Either'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'list_splat', 'children': ['267']},{'id': '267', 'type': 'list_comprehension', 'children': ['268', '273']},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'Required'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'list_splat', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '273', 'type': 'for_in_clause', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'ret'}
def either(self): if not hasattr(self, 'children'): return Either(Required(self)) else: ret = [] groups = [[self]] while groups: children = groups.pop(0) types = [type(c) for c in children] if Either in types: either = [c for c in children if type(c) is Either][0] children.pop(children.index(either)) for c in either.children: groups.append([c] + children) elif Required in types: required = [c for c in children if type(c) is Required][0] children.pop(children.index(required)) groups.append(list(required.children) + children) elif Optional in types: optional = [c for c in children if type(c) is Optional][0] children.pop(children.index(optional)) groups.append(list(optional.children) + children) elif OneOrMore in types: oneormore = [c for c in children if type(c) is OneOrMore][0] children.pop(children.index(oneormore)) groups.append(list(oneormore.children) * 2 + children) else: ret.append(children) return Either(*[Required(*e) for e in ret])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'TranslateManagedObject'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mObj'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'xlateOrg'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'xlateMap'},{'id': '7', 'type': 'block', 'children': ['8', '15', '20', '28', '39', '198', '352']},{'id': '8', 'type': 'import_from_statement', 'children': ['9', '11', '13']},{'id': '9', 'type': 'dotted_name', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'UcsBase'},{'id': '11', 'type': 'dotted_name', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '13', 'type': 'dotted_name', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'WriteUcsWarning'},{'id': '15', 'type': 'import_from_statement', 'children': ['16', '18']},{'id': '16', 'type': 'dotted_name', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Mos'},{'id': '18', 'type': 'dotted_name', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'OrgOrg'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'mObj'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Clone'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'SetHandle'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mObj'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'GetHandle'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'if_statement', 'children': ['40', '44']},{'id': '40', 'type': '()', 'children': ['41']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '!='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'xlateOrg'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45', '57']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'matchObj'},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "r'^(org-[\\-\\.:_a-zA-Z0-9]{1,16}/)*org-[\\-\\.:_a-zA-Z0-9]{1,16}'"},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '57', 'type': 'if_statement', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'matchObj'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'if_statement', 'children': ['61', '75', '166']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '70'], 'value': '=='},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'WordL'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'OrgOrg'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ClassId'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'block', 'children': ['76', '95', '112', '124']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'orgMoMeta'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'GetUcsPropertyMeta'},{'id': '83', 'type': 'argument_list', 'children': ['84', '94']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'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': 'OrgOrg'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ClassId'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'string', 'children': [], 'value': '"Meta"'},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': '=='},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'orgMoMeta'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'block', 'children': ['100', '110']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'WriteUcsWarning'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '%'},{'id': '105', 'type': 'string', 'children': [], 'value': "'[Warning]: Could not translate [%s]'"},{'id': '106', 'type': '()', 'children': ['107']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'matchObj1'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '119', 'type': 'argument_list', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': "r'(\\[[^\\]]+\\])'"},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'orgMoMeta'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'rn'},{'id': '124', 'type': 'if_statement', 'children': ['125', '126', '134']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'matchObj1'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'UpdateMoDnAlongWithNamingProperties'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'orgMoMeta'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'xlateOrg'},{'id': '134', 'type': 'else_clause', 'children': ['135']},{'id': '135', 'type': 'block', 'children': ['136', '160']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'newDn'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '143', 'type': 'argument_list', 'children': ['144', '153', '157']},{'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '%'},{'id': '145', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '146', 'type': '()', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'matchObj'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '%'},{'id': '154', 'type': 'string', 'children': [], 'value': '"%s"'},{'id': '155', 'type': '()', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'xlateOrg'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'newDn'},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168', '192']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'newDn'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '175', 'type': 'argument_list', 'children': ['176', '185', '189']},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '%'},{'id': '177', 'type': 'string', 'children': [], 'value': '"^%s/"'},{'id': '178', 'type': '()', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'matchObj'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'integer', 'children': [], 'value': '0'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '%'},{'id': '186', 'type': 'string', 'children': [], 'value': '"%s/"'},{'id': '187', 'type': '()', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'xlateOrg'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'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': 'xMO'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'newDn'},{'id': '198', 'type': 'if_statement', 'children': ['199', '203']},{'id': '199', 'type': '()', 'children': ['200']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': '!='},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'xlateMap'},{'id': '202', 'type': 'None', 'children': []},{'id': '203', 'type': 'block', 'children': ['204', '210']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '210', 'type': 'if_statement', 'children': ['211', '214', '281']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'in'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'xlateMap'},{'id': '214', 'type': 'block', 'children': ['215', '232', '247', '259']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'xMoMeta'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'GetUcsPropertyMeta'},{'id': '222', 'type': 'argument_list', 'children': ['223', '231']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '231', 'type': 'string', 'children': [], 'value': '"Meta"'},{'id': '232', 'type': 'if_statement', 'children': ['233', '236']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '=='},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'xMoMeta'},{'id': '235', 'type': 'None', 'children': []},{'id': '236', 'type': 'block', 'children': ['237', '245']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'WriteUcsWarning'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'binary_operator', 'children': ['242', '243'], 'value': '%'},{'id': '242', 'type': 'string', 'children': [], 'value': "'[Warning]: Could not translate [%s]'"},{'id': '243', 'type': '()', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '245', 'type': 'return_statement', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'matchObj'},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '254', 'type': 'argument_list', 'children': ['255', '256']},{'id': '255', 'type': 'string', 'children': [], 'value': "r'(\\[[^\\]]+\\])'"},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'xMoMeta'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'rn'},{'id': '259', 'type': 'if_statement', 'children': ['260', '261', '271']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'matchObj'},{'id': '261', 'type': 'block', 'children': ['262']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'UpdateMoDnAlongWithNamingProperties'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267', '268']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'xMoMeta'},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'xlateMap'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '271', 'type': 'else_clause', 'children': ['272']},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'xlateMap'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '281', 'type': 'else_clause', 'children': ['282']},{'id': '282', 'type': 'block', 'children': ['283', '294']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292', '293']},{'id': '291', 'type': 'string', 'children': [], 'value': "r'[/]*[^/]+$'"},{'id': '292', 'type': 'string', 'children': [], 'value': "''"},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '294', 'type': 'while_statement', 'children': ['295', '303']},{'id': '295', 'type': '()', 'children': ['296']},{'id': '296', 'type': 'boolean_operator', 'children': ['297', '300'], 'value': 'or'},{'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': '!='},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '299', 'type': 'None', 'children': []},{'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': '=='},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '302', 'type': 'string', 'children': [], 'value': '""'},{'id': '303', 'type': 'block', 'children': ['304', '324', '345', '351']},{'id': '304', 'type': 'if_statement', 'children': ['305', '311']},{'id': '305', 'type': '()', 'children': ['306']},{'id': '306', 'type': 'not_operator', 'children': ['307']},{'id': '307', 'type': '()', 'children': ['308']},{'id': '308', 'type': 'comparison_operator', 'children': ['309', '310'], 'value': 'in'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'xlateMap'},{'id': '311', 'type': 'block', 'children': ['312', '323']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '319', 'type': 'argument_list', 'children': ['320', '321', '322']},{'id': '320', 'type': 'string', 'children': [], 'value': "r'[/]*[^/]+$'"},{'id': '321', 'type': 'string', 'children': [], 'value': "''"},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '323', 'type': 'continue_statement', 'children': []},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'newDn'},{'id': '327', 'type': 'call', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '331', 'type': 'argument_list', 'children': ['332', '336', '342']},{'id': '332', 'type': 'binary_operator', 'children': ['333', '334'], 'value': '%'},{'id': '333', 'type': 'string', 'children': [], 'value': '"^%s/"'},{'id': '334', 'type': '()', 'children': ['335']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '336', 'type': 'binary_operator', 'children': ['337', '338'], 'value': '%'},{'id': '337', 'type': 'string', 'children': [], 'value': '"%s/"'},{'id': '338', 'type': '()', 'children': ['339']},{'id': '339', 'type': 'subscript', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'xlateMap'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'originalDn'},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '345', 'type': 'expression_statement', 'children': ['346']},{'id': '346', 'type': 'assignment', 'children': ['347', '350']},{'id': '347', 'type': 'attribute', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'xMO'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'newDn'},{'id': '351', 'type': 'break_statement', 'children': []},{'id': '352', 'type': 'return_statement', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'xMO'}
def TranslateManagedObject(mObj, xlateOrg, xlateMap): from UcsBase import UcsUtils, WriteUcsWarning from Mos import OrgOrg xMO = mObj.Clone() xMO.SetHandle(mObj.GetHandle()) if (xlateOrg != None): matchObj = re.match(r'^(org-[\-\.:_a-zA-Z0-9]{1,16}/)*org-[\-\.:_a-zA-Z0-9]{1,16}', xMO.Dn) if matchObj: if UcsUtils.WordL(xMO.classId) == OrgOrg.ClassId(): orgMoMeta = UcsUtils.GetUcsPropertyMeta(UcsUtils.WordU(OrgOrg.ClassId()), "Meta") if orgMoMeta == None: WriteUcsWarning('[Warning]: Could not translate [%s]' % (xMO.Dn)) return xMO matchObj1 = re.findall(r'(\[[^\]]+\])', orgMoMeta.rn) if matchObj1: UpdateMoDnAlongWithNamingProperties(xMO, orgMoMeta, xlateOrg) else: newDn = re.sub("%s" % (matchObj.group(0)), "%s" % (xlateOrg), xMO.Dn) xMO.Dn = newDn else: newDn = re.sub("^%s/" % (matchObj.group(0)), "%s/" % (xlateOrg), xMO.Dn) xMO.Dn = newDn if (xlateMap != None): originalDn = xMO.Dn if originalDn in xlateMap: xMoMeta = UcsUtils.GetUcsPropertyMeta(UcsUtils.WordU(xMO.classId), "Meta") if xMoMeta == None: WriteUcsWarning('[Warning]: Could not translate [%s]' % (originalDn)) return xMO matchObj = re.findall(r'(\[[^\]]+\])', xMoMeta.rn) if matchObj: UpdateMoDnAlongWithNamingProperties(xMO, xMoMeta, xlateMap[originalDn]) else: xMO.Dn = xlateMap[originalDn] else: originalDn = re.sub(r'[/]*[^/]+$', '', originalDn) while (originalDn != None or originalDn == ""): if (not (originalDn in xlateMap)): originalDn = re.sub(r'[/]*[^/]+$', '', originalDn) continue newDn = re.sub("^%s/" % (originalDn), "%s/" % (xlateMap[originalDn]), xMO.Dn) xMO.Dn = newDn break return xMO
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ImportUcsSession'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7', '16', '26', '36', '65', '78', '84', '99']},{'id': '7', 'type': 'import_from_statement', 'children': ['8', '10', '12', '14']},{'id': '8', 'type': 'dotted_name', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'UcsBase'},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '12', 'type': 'dotted_name', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'WriteUcsWarning'},{'id': '14', 'type': 'dotted_name', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'raise_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"filePath parameter is not provided."'},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'None', 'children': []},{'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': 'UcsValidationException'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': '"key parameter is not provided."'},{'id': '36', 'type': 'if_statement', 'children': ['37', '56']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '47'], 'value': 'or'},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '54']},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'raise_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '%'},{'id': '62', 'type': 'string', 'children': [], 'value': "'[Error]: File <%s> does not exist '"},{'id': '63', 'type': '()', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '68', 'type': 'call', 'children': ['69', '76']},{'id': '69', 'type': 'attribute', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'xml'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'dom'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'minidom'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'topNode'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'documentElement'},{'id': '84', 'type': 'if_statement', 'children': ['85', '96']},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '89'], 'value': 'or'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'topNode'},{'id': '88', 'type': 'None', 'children': []},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '!='},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'topNode'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'localName'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'UCS_HANDLES'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'if_statement', 'children': ['100', '106']},{'id': '100', 'type': '()', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'topNode'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'hasChildNodes'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'block', 'children': ['107', '113', '120']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'childList'},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'topNode'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'childNodes'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'childCount'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'childList'},{'id': '120', 'type': 'for_statement', 'children': ['121', '122', '126']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'childCount'},{'id': '126', 'type': 'block', 'children': ['127', '136', '147', '157', '161', '165', '169', '173', '177', '198', '219', '246', '267', '288', '306']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'childList'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '136', 'type': 'if_statement', 'children': ['137', '145']},{'id': '137', 'type': '()', 'children': ['138']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': '!='},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ELEMENT_NODE'},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'continue_statement', 'children': []},{'id': '147', 'type': 'if_statement', 'children': ['148', '155']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '152'], 'value': '!='},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'localName'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'UCS'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'continue_statement', 'children': []},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'lName'},{'id': '160', 'type': 'None', 'children': []},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'lUsername'},{'id': '164', 'type': 'None', 'children': []},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'lPassword'},{'id': '168', 'type': 'None', 'children': []},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'lNoSsl'},{'id': '172', 'type': 'False', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'lPort'},{'id': '176', 'type': 'None', 'children': []},{'id': '177', 'type': 'if_statement', 'children': ['178', '186']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'NAME'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'lName'},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'NAME'},{'id': '198', 'type': 'if_statement', 'children': ['199', '207']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'USER_NAME'},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'lUsername'},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'USER_NAME'},{'id': '219', 'type': 'if_statement', 'children': ['220', '228']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'PASSWORD'},{'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': 'lPassword'},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'DecryptPassword'},{'id': '236', 'type': 'argument_list', 'children': ['237', '245']},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'PASSWORD'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '246', 'type': 'if_statement', 'children': ['247', '255']},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'NO_SSL'},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'lNoSsl'},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'NO_SSL'},{'id': '267', 'type': 'if_statement', 'children': ['268', '276']},{'id': '268', 'type': 'call', 'children': ['269', '272']},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'PORT'},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'lPort'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'UcsLoginXml'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'PORT'},{'id': '288', 'type': 'if_statement', 'children': ['289', '304']},{'id': '289', 'type': '()', 'children': ['290']},{'id': '290', 'type': 'boolean_operator', 'children': ['291', '300'], 'value': 'or'},{'id': '291', 'type': 'boolean_operator', 'children': ['292', '296'], 'value': 'or'},{'id': '292', 'type': '()', 'children': ['293']},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '295'], 'value': 'is'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'lName'},{'id': '295', 'type': 'None', 'children': []},{'id': '296', 'type': '()', 'children': ['297']},{'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': '=='},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'lUsername'},{'id': '299', 'type': 'None', 'children': []},{'id': '300', 'type': '()', 'children': ['301']},{'id': '301', 'type': 'comparison_operator', 'children': ['302', '303'], 'value': '=='},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'lPassword'},{'id': '303', 'type': 'None', 'children': []},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'continue_statement', 'children': []},{'id': '306', 'type': 'try_statement', 'children': ['307', '335']},{'id': '307', 'type': 'block', 'children': ['308', '314']},{'id': '308', 'type': 'expression_statement', 'children': ['309']},{'id': '309', 'type': 'assignment', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '311', 'type': 'call', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'UcsHandle'},{'id': '313', 'type': 'argument_list', 'children': []},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'call', 'children': ['316', '319']},{'id': '316', 'type': 'attribute', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'Login'},{'id': '319', 'type': 'argument_list', 'children': ['320', '323', '326', '329', '332']},{'id': '320', 'type': 'keyword_argument', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'lName'},{'id': '323', 'type': 'keyword_argument', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'lUsername'},{'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'lPassword'},{'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'noSsl'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'lNoSsl'},{'id': '332', 'type': 'keyword_argument', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'lPort'},{'id': '335', 'type': 'except_clause', 'children': ['336', '337', '338']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '338', 'type': 'block', 'children': ['339']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'WriteUcsWarning'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'binary_operator', 'children': ['344', '345'], 'value': '%'},{'id': '344', 'type': 'string', 'children': [], 'value': '"[Connection Error<%s>] %s"'},{'id': '345', 'type': 'tuple', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'lName'},{'id': '347', 'type': 'call', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'err'}
def ImportUcsSession(filePath, key): from UcsBase import UcsUtils, WriteUcsWarning, UcsValidationException if filePath is None: raise UcsValidationException("filePath parameter is not provided.") if key is None: raise UcsValidationException("key parameter is not provided.") if not os.path.isfile(filePath) or not os.path.exists(filePath): raise UcsValidationException('[Error]: File <%s> does not exist ' % (filePath)) doc = xml.dom.minidom.parse(filePath) topNode = doc.documentElement if topNode is None or topNode.localName != UcsLoginXml.UCS_HANDLES: return None if (topNode.hasChildNodes()): childList = topNode.childNodes childCount = len(childList) for i in range(childCount): childNode = childList.item(i) if (childNode.nodeType != Node.ELEMENT_NODE): continue if childNode.localName != UcsLoginXml.UCS: continue lName = None lUsername = None lPassword = None lNoSsl = False lPort = None if childNode.hasAttribute(UcsLoginXml.NAME): lName = childNode.getAttribute(UcsLoginXml.NAME) if childNode.hasAttribute(UcsLoginXml.USER_NAME): lUsername = childNode.getAttribute(UcsLoginXml.USER_NAME) if childNode.hasAttribute(UcsLoginXml.PASSWORD): lPassword = UcsUtils.DecryptPassword(childNode.getAttribute(UcsLoginXml.PASSWORD), key) if childNode.hasAttribute(UcsLoginXml.NO_SSL): lNoSsl = childNode.getAttribute(UcsLoginXml.NO_SSL) if childNode.hasAttribute(UcsLoginXml.PORT): lPort = childNode.getAttribute(UcsLoginXml.PORT) if ((lName is None) or (lUsername == None) or (lPassword == None)): continue try: handle = UcsHandle() handle.Login(name=lName, username=lUsername, password=lPassword, noSsl=lNoSsl, port=lPort) except Exception, err: WriteUcsWarning("[Connection Error<%s>] %s" % (lName, str(err)))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'ImportUcsBackup'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dumpXml'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '33', '38', '43', '48', '59', '68', '87', '91', '95', '106', '115', '124', '149', '168', '174', '182', '188', '196', '204', '225', '231', '238', '250', '295', '304', '317', '324', '337', '346', '368', '386']},{'id': '15', 'type': 'import_from_statement', 'children': ['16', '18', '20', '22', '24', '26', '28', '30', '31']},{'id': '16', 'type': 'dotted_name', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'UcsBase'},{'id': '18', 'type': 'dotted_name', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'WriteUcsWarning'},{'id': '20', 'type': 'dotted_name', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '22', 'type': 'dotted_name', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ManagedObject'},{'id': '24', 'type': 'dotted_name', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'WriteObject'},{'id': '26', 'type': 'dotted_name', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '28', 'type': 'dotted_name', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'UcsException'},{'id': '30', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '31', 'type': 'dotted_name', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '33', 'type': 'import_from_statement', 'children': ['34', '36']},{'id': '34', 'type': 'dotted_name', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'Ucs'},{'id': '36', 'type': 'dotted_name', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ConfigConfig'},{'id': '38', 'type': 'import_from_statement', 'children': ['39', '41']},{'id': '39', 'type': 'dotted_name', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'Mos'},{'id': '41', 'type': 'dotted_name', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'MgmtImporter'},{'id': '43', 'type': 'import_from_statement', 'children': ['44', '46']},{'id': '44', 'type': 'dotted_name', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '46', 'type': 'dotted_name', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '48', 'type': 'if_statement', 'children': ['49', '53']},{'id': '49', 'type': '()', 'children': ['50']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_transactionInProgress'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'raise_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'string', 'children': [], 'value': '"UCS transaction in progress. Cannot execute ImportUcsBackup. Complete or Undo UCS transaction."'},{'id': '59', 'type': 'if_statement', 'children': ['60', '62']},{'id': '60', 'type': 'not_operator', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'raise_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'string', 'children': [], 'value': '"path parameter is not provided."'},{'id': '68', 'type': 'if_statement', 'children': ['69', '78']},{'id': '69', 'type': 'not_operator', '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': 'os'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'raise_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '%'},{'id': '84', 'type': 'string', 'children': [], 'value': '"Backup File not found <%s>"'},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'dn'},{'id': '90', 'type': 'None', 'children': []},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'localFile'},{'id': '98', 'type': 'call', 'children': ['99', '104']},{'id': '99', 'type': 'attribute', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'topSystem'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'ManagedObject'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'NamingId'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'TOP_SYSTEM'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'mgmtImporter'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ManagedObject'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'NamingId'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'MGMT_IMPORTER'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'mgmtImporter'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'Hostname'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '139'], 'value': '+'},{'id': '130', 'type': 'call', 'children': ['131', '138']},{'id': '131', 'type': 'attribute', 'children': ['132', '137']},{'id': '132', 'type': 'subscript', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '136', 'type': 'string', 'children': [], 'value': "'COMPUTERNAME'"},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '138', 'type': 'argument_list', 'children': []},{'id': '139', 'type': 'call', 'children': ['140', '147']},{'id': '140', 'type': 'attribute', 'children': ['141', '146']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': "'%Y%m%d%H%M'"},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'dn'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'MakeDn'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'list', 'children': ['158', '163'], 'value': '[topSystem.MakeRn(), mgmtImporter.MakeRn()]'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'topSystem'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'MakeRn'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'mgmtImporter'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'MakeRn'},{'id': '167', 'type': 'argument_list', 'children': []},{'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': 'mgmtImporter'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'Dn'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'dn'},{'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': 'mgmtImporter'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'Status'},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'Status'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'CREATED'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mgmtImporter'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'RemoteFile'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'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': 'mgmtImporter'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'Proto'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'MgmtImporter'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'CONST_PROTO_HTTP'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'mgmtImporter'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'AdminState'},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'MgmtImporter'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'CONST_ADMIN_STATE_ENABLED'},{'id': '204', 'type': 'if_statement', 'children': ['205', '206', '215']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'merge'},{'id': '206', 'type': 'block', 'children': ['207']},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'mgmtImporter'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'MgmtImporter'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'CONST_ACTION_MERGE'},{'id': '215', 'type': 'else_clause', 'children': ['216']},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'mgmtImporter'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'Action'},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'MgmtImporter'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'CONST_ACTION_REPLACE'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'inConfig'},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'ConfigConfig'},{'id': '230', 'type': 'argument_list', 'children': []},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '236']},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'inConfig'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'AddChild'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'mgmtImporter'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'uri'},{'id': '241', 'type': 'binary_operator', 'children': ['242', '243'], 'value': '%'},{'id': '242', 'type': 'string', 'children': [], 'value': '"%s/operations/file-%s/importconfig.txt"'},{'id': '243', 'type': 'tuple', 'children': ['244', '249']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'Uri'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'localFile'},{'id': '250', 'type': 'if_statement', 'children': ['251', '258', '275']},{'id': '251', 'type': 'comparison_operator', 'children': ['252', '255'], 'value': '<'},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '255', 'type': 'tuple', 'children': ['256', '257']},{'id': '256', 'type': 'integer', 'children': [], 'value': '2'},{'id': '257', 'type': 'integer', 'children': [], 'value': '6'},{'id': '258', 'type': 'block', 'children': ['259', '267']},{'id': '259', 'type': 'expression_statement', 'children': ['260']},{'id': '260', 'type': 'assignment', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'uploadFileHandle'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '266', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '267', 'type': 'expression_statement', 'children': ['268']},{'id': '268', 'type': 'assignment', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'uploadFileHandle'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '274', 'type': 'argument_list', 'children': []},{'id': '275', 'type': 'else_clause', 'children': ['276']},{'id': '276', 'type': 'block', 'children': ['277', '283']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'Progress'},{'id': '282', 'type': 'argument_list', 'children': []},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'file_with_callback'},{'id': '288', 'type': 'argument_list', 'children': ['289', '290', '291', '294']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '290', 'type': 'string', 'children': [], 'value': "'rb'"},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'progress'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'filePath'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'urllib2'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'Request'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'uri'},{'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': 'request'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'add_header'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311']},{'id': '310', 'type': 'string', 'children': [], 'value': "'Cookie'"},{'id': '311', 'type': 'binary_operator', 'children': ['312', '313'], 'value': '%'},{'id': '312', 'type': 'string', 'children': [], 'value': "'ucsm-cookie=%s'"},{'id': '313', 'type': '()', 'children': ['314']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': '_cookie'},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'call', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'add_data'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'assignment', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '327', 'type': 'call', 'children': ['328', '336']},{'id': '328', 'type': 'attribute', 'children': ['329', '335']},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'urllib2'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'urlopen'},{'id': '333', 'type': 'argument_list', 'children': ['334']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '336', 'type': 'argument_list', 'children': []},{'id': '337', 'type': 'if_statement', 'children': ['338', '340']},{'id': '338', 'type': 'not_operator', 'children': ['339']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '340', 'type': 'block', 'children': ['341']},{'id': '341', 'type': 'raise_statement', 'children': ['342']},{'id': '342', 'type': 'call', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'string', 'children': [], 'value': '"Unable to upload properly."'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'ccm'},{'id': '349', 'type': 'call', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'ConfigConfMo'},{'id': '353', 'type': 'argument_list', 'children': ['354', '357', '360', '365']},{'id': '354', 'type': 'keyword_argument', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'dn'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'dn'},{'id': '357', 'type': 'keyword_argument', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'inConfig'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'inConfig'},{'id': '360', 'type': 'keyword_argument', 'children': ['361', '362']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'inHierarchical'},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'YesOrNo'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'FALSE'},{'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'dumpXml'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'dumpXml'},{'id': '368', 'type': 'if_statement', 'children': ['369', '375']},{'id': '369', 'type': '()', 'children': ['370']},{'id': '370', 'type': 'comparison_operator', 'children': ['371', '374'], 'value': '!='},{'id': '371', 'type': 'attribute', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'ccm'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'errorCode'},{'id': '374', 'type': 'integer', 'children': [], 'value': '0'},{'id': '375', 'type': 'block', 'children': ['376']},{'id': '376', 'type': 'raise_statement', 'children': ['377']},{'id': '377', 'type': 'call', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'UcsException'},{'id': '379', 'type': 'argument_list', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'ccm'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'errorCode'},{'id': '383', 'type': 'attribute', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'ccm'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'errorDescr'},{'id': '386', 'type': 'return_statement', 'children': ['387']},{'id': '387', 'type': 'call', 'children': ['388', '393']},{'id': '388', 'type': 'attribute', 'children': ['389', '392']},{'id': '389', 'type': 'attribute', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'ccm'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'OutConfig'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'GetChild'},{'id': '393', 'type': 'argument_list', 'children': []}
def ImportUcsBackup(self, path=None, merge=False, dumpXml=False): from UcsBase import WriteUcsWarning, UcsUtils, ManagedObject, WriteObject, UcsUtils, UcsException, \ UcsValidationException from Ucs import ConfigConfig from Mos import MgmtImporter from datetime import datetime if (self._transactionInProgress): raise UcsValidationException( "UCS transaction in progress. Cannot execute ImportUcsBackup. Complete or Undo UCS transaction.") if not path: raise UcsValidationException("path parameter is not provided.") if not os.path.exists(path): raise UcsValidationException("Backup File not found <%s>" % (path)) dn = None filePath = path localFile = os.path.basename(filePath) topSystem = ManagedObject(NamingId.TOP_SYSTEM) mgmtImporter = ManagedObject(NamingId.MGMT_IMPORTER) mgmtImporter.Hostname = os.environ['COMPUTERNAME'].lower() + datetime.now().strftime('%Y%m%d%H%M') dn = UcsUtils.MakeDn([topSystem.MakeRn(), mgmtImporter.MakeRn()]) mgmtImporter.Dn = dn mgmtImporter.Status = Status.CREATED mgmtImporter.RemoteFile = filePath mgmtImporter.Proto = MgmtImporter.CONST_PROTO_HTTP mgmtImporter.AdminState = MgmtImporter.CONST_ADMIN_STATE_ENABLED if merge: mgmtImporter.Action = MgmtImporter.CONST_ACTION_MERGE else: mgmtImporter.Action = MgmtImporter.CONST_ACTION_REPLACE inConfig = ConfigConfig() inConfig.AddChild(mgmtImporter) uri = "%s/operations/file-%s/importconfig.txt" % (self.Uri(), localFile) if sys.version_info < (2, 6): uploadFileHandle = open(filePath, 'rb') stream = uploadFileHandle.read() else: progress = Progress() stream = file_with_callback(filePath, 'rb', progress.update, filePath) request = urllib2.Request(uri) request.add_header('Cookie', 'ucsm-cookie=%s' % (self._cookie)) request.add_data(stream) response = urllib2.urlopen(request).read() if not response: raise UcsValidationException("Unable to upload properly.") ccm = self.ConfigConfMo(dn=dn, inConfig=inConfig, inHierarchical=YesOrNo.FALSE, dumpXml=dumpXml) if (ccm.errorCode != 0): raise UcsException(ccm.errorCode, ccm.errorDescr) return ccm.OutConfig.GetChild()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_suffix_links'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '8', '14']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n Sets all suffix links in all nodes in this trie.\n '''"},{'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': '_suffix_links_set'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'for_statement', 'children': ['15', '18', '23']},{'id': '15', 'type': 'pattern_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'bfs'},{'id': '22', 'type': 'argument_list', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '30', '38', '49', '55', '59', '103', '109', '125']},{'id': '24', 'type': 'if_statement', 'children': ['25', '28']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'continue_statement', 'children': []},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'longest_prefix'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'longest_prefix'},{'id': '38', 'type': 'if_statement', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'has_value'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'longest_prefix'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '49', 'type': 'if_statement', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'has_suffix'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'continue_statement', 'children': []},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '59', 'type': 'while_statement', 'children': ['60', '61']},{'id': '60', 'type': 'True', 'children': []},{'id': '61', 'type': 'block', 'children': ['62', '85']},{'id': '62', 'type': 'if_statement', 'children': ['63', '67', '77']},{'id': '63', 'type': 'not_operator', 'children': ['64']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'has_suffix'},{'id': '67', 'type': 'block', 'children': ['68', '76']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '76', 'type': 'break_statement', 'children': []},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '85', 'type': 'if_statement', 'children': ['86', '91']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '90'], 'value': 'in'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'uplink'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '91', 'type': 'block', 'children': ['92', '102']},{'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': 'current'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'uplink'},{'id': '102', 'type': 'break_statement', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '109', 'type': 'while_statement', 'children': ['110', '118']},{'id': '110', 'type': 'boolean_operator', 'children': ['111', '115'], 'value': 'and'},{'id': '111', 'type': 'not_operator', 'children': ['112']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'has_value'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'has_suffix'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '125', 'type': 'if_statement', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'has_value'},{'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': 'current'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'dict_suffix'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'suffix'}
def _set_suffix_links(self): ''' Sets all suffix links in all nodes in this trie. ''' self._suffix_links_set = True for current, parent in self.bfs(): if parent is None: continue current.longest_prefix = parent.longest_prefix if parent.has_value: current.longest_prefix = parent if current.has_suffix: continue suffix = parent while True: if not suffix.has_suffix: current.suffix = self.root break else: suffix = suffix.suffix if current.uplink in suffix: current.suffix = suffix[current.uplink] break suffix = current.suffix while not suffix.has_value and suffix.has_suffix: suffix = suffix.suffix if suffix.has_value: current.dict_suffix = suffix
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_write_mo'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '5', 'type': 'block', 'children': ['6', '10', '27', '31', '35', '73', '84', '216', '270', '297', '301']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'classNotFound'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'if_statement', 'children': ['11', '22']},{'id': '11', 'type': '()', 'children': ['12']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '21'], 'value': '=='},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'FindClassIdInMoMetaIgnoreCase'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'classNotFound'},{'id': '26', 'type': 'True', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'tabsize'},{'id': '30', 'type': 'integer', 'children': [], 'value': '8'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '34', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '35', 'type': 'if_statement', 'children': ['36', '37', '56']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'classNotFound'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'augmented_assignment', 'children': ['40', '41'], 'value': '+='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '55'], 'value': '+'},{'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '+'},{'id': '43', 'type': 'string', 'children': [], 'value': '"Managed Object\\t\\t\\t:\\t"'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '55', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '56', 'type': 'else_clause', 'children': ['57']},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'augmented_assignment', 'children': ['60', '61'], 'value': '+='},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '72'], 'value': '+'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'},{'id': '63', 'type': 'string', 'children': [], 'value': '"Managed Object\\t\\t\\t:\\t"'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'propMoMeta'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '72', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'augmented_assignment', 'children': ['75', '76'], 'value': '+='},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '83'], 'value': '+'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '*'},{'id': '78', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': '"Managed Object"'},{'id': '83', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '84', 'type': 'if_statement', 'children': ['85', '88', '159']},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'not_operator', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'classNotFound'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '101']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'GetUcsPropertyMetaAttributeList'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'attribute', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'propMoMeta'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '101', 'type': 'block', 'children': ['102', '116', '127', '136']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'propMeta'},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'GetUcsPropertyMeta'},{'id': '109', 'type': 'argument_list', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'propMoMeta'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '116', 'type': 'if_statement', 'children': ['117', '125']},{'id': '117', 'type': '()', 'children': ['118']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '122'], 'value': '=='},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'propMeta'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'access'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'UcsPropertyMeta'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'Internal'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'continue_statement', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '158'], 'value': '+'},{'id': '140', 'type': 'binary_operator', 'children': ['141', '154'], 'value': '+'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '153'], 'value': '+'},{'id': '142', 'type': 'call', 'children': ['143', '149']},{'id': '143', 'type': 'attribute', 'children': ['144', '148']},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'ljust'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '*'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'tabsize'},{'id': '152', 'type': 'integer', 'children': [], 'value': '4'},{'id': '153', 'type': 'string', 'children': [], 'value': "':'"},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '158', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '159', 'type': 'else_clause', 'children': ['160']},{'id': '160', 'type': 'block', 'children': ['161']},{'id': '161', 'type': 'for_statement', 'children': ['162', '163', '166']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '165', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '166', 'type': 'block', 'children': ['167', '180', '188']},{'id': '167', 'type': 'if_statement', 'children': ['168', '178']},{'id': '168', 'type': '()', 'children': ['169']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'in'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '171', 'type': 'list', 'children': ['172', '173', '174', '175', '176', '177'], 'value': "['classId', 'XtraProperty', 'handle', 'propMoMeta', 'dirtyMask', 'child']"},{'id': '172', 'type': 'string', 'children': [], 'value': "'classId'"},{'id': '173', 'type': 'string', 'children': [], 'value': "'XtraProperty'"},{'id': '174', 'type': 'string', 'children': [], 'value': "'handle'"},{'id': '175', 'type': 'string', 'children': [], 'value': "'propMoMeta'"},{'id': '176', 'type': 'string', 'children': [], 'value': "'dirtyMask'"},{'id': '177', 'type': 'string', 'children': [], 'value': "'child'"},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'continue_statement', 'children': []},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '183', 'type': 'subscript', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'augmented_assignment', 'children': ['190', '191'], 'value': '+='},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '191', 'type': 'binary_operator', 'children': ['192', '215'], 'value': '+'},{'id': '192', 'type': 'binary_operator', 'children': ['193', '211'], 'value': '+'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '210'], 'value': '+'},{'id': '194', 'type': 'call', 'children': ['195', '206']},{'id': '195', 'type': 'attribute', 'children': ['196', '205']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ljust'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '*'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'tabsize'},{'id': '209', 'type': 'integer', 'children': [], 'value': '4'},{'id': '210', 'type': 'string', 'children': [], 'value': "':'"},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '215', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '216', 'type': 'if_statement', 'children': ['217', '225']},{'id': '217', 'type': 'call', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '221', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'has_key'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'string', 'children': [], 'value': "'XtraProperty'"},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'for_statement', 'children': ['227', '228', '233']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'xtraProp'},{'id': '228', 'type': 'subscript', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '231', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '232', 'type': 'string', 'children': [], 'value': "'XtraProperty'"},{'id': '233', 'type': 'block', 'children': ['234']},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'augmented_assignment', 'children': ['236', '237'], 'value': '+='},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '237', 'type': 'binary_operator', 'children': ['238', '269'], 'value': '+'},{'id': '238', 'type': 'binary_operator', 'children': ['239', '259'], 'value': '+'},{'id': '239', 'type': 'binary_operator', 'children': ['240', '258'], 'value': '+'},{'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '+'},{'id': '241', 'type': 'string', 'children': [], 'value': "'[X]'"},{'id': '242', 'type': 'call', 'children': ['243', '254']},{'id': '243', 'type': 'attribute', 'children': ['244', '253']},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'xtraProp'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'ljust'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'binary_operator', 'children': ['256', '257'], 'value': '*'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'tabsize'},{'id': '257', 'type': 'integer', 'children': [], 'value': '4'},{'id': '258', 'type': 'string', 'children': [], 'value': "':'"},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'subscript', 'children': ['263', '268']},{'id': '263', 'type': 'subscript', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '266', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '267', 'type': 'string', 'children': [], 'value': "'XtraProperty'"},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'xtraProp'},{'id': '269', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'augmented_assignment', 'children': ['272', '273'], 'value': '+='},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '273', 'type': 'binary_operator', 'children': ['274', '296'], 'value': '+'},{'id': '274', 'type': 'binary_operator', 'children': ['275', '288'], 'value': '+'},{'id': '275', 'type': 'binary_operator', 'children': ['276', '287'], 'value': '+'},{'id': '276', 'type': 'call', 'children': ['277', '283']},{'id': '277', 'type': 'attribute', 'children': ['278', '282']},{'id': '278', 'type': 'call', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'string', 'children': [], 'value': '"Ucs"'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'ljust'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'binary_operator', 'children': ['285', '286'], 'value': '*'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'tabsize'},{'id': '286', 'type': 'integer', 'children': [], 'value': '4'},{'id': '287', 'type': 'string', 'children': [], 'value': "':'"},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'attribute', 'children': ['292', '295']},{'id': '292', 'type': 'attribute', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'mo'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '295', 'type': 'identifier', 'children': [], 'value': '_ucs'},{'id': '296', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'augmented_assignment', 'children': ['299', '300'], 'value': '+='},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'outstr'},{'id': '300', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '301', 'type': 'return_statement', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'outstr'}
def _write_mo(mo): classNotFound = False if (UcsUtils.FindClassIdInMoMetaIgnoreCase(mo.classId) == None): classNotFound = True tabsize = 8 outstr = "\n" if classNotFound: outstr += "Managed Object\t\t\t:\t" + str(UcsUtils.WordU(mo.classId)) + "\n" else: outstr += "Managed Object\t\t\t:\t" + str(mo.propMoMeta.name) + "\n" outstr += "-" * len("Managed Object") + "\n" if (not classNotFound): for prop in UcsUtils.GetUcsPropertyMetaAttributeList(mo.propMoMeta.name): propMeta = UcsUtils.GetUcsPropertyMeta(mo.propMoMeta.name, prop) if (propMeta.access == UcsPropertyMeta.Internal): continue val = mo.getattr(prop) outstr += str(prop).ljust(tabsize * 4) + ':' + str(val) + "\n" else: for prop in mo.__dict__: if (prop in ['classId', 'XtraProperty', 'handle', 'propMoMeta', 'dirtyMask', 'child']): continue val = mo.__dict__[prop] outstr += str(UcsUtils.WordU(prop)).ljust(tabsize * 4) + ':' + str(val) + "\n" if mo.__dict__.has_key('XtraProperty'): for xtraProp in mo.__dict__['XtraProperty']: outstr += '[X]' + str(UcsUtils.WordU(xtraProp)).ljust(tabsize * 4) + ':' + str( mo.__dict__['XtraProperty'][xtraProp]) + "\n" outstr += str("Ucs").ljust(tabsize * 4) + ':' + str(mo.handle._ucs) + "\n" outstr += "\n" return outstr
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'LoadFromXml'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '7', 'type': 'block', 'children': ['8', '15', '183']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'SetHandle'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'handle'},{'id': '15', 'type': 'if_statement', 'children': ['16', '21']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'hasAttributes'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '28', '35', '141']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'attCount'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '41']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'attCount'},{'id': '41', 'type': 'block', 'children': ['42', '51', '62']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'attNode'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'attNode'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'localName'},{'id': '62', 'type': 'if_statement', 'children': ['63', '74', '121']},{'id': '63', 'type': '()', 'children': ['64']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '73'], 'value': '!='},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'FindClassIdInMoMetaIgnoreCase'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'if_statement', 'children': ['76', '87', '101']},{'id': '76', 'type': '()', 'children': ['77']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'in'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'GetUcsPropertyMetaAttributeList'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '87', 'type': 'block', 'children': ['88']},{'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': 'setattr'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'attNode'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'value'},{'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', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '108', 'type': 'argument_list', 'children': ['109', '115']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'attNode'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '121', 'type': 'else_clause', 'children': ['122']},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_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': 'setattr'},{'id': '128', 'type': 'argument_list', 'children': ['129', '135']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'attr'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'attNode'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '141', 'type': 'if_statement', 'children': ['142', '159']},{'id': '142', 'type': 'boolean_operator', 'children': ['143', '151'], 'value': 'and'},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '150'], 'value': '=='},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': '"Rn"'},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '158'], 'value': '!='},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': '"Dn"'},{'id': '158', 'type': 'None', 'children': []},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '165', 'type': 'argument_list', 'children': ['166', '167']},{'id': '166', 'type': 'string', 'children': [], 'value': '"Rn"'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176', '177']},{'id': '175', 'type': 'string', 'children': [], 'value': "r'^.*/'"},{'id': '176', 'type': 'string', 'children': [], 'value': "''"},{'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': 'getattr'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'string', 'children': [], 'value': '"Dn"'},{'id': '183', 'type': 'if_statement', 'children': ['184', '190']},{'id': '184', 'type': '()', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'hasChildNodes'},{'id': '189', 'type': 'argument_list', 'children': []},{'id': '190', 'type': 'block', 'children': ['191', '197', '204']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'childList'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'childNodes'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'childCount'},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'childList'},{'id': '204', 'type': 'for_statement', 'children': ['205', '206', '210']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'childCount'},{'id': '210', 'type': 'block', 'children': ['211', '220', '231', '243', '257', '266']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'childList'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '220', 'type': 'if_statement', 'children': ['221', '229']},{'id': '221', 'type': '()', 'children': ['222']},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '226'], 'value': '!='},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'Node'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'ELEMENT_NODE'},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'continue_statement', 'children': []},{'id': '231', 'type': 'if_statement', 'children': ['232', '241']},{'id': '232', 'type': 'comparison_operator', 'children': ['233', '236'], 'value': 'in'},{'id': '233', 'type': 'attribute', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'localName'},{'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': 'propMoMeta'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'fieldNames'},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'pass_statement', 'children': []},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'ManagedObject'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'WordU'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'localName'},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'call', 'children': ['259', '264']},{'id': '259', 'type': 'attribute', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'LoadFromXml'},{'id': '271', 'type': 'argument_list', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'childNode'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'handle'}
def LoadFromXml(self, node, handle): self.SetHandle(handle) if node.hasAttributes(): attributes = node.attributes attCount = len(attributes) for i in range(attCount): attNode = attributes.item(i) attr = UcsUtils.WordU(attNode.localName) if (UcsUtils.FindClassIdInMoMetaIgnoreCase(self.classId) != None): if (attr in UcsUtils.GetUcsPropertyMetaAttributeList(self.classId)): self.setattr(attr, str(attNode.value)) else: self.setattr(UcsUtils.WordU(attr), str(attNode.value)) else: self.setattr(UcsUtils.WordU(attr), str(attNode.value)) if self.getattr("Rn") == None and self.getattr("Dn") != None: self.setattr("Rn", str(re.sub(r'^.*/', '', self.getattr("Dn")))) if (node.hasChildNodes()): childList = node.childNodes childCount = len(childList) for i in range(childCount): childNode = childList.item(i) if (childNode.nodeType != Node.ELEMENT_NODE): continue if childNode.localName in self.propMoMeta.fieldNames: pass c = ManagedObject(UcsUtils.WordU(childNode.localName)) self.child.append(c) c.LoadFromXml(childNode, handle)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetJavaInstallationPath'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '10']},{'id': '5', 'type': 'import_statement', 'children': ['6', '8']},{'id': '6', 'type': 'dotted_name', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '8', 'type': 'dotted_name', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '10', 'type': 'if_statement', 'children': ['11', '18', '85']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '17'], 'value': '=='},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'string', 'children': [], 'value': '"Linux"'},{'id': '18', 'type': 'block', 'children': ['19', '30']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '22', 'type': 'call', 'children': ['23', '28']},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': "'JAVA_HOME'"},{'id': '30', 'type': 'if_statement', 'children': ['31', '33', '39']},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'raise_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': '"Please make sure JAVA is installed and variable JAVA_HOME is set properly."'},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41', '53', '65']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '52', 'type': 'string', 'children': [], 'value': "'bin'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '64', 'type': 'string', 'children': [], 'value': "'javaws'"},{'id': '65', 'type': 'if_statement', 'children': ['66', '75', '81']},{'id': '66', 'type': 'not_operator', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '73']},{'id': '68', 'type': 'attribute', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'raise_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'string', 'children': [], 'value': '"javaws is not installed on System."'},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '85', 'type': 'elif_clause', 'children': ['86', '101']},{'id': '86', 'type': 'boolean_operator', 'children': ['87', '94'], 'value': 'or'},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '93'], 'value': '=='},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '92', 'type': 'argument_list', 'children': []},{'id': '93', 'type': 'string', 'children': [], 'value': '"Windows"'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '100'], 'value': '=='},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '99', 'type': 'argument_list', 'children': []},{'id': '100', 'type': 'string', 'children': [], 'value': '"Microsoft"'},{'id': '101', 'type': 'block', 'children': ['102', '113', '127', '141']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '105', 'type': 'call', 'children': ['106', '111']},{'id': '106', 'type': 'attribute', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': "'JAVA_HOME'"},{'id': '113', 'type': 'if_statement', 'children': ['114', '117']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '=='},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '116', 'type': 'None', 'children': []},{'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': 'path'},{'id': '121', 'type': 'call', 'children': ['122', '125']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'CheckRegistryKey'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'string', 'children': [], 'value': 'r"SOFTWARE\\\\JavaSoft\\\\Java Runtime Environment\\\\"'},{'id': '127', 'type': 'if_statement', 'children': ['128', '131']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '130', 'type': 'None', 'children': []},{'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': 'path'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'UcsUtils'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'CheckRegistryKey'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'string', 'children': [], 'value': 'r"SOFTWARE\\\\Wow6432Node\\\\JavaSoft\\\\Java Runtime Environment"'},{'id': '141', 'type': 'if_statement', 'children': ['142', '144', '150']},{'id': '142', 'type': 'not_operator', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'raise_statement', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'string', 'children': [], 'value': '"Please make sure JAVA is installed."'},{'id': '150', 'type': 'else_clause', 'children': ['151']},{'id': '151', 'type': 'block', 'children': ['152', '164', '176']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '155', 'type': 'call', 'children': ['156', '161']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '161', 'type': 'argument_list', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '163', 'type': 'string', 'children': [], 'value': "'bin'"},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'join'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '175', 'type': 'string', 'children': [], 'value': "'javaws.exe'"},{'id': '176', 'type': 'if_statement', 'children': ['177', '186', '192']},{'id': '177', 'type': 'not_operator', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'raise_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'UcsValidationException'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'string', 'children': [], 'value': '"javaws.exe is not installed on System."'},{'id': '192', 'type': 'else_clause', 'children': ['193']},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'return_statement', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'path'}
def GetJavaInstallationPath(): import os, platform if platform.system() == "Linux": path = os.environ.get('JAVA_HOME') if not path: raise UcsValidationException( "Please make sure JAVA is installed and variable JAVA_HOME is set properly.") else: path = os.path.join(path, 'bin') path = os.path.join(path, 'javaws') if not os.path.exists(path): raise UcsValidationException("javaws is not installed on System.") else: return path elif platform.system() == "Windows" or platform.system() == "Microsoft": path = os.environ.get('JAVA_HOME') if path == None: path = UcsUtils.CheckRegistryKey(r"SOFTWARE\\JavaSoft\\Java Runtime Environment\\") if path == None: path = UcsUtils.CheckRegistryKey(r"SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment") if not path: raise UcsValidationException("Please make sure JAVA is installed.") else: path = os.path.join(path, 'bin') path = os.path.join(path, 'javaws.exe') if not os.path.exists(path): raise UcsValidationException("javaws.exe is not installed on System.") else: return path
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GetSyncMoConfig'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ConfigDoc'},{'id': '5', 'type': 'block', 'children': ['6', '10', '19', '245']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'moConfigMap'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'configList'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ConfigDoc'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'getElementsByTagName'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'string', 'children': [], 'value': '"mo"'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'configList'},{'id': '22', 'type': 'block', 'children': ['23', '27', '31', '35', '39', '43', '47', '51', '55', '72', '89', '106', '123', '140', '157', '174', '191', '195', '212']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '26', 'type': 'None', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'noun'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'actionVersion'},{'id': '38', 'type': 'None', 'children': []},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ignoreReason'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'excludeList'},{'id': '54', 'type': 'None', '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': 'moConfigNode'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': '"classid"'},{'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': 'classId'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': '"classid"'},{'id': '72', 'type': 'if_statement', 'children': ['73', '79']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'string', 'children': [], 'value': '"noun"'},{'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': 'noun'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'string', 'children': [], 'value': '"noun"'},{'id': '89', 'type': 'if_statement', 'children': ['90', '96']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': '"version"'},{'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': 'version'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'string', 'children': [], 'value': '"version"'},{'id': '106', 'type': 'if_statement', 'children': ['107', '113']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'string', 'children': [], 'value': '"actionVersion"'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'actionVersion'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': '"actionVersion"'},{'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': 'moConfigNode'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'string', 'children': [], 'value': '"action"'},{'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': 'action'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'string', 'children': [], 'value': '"action"'},{'id': '140', 'type': 'if_statement', 'children': ['141', '147']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'string', 'children': [], 'value': '"ignoreReason"'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'ignoreReason'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'string', 'children': [], 'value': '"ignoreReason"'},{'id': '157', 'type': 'if_statement', 'children': ['158', '164']},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'string', 'children': [], 'value': '"status"'},{'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': 'status'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'string', 'children': [], 'value': '"status"'},{'id': '174', 'type': 'if_statement', 'children': ['175', '181']},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'hasAttribute'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'string', 'children': [], 'value': '"excludeList"'},{'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': 'excludeList'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'moConfigNode'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'string', 'children': [], 'value': '"excludeList"'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'moConfig'},{'id': '194', 'type': 'None', 'children': []},{'id': '195', 'type': 'if_statement', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'classId'},{'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': 'moConfig'},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'SyncMoConfig'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205', '206', '207', '208', '209', '210', '211']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'noun'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'version'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'actionVersion'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ignoreReason'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'status'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'excludeList'},{'id': '212', 'type': 'if_statement', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'moConfig'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'if_statement', 'children': ['216', '219', '226']},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': 'in'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'moConfigMap'},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '225']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'moConfigMap'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'moConfig'},{'id': '226', 'type': 'else_clause', 'children': ['227']},{'id': '227', 'type': 'block', 'children': ['228', '232', '239']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'moConfigList'},{'id': '231', 'type': 'list', 'children': [], 'value': '[]'},{'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': 'moConfigList'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'moConfig'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '244']},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'moConfigMap'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'classId'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'moConfigList'},{'id': '245', 'type': 'return_statement', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'moConfigMap'}
def GetSyncMoConfig(ConfigDoc): moConfigMap = {} configList = ConfigDoc.getElementsByTagName("mo") for moConfigNode in configList: classId = None noun = None version = None actionVersion = None action = None ignoreReason = None status = None excludeList = None if moConfigNode.hasAttribute("classid"): classId = moConfigNode.getAttribute("classid") if moConfigNode.hasAttribute("noun"): noun = moConfigNode.getAttribute("noun") if moConfigNode.hasAttribute("version"): version = moConfigNode.getAttribute("version") if moConfigNode.hasAttribute("actionVersion"): actionVersion = moConfigNode.getAttribute("actionVersion") if moConfigNode.hasAttribute("action"): action = moConfigNode.getAttribute("action") if moConfigNode.hasAttribute("ignoreReason"): ignoreReason = moConfigNode.getAttribute("ignoreReason") if moConfigNode.hasAttribute("status"): status = moConfigNode.getAttribute("status") if moConfigNode.hasAttribute("excludeList"): excludeList = moConfigNode.getAttribute("excludeList") moConfig = None if classId: moConfig = SyncMoConfig(classId, noun, version, actionVersion, action, ignoreReason, status, excludeList) if moConfig: if classId in moConfigMap: moConfigMap[classId] = moConfig else: moConfigList = [] moConfigList.append(moConfig) moConfigMap[classId] = moConfigList return moConfigMap
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'duration'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'pad'},{'id': '13', 'type': 'string', 'children': [], 'value': "', '"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'justnow'},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '26', 'type': 'integer', 'children': [], 'value': '10'},{'id': '27', 'type': 'block', 'children': ['28', '30', '41', '48', '63', '84', '100']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'string', 'children': [], 'value': '\'\'\'\n Time delta compared to ``t``. You can override ``now`` to specify what time\n to compare to.\n :param t: timestamp, :class:`datetime.date` or :class:`datetime.datetime`\n object\n :param now: default ``None``, optionally a :class:`datetime.datetime`\n object\n :param precision: default ``1``, number of fragments to return\n :param words: default ``None``, allow words like "yesterday", if set to\n ``None`` this will be enabled if ``precision`` is set to\n ``1``\n :param justnow: default ``datetime.timedelta(seconds=10)``,\n :class:`datetime.timedelta` object passed to :func:`delta`\n representing tolerance for considering argument ``t`` as\n meaning \'just now\'\n >>> import time\n >>> from datetime import datetime\n >>> print(duration(time.time() + 1))\n just now\n >>> print(duration(time.time() + 11))\n 11 seconds from now\n >>> print(duration(time.time() - 1))\n just now\n >>> print(duration(time.time() - 11))\n 11 seconds ago\n >>> print(duration(time.time() - 3601))\n an hour ago\n >>> print(duration(time.time() - 7201))\n 2 hours ago\n >>> print(duration(time.time() - 1234567))\n 2 weeks ago\n >>> print(duration(time.time() + 7200, precision=1))\n 2 hours from now\n >>> print(duration(time.time() - 1234567, precision=3))\n 2 weeks, 6 hours, 56 minutes ago\n >>> print(duration(datetime(2014, 9, 8), now=datetime(2014, 9, 9)))\n yesterday\n >>> print(duration(datetime(2014, 9, 7, 23), now=datetime(2014, 9, 9)))\n 1 day ago\n >>> print(duration(datetime(2014, 9, 10), now=datetime(2014, 9, 9)))\n tomorrow\n >>> print(duration(datetime(2014, 9, 11, 1), now=datetime(2014, 9, 9, 23)))\n 1 day from now\n \'\'\''},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '33', 'type': 'None', 'children': []},{'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': 'words'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': '_to_datetime'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_to_datetime'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '56'], 'value': 'or'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'now'},{'id': '62', 'type': 'argument_list', 'children': []},{'id': '63', 'type': 'if_statement', 'children': ['64', '67', '75']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': '<'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 't2'},{'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': 'format'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': "'%s ago'"},{'id': '75', 'type': 'else_clause', 'children': ['76']},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': "'%s from now'"},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'pattern_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'remains'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'delta'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '94', '97']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 't1'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'justnow'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'justnow'},{'id': '100', 'type': 'if_statement', 'children': ['101', '124', '127', '167']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'in'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '103', 'type': 'tuple', 'children': ['104', '108', '112', '116', '120']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': "'just now'"},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'string', 'children': [], 'value': "'yesterday'"},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'string', 'children': [], 'value': "'tomorrow'"},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'last week'"},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': "'next week'"},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '127', 'type': 'elif_clause', 'children': ['128', '133']},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '132'], 'value': 'and'},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': '>'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'remains'},{'id': '133', 'type': 'block', 'children': ['134', '147']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 't3'},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '-'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'timedelta'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'seconds'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'remains'},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'pad'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'list', 'children': ['154', '155'], 'value': '[\n result,\n duration(t2, t3, precision - 1, pad, words=False),\n ]'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'duration'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159', '160', '163', '164']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 't2'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 't3'},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '-'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'precision'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'pad'},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'words'},{'id': '166', 'type': 'False', 'children': []},{'id': '167', 'type': 'else_clause', 'children': ['168']},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '%'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '172', 'type': 'tuple', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'result'}
def duration(t, now=None, precision=1, pad=', ', words=None, justnow=datetime.timedelta(seconds=10)): ''' Time delta compared to ``t``. You can override ``now`` to specify what time to compare to. :param t: timestamp, :class:`datetime.date` or :class:`datetime.datetime` object :param now: default ``None``, optionally a :class:`datetime.datetime` object :param precision: default ``1``, number of fragments to return :param words: default ``None``, allow words like "yesterday", if set to ``None`` this will be enabled if ``precision`` is set to ``1`` :param justnow: default ``datetime.timedelta(seconds=10)``, :class:`datetime.timedelta` object passed to :func:`delta` representing tolerance for considering argument ``t`` as meaning 'just now' >>> import time >>> from datetime import datetime >>> print(duration(time.time() + 1)) just now >>> print(duration(time.time() + 11)) 11 seconds from now >>> print(duration(time.time() - 1)) just now >>> print(duration(time.time() - 11)) 11 seconds ago >>> print(duration(time.time() - 3601)) an hour ago >>> print(duration(time.time() - 7201)) 2 hours ago >>> print(duration(time.time() - 1234567)) 2 weeks ago >>> print(duration(time.time() + 7200, precision=1)) 2 hours from now >>> print(duration(time.time() - 1234567, precision=3)) 2 weeks, 6 hours, 56 minutes ago >>> print(duration(datetime(2014, 9, 8), now=datetime(2014, 9, 9))) yesterday >>> print(duration(datetime(2014, 9, 7, 23), now=datetime(2014, 9, 9))) 1 day ago >>> print(duration(datetime(2014, 9, 10), now=datetime(2014, 9, 9))) tomorrow >>> print(duration(datetime(2014, 9, 11, 1), now=datetime(2014, 9, 9, 23))) 1 day from now ''' if words is None: words = precision == 1 t1 = _to_datetime(t) t2 = _to_datetime(now or datetime.datetime.now()) if t1 < t2: format = _('%s ago') else: format = _('%s from now') result, remains = delta(t1, t2, words=words, justnow=justnow) if result in ( _('just now'), _('yesterday'), _('tomorrow'), _('last week'), _('next week'), ): return result elif precision > 1 and remains: t3 = t2 - datetime.timedelta(seconds=remains) return pad.join([ result, duration(t2, t3, precision - 1, pad, words=False), ]) else: return format % (result,)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '6', 'type': 'block', 'children': ['7', '15', '23', '29']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'create_query'},{'id': '14', 'type': 'argument_list', 'children': []},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'QueryParser'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'query_string'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'query'},{'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': 'parser'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'query'}
def search(self, query_string): query = self.create_query() parser = QueryParser(query_string, query) parser.parse() return self.query(query)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'wrap_error'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'renderer_context'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'keys_are_fields'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'issue_is_title'},{'id': '9', 'type': 'block', 'children': ['10', '20', '31', '35', '127', '135', '141']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'renderer_context'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"response"'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '28'], 'value': 'and'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '34', 'type': 'list', 'children': [], 'value': '[]'},{'id': '35', 'type': 'for_statement', 'children': ['36', '39', '44']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'issues'},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '43', 'type': 'argument_list', 'children': []},{'id': '44', 'type': 'block', 'children': ['45', '59']},{'id': '45', 'type': 'if_statement', 'children': ['46', '53']},{'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': 'issues'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'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': 'issues'},{'id': '57', 'type': 'list', 'children': ['58'], 'value': '[issues]'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'issues'},{'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'issue'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'issues'},{'id': '62', 'type': 'block', 'children': ['63', '71', '77', '94', '120']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dict_class'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '75', 'type': 'string', 'children': [], 'value': '"status"'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '77', 'type': 'if_statement', 'children': ['78', '79', '86']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'issue_is_title'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '84', 'type': 'string', 'children': [], 'value': '"title"'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'issue'},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '92', 'type': 'string', 'children': [], 'value': '"detail"'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'issue'},{'id': '94', 'type': 'if_statement', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'keys_are_fields'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'if_statement', 'children': ['98', '103', '110']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'in'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '100', 'type': 'tuple', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "'non_field_errors'"},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'NON_FIELD_ERRORS'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '108', 'type': 'string', 'children': [], 'value': '"path"'},{'id': '109', 'type': 'string', 'children': [], 'value': "'/-'"},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '116', 'type': 'string', 'children': [], 'value': '"path"'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '+'},{'id': '118', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': 'errors'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'wrapper'},{'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': 'dict_class'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'wrapper'},{'id': '139', 'type': 'string', 'children': [], 'value': '"errors"'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'wrapper'}
def wrap_error( self, data, renderer_context, keys_are_fields, issue_is_title): response = renderer_context.get("response", None) status_code = str(response and response.status_code) errors = [] for field, issues in data.items(): if isinstance(issues, six.string_types): issues = [issues] for issue in issues: error = self.dict_class() error["status"] = status_code if issue_is_title: error["title"] = issue else: error["detail"] = issue if keys_are_fields: if field in ('non_field_errors', NON_FIELD_ERRORS): error["path"] = '/-' else: error["path"] = '/' + field errors.append(error) wrapper = self.dict_class() wrapper["errors"] = errors return wrapper
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lunr'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'documents'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '115', '122', '150', '186']},{'id': '11', 'type': 'if_statement', 'children': ['12', '19', '87']},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '16'], 'value': 'and'},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'LANGUAGE_SUPPORT'},{'id': '19', 'type': 'block', 'children': ['20', '32', '46', '78']},{'id': '20', 'type': 'if_statement', 'children': ['21', '26']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '30', 'type': 'list', 'children': ['31'], 'value': '[languages]'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'unsupported_languages'},{'id': '35', 'type': 'binary_operator', 'children': ['36', '40'], 'value': '-'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'SUPPORTED_LANGUAGES'},{'id': '46', 'type': 'if_statement', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'unsupported_languages'},{'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': 'RuntimeError'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '59']},{'id': '54', 'type': 'attribute', 'children': ['55', '58']},{'id': '55', 'type': 'concatenated_string', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': '"The specified languages {} are not supported, "'},{'id': '57', 'type': 'string', 'children': [], 'value': '"please choose one of {}"'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '59', 'type': 'argument_list', 'children': ['60', '66']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': '", "'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'unsupported_languages'},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': '", "'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'SUPPORTED_LANGUAGES'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '77', 'type': 'argument_list', 'children': []},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'get_nltk_builder'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'languages'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89', '95', '106']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'Builder'},{'id': '94', 'type': 'argument_list', 'children': []},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '102']},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'pipeline'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104', '105']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'trimmer'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'stop_word_filter'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'stemmer'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'search_pipeline'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'stemmer'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '122', 'type': 'for_statement', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'if_statement', 'children': ['127', '132', '141']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'dictionary_splat', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '141', 'type': 'else_clause', 'children': ['142']},{'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': 'builder'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '153']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'documents'},{'id': '153', 'type': 'block', 'children': ['154']},{'id': '154', 'type': 'if_statement', 'children': ['155', '162', '177']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '159', 'type': 'tuple', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '168', 'type': 'argument_list', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'},{'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '176', 'type': 'integer', 'children': [], 'value': '1'},{'id': '177', 'type': 'else_clause', 'children': ['178']},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '186', 'type': 'return_statement', 'children': ['187']},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'builder'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'build'},{'id': '191', 'type': 'argument_list', 'children': []}
def lunr(ref, fields, documents, languages=None): if languages is not None and lang.LANGUAGE_SUPPORT: if isinstance(languages, basestring): languages = [languages] unsupported_languages = set(languages) - set(lang.SUPPORTED_LANGUAGES) if unsupported_languages: raise RuntimeError( "The specified languages {} are not supported, " "please choose one of {}".format( ", ".join(unsupported_languages), ", ".join(lang.SUPPORTED_LANGUAGES.keys()), ) ) builder = lang.get_nltk_builder(languages) else: builder = Builder() builder.pipeline.add(trimmer, stop_word_filter, stemmer) builder.search_pipeline.add(stemmer) builder.ref(ref) for field in fields: if isinstance(field, dict): builder.field(**field) else: builder.field(field) for document in documents: if isinstance(document, (tuple, list)): builder.add(document[0], attributes=document[1]) else: builder.add(document) return builder.build()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_trie'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pattern_filename'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'pattern_format'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'on_word_boundaries'},{'id': '8', 'type': 'block', 'children': ['9', '11', '15', '34', '52', '62', '66', '357', '370']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "'''\n Constructs a finite state machine for performing string rewriting.\n Arguments:\n - `pattern_filename`:\n - `pattern_format`:\n - `encoding`:\n - `on_word_boundaries`:\n '''"},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'boundaries'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'on_word_boundaries'},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'boolean_operator', 'children': ['17', '20'], 'value': 'or'},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': '=='},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'pattern_format'},{'id': '19', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'on_word_boundaries'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '28']},{'id': '25', 'type': 'pattern_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'tsv'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'boundaries'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'detect_pattern_format'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'pattern_filename'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'on_word_boundaries'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '=='},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'pattern_format'},{'id': '37', 'type': 'string', 'children': [], 'value': "'auto'"},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'if_statement', 'children': ['40', '41', '46']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'tsv'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pattern_format'},{'id': '45', 'type': 'string', 'children': [], 'value': "'tsv'"},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'pattern_format'},{'id': '51', 'type': 'string', 'children': [], 'value': "'sed'"},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'trie'},{'id': '55', 'type': 'call', 'children': ['56', '61']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'fsed'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ahocorasick'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'AhoCorasickTrie'},{'id': '61', 'type': 'argument_list', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'num_candidates'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'with_statement', 'children': ['67', '76']},{'id': '67', 'type': 'with_clause', 'children': ['68']},{'id': '68', 'type': 'with_item', 'children': ['69']},{'id': '69', 'type': 'as_pattern', 'children': ['70', '74']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'open_file'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'pattern_filename'},{'id': '74', 'type': 'as_pattern_target', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pattern_file'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'for_statement', 'children': ['78', '81', '85']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pattern_file'},{'id': '85', 'type': 'block', 'children': ['86', '100', '109', '290', '294', '322', '329', '336', '351']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '89', 'type': 'call', 'children': ['90', '98']},{'id': '90', 'type': 'attribute', 'children': ['91', '97']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '100', 'type': 'if_statement', 'children': ['101', '107']},{'id': '101', 'type': 'not_operator', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'continue_statement', 'children': []},{'id': '109', 'type': 'if_statement', 'children': ['110', '113', '154']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'pattern_format'},{'id': '112', 'type': 'string', 'children': [], 'value': "'tsv'"},{'id': '113', 'type': 'block', 'children': ['114', '123', '148']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '123', 'type': 'if_statement', 'children': ['124', '130']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '129'], 'value': '!='},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '129', 'type': 'integer', 'children': [], 'value': '2'},{'id': '130', 'type': 'block', 'children': ['131', '147']},{'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': 'LOGGER'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '144']},{'id': '138', 'type': 'attribute', 'children': ['139', '143']},{'id': '139', 'type': '()', 'children': ['140']},{'id': '140', 'type': 'concatenated_string', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': "'skipping line {} of pattern file (not '"},{'id': '142', 'type': 'string', 'children': [], 'value': "'in tab-separated format): {}'"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '147', 'type': 'continue_statement', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '153']},{'id': '150', 'type': 'pattern_list', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '154', 'type': 'elif_clause', 'children': ['155', '158']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '=='},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'pattern_format'},{'id': '157', 'type': 'string', 'children': [], 'value': "'sed'"},{'id': '158', 'type': 'block', 'children': ['159', '165', '173', '264']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '164', 'type': 'None', 'children': []},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'if_statement', 'children': ['174', '179']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': '=='},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '177', 'type': 'integer', 'children': [], 'value': '0'},{'id': '178', 'type': 'string', 'children': [], 'value': "'s'"},{'id': '179', 'type': 'block', 'children': ['180', '186', '197', '212']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'if_statement', 'children': ['187', '190']},{'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'in'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '189', 'type': 'string', 'children': [], 'value': "'.^$*+?[](){}|\\\\'"},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '+'},{'id': '195', 'type': 'string', 'children': [], 'value': "'\\\\'"},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '204', 'type': 'argument_list', 'children': ['205', '211']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'string', 'children': [], 'value': "r'(?<!\\\\){}'"},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '212', 'type': 'if_statement', 'children': ['213', '219']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '218'], 'value': '=='},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '218', 'type': 'integer', 'children': [], 'value': '4'},{'id': '219', 'type': 'block', 'children': ['220', '232', '248']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '225']},{'id': '222', 'type': 'pattern_list', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '225', 'type': 'expression_list', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '228', 'type': 'integer', 'children': [], 'value': '1'},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '231', 'type': 'integer', 'children': [], 'value': '2'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '239', 'type': 'argument_list', 'children': ['240', '246', '247']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'string', 'children': [], 'value': "r'(?<!\\\\)\\\\{}'"},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '248', 'type': 'expression_statement', 'children': ['249']},{'id': '249', 'type': 'assignment', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '255', 'type': 'argument_list', 'children': ['256', '262', '263']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'string', 'children': [], 'value': "r'(?<!\\\\)\\\\{}'"},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'delim'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '264', 'type': 'if_statement', 'children': ['265', '272']},{'id': '265', 'type': 'boolean_operator', 'children': ['266', '269'], 'value': 'or'},{'id': '266', 'type': 'comparison_operator', 'children': ['267', '268'], 'value': 'is'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '268', 'type': 'None', 'children': []},{'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': 'is'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '271', 'type': 'None', 'children': []},{'id': '272', 'type': 'block', 'children': ['273', '289']},{'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': 'LOGGER'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '286']},{'id': '280', 'type': 'attribute', 'children': ['281', '285']},{'id': '281', 'type': '()', 'children': ['282']},{'id': '282', 'type': 'concatenated_string', 'children': ['283', '284']},{'id': '283', 'type': 'string', 'children': [], 'value': "'skipping line {} of pattern file (not '"},{'id': '284', 'type': 'string', 'children': [], 'value': "'in sed format): {}'"},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '286', 'type': 'argument_list', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '289', 'type': 'continue_statement', 'children': []},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'augmented_assignment', 'children': ['292', '293'], 'value': '+='},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'num_candidates'},{'id': '293', 'type': 'integer', 'children': [], 'value': '1'},{'id': '294', 'type': 'if_statement', 'children': ['295', '304']},{'id': '295', 'type': 'boolean_operator', 'children': ['296', '297'], 'value': 'and'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'on_word_boundaries'},{'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': '!='},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '303', 'type': 'argument_list', 'children': []},{'id': '304', 'type': 'block', 'children': ['305']},{'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': 'warning'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'call', 'children': ['312', '319']},{'id': '312', 'type': 'attribute', 'children': ['313', '318']},{'id': '313', 'type': '()', 'children': ['314']},{'id': '314', 'type': 'concatenated_string', 'children': ['315', '316', '317']},{'id': '315', 'type': 'string', 'children': [], 'value': "'before pattern on line {} padded whitespace; '"},{'id': '316', 'type': 'string', 'children': [], 'value': "'this may interact strangely with the --words '"},{'id': '317', 'type': 'string', 'children': [], 'value': "'option: {}'"},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '319', 'type': 'argument_list', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'lineno'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'sub_escapes'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '329', 'type': 'expression_statement', 'children': ['330']},{'id': '330', 'type': 'assignment', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '332', 'type': 'call', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'sub_escapes'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'after'},{'id': '336', 'type': 'if_statement', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'boundaries'},{'id': '338', 'type': 'block', 'children': ['339']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'assignment', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '342', 'type': 'call', 'children': ['343', '348']},{'id': '343', 'type': 'attribute', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'fsed'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'ahocorasick'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'boundary_transform'},{'id': '348', 'type': 'argument_list', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'on_word_boundaries'},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'assignment', 'children': ['353', '356']},{'id': '353', 'type': 'subscript', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'trie'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'before'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'after'},{'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': 'LOGGER'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '362', 'type': 'argument_list', 'children': ['363']},{'id': '363', 'type': 'call', 'children': ['364', '367']},{'id': '364', 'type': 'attribute', 'children': ['365', '366']},{'id': '365', 'type': 'string', 'children': [], 'value': "'{} patterns loaded from {}'"},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '367', 'type': 'argument_list', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'num_candidates'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'pattern_filename'},{'id': '370', 'type': 'return_statement', 'children': ['371']},{'id': '371', 'type': 'expression_list', 'children': ['372', '373']},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'trie'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'boundaries'}
def build_trie(pattern_filename, pattern_format, encoding, on_word_boundaries): ''' Constructs a finite state machine for performing string rewriting. Arguments: - `pattern_filename`: - `pattern_format`: - `encoding`: - `on_word_boundaries`: ''' boundaries = on_word_boundaries if pattern_format == 'auto' or not on_word_boundaries: tsv, boundaries = detect_pattern_format(pattern_filename, encoding, on_word_boundaries) if pattern_format == 'auto': if tsv: pattern_format = 'tsv' else: pattern_format = 'sed' trie = fsed.ahocorasick.AhoCorasickTrie() num_candidates = 0 with open_file(pattern_filename) as pattern_file: for lineno, line in enumerate(pattern_file): line = line.decode(encoding).rstrip('\n') if not line.strip(): continue if pattern_format == 'tsv': fields = line.split('\t') if len(fields) != 2: LOGGER.warning(('skipping line {} of pattern file (not ' 'in tab-separated format): {}').format(lineno, line)) continue before, after = fields elif pattern_format == 'sed': before = after = None line = line.lstrip() if line[0] == 's': delim = line[1] if delim in '.^$*+?[](){}|\\': delim = '\\' + delim fields = re.split(r'(?<!\\){}'.format(delim), line) if len(fields) == 4: before, after = fields[1], fields[2] before = re.sub(r'(?<!\\)\\{}'.format(delim), delim, before) after = re.sub(r'(?<!\\)\\{}'.format(delim), delim, after) if before is None or after is None: LOGGER.warning(('skipping line {} of pattern file (not ' 'in sed format): {}').format(lineno, line)) continue num_candidates += 1 if on_word_boundaries and before != before.strip(): LOGGER.warning(('before pattern on line {} padded whitespace; ' 'this may interact strangely with the --words ' 'option: {}').format(lineno, line)) before = sub_escapes(before) after = sub_escapes(after) if boundaries: before = fsed.ahocorasick.boundary_transform(before, on_word_boundaries) trie[before] = after LOGGER.info('{} patterns loaded from {}'.format(num_candidates, pattern_filename)) return trie, boundaries
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_parser'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'add_help'},{'id': '6', 'type': 'True', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '20', '31', '40', '58', '83', '105', '123', '138', '156', '174', '192', '210', '232']},{'id': '11', 'type': 'if_statement', 'children': ['12', '15']},{'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'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': 'parser'},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'argparse'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'add_help'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'add_help'},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'description'},{'id': '36', 'type': '()', 'children': ['37']},{'id': '37', 'type': 'concatenated_string', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': '"Filter, transform and export a list of JSON "'},{'id': '39', 'type': 'string', 'children': [], 'value': '"objects on stdin to JSON or CSV on stdout"'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'not'},{'id': '42', 'type': 'string', 'children': [], 'value': '"--columns"'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52', '55']},{'id': '51', 'type': 'string', 'children': [], 'value': '"--columns"'},{'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '54', 'type': 'string', 'children': [], 'value': '"columns_file"'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '57', 'type': 'string', 'children': [], 'value': '"the JSON file specifying the columns to be output"'},{'id': '58', 'type': 'if_statement', 'children': ['59', '68']},{'id': '59', 'type': 'boolean_operator', 'children': ['60', '64'], 'value': 'and'},{'id': '60', 'type': '()', 'children': ['61']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'not'},{'id': '62', 'type': 'string', 'children': [], 'value': '"-i"'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '64', 'type': '()', 'children': ['65']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'not'},{'id': '66', 'type': 'string', 'children': [], 'value': '"--input"'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '68', 'type': 'block', 'children': ['69']},{'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': 'parser'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76', '77', '80']},{'id': '75', 'type': 'string', 'children': [], 'value': '"-i"'},{'id': '76', 'type': 'string', 'children': [], 'value': '"--input"'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'help'},{'id': '79', 'type': 'string', 'children': [], 'value': '"read input from the given file instead of from stdin"'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dest'},{'id': '82', 'type': 'string', 'children': [], 'value': "'input_data'"},{'id': '83', 'type': 'if_statement', 'children': ['84', '93']},{'id': '84', 'type': 'boolean_operator', 'children': ['85', '89'], 'value': 'and'},{'id': '85', 'type': '()', 'children': ['86']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'not'},{'id': '87', 'type': 'string', 'children': [], 'value': '"-c"'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '89', 'type': '()', 'children': ['90']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'not'},{'id': '91', 'type': 'string', 'children': [], 'value': '"--column"'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '93', 'type': 'block', 'children': ['94']},{'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': 'parser'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']},{'id': '100', 'type': 'string', 'children': [], 'value': '"-c"'},{'id': '101', 'type': 'string', 'children': [], 'value': '"--column"'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ColumnsAction'},{'id': '105', 'type': 'if_statement', 'children': ['106', '109']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'not'},{'id': '107', 'type': 'string', 'children': [], 'value': '"--pattern"'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117', '120']},{'id': '116', 'type': 'string', 'children': [], 'value': '"--pattern"'},{'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ColumnsAction'},{'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '122', 'type': 'string', 'children': [], 'value': "'+'"},{'id': '123', 'type': 'if_statement', 'children': ['124', '127']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'not'},{'id': '125', 'type': 'string', 'children': [], 'value': '"--max-length"'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': '"--max-length"'},{'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'ColumnsAction'},{'id': '138', 'type': 'if_statement', 'children': ['139', '142']},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': 'not'},{'id': '140', 'type': 'string', 'children': [], 'value': '"--strip"'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'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': 'parser'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150', '153']},{'id': '149', 'type': 'string', 'children': [], 'value': '"--strip"'},{'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '152', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ColumnsAction'},{'id': '156', 'type': 'if_statement', 'children': ['157', '160']},{'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'not'},{'id': '158', 'type': 'string', 'children': [], 'value': '"--deduplicate"'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '160', 'type': 'block', 'children': ['161']},{'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': 'parser'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '166', 'type': 'argument_list', 'children': ['167', '168', '171']},{'id': '167', 'type': 'string', 'children': [], 'value': '"--deduplicate"'},{'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '170', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'ColumnsAction'},{'id': '174', 'type': 'if_statement', 'children': ['175', '178']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'not'},{'id': '176', 'type': 'string', 'children': [], 'value': '"--case-sensitive"'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186', '189']},{'id': '185', 'type': 'string', 'children': [], 'value': '"--case-sensitive"'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '188', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ColumnsAction'},{'id': '192', 'type': 'if_statement', 'children': ['193', '196']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'not'},{'id': '194', 'type': 'string', 'children': [], 'value': '"--unique"'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '196', 'type': 'block', 'children': ['197']},{'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': 'parser'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '202', 'type': 'argument_list', 'children': ['203', '204', '207']},{'id': '203', 'type': 'string', 'children': [], 'value': '"--unique"'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'nargs'},{'id': '206', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ColumnsAction'},{'id': '210', 'type': 'if_statement', 'children': ['211', '220']},{'id': '211', 'type': 'boolean_operator', 'children': ['212', '216'], 'value': 'and'},{'id': '212', 'type': '()', 'children': ['213']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': 'not'},{'id': '214', 'type': 'string', 'children': [], 'value': '"-p"'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '216', 'type': '()', 'children': ['217']},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': 'not'},{'id': '218', 'type': 'string', 'children': [], 'value': '"--pretty"'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'exclude_args'},{'id': '220', 'type': 'block', 'children': ['221']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'add_argument'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228', '229']},{'id': '227', 'type': 'string', 'children': [], 'value': '"-p"'},{'id': '228', 'type': 'string', 'children': [], 'value': '"--pretty"'},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '231', 'type': 'string', 'children': [], 'value': '"store_true"'},{'id': '232', 'type': 'return_statement', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'parser'}
def make_parser(add_help=True, exclude_args=None): if exclude_args is None: exclude_args = [] parser = argparse.ArgumentParser(add_help=add_help) parser.description = ("Filter, transform and export a list of JSON " "objects on stdin to JSON or CSV on stdout") if "--columns" not in exclude_args: parser.add_argument( "--columns", dest="columns_file", help="the JSON file specifying the columns to be output", ) if ("-i" not in exclude_args) and ("--input" not in exclude_args): parser.add_argument( "-i", "--input", help="read input from the given file instead of from stdin", dest='input_data', ) if ("-c" not in exclude_args) and ("--column" not in exclude_args): parser.add_argument("-c", "--column", action=ColumnsAction) if "--pattern" not in exclude_args: parser.add_argument("--pattern", action=ColumnsAction, nargs='+') if "--max-length" not in exclude_args: parser.add_argument("--max-length", action=ColumnsAction) if "--strip" not in exclude_args: parser.add_argument("--strip", nargs="?", action=ColumnsAction) if "--deduplicate" not in exclude_args: parser.add_argument("--deduplicate", nargs='?', action=ColumnsAction) if "--case-sensitive" not in exclude_args: parser.add_argument( "--case-sensitive", nargs='?', action=ColumnsAction) if "--unique" not in exclude_args: parser.add_argument("--unique", nargs="?", action=ColumnsAction) if ("-p" not in exclude_args) and ("--pretty" not in exclude_args): parser.add_argument("-p", "--pretty", action="store_true") return parser
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '21', '45', '70', '115', '165']},{'id': '11', 'type': 'if_statement', 'children': ['12', '14']},{'id': '12', 'type': 'not_operator', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'make_parser'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'try_statement', 'children': ['22', '32']},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parsed_args'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'parse_args'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '32', 'type': 'except_clause', 'children': ['33', '37']},{'id': '33', 'type': 'as_pattern', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'SystemExit'},{'id': '35', 'type': 'as_pattern_target', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'raise_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'CommandLineExit'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '45', 'type': 'try_statement', 'children': ['46', '53']},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'parsed_args'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '53', 'type': 'except_clause', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '55', 'type': 'block', 'children': ['56', '64']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'parsed_args'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '70', 'type': 'for_statement', 'children': ['71', '74', '79']},{'id': '71', 'type': 'pattern_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '78', 'type': 'argument_list', 'children': []},{'id': '79', 'type': 'block', 'children': ['80', '95']},{'id': '80', 'type': 'if_statement', 'children': ['81', '84']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'not'},{'id': '82', 'type': 'string', 'children': [], 'value': '"pattern"'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'raise_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ColumnWithoutPatternError'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'string', 'children': [], 'value': '\'Column "{0}" needs a pattern\''},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '95', 'type': 'if_statement', 'children': ['96', '104']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '103'], 'value': '=='},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '102', 'type': 'string', 'children': [], 'value': '"pattern"'},{'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': 'spec'},{'id': '109', 'type': 'string', 'children': [], 'value': '"pattern"'},{'id': '110', 'type': 'subscript', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '113', 'type': 'string', 'children': [], 'value': '"pattern"'},{'id': '114', 'type': 'integer', 'children': [], 'value': '0'},{'id': '115', 'type': 'if_statement', 'children': ['116', '121', '127', '143', '161']},{'id': '116', 'type': 'boolean_operator', 'children': ['117', '118'], 'value': 'and'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'parsed_args'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'columns_file'},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'raise_statement', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ColumnsAndColumnsFileError'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'string', 'children': [], 'value': '"You can\'t use the --column and --columns options together (yet)"'},{'id': '127', 'type': 'elif_clause', 'children': ['128', '134']},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '132'], 'value': 'and'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'parsed_args'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'columns_file'},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'parsed_args'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'parsed_args'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'columns_file'},{'id': '143', 'type': 'elif_clause', 'children': ['144', '153']},{'id': '144', 'type': 'boolean_operator', 'children': ['145', '148'], 'value': 'and'},{'id': '145', 'type': '()', 'children': ['146']},{'id': '146', 'type': 'not_operator', 'children': ['147']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '148', 'type': '()', 'children': ['149']},{'id': '149', 'type': 'not_operator', 'children': ['150']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'parsed_args'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'columns_file'},{'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': 'NoColumnsError'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'concatenated_string', 'children': ['159', '160']},{'id': '159', 'type': 'string', 'children': [], 'value': '"You must give either a --columns or at least one -c/--column "'},{'id': '160', 'type': 'string', 'children': [], 'value': '"argument"'},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'assert_statement', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '165', 'type': 'return_statement', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'parsed_args'}
def parse(parser=None, args=None): if not parser: parser = make_parser() try: parsed_args = parser.parse_args(args) except SystemExit as err: raise CommandLineExit(err.code) try: columns = parsed_args.columns except AttributeError: columns = collections.OrderedDict() parsed_args.columns = columns for title, spec in columns.items(): if "pattern" not in spec: raise ColumnWithoutPatternError( 'Column "{0}" needs a pattern'.format(title)) if len(spec["pattern"]) == 1: spec["pattern"] = spec["pattern"][0] if columns and parsed_args.columns_file: raise ColumnsAndColumnsFileError( "You can't use the --column and --columns options together (yet)") elif parsed_args.columns_file and not columns: parsed_args.columns = parsed_args.columns_file elif (not columns) and (not parsed_args.columns_file): raise NoColumnsError( "You must give either a --columns or at least one -c/--column " "argument") else: assert columns return parsed_args
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_value'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'allowed_single_chars'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'question_mark'},{'id': '20', 'type': 'True', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '26', '39', '76', '113', '178', '182', '391']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'if_statement', 'children': ['27', '28', '33']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'question_mark'},{'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': 'cquestion_mark'},{'id': '32', 'type': 'string', 'children': [], 'value': "' ? '"},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'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': 'cquestion_mark'},{'id': '38', 'type': 'string', 'children': [], 'value': "''"},{'id': '39', 'type': 'if_statement', 'children': ['40', '43', '70']},{'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'try_statement', 'children': ['45', '53']},{'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': 'iminval'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '53', 'type': 'except_clause', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'raise_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'binary_operator', 'children': ['61', '69'], 'value': '+'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '68'], 'value': '+'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'},{'id': '63', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '68', 'type': 'string', 'children': [], 'value': '"\' cannot "'},{'id': '69', 'type': 'string', 'children': [], 'value': '"be used as an minval in readi()"'},{'id': '70', 'type': 'else_clause', 'children': ['71']},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'iminval'},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'if_statement', 'children': ['77', '80', '107']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'try_statement', 'children': ['82', '90']},{'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': 'imaxval'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '90', 'type': 'except_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'raise_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'binary_operator', 'children': ['98', '106'], 'value': '+'},{'id': '98', 'type': 'binary_operator', 'children': ['99', '105'], 'value': '+'},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'},{'id': '100', 'type': 'string', 'children': [], 'value': '"\'"'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '105', 'type': 'string', 'children': [], 'value': '"\' cannot "'},{'id': '106', 'type': 'string', 'children': [], 'value': '"be used as an maxval in readi()"'},{'id': '107', 'type': 'else_clause', 'children': ['108']},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'imaxval'},{'id': '112', 'type': 'None', 'children': []},{'id': '113', 'type': 'if_statement', 'children': ['114', '121', '126', '142', '158']},{'id': '114', 'type': 'boolean_operator', 'children': ['115', '118'], 'value': 'and'},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'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': 'cminmax'},{'id': '125', 'type': 'string', 'children': [], 'value': "''"},{'id': '126', 'type': 'elif_clause', 'children': ['127', '130']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '129', 'type': 'None', 'children': []},{'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': 'cminmax'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '141'], 'value': '+'},{'id': '135', 'type': 'binary_operator', 'children': ['136', '137'], 'value': '+'},{'id': '136', 'type': 'string', 'children': [], 'value': "' (number <= '"},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'imaxval'},{'id': '141', 'type': 'string', 'children': [], 'value': "')'"},{'id': '142', 'type': 'elif_clause', 'children': ['143', '146']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'is'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '145', 'type': 'None', 'children': []},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cminmax'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '157'], 'value': '+'},{'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '+'},{'id': '152', 'type': 'string', 'children': [], 'value': "' (number >= '"},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'iminval'},{'id': '157', 'type': 'string', 'children': [], 'value': "')'"},{'id': '158', 'type': 'else_clause', 'children': ['159']},{'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': 'cminmax'},{'id': '163', 'type': 'binary_operator', 'children': ['164', '177'], 'value': '+'},{'id': '164', 'type': 'binary_operator', 'children': ['165', '173'], 'value': '+'},{'id': '165', 'type': 'binary_operator', 'children': ['166', '172'], 'value': '+'},{'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '+'},{'id': '167', 'type': 'string', 'children': [], 'value': "' ('"},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '172', 'type': 'string', 'children': [], 'value': "' <= number <= '"},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '177', 'type': 'string', 'children': [], 'value': "')'"},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '181', 'type': 'True', 'children': []},{'id': '182', 'type': 'while_statement', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '184', 'type': 'block', 'children': ['185', '241', '255', '271', '291']},{'id': '185', 'type': 'if_statement', 'children': ['186', '189', '210']},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'is'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '188', 'type': 'None', 'children': []},{'id': '189', 'type': 'block', 'children': ['190', '202']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '193', 'type': 'argument_list', 'children': ['194', '199']},{'id': '194', 'type': 'binary_operator', 'children': ['195', '198'], 'value': '+'},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '+'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'cminmax'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'cquestion_mark'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '201', 'type': 'string', 'children': [], 'value': "''"},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '209']},{'id': '204', 'type': 'attribute', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '209', 'type': 'argument_list', 'children': []},{'id': '210', 'type': 'else_clause', 'children': ['211']},{'id': '211', 'type': 'block', 'children': ['212', '233']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '215', 'type': 'argument_list', 'children': ['216', '230']},{'id': '216', 'type': 'binary_operator', 'children': ['217', '229'], 'value': '+'},{'id': '217', 'type': 'binary_operator', 'children': ['218', '228'], 'value': '+'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '224'], 'value': '+'},{'id': '219', 'type': 'binary_operator', 'children': ['220', '223'], 'value': '+'},{'id': '220', 'type': 'binary_operator', 'children': ['221', '222'], 'value': '+'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'prompt'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'cminmax'},{'id': '223', 'type': 'string', 'children': [], 'value': "' ['"},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '228', 'type': 'string', 'children': [], 'value': "']'"},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'cquestion_mark'},{'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '232', 'type': 'string', 'children': [], 'value': "''"},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '240']},{'id': '235', 'type': 'attribute', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'cresult'},{'id': '244', 'type': 'call', 'children': ['245', '254']},{'id': '245', 'type': 'attribute', 'children': ['246', '253']},{'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': 'sys'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '252', 'type': 'argument_list', 'children': []},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '254', 'type': 'argument_list', 'children': []},{'id': '255', 'type': 'if_statement', 'children': ['256', '263']},{'id': '256', 'type': 'boolean_operator', 'children': ['257', '260'], 'value': 'and'},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': '=='},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'cresult'},{'id': '259', 'type': 'string', 'children': [], 'value': "''"},{'id': '260', 'type': 'comparison_operator', 'children': ['261', '262'], 'value': 'is'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '262', 'type': 'None', 'children': []},{'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': 'cresult'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '271', 'type': 'if_statement', 'children': ['272', '278']},{'id': '272', 'type': 'comparison_operator', 'children': ['273', '277'], 'value': '=='},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'cresult'},{'id': '277', 'type': 'integer', 'children': [], 'value': '1'},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'if_statement', 'children': ['280', '283']},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': 'is'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'allowed_single_chars'},{'id': '282', 'type': 'None', 'children': []},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'if_statement', 'children': ['285', '288']},{'id': '285', 'type': 'comparison_operator', 'children': ['286', '287'], 'value': 'in'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'cresult'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'allowed_single_chars'},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'return_statement', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'cresult'},{'id': '291', 'type': 'try_statement', 'children': ['292', '300', '315']},{'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': 'result'},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'cresult'},{'id': '300', 'type': 'except_clause', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '302', 'type': 'block', 'children': ['303']},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'binary_operator', 'children': ['308', '314'], 'value': '+'},{'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '+'},{'id': '309', 'type': 'string', 'children': [], 'value': '"*** Error: invalid "'},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'ftype'},{'id': '314', 'type': 'string', 'children': [], 'value': '" value. Try again!"'},{'id': '315', 'type': 'else_clause', 'children': ['316']},{'id': '316', 'type': 'block', 'children': ['317']},{'id': '317', 'type': 'if_statement', 'children': ['318', '325', '330', '351', '372']},{'id': '318', 'type': 'boolean_operator', 'children': ['319', '322'], 'value': 'and'},{'id': '319', 'type': 'comparison_operator', 'children': ['320', '321'], 'value': 'is'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '321', 'type': 'None', 'children': []},{'id': '322', 'type': 'comparison_operator', 'children': ['323', '324'], 'value': 'is'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '324', 'type': 'None', 'children': []},{'id': '325', 'type': 'block', 'children': ['326']},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'assignment', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '329', 'type': 'False', 'children': []},{'id': '330', 'type': 'elif_clause', 'children': ['331', '334']},{'id': '331', 'type': 'comparison_operator', 'children': ['332', '333'], 'value': 'is'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'minval'},{'id': '333', 'type': 'None', 'children': []},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'if_statement', 'children': ['336', '339', '344']},{'id': '336', 'type': 'comparison_operator', 'children': ['337', '338'], 'value': '<='},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'imaxval'},{'id': '339', 'type': 'block', 'children': ['340']},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'assignment', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '343', 'type': 'False', 'children': []},{'id': '344', 'type': 'else_clause', 'children': ['345']},{'id': '345', 'type': 'block', 'children': ['346']},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'call', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'string', 'children': [], 'value': '"*** Error: number out of range. Try again!"'},{'id': '351', 'type': 'elif_clause', 'children': ['352', '355']},{'id': '352', 'type': 'comparison_operator', 'children': ['353', '354'], 'value': 'is'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'maxval'},{'id': '354', 'type': 'None', 'children': []},{'id': '355', 'type': 'block', 'children': ['356']},{'id': '356', 'type': 'if_statement', 'children': ['357', '360', '365']},{'id': '357', 'type': 'comparison_operator', 'children': ['358', '359'], 'value': '>='},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'iminval'},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '364', 'type': 'False', 'children': []},{'id': '365', 'type': 'else_clause', 'children': ['366']},{'id': '366', 'type': 'block', 'children': ['367']},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'call', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '370', 'type': 'argument_list', 'children': ['371']},{'id': '371', 'type': 'string', 'children': [], 'value': '"*** Error: number out of range. Try again!"'},{'id': '372', 'type': 'else_clause', 'children': ['373']},{'id': '373', 'type': 'block', 'children': ['374']},{'id': '374', 'type': 'if_statement', 'children': ['375', '379', '384']},{'id': '375', 'type': 'comparison_operator', 'children': ['376', '377', '378'], 'value': '<='},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'iminval'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'imaxval'},{'id': '379', 'type': 'block', 'children': ['380']},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'assignment', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '383', 'type': 'False', 'children': []},{'id': '384', 'type': 'else_clause', 'children': ['385']},{'id': '385', 'type': 'block', 'children': ['386']},{'id': '386', 'type': 'expression_statement', 'children': ['387']},{'id': '387', 'type': 'call', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'string', 'children': [], 'value': '"*** Error: number out of range. Try again!"'},{'id': '391', 'type': 'return_statement', 'children': ['392']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'result'}
def read_value(ftype, prompt, default=None, minval=None, maxval=None, allowed_single_chars=None, question_mark=True): result = None if question_mark: cquestion_mark = ' ? ' else: cquestion_mark = '' if minval is not None: try: iminval = ftype(minval) except ValueError: raise ValueError("'" + str(minval) + "' cannot " + "be used as an minval in readi()") else: iminval = None if maxval is not None: try: imaxval = ftype(maxval) except ValueError: raise ValueError("'" + str(maxval) + "' cannot " + "be used as an maxval in readi()") else: imaxval = None if minval is None and maxval is None: cminmax = '' elif minval is None: cminmax = ' (number <= ' + str(imaxval) + ')' elif maxval is None: cminmax = ' (number >= ' + str(iminval) + ')' else: cminmax = ' (' + str(minval) + ' <= number <= ' + str(maxval) + ')' loop = True while loop: if default is None: print(prompt + cminmax + cquestion_mark, end='') sys.stdout.flush() else: print(prompt + cminmax + ' [' + str(default) + ']' + cquestion_mark, end='') sys.stdout.flush() cresult = sys.stdin.readline().strip() if cresult == '' and default is not None: cresult = str(default) if len(cresult) == 1: if allowed_single_chars is not None: if cresult in allowed_single_chars: return cresult try: result = ftype(cresult) except ValueError: print("*** Error: invalid " + str(ftype) + " value. Try again!") else: if minval is None and maxval is None: loop = False elif minval is None: if result <= imaxval: loop = False else: print("*** Error: number out of range. Try again!") elif maxval is None: if result >= iminval: loop = False else: print("*** Error: number out of range. Try again!") else: if iminval <= result <= imaxval: loop = False else: print("*** Error: number out of range. Try again!") return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'select_configuration'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'obresult'},{'id': '6', 'type': 'block', 'children': ['7', '16', '23', '31', '41']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'getLogger'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'string', 'children': [], 'value': "'calling default configuration selector'"},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'obresult'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_sample_frame'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'extr'},{'id': '34', 'type': 'subscript', 'children': ['35', '40']},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'datamodel'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'extractor_map'},{'id': '40', 'type': 'string', 'children': [], 'value': "'fits'"},{'id': '41', 'type': 'if_statement', 'children': ['42', '43', '180']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '43', 'type': 'block', 'children': ['44', '54', '111', '121']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'extr'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'extract'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'insconf'"},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '54', 'type': 'if_statement', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '56', 'type': 'block', 'children': ['57', '65']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'found insconf config uuid=%s'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '65', 'type': 'if_statement', 'children': ['66', '71', '78']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'configurations'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'return_statement', 'children': ['73']},{'id': '73', 'type': 'subscript', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'configurations'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '78', 'type': 'else_clause', 'children': ['79']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'for_statement', 'children': ['81', '82', '89', '99']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '82', 'type': 'call', 'children': ['83', '88']},{'id': '83', 'type': 'attribute', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'configurations'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '88', 'type': 'argument_list', 'children': []},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'if_statement', 'children': ['91', '96']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '95'], 'value': '=='},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '99', 'type': 'else_clause', 'children': ['100']},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'raise_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'string', 'children': [], 'value': "'insconf {} does not match any config'"},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'date_obs'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'extr'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'extract'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'observation_date'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '121', 'type': 'for_statement', 'children': ['122', '125', '132']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '125', 'type': 'call', 'children': ['126', '131']},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'configurations'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'block', 'children': ['133', '139', '160']},{'id': '133', 'type': 'if_statement', 'children': ['134', '137']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '=='},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '136', 'type': 'string', 'children': [], 'value': "'default'"},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'continue_statement', 'children': []},{'id': '139', 'type': 'if_statement', 'children': ['140', '145', '154']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '144'], 'value': 'is'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'date_end'},{'id': '144', 'type': 'None', 'children': []},{'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': 'upper_t'},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '<'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'date_obs'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'date_end'},{'id': '154', 'type': 'else_clause', 'children': ['155']},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'upper_t'},{'id': '159', 'type': 'True', 'children': []},{'id': '160', 'type': 'if_statement', 'children': ['161', '169']},{'id': '161', 'type': 'boolean_operator', 'children': ['162', '163'], 'value': 'and'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'upper_t'},{'id': '163', 'type': '()', 'children': ['164']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '>='},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'date_obs'},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'date_start'},{'id': '169', 'type': 'block', 'children': ['170', '178']},{'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': 'logger'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'string', 'children': [], 'value': "'found date match, config uuid=%s'"},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '178', 'type': 'return_statement', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'conf'},{'id': '180', 'type': 'else_clause', 'children': ['181']},{'id': '181', 'type': 'block', 'children': ['182', '189']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'string', 'children': [], 'value': "'no match, using default configuration'"},{'id': '189', 'type': 'return_statement', 'children': ['190']},{'id': '190', 'type': 'subscript', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'configurations'},{'id': '194', 'type': 'string', 'children': [], 'value': "'default'"}
def select_configuration(self, obresult): logger = logging.getLogger(__name__) logger.debug('calling default configuration selector') ref = obresult.get_sample_frame() extr = self.datamodel.extractor_map['fits'] if ref: result = extr.extract('insconf', ref) if result: logger.debug('found insconf config uuid=%s', result) if result in self.configurations: return self.configurations[result] else: for conf in self.configurations.values(): if conf.name == result: return conf else: raise KeyError('insconf {} does not match any config'.format(result)) date_obs = extr.extract('observation_date', ref) for key, conf in self.configurations.items(): if key == 'default': continue if conf.date_end is not None: upper_t = date_obs < conf.date_end else: upper_t = True if upper_t and (date_obs >= conf.date_start): logger.debug('found date match, config uuid=%s', key) return conf else: logger.debug('no match, using default configuration') return self.configurations['default']
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'pause_debugplot'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'optional_prompt'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pltshow'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'tight_layout'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '26', '50', '187']},{'id': '15', 'type': 'if_statement', 'children': ['16', '19']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'not'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'DEBUGPLOT_CODES'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '23', 'type': 'argument_list', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': "'Invalid debugplot value:'"},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '26', 'type': 'if_statement', 'children': ['27', '30', '40']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '<'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'block', 'children': ['31', '36']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'debugplot_'},{'id': '34', 'type': 'unary_operator', 'children': ['35'], 'value': '-'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'pltclose'},{'id': '39', 'type': 'True', 'children': []},{'id': '40', 'type': 'else_clause', 'children': ['41']},{'id': '41', 'type': 'block', 'children': ['42', '46']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'debugplot_'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pltclose'},{'id': '49', 'type': 'False', 'children': []},{'id': '50', 'type': 'if_statement', 'children': ['51', '52', '132']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'pltshow'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'if_statement', 'children': ['54', '63']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'in'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'debugplot_'},{'id': '56', 'type': 'list', 'children': ['57', '58', '59', '60', '61', '62'], 'value': '[1, 2, 11, 12, 21, 22]'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'integer', 'children': [], 'value': '2'},{'id': '59', 'type': 'integer', 'children': [], 'value': '11'},{'id': '60', 'type': 'integer', 'children': [], 'value': '12'},{'id': '61', 'type': 'integer', 'children': [], 'value': '21'},{'id': '62', 'type': 'integer', 'children': [], 'value': '22'},{'id': '63', 'type': 'block', 'children': ['64', '73']},{'id': '64', 'type': 'if_statement', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'tight_layout'},{'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': 'plt'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'tight_layout'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'if_statement', 'children': ['74', '80', '97']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'in'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'debugplot_'},{'id': '76', 'type': 'list', 'children': ['77', '78', '79'], 'value': '[1, 11, 21]'},{'id': '77', 'type': 'integer', 'children': [], 'value': '1'},{'id': '78', 'type': 'integer', 'children': [], 'value': '11'},{'id': '79', 'type': 'integer', 'children': [], 'value': '21'},{'id': '80', 'type': 'block', 'children': ['81', '90']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '89', 'type': 'False', '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': 'plt'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'pause'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'float', 'children': [], 'value': '0.2'},{'id': '97', 'type': 'elif_clause', 'children': ['98', '104']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'in'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'debugplot_'},{'id': '100', 'type': 'list', 'children': ['101', '102', '103'], 'value': '[2, 12, 22]'},{'id': '101', 'type': 'integer', 'children': [], 'value': '2'},{'id': '102', 'type': 'integer', 'children': [], 'value': '12'},{'id': '103', 'type': 'integer', 'children': [], 'value': '22'},{'id': '104', 'type': 'block', 'children': ['105', '113', '121', '127']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '108', 'type': 'argument_list', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': '\'Press "q" to continue...\''},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '112', 'type': 'string', 'children': [], 'value': "''"},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '120']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '120', 'type': 'argument_list', 'children': []},{'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': 'plt'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'show'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': "''"},{'id': '132', 'type': 'else_clause', 'children': ['133']},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'if_statement', 'children': ['135', '141']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'in'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'debugplot_'},{'id': '137', 'type': 'list', 'children': ['138', '139', '140'], 'value': '[2, 12, 22]'},{'id': '138', 'type': 'integer', 'children': [], 'value': '2'},{'id': '139', 'type': 'integer', 'children': [], 'value': '12'},{'id': '140', 'type': 'integer', 'children': [], 'value': '22'},{'id': '141', 'type': 'block', 'children': ['142', '165', '173']},{'id': '142', 'type': 'if_statement', 'children': ['143', '146', '155']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'is'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'optional_prompt'},{'id': '145', 'type': 'None', 'children': []},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152']},{'id': '151', 'type': 'string', 'children': [], 'value': "'Press <RETURN> to continue...'"},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '154', 'type': 'string', 'children': [], 'value': "''"},{'id': '155', 'type': 'else_clause', 'children': ['156']},{'id': '156', 'type': 'block', 'children': ['157']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '160', 'type': 'argument_list', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'optional_prompt'},{'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '164', 'type': 'string', 'children': [], 'value': "''"},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '172']},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '172', 'type': 'argument_list', 'children': []},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'cdummy'},{'id': '176', 'type': 'call', 'children': ['177', '186']},{'id': '177', 'type': 'attribute', 'children': ['178', '185']},{'id': '178', 'type': 'call', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '184', 'type': 'argument_list', 'children': []},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '186', 'type': 'argument_list', 'children': []},{'id': '187', 'type': 'if_statement', 'children': ['188', '199']},{'id': '188', 'type': 'boolean_operator', 'children': ['189', '198'], 'value': 'and'},{'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'in'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'debugplot_'},{'id': '191', 'type': 'list', 'children': ['192', '193', '194', '195', '196', '197'], 'value': '[1, 2, 11, 12, 21, 22]'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'integer', 'children': [], 'value': '2'},{'id': '194', 'type': 'integer', 'children': [], 'value': '11'},{'id': '195', 'type': 'integer', 'children': [], 'value': '12'},{'id': '196', 'type': 'integer', 'children': [], 'value': '21'},{'id': '197', 'type': 'integer', 'children': [], 'value': '22'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'pltclose'},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '205', 'type': 'argument_list', 'children': []}
def pause_debugplot(debugplot, optional_prompt=None, pltshow=False, tight_layout=True): if debugplot not in DEBUGPLOT_CODES: raise ValueError('Invalid debugplot value:', debugplot) if debugplot < 0: debugplot_ = -debugplot pltclose = True else: debugplot_ = debugplot pltclose = False if pltshow: if debugplot_ in [1, 2, 11, 12, 21, 22]: if tight_layout: plt.tight_layout() if debugplot_ in [1, 11, 21]: plt.show(block=False) plt.pause(0.2) elif debugplot_ in [2, 12, 22]: print('Press "q" to continue...', end='') sys.stdout.flush() plt.show() print('') else: if debugplot_ in [2, 12, 22]: if optional_prompt is None: print('Press <RETURN> to continue...', end='') else: print(optional_prompt, end='') sys.stdout.flush() cdummy = sys.stdin.readline().strip() if debugplot_ in [1, 2, 11, 12, 21, 22] and pltclose: plt.close()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mode_half_sample'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'is_sorted'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '20', '39', '46']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': '\'\'\'\n Estimate the mode using the Half Sample mode.\n A method to estimate the mode, as described in\n D. R. Bickel and R. Frühwirth (contributed equally),\n "On a fast, robust estimator of the mode: Comparisons to other\n robust estimators with applications,"\n Computational Statistics and Data Analysis 50, 3500-3530 (2006).\n Example\n =======\n >> import numpy as np\n >> np.random.seed(1392838)\n >> a = np.random.normal(1000, 200, size=1000)\n >> a[:100] = np.random.normal(2000, 300, size=100)\n >> b = np.sort(a)\n >> mode_half_sample(b, is_sorted=True)\n 1041.9327885039545\n \'\'\''},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'asanyarray'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '20', 'type': 'if_statement', 'children': ['21', '23', '33']},{'id': '21', 'type': 'not_operator', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'is_sorted'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'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': 'sdata'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '46', 'type': 'if_statement', 'children': ['47', '50', '55', '71', '131']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'elif_clause', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '58', 'type': 'integer', 'children': [], 'value': '2'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '*'},{'id': '62', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '63', 'type': '()', 'children': ['64']},{'id': '64', 'type': 'binary_operator', 'children': ['65', '68'], 'value': '+'},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'elif_clause', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': '=='},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '74', 'type': 'integer', 'children': [], 'value': '3'},{'id': '75', 'type': 'block', 'children': ['76', '93']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '90'], 'value': '-'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '85'], 'value': '+'},{'id': '81', 'type': 'unary_operator', 'children': ['82'], 'value': '-'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '*'},{'id': '86', 'type': 'integer', 'children': [], 'value': '2'},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '89', 'type': 'integer', 'children': [], 'value': '1'},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '92', 'type': 'integer', 'children': [], 'value': '2'},{'id': '93', 'type': 'if_statement', 'children': ['94', '97', '109', '125']},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '<'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '96', 'type': 'integer', 'children': [], 'value': '0'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'return_statement', 'children': ['99']},{'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '*'},{'id': '100', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '101', 'type': '()', 'children': ['102']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '106'], 'value': '+'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '108', 'type': 'integer', 'children': [], 'value': '1'},{'id': '109', 'type': 'elif_clause', 'children': ['110', '113']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '>'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '*'},{'id': '116', 'type': 'float', 'children': [], 'value': '0.5'},{'id': '117', 'type': '()', 'children': ['118']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '122'], 'value': '+'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '124', 'type': 'integer', 'children': [], 'value': '2'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'return_statement', 'children': ['128']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'else_clause', 'children': ['132']},{'id': '132', 'type': 'block', 'children': ['133', '147', '169', '177']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'int'},{'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': 'math'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'ceil'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '/'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '146', 'type': 'float', 'children': [], 'value': '2.0'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '159'], 'value': '-'},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '153', 'type': 'slice', 'children': ['154', '158']},{'id': '154', 'type': '()', 'children': ['155']},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '-'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '157', 'type': 'integer', 'children': [], 'value': '1'},{'id': '158', 'type': 'colon', 'children': []},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '161', 'type': 'slice', 'children': ['162', '163']},{'id': '162', 'type': 'colon', 'children': []},{'id': '163', 'type': '()', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '168'], 'value': '+'},{'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '-'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'ar'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'argmin'},{'id': '176', 'type': 'argument_list', 'children': []},{'id': '177', 'type': 'return_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'mode_half_sample'},{'id': '180', 'type': 'argument_list', 'children': ['181', '189']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'sdata'},{'id': '183', 'type': 'slice', 'children': ['184', '185', '186']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'ar'},{'id': '185', 'type': 'colon', 'children': []},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '+'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ar'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'is_sorted'},{'id': '191', 'type': 'True', 'children': []}
def mode_half_sample(a, is_sorted=False): ''' Estimate the mode using the Half Sample mode. A method to estimate the mode, as described in D. R. Bickel and R. Frühwirth (contributed equally), "On a fast, robust estimator of the mode: Comparisons to other robust estimators with applications," Computational Statistics and Data Analysis 50, 3500-3530 (2006). Example ======= >> import numpy as np >> np.random.seed(1392838) >> a = np.random.normal(1000, 200, size=1000) >> a[:100] = np.random.normal(2000, 300, size=100) >> b = np.sort(a) >> mode_half_sample(b, is_sorted=True) 1041.9327885039545 ''' a = np.asanyarray(a) if not is_sorted: sdata = np.sort(a) else: sdata = a n = len(sdata) if n == 1: return sdata[0] elif n == 2: return 0.5 * (sdata[0] + sdata[1]) elif n == 3: ind = -sdata[0] + 2 * sdata[1] - sdata[2] if ind < 0: return 0.5 * (sdata[0] + sdata[1]) elif ind > 0: return 0.5 * (sdata[1] + sdata[2]) else: return sdata[1] else: N = int(math.ceil(n / 2.0)) w = sdata[(N-1):] - sdata[:(n-N+1)] ar = w.argmin() return mode_half_sample(sdata[ar:ar+N], is_sorted=True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'author_id_normalize_and_schema'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '47', '70', '82', '108', '116', '147', '154']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '14']},{'id': '10', 'type': 'function_name', 'children': [], 'value': '_get_uid_normalized_in_schema'},{'id': '11', 'type': 'parameters', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_uid'},{'id': '13', 'type': 'identifier', 'children': [], 'value': '_schema'},{'id': '14', 'type': 'block', 'children': ['15', '23', '32']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_RE_AUTHORS_UID'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '_schema'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_uid'},{'id': '32', 'type': 'if_statement', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'template'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "'uid'"},{'id': '47', 'type': 'if_statement', 'children': ['48', '60']},{'id': '48', 'type': 'boolean_operator', 'children': ['49', '55'], 'value': 'and'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'idutils'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'is_orcid'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '57', 'type': 'tuple', 'children': ['58', '59']},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'string', 'children': [], 'value': "'ORCID'"},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'return_statement', 'children': ['62']},{'id': '62', 'type': 'expression_list', 'children': ['63', '69']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'idutils'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'normalize_orcid'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '69', 'type': 'string', 'children': [], 'value': "'ORCID'"},{'id': '70', 'type': 'if_statement', 'children': ['71', '76']},{'id': '71', 'type': 'boolean_operator', 'children': ['72', '73'], 'value': 'and'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'not'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_RE_AUTHORS_UID'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'raise_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'UnknownUIDSchema'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '82', 'type': 'if_statement', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '84', 'type': 'block', 'children': ['85', '93']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'normalized_uid'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_get_uid_normalized_in_schema'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '93', 'type': 'if_statement', 'children': ['94', '95', '100']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'normalized_uid'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'return_statement', 'children': ['97']},{'id': '97', 'type': 'expression_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'normalized_uid'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '100', 'type': 'else_clause', 'children': ['101']},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'raise_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'SchemaUIDConflict'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'pattern_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'match_schema'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'normalized_uid'},{'id': '113', 'type': 'expression_list', 'children': ['114', '115']},{'id': '114', 'type': 'None', 'children': []},{'id': '115', 'type': 'None', 'children': []},{'id': '116', 'type': 'for_statement', 'children': ['117', '118', '119']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'candidate_schema'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_RE_AUTHORS_UID'},{'id': '119', 'type': 'block', 'children': ['120', '128']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'candidate_uid'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': '_get_uid_normalized_in_schema'},{'id': '125', 'type': 'argument_list', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'candidate_schema'},{'id': '128', 'type': 'if_statement', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'candidate_uid'},{'id': '130', 'type': 'block', 'children': ['131', '139', '143']},{'id': '131', 'type': 'if_statement', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'match_schema'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'raise_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'UnknownUIDSchema'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'uid'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'match_schema'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'candidate_schema'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'normalized_uid'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'candidate_uid'},{'id': '147', 'type': 'if_statement', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'match_schema'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'expression_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'normalized_uid'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'match_schema'},{'id': '154', 'type': 'raise_statement', 'children': ['155']},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'UnknownUIDSchema'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'uid'}
def author_id_normalize_and_schema(uid, schema=None): def _get_uid_normalized_in_schema(_uid, _schema): regex, template = _RE_AUTHORS_UID[_schema] match = regex.match(_uid) if match: return template.format(match.group('uid')) if idutils.is_orcid(uid) and schema in (None, 'ORCID'): return idutils.normalize_orcid(uid), 'ORCID' if schema and schema not in _RE_AUTHORS_UID: raise UnknownUIDSchema(uid) if schema: normalized_uid = _get_uid_normalized_in_schema(uid, schema) if normalized_uid: return normalized_uid, schema else: raise SchemaUIDConflict(schema, uid) match_schema, normalized_uid = None, None for candidate_schema in _RE_AUTHORS_UID: candidate_uid = _get_uid_normalized_in_schema(uid, candidate_schema) if candidate_uid: if match_schema: raise UnknownUIDSchema(uid) match_schema = candidate_schema normalized_uid = candidate_uid if match_schema: return normalized_uid, match_schema raise UnknownUIDSchema(uid)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_schema_path'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '39', '101', '108', '180']},{'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']},{'id': '10', 'type': 'function_name', 'children': [], 'value': '_strip_first_path_elem'},{'id': '11', 'type': 'parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '13', 'type': 'block', 'children': ['14', '32']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'stripped_path'},{'id': '17', 'type': 'subscript', 'children': ['18', '29']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '22', 'type': 'argument_list', 'children': ['23', '28']},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'slice', 'children': ['30', '31']},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'colon', 'children': []},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'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': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'stripped_path'},{'id': '39', 'type': 'function_definition', 'children': ['40', '41', '43']},{'id': '40', 'type': 'function_name', 'children': [], 'value': '_schema_to_normalized_path'},{'id': '41', 'type': 'parameters', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '43', 'type': 'block', 'children': ['44', '66', '86', '99']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'os'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'normpath'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'binary_operator', 'children': ['55', '60'], 'value': '+'},{'id': '55', 'type': 'attribute', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '60', 'type': 'attribute', 'children': ['61', '65']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'urlsplit'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '66', 'type': 'if_statement', 'children': ['67', '77']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'attribute', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sep'},{'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': 'path'},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '83', 'type': 'slice', 'children': ['84', '85']},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'id': '85', 'type': 'colon', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '94']},{'id': '87', 'type': 'not_operator', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'string', 'children': [], 'value': "'.json'"},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'augmented_assignment', 'children': ['97', '98'], 'value': '+='},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '98', 'type': 'string', 'children': [], 'value': "'.json'"},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_schema_to_normalized_path'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '108', 'type': 'while_statement', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '110', 'type': 'block', 'children': ['111', '154', '173']},{'id': '111', 'type': 'if_statement', 'children': ['112', '113', '133']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'schema_path'},{'id': '117', 'type': 'call', 'children': ['118', '123']},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '130']},{'id': '125', 'type': 'attribute', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': '_resolved_schema_root_path'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '133', 'type': 'else_clause', 'children': ['134']},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'schema_path'},{'id': '138', 'type': 'call', 'children': ['139', '144']},{'id': '139', 'type': 'attribute', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'attribute', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': '_schema_root_path'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '154', 'type': 'if_statement', 'children': ['155', '163']},{'id': '155', 'type': 'call', 'children': ['156', '161']},{'id': '156', 'type': 'attribute', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'schema_path'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'return_statement', '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': 'os'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'schema_path'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': '_strip_first_path_elem'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '180', 'type': 'raise_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'SchemaNotFound'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'schema'}
def get_schema_path(schema, resolved=False): def _strip_first_path_elem(path): stripped_path = path.split(os.path.sep, 1)[1:] return ''.join(stripped_path) def _schema_to_normalized_path(schema): path = os.path.normpath(os.path.sep + urlsplit(schema).path) if path.startswith(os.path.sep): path = path[1:] if not path.endswith('.json'): path += '.json' return path path = _schema_to_normalized_path(schema) while path: if resolved: schema_path = os.path.abspath(os.path.join(_resolved_schema_root_path, path)) else: schema_path = os.path.abspath(os.path.join(_schema_root_path, path)) if os.path.exists(schema_path): return os.path.abspath(schema_path) path = _strip_first_path_elem(path) raise SchemaNotFound(schema=schema)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_license_from_url'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '5', 'type': 'block', 'children': ['6', '11', '21', '167']},{'id': '6', 'type': 'if_statement', 'children': ['7', '9']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': []},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'split_url'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'urlsplit'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'scheme'},{'id': '20', 'type': 'string', 'children': [], 'value': "'http'"},{'id': '21', 'type': 'if_statement', 'children': ['22', '31', '121', '160']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '30'], 'value': '=='},{'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': 'split_url'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'netloc'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'string', 'children': [], 'value': "'creativecommons.org'"},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '38', '83']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'},{'id': '34', 'type': 'string', 'children': [], 'value': "'publicdomain'"},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'split_url'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '38', 'type': 'block', 'children': ['39', '50']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_RE_PUBLIC_DOMAIN_URL'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'split_url'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54', '60']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '53', 'type': 'None', 'children': []},{'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': 'license'},{'id': '58', 'type': 'list', 'children': ['59'], 'value': "['public domain']"},{'id': '59', 'type': 'string', 'children': [], 'value': "'public domain'"},{'id': '60', 'type': 'else_clause', 'children': ['61']},{'id': '61', 'type': 'block', 'children': ['62', '67']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'license'},{'id': '65', 'type': 'list', 'children': ['66'], 'value': "['CC0']"},{'id': '66', 'type': 'string', 'children': [], 'value': "'CC0'"},{'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': 'license'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '72', 'type': 'generator_expression', 'children': ['73', '74', '81']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'if_clause', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '83', 'type': 'else_clause', 'children': ['84']},{'id': '84', 'type': 'block', 'children': ['85', '90', '101']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'license'},{'id': '88', 'type': 'list', 'children': ['89'], 'value': "['CC']"},{'id': '89', 'type': 'string', 'children': [], 'value': "'CC'"},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_RE_LICENSE_URL'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'split_url'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'path'},{'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': 'license'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '106', 'type': 'generator_expression', 'children': ['107', '112', '119']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '118', 'type': 'argument_list', 'children': []},{'id': '119', 'type': 'if_clause', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '121', 'type': 'elif_clause', 'children': ['122', '127']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': '=='},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'split_url'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'netloc'},{'id': '126', 'type': 'string', 'children': [], 'value': "'arxiv.org'"},{'id': '127', 'type': 'block', 'children': ['128', '133', '144']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'license'},{'id': '131', 'type': 'list', 'children': ['132'], 'value': "['arXiv']"},{'id': '132', 'type': 'string', 'children': [], 'value': "'arXiv'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_RE_LICENSE_URL'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'split_url'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'license'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '149', 'type': 'generator_expression', 'children': ['150', '151', '158']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '151', 'type': 'for_in_clause', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'if_clause', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'part'},{'id': '160', 'type': 'else_clause', 'children': ['161']},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'raise_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'string', 'children': [], 'value': "'Unknown license URL'"},{'id': '167', 'type': 'return_statement', 'children': ['168']},{'id': '168', 'type': 'call', 'children': ['169', '172']},{'id': '169', 'type': 'attribute', 'children': ['170', '171']},{'id': '170', 'type': 'string', 'children': [], 'value': "u' '"},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'license'}
def get_license_from_url(url): if not url: return split_url = urlsplit(url, scheme='http') if split_url.netloc.lower() == 'creativecommons.org': if 'publicdomain' in split_url.path: match = _RE_PUBLIC_DOMAIN_URL.match(split_url.path) if match is None: license = ['public domain'] else: license = ['CC0'] license.extend(part for part in match.groups() if part) else: license = ['CC'] match = _RE_LICENSE_URL.match(split_url.path) license.extend(part.upper() for part in match.groups() if part) elif split_url.netloc == 'arxiv.org': license = ['arXiv'] match = _RE_LICENSE_URL.match(split_url.path) license.extend(part for part in match.groups() if part) else: raise ValueError('Unknown license URL') return u' '.join(license)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert_old_publication_info_to_new'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'publication_infos'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '280', '302']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': 'hidden_publication_infos'},{'id': '13', 'type': 'list', 'children': [], 'value': '[]'},{'id': '14', 'type': 'for_statement', 'children': ['15', '16', '17']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'publication_info'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'publication_infos'},{'id': '17', 'type': 'block', 'children': ['18', '27', '36', '62', '71', '148', '251', '261']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'publication_info'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'string', 'children': [], 'value': "'journal_title'"},{'id': '36', 'type': 'try_statement', 'children': ['37', '58']},{'id': '37', 'type': 'block', 'children': ['38', '44', '50', '57']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_JOURNALS_RENAMED_OLD_TO_NEW'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '48', 'type': 'string', 'children': [], 'value': "'journal_title'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '57', 'type': 'continue_statement', 'children': []},{'id': '58', 'type': 'except_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'pass_statement', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'string', 'children': [], 'value': "'journal_volume'"},{'id': '71', 'type': 'if_statement', 'children': ['72', '84']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '78'], 'value': 'and'},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '77'], 'value': 'and'},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'in'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_JOURNALS_WITH_YEAR_ADDED_TO_VOLUME'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '83'], 'value': '=='},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '83', 'type': 'integer', 'children': [], 'value': '4'},{'id': '84', 'type': 'block', 'children': ['85', '140', '147']},{'id': '85', 'type': 'try_statement', 'children': ['86', '100', '104']},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'was_last_century'},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '99'], 'value': '>'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '96', 'type': 'slice', 'children': ['97', '98']},{'id': '97', 'type': 'colon', 'children': []},{'id': '98', 'type': 'integer', 'children': [], 'value': '2'},{'id': '99', 'type': 'integer', 'children': [], 'value': '50'},{'id': '100', 'type': 'except_clause', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'pass_statement', 'children': []},{'id': '104', 'type': 'else_clause', 'children': ['105']},{'id': '105', 'type': 'block', 'children': ['106', '130']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '111']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '110', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'conditional_expression', 'children': ['115', '122', '123'], 'value': 'if'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'},{'id': '116', 'type': 'string', 'children': [], 'value': "'19'"},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '119', 'type': 'slice', 'children': ['120', '121']},{'id': '120', 'type': 'colon', 'children': []},{'id': '121', 'type': 'integer', 'children': [], 'value': '2'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'was_last_century'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '+'},{'id': '124', 'type': 'string', 'children': [], 'value': "'20'"},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '127', 'type': 'slice', 'children': ['128', '129']},{'id': '128', 'type': 'colon', 'children': []},{'id': '129', 'type': 'integer', 'children': [], 'value': '2'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '135']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '134', 'type': 'string', 'children': [], 'value': "'journal_volume'"},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '137', 'type': 'slice', 'children': ['138', '139']},{'id': '138', 'type': 'integer', 'children': [], 'value': '2'},{'id': '139', 'type': 'colon', 'children': []},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '147', 'type': 'continue_statement', 'children': []},{'id': '148', 'type': 'if_statement', 'children': ['149', '160']},{'id': '149', 'type': 'boolean_operator', 'children': ['150', '153'], 'value': 'and'},{'id': '150', 'type': 'boolean_operator', 'children': ['151', '152'], 'value': 'and'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '159'], 'value': 'not'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '158', 'type': 'argument_list', 'children': []},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'JOURNALS_IGNORED_IN_OLD_TO_NEW'},{'id': '160', 'type': 'block', 'children': ['161', '170', '179', '185']},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'volume_starts_with_a_letter'},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': '_RE_VOLUME_STARTS_WITH_A_LETTER'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'volume_ends_with_a_letter'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_RE_VOLUME_ENDS_WITH_A_LETTER'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '179', 'type': 'expression_statement', 'children': ['180']},{'id': '180', 'type': 'assignment', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '182', 'type': 'boolean_operator', 'children': ['183', '184'], 'value': 'or'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'volume_starts_with_a_letter'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'volume_ends_with_a_letter'},{'id': '185', 'type': 'if_statement', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '187', 'type': 'block', 'children': ['188', '196', '240']},{'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': '_publication_info'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '193', 'type': 'argument_list', 'children': ['194', '195']},{'id': '194', 'type': 'string', 'children': [], 'value': "'journal_record'"},{'id': '195', 'type': 'None', 'children': []},{'id': '196', 'type': 'if_statement', 'children': ['197', '204', '211']},{'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'in'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': '_JOURNALS_RENAMED_OLD_TO_NEW'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '203', 'type': 'argument_list', 'children': []},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '210']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '209', 'type': 'string', 'children': [], 'value': "'journal_title'"},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '211', 'type': 'else_clause', 'children': ['212']},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '218']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '217', 'type': 'string', 'children': [], 'value': "'journal_title'"},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': "''"},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'list', 'children': ['224', '225', '234'], 'value': "[\n journal_title,\n '' if journal_title.endswith('.') else ' ',\n match.group('letter'),\n ]"},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '225', 'type': 'conditional_expression', 'children': ['226', '227', '233'], 'value': 'if'},{'id': '226', 'type': 'string', 'children': [], 'value': "''"},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '233', 'type': 'string', 'children': [], 'value': "' '"},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'string', 'children': [], 'value': "'letter'"},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '245']},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '244', 'type': 'string', 'children': [], 'value': "'journal_volume'"},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'string', 'children': [], 'value': "'volume'"},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '254', 'type': 'call', 'children': ['255', '258']},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '258', 'type': 'argument_list', 'children': ['259', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': "'hidden'"},{'id': '260', 'type': 'None', 'children': []},{'id': '261', 'type': 'if_statement', 'children': ['262', '263', '271']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'hidden'},{'id': '263', 'type': 'block', 'children': ['264']},{'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': 'hidden_publication_infos'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '271', 'type': 'else_clause', 'children': ['272']},{'id': '272', 'type': 'block', 'children': ['273']},{'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': 'result'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'identifier', 'children': [], 'value': '_publication_info'},{'id': '280', 'type': 'for_statement', 'children': ['281', '282', '283']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'publication_info'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'hidden_publication_infos'},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'if_statement', 'children': ['285', '288']},{'id': '285', 'type': 'comparison_operator', 'children': ['286', '287'], 'value': 'not'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'publication_info'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '288', 'type': 'block', 'children': ['289', '295']},{'id': '289', 'type': 'expression_statement', 'children': ['290']},{'id': '290', 'type': 'assignment', 'children': ['291', '294']},{'id': '291', 'type': 'subscript', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'publication_info'},{'id': '293', 'type': 'string', 'children': [], 'value': "'hidden'"},{'id': '294', 'type': 'True', 'children': []},{'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': 'result'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'publication_info'},{'id': '302', 'type': 'return_statement', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'result'}
def convert_old_publication_info_to_new(publication_infos): result = [] hidden_publication_infos = [] for publication_info in publication_infos: _publication_info = copy.deepcopy(publication_info) journal_title = _publication_info.get('journal_title') try: journal_title = _JOURNALS_RENAMED_OLD_TO_NEW[journal_title] _publication_info['journal_title'] = journal_title result.append(_publication_info) continue except KeyError: pass journal_volume = _publication_info.get('journal_volume') if journal_title in _JOURNALS_WITH_YEAR_ADDED_TO_VOLUME and journal_volume and len(journal_volume) == 4: try: was_last_century = int(journal_volume[:2]) > 50 except ValueError: pass else: _publication_info['year'] = int('19' + journal_volume[:2] if was_last_century else '20' + journal_volume[:2]) _publication_info['journal_volume'] = journal_volume[2:] result.append(_publication_info) continue if journal_title and journal_volume and journal_title.lower() not in JOURNALS_IGNORED_IN_OLD_TO_NEW: volume_starts_with_a_letter = _RE_VOLUME_STARTS_WITH_A_LETTER.match(journal_volume) volume_ends_with_a_letter = _RE_VOLUME_ENDS_WITH_A_LETTER.match(journal_volume) match = volume_starts_with_a_letter or volume_ends_with_a_letter if match: _publication_info.pop('journal_record', None) if journal_title in _JOURNALS_RENAMED_OLD_TO_NEW.values(): _publication_info['journal_title'] = journal_title else: _publication_info['journal_title'] = ''.join([ journal_title, '' if journal_title.endswith('.') else ' ', match.group('letter'), ]) _publication_info['journal_volume'] = match.group('volume') hidden = _publication_info.pop('hidden', None) if hidden: hidden_publication_infos.append(_publication_info) else: result.append(_publication_info) for publication_info in hidden_publication_infos: if publication_info not in result: publication_info['hidden'] = True result.append(publication_info) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'construct_reference_system'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'symbols'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '33', '37', '50', '88', '92', '213', '217', '228']},{'id': '12', 'type': 'if_statement', 'children': ['13', '22', '27']},{'id': '13', 'type': 'boolean_operator', 'children': ['14', '19'], 'value': 'and'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '18', 'type': 'string', 'children': [], 'value': "'no_hydrogen'"},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'no_hydrogen'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'add_hydrogen'},{'id': '26', 'type': 'False', 'children': []},{'id': '27', 'type': 'else_clause', 'children': ['28']},{'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': 'add_hydrogen'},{'id': '32', 'type': 'True', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'references'},{'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': 'sorted_candidates'},{'id': '40', 'type': 'list', 'children': ['41', '42', '43', '44', '45', '46', '47', '48', '49'], 'value': "[\n 'H2',\n 'H2O',\n 'NH3',\n 'N2',\n 'CH4',\n 'CO',\n 'H2S',\n 'HCl',\n 'O2']"},{'id': '41', 'type': 'string', 'children': [], 'value': "'H2'"},{'id': '42', 'type': 'string', 'children': [], 'value': "'H2O'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'NH3'"},{'id': '44', 'type': 'string', 'children': [], 'value': "'N2'"},{'id': '45', 'type': 'string', 'children': [], 'value': "'CH4'"},{'id': '46', 'type': 'string', 'children': [], 'value': "'CO'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'H2S'"},{'id': '48', 'type': 'string', 'children': [], 'value': "'HCl'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'O2'"},{'id': '50', 'type': 'if_statement', 'children': ['51', '54', '59']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '53', 'type': 'None', 'children': []},{'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': 'candidates'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted_candidates'},{'id': '59', 'type': 'else_clause', 'children': ['60']},{'id': '60', 'type': 'block', 'children': ['61', '73']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'odd_candidates'},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '66', '69']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '69', 'type': 'if_clause', 'children': ['70']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'not'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorted_candidates'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '86', '87'], 'value': '+'},{'id': '77', 'type': 'list_comprehension', 'children': ['78', '79', '82']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '79', 'type': 'for_in_clause', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sorted_candidates'},{'id': '82', 'type': 'if_clause', 'children': ['83']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'in'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '86', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'odd_candidates'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'added_symbols'},{'id': '91', 'type': 'list', 'children': [], 'value': '[]'},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'symbols'},{'id': '95', 'type': 'block', 'children': ['96', '103']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'added_symbols'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '103', 'type': 'for_statement', 'children': ['104', '105', '106', '174']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'candidate'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '106', 'type': 'block', 'children': ['107', '118']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_symbols'},{'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': 'ase'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'symbols'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'string2symbols'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'candidate'},{'id': '118', 'type': 'if_statement', 'children': ['119', '166']},{'id': '119', 'type': 'boolean_operator', 'children': ['120', '158', '159'], 'value': 'and'},{'id': '120', 'type': 'boolean_operator', 'children': ['121', '139', '140'], 'value': 'and'},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '126'], 'value': '<='},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'added_symbols'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'binary_operator', 'children': ['130', '138'], 'value': '+'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'identifier', 'children': [], 'value': '_symbols'},{'id': '139', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '154'], 'value': '<='},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'binary_operator', 'children': ['145', '153'], 'value': '+'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '152', 'type': 'argument_list', 'children': []},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_symbols'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'symbols'},{'id': '158', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'not'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'candidate'},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'block', 'children': ['167', '173']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'candidate'},{'id': '173', 'type': 'break_statement', 'children': []},{'id': '174', 'type': 'else_clause', 'children': ['175']},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'raise_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'UserWarning'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '190']},{'id': '181', 'type': 'attribute', 'children': ['182', '189']},{'id': '182', 'type': '()', 'children': ['183']},{'id': '183', 'type': 'concatenated_string', 'children': ['184', '185', '186', '187', '188']},{'id': '184', 'type': 'string', 'children': [], 'value': '"No candidate satisfied {symbol}. Add more candidates\\n"'},{'id': '185', 'type': 'string', 'children': [], 'value': '" Symbols {symbols}\\n"'},{'id': '186', 'type': 'string', 'children': [], 'value': '" _Symbols {_symbols}\\n"'},{'id': '187', 'type': 'string', 'children': [], 'value': '" References {references}\\n"'},{'id': '188', 'type': 'string', 'children': [], 'value': '" Candidates {candidates}\\n"'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194', '197', '200', '203']},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'symbol'},{'id': '194', 'type': 'keyword_argument', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'symbols'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'symbols'},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': '_symbols'},{'id': '199', 'type': 'identifier', 'children': [], 'value': '_symbols'},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'candidates'},{'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '205', 'type': 'call', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'assignment', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'sorted_references'},{'id': '216', 'type': 'list', 'children': [], 'value': '[]'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'references'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '227', 'type': 'argument_list', 'children': []},{'id': '228', 'type': 'return_statement', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'references'}
def construct_reference_system( symbols, candidates=None, options=None, ): if hasattr(options, 'no_hydrogen') and options.no_hydrogen: add_hydrogen = False else: add_hydrogen = True references = {} sorted_candidates = [ 'H2', 'H2O', 'NH3', 'N2', 'CH4', 'CO', 'H2S', 'HCl', 'O2'] if candidates is None: candidates = sorted_candidates else: odd_candidates = [c for c in candidates if c not in sorted_candidates] candidates = [c for c in sorted_candidates if c in candidates] \ + odd_candidates added_symbols = [] for symbol in symbols: added_symbols.append(symbol) for candidate in candidates: _symbols = ase.symbols.string2symbols(candidate) if set(added_symbols) <= set(list(references.keys()) + _symbols) \ and set(list(references.keys()) + _symbols) <= set(symbols) \ and candidate not in references.values(): references[symbol] = candidate break else: raise UserWarning(( "No candidate satisfied {symbol}. Add more candidates\n" " Symbols {symbols}\n" " _Symbols {_symbols}\n" " References {references}\n" " Candidates {candidates}\n" ).format( symbol=symbol, symbols=symbols, _symbols=_symbols, candidates=candidates, references=list(references.keys()), )) sorted_references = [] references = list(references.items()) return references
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gen_triplets_master'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'geometry'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'block', 'children': ['12', '18', '24', '66', '79', '87', '94', '133', '142', '186', '195', '201', '211', '365']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'nlines_master'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'wv_previous'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '31']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'nlines_master'},{'id': '31', 'type': 'block', 'children': ['32', '60']},{'id': '32', 'type': 'if_statement', 'children': ['33', '38']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '>='},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'wv_previous'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'raise_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'binary_operator', 'children': ['44', '59'], 'value': '+'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '53'], 'value': '+'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '52'], 'value': '+'},{'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '+'},{'id': '47', 'type': 'string', 'children': [], 'value': "'Wavelengths:\\n--> '"},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'wv_previous'},{'id': '52', 'type': 'string', 'children': [], 'value': "'\\n--> '"},{'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': 'wv_master'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '59', 'type': 'string', 'children': [], 'value': "'\\nin master table are duplicated or not sorted'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'wv_previous'},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'iter_comb_triplets'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'combinations'},{'id': '73', 'type': 'argument_list', 'children': ['74', '78']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'nlines_master'},{'id': '78', 'type': 'integer', 'children': [], 'value': '3'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'triplets_master_list'},{'id': '82', 'type': 'list_comprehension', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'iter_comb_triplets'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ntriplets_master'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'triplets_master_list'},{'id': '94', 'type': 'if_statement', 'children': ['95', '105', '126']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '=='},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'ntriplets_master'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'comb'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101', '102']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'nlines_master'},{'id': '101', 'type': 'integer', 'children': [], 'value': '3'},{'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'exact'},{'id': '104', 'type': 'True', 'children': []},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'if_statement', 'children': ['107', '113']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '112'], 'value': '>='},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '112', 'type': 'integer', 'children': [], 'value': '10'},{'id': '113', 'type': 'block', 'children': ['114', '120']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'string', 'children': [], 'value': "'>>> Total number of lines in master table:'"},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'nlines_master'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': "'>>> Number of triplets in master table...:'"},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ntriplets_master'},{'id': '126', 'type': 'else_clause', 'children': ['127']},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'raise_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'string', 'children': [], 'value': "'Invalid number of combinations'"},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ratios_master'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'ntriplets_master'},{'id': '142', 'type': 'for_statement', 'children': ['143', '146', '150']},{'id': '143', 'type': 'pattern_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'triplets_master_list'},{'id': '150', 'type': 'block', 'children': ['151', '158', '168', '178']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '157']},{'id': '153', 'type': 'pattern_list', 'children': ['154', '155', '156']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'i2'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'i3'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'delta1'},{'id': '161', 'type': 'binary_operator', 'children': ['162', '165'], 'value': '-'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'i2'},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'delta2'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '-'},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'i3'},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'i1'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '183']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ratios_master'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '/'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'delta1'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'delta2'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'isort_ratios_master'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'ratios_master'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'ratios_master_sorted'},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'ratios_master'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'isort_ratios_master'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'triplets_master_sorted_list'},{'id': '204', 'type': 'list_comprehension', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'triplets_master_list'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '208', 'type': 'for_in_clause', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'isort_ratios_master'},{'id': '211', 'type': 'if_statement', 'children': ['212', '220']},{'id': '212', 'type': 'comparison_operator', 'children': ['213', '217'], 'value': 'in'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '217', 'type': 'list', 'children': ['218', '219'], 'value': '[21, 22]'},{'id': '218', 'type': 'integer', 'children': [], 'value': '21'},{'id': '219', 'type': 'integer', 'children': [], 'value': '22'},{'id': '220', 'type': 'block', 'children': ['221', '232', '246', '254', '262', '271', '284', '302', '316', '323', '330', '349', '354']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'bins_in'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'linspace'},{'id': '228', 'type': 'argument_list', 'children': ['229', '230', '231']},{'id': '229', 'type': 'float', 'children': [], 'value': '0.0'},{'id': '230', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '231', 'type': 'integer', 'children': [], 'value': '41'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '237']},{'id': '234', 'type': 'pattern_list', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'hist'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'bins_out'},{'id': '237', 'type': 'call', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'histogram'},{'id': '241', 'type': 'argument_list', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'ratios_master'},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'bins'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'bins_in'},{'id': '246', 'type': 'import_from_statement', 'children': ['247', '252']},{'id': '247', 'type': 'dotted_name', 'children': ['248', '249', '250', '251']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'numina'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'display'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'matplotlib_qt'},{'id': '252', 'type': 'dotted_name', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'figure'},{'id': '261', 'type': 'argument_list', 'children': []},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'add_subplot'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'integer', 'children': [], 'value': '111'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'width_hist'},{'id': '274', 'type': 'binary_operator', 'children': ['275', '276'], 'value': '*'},{'id': '275', 'type': 'float', 'children': [], 'value': '0.8'},{'id': '276', 'type': '()', 'children': ['277']},{'id': '277', 'type': 'binary_operator', 'children': ['278', '281'], 'value': '-'},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'bins_out'},{'id': '280', 'type': 'integer', 'children': [], 'value': '1'},{'id': '281', 'type': 'subscript', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'bins_out'},{'id': '283', 'type': 'integer', 'children': [], 'value': '0'},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '287', 'type': 'binary_operator', 'children': ['288', '301'], 'value': '/'},{'id': '288', 'type': '()', 'children': ['289']},{'id': '289', 'type': 'binary_operator', 'children': ['290', '296'], 'value': '+'},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'bins_out'},{'id': '292', 'type': 'slice', 'children': ['293', '294']},{'id': '293', 'type': 'colon', 'children': []},{'id': '294', 'type': 'unary_operator', 'children': ['295'], 'value': '-'},{'id': '295', 'type': 'integer', 'children': [], 'value': '1'},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'bins_out'},{'id': '298', 'type': 'slice', 'children': ['299', '300']},{'id': '299', 'type': 'integer', 'children': [], 'value': '1'},{'id': '300', 'type': 'colon', 'children': []},{'id': '301', 'type': 'integer', 'children': [], 'value': '2'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'call', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'bar'},{'id': '307', 'type': 'argument_list', 'children': ['308', '309', '310', '313']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'center'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'hist'},{'id': '310', 'type': 'keyword_argument', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'align'},{'id': '312', 'type': 'string', 'children': [], 'value': "'center'"},{'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'width'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'width_hist'},{'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': 'ax'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'string', 'children': [], 'value': "'distance ratio in each triplet'"},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'string', 'children': [], 'value': "'Number of triplets'"},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'set_title'},{'id': '335', 'type': 'argument_list', 'children': ['336']},{'id': '336', 'type': 'binary_operator', 'children': ['337', '345'], 'value': '+'},{'id': '337', 'type': 'binary_operator', 'children': ['338', '344'], 'value': '+'},{'id': '338', 'type': 'binary_operator', 'children': ['339', '340'], 'value': '+'},{'id': '339', 'type': 'string', 'children': [], 'value': '"Number of lines/triplets: "'},{'id': '340', 'type': 'call', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'nlines_master'},{'id': '344', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '345', 'type': 'call', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '347', 'type': 'argument_list', 'children': ['348']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'ntriplets_master'},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'call', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'set_window_geometry'},{'id': '352', 'type': 'argument_list', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'geometry'},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'call', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'pause_debugplot'},{'id': '357', 'type': 'argument_list', 'children': ['358', '359', '362']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '359', 'type': 'keyword_argument', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'pltshow'},{'id': '361', 'type': 'True', 'children': []},{'id': '362', 'type': 'keyword_argument', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'tight_layout'},{'id': '364', 'type': 'True', 'children': []},{'id': '365', 'type': 'return_statement', 'children': ['366']},{'id': '366', 'type': 'expression_list', 'children': ['367', '368', '369']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'ntriplets_master'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'ratios_master_sorted'},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'triplets_master_sorted_list'}
def gen_triplets_master(wv_master, geometry=None, debugplot=0): nlines_master = wv_master.size wv_previous = wv_master[0] for i in range(1, nlines_master): if wv_previous >= wv_master[i]: raise ValueError('Wavelengths:\n--> ' + str(wv_previous) + '\n--> ' + str(wv_master[i]) + '\nin master table are duplicated or not sorted') wv_previous = wv_master[i] iter_comb_triplets = itertools.combinations(range(nlines_master), 3) triplets_master_list = [val for val in iter_comb_triplets] ntriplets_master = len(triplets_master_list) if ntriplets_master == comb(nlines_master, 3, exact=True): if abs(debugplot) >= 10: print('>>> Total number of lines in master table:', nlines_master) print('>>> Number of triplets in master table...:', ntriplets_master) else: raise ValueError('Invalid number of combinations') ratios_master = np.zeros(ntriplets_master) for index, value in enumerate(triplets_master_list): i1, i2, i3 = value delta1 = wv_master[i2] - wv_master[i1] delta2 = wv_master[i3] - wv_master[i1] ratios_master[index] = delta1 / delta2 isort_ratios_master = np.argsort(ratios_master) ratios_master_sorted = ratios_master[isort_ratios_master] triplets_master_sorted_list = [triplets_master_list[i] for i in isort_ratios_master] if abs(debugplot) in [21, 22]: bins_in = np.linspace(0.0, 1.0, 41) hist, bins_out = np.histogram(ratios_master, bins=bins_in) from numina.array.display.matplotlib_qt import plt fig = plt.figure() ax = fig.add_subplot(111) width_hist = 0.8*(bins_out[1]-bins_out[0]) center = (bins_out[:-1]+bins_out[1:])/2 ax.bar(center, hist, align='center', width=width_hist) ax.set_xlabel('distance ratio in each triplet') ax.set_ylabel('Number of triplets') ax.set_title("Number of lines/triplets: " + str(nlines_master) + "/" + str(ntriplets_master)) set_window_geometry(geometry) pause_debugplot(debugplot, pltshow=True, tight_layout=True) return ntriplets_master, ratios_master_sorted, triplets_master_sorted_list
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_wv_arrays'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'delta_wv_max'},{'id': '7', 'type': 'block', 'children': ['8', '17', '29', '41', '47', '343']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'zeros_like'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'wv_unused'},{'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': 'ones_like'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'minimum_delta_wv'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ones_like'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'augmented_assignment', 'children': ['43', '44'], 'value': '*='},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'minimum_delta_wv'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'infty'},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '56']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '56', 'type': 'block', 'children': ['57', '69']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'searchsorted'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '69', 'type': 'if_statement', 'children': ['70', '73', '140', '214']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '=='},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '72', 'type': 'integer', 'children': [], 'value': '0'},{'id': '73', 'type': 'block', 'children': ['74', '87']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'delta_wv'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'binary_operator', 'children': ['81', '84'], 'value': '-'},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '87', 'type': 'if_statement', 'children': ['88', '91']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '<'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'delta_wv'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'delta_wv_max'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'if_statement', 'children': ['93', '96', '117']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'wv_unused'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '96', 'type': 'block', 'children': ['97', '105', '111']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '102']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': 'wv_unused'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '110', 'type': 'False', 'children': []},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'minimum_delta_wv'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'delta_wv'},{'id': '117', 'type': 'else_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'if_statement', 'children': ['120', '125']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '<'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'delta_wv'},{'id': '122', 'type': 'subscript', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'minimum_delta_wv'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '125', 'type': 'block', 'children': ['126', '134']},{'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': 'wv_verified_all_peaks'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '139']},{'id': '136', 'type': 'subscript', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'minimum_delta_wv'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'delta_wv'},{'id': '140', 'type': 'elif_clause', 'children': ['141', '147']},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '=='},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'j'},{'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': 'wv_expected_all_peaks'},{'id': '147', 'type': 'block', 'children': ['148', '163']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'delta_wv'},{'id': '151', 'type': 'call', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'binary_operator', 'children': ['155', '158'], 'value': '-'},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '-'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'if_statement', 'children': ['164', '167']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '<'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'delta_wv'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'delta_wv_max'},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'if_statement', 'children': ['169', '174', '193']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'wv_unused'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '-'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '173', 'type': 'integer', 'children': [], 'value': '1'},{'id': '174', 'type': 'block', 'children': ['175', '185']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '182']},{'id': '177', 'type': 'subscript', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '-'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '181', 'type': 'integer', 'children': [], 'value': '1'},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '192']},{'id': '187', 'type': 'subscript', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'wv_unused'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '-'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'id': '192', 'type': 'False', 'children': []},{'id': '193', 'type': 'else_clause', 'children': ['194']},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'if_statement', 'children': ['196', '203']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '<'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'delta_wv'},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'minimum_delta_wv'},{'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '-'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '202', 'type': 'integer', 'children': [], 'value': '1'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'assignment', 'children': ['206', '211']},{'id': '206', 'type': 'subscript', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '-'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '210', 'type': 'integer', 'children': [], 'value': '1'},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '214', 'type': 'else_clause', 'children': ['215']},{'id': '215', 'type': 'block', 'children': ['216', '231', '244']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'assignment', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'delta_wv1'},{'id': '219', 'type': 'call', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'binary_operator', 'children': ['223', '226'], 'value': '-'},{'id': '223', 'type': 'subscript', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '228', 'type': 'binary_operator', 'children': ['229', '230'], 'value': '-'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '230', 'type': 'integer', 'children': [], 'value': '1'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'delta_wv2'},{'id': '234', 'type': 'call', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'binary_operator', 'children': ['238', '241'], 'value': '-'},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'wv_expected_all_peaks'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '244', 'type': 'if_statement', 'children': ['245', '248', '300']},{'id': '245', 'type': 'comparison_operator', 'children': ['246', '247'], 'value': '<'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'delta_wv1'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'delta_wv2'},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'if_statement', 'children': ['250', '253']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '<'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'delta_wv1'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'delta_wv_max'},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'if_statement', 'children': ['255', '260', '279']},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'wv_unused'},{'id': '257', 'type': 'binary_operator', 'children': ['258', '259'], 'value': '-'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '259', 'type': 'integer', 'children': [], 'value': '1'},{'id': '260', 'type': 'block', 'children': ['261', '271']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '268']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'},{'id': '265', 'type': 'binary_operator', 'children': ['266', '267'], 'value': '-'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '267', 'type': 'integer', 'children': [], 'value': '1'},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '278']},{'id': '273', 'type': 'subscript', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'wv_unused'},{'id': '275', 'type': 'binary_operator', 'children': ['276', '277'], 'value': '-'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '277', 'type': 'integer', 'children': [], 'value': '1'},{'id': '278', 'type': 'False', 'children': []},{'id': '279', 'type': 'else_clause', 'children': ['280']},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'if_statement', 'children': ['282', '289']},{'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': '<'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'delta_wv1'},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'minimum_delta_wv'},{'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '-'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '288', 'type': 'integer', 'children': [], 'value': '1'},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'expression_statement', 'children': ['291']},{'id': '291', 'type': 'assignment', 'children': ['292', '297']},{'id': '292', 'type': 'subscript', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'},{'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '-'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '296', 'type': 'integer', 'children': [], 'value': '1'},{'id': '297', 'type': 'subscript', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '300', 'type': 'else_clause', 'children': ['301']},{'id': '301', 'type': 'block', 'children': ['302']},{'id': '302', 'type': 'if_statement', 'children': ['303', '306']},{'id': '303', 'type': 'comparison_operator', 'children': ['304', '305'], 'value': '<'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'delta_wv2'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'delta_wv_max'},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'if_statement', 'children': ['308', '311', '326']},{'id': '308', 'type': 'subscript', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'wv_unused'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '311', 'type': 'block', 'children': ['312', '320']},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '317']},{'id': '314', 'type': 'subscript', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'i'},{'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': 'wv_unused'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '325', 'type': 'False', 'children': []},{'id': '326', 'type': 'else_clause', 'children': ['327']},{'id': '327', 'type': 'block', 'children': ['328']},{'id': '328', 'type': 'if_statement', 'children': ['329', '334']},{'id': '329', 'type': 'comparison_operator', 'children': ['330', '331'], 'value': '<'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'delta_wv2'},{'id': '331', 'type': 'subscript', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'minimum_delta_wv'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '334', 'type': 'block', 'children': ['335']},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'assignment', 'children': ['337', '340']},{'id': '337', 'type': 'subscript', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'wv_master'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '343', 'type': 'return_statement', 'children': ['344']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'wv_verified_all_peaks'}
def match_wv_arrays(wv_master, wv_expected_all_peaks, delta_wv_max): wv_verified_all_peaks = np.zeros_like(wv_expected_all_peaks) wv_unused = np.ones_like(wv_expected_all_peaks, dtype=bool) minimum_delta_wv = np.ones_like(wv_expected_all_peaks, dtype=float) minimum_delta_wv *= np.infty for i in range(len(wv_master)): j = np.searchsorted(wv_expected_all_peaks, wv_master[i]) if j == 0: delta_wv = abs(wv_master[i] - wv_expected_all_peaks[j]) if delta_wv < delta_wv_max: if wv_unused[j]: wv_verified_all_peaks[j] = wv_master[i] wv_unused[j] = False minimum_delta_wv[j] = delta_wv else: if delta_wv < minimum_delta_wv[j]: wv_verified_all_peaks[j] = wv_master[i] minimum_delta_wv[j] = delta_wv elif j == len(wv_expected_all_peaks): delta_wv = abs(wv_master[i] - wv_expected_all_peaks[j-1]) if delta_wv < delta_wv_max: if wv_unused[j-1]: wv_verified_all_peaks[j-1] = wv_master[i] wv_unused[j-1] = False else: if delta_wv < minimum_delta_wv[j-1]: wv_verified_all_peaks[j-1] = wv_master[i] else: delta_wv1 = abs(wv_master[i] - wv_expected_all_peaks[j-1]) delta_wv2 = abs(wv_master[i] - wv_expected_all_peaks[j]) if delta_wv1 < delta_wv2: if delta_wv1 < delta_wv_max: if wv_unused[j-1]: wv_verified_all_peaks[j-1] = wv_master[i] wv_unused[j-1] = False else: if delta_wv1 < minimum_delta_wv[j-1]: wv_verified_all_peaks[j-1] = wv_master[i] else: if delta_wv2 < delta_wv_max: if wv_unused[j]: wv_verified_all_peaks[j] = wv_master[i] wv_unused[j] = False else: if delta_wv2 < minimum_delta_wv[j]: wv_verified_all_peaks[j] = wv_master[i] return wv_verified_all_peaks
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '41']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_publication_info'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'cnum'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'artid'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'page_end'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'page_start'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'journal_issue'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '25', 'type': 'None', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'pubinfo_freetext'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'material'},{'id': '34', 'type': 'None', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'parent_record'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'parent_isbn'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '73', '77', '110', '128', '142', '172', '180']},{'id': '42', 'type': 'if_statement', 'children': ['43', '59']},{'id': '43', 'type': 'boolean_operator', 'children': ['44', '45'], 'value': 'and'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '47', 'type': 'generator_expression', 'children': ['48', '50']},{'id': '48', 'type': 'not_operator', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '52', 'type': 'tuple', 'children': ['53', '54', '55', '56', '57', '58']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cnum'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'artid'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'journal_issue'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'journal_volume'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'page_start'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'page_end'},{'id': '59', 'type': 'block', 'children': ['60', '72']},{'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': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'add_public_note'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'Submitted to {}'"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'journal_title'},{'id': '72', 'type': 'return_statement', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'publication_item'},{'id': '76', 'type': 'dictionary', 'children': []},{'id': '77', 'type': 'for_statement', 'children': ['78', '79', '90']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '79', 'type': 'tuple', 'children': ['80', '81', '82', '83', '84', '85', '86', '87', '88', '89']},{'id': '80', 'type': 'string', 'children': [], 'value': "'cnum'"},{'id': '81', 'type': 'string', 'children': [], 'value': "'artid'"},{'id': '82', 'type': 'string', 'children': [], 'value': "'page_end'"},{'id': '83', 'type': 'string', 'children': [], 'value': "'page_start'"},{'id': '84', 'type': 'string', 'children': [], 'value': "'journal_issue'"},{'id': '85', 'type': 'string', 'children': [], 'value': "'journal_title'"},{'id': '86', 'type': 'string', 'children': [], 'value': "'journal_volume'"},{'id': '87', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'pubinfo_freetext'"},{'id': '89', 'type': 'string', 'children': [], 'value': "'material'"},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'if_statement', 'children': ['92', '99']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '98'], 'value': 'is'},{'id': '93', 'type': 'subscript', 'children': ['94', '97']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '96', 'type': 'argument_list', 'children': []},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '98', 'type': 'None', 'children': []},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'publication_item'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '105', 'type': 'subscript', 'children': ['106', '109']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'locals'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '110', 'type': 'if_statement', 'children': ['111', '114']},{'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'is'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'parent_record'},{'id': '113', 'type': 'None', 'children': []},{'id': '114', 'type': 'block', 'children': ['115', '122']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'parent_item'},{'id': '118', 'type': 'dictionary', 'children': ['119']},{'id': '119', 'type': 'pair', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': "'$ref'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'parent_record'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '127']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'publication_item'},{'id': '126', 'type': 'string', 'children': [], 'value': "'parent_record'"},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'parent_item'},{'id': '128', 'type': 'if_statement', 'children': ['129', '132']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'is'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'parent_isbn'},{'id': '131', 'type': 'None', 'children': []},{'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': 'publication_item'},{'id': '137', 'type': 'string', 'children': [], 'value': "'parent_isbn'"},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'normalize_isbn'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'parent_isbn'},{'id': '142', 'type': 'if_statement', 'children': ['143', '146']},{'id': '143', 'type': 'boolean_operator', 'children': ['144', '145'], 'value': 'and'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'page_start'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'page_end'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'try_statement', 'children': ['148', '166']},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'add_number_of_pages'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'binary_operator', 'children': ['156', '165'], 'value': '+'},{'id': '156', 'type': 'binary_operator', 'children': ['157', '161'], 'value': '-'},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'page_end'},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'page_start'},{'id': '165', 'type': 'integer', 'children': [], 'value': '1'},{'id': '166', 'type': 'except_clause', 'children': ['167', '170']},{'id': '167', 'type': 'tuple', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'pass_statement', 'children': []},{'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': 'self'},{'id': '176', 'type': 'identifier', 'children': [], 'value': '_append_to'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'string', 'children': [], 'value': "'publication_info'"},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'publication_item'},{'id': '180', 'type': 'if_statement', 'children': ['181', '189']},{'id': '181', 'type': 'call', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'is_citeable'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'subscript', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'record'},{'id': '188', 'type': 'string', 'children': [], 'value': "'publication_info'"},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '195']},{'id': '192', 'type': 'attribute', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'set_citeable'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'True', 'children': []}
def add_publication_info( self, year=None, cnum=None, artid=None, page_end=None, page_start=None, journal_issue=None, journal_title=None, journal_volume=None, pubinfo_freetext=None, material=None, parent_record=None, parent_isbn=None, ): if journal_title and all( not field for field in (cnum, artid, journal_issue, journal_volume, page_start, page_end)): self.add_public_note('Submitted to {}'.format(journal_title)) return publication_item = {} for key in ('cnum', 'artid', 'page_end', 'page_start', 'journal_issue', 'journal_title', 'journal_volume', 'year', 'pubinfo_freetext', 'material'): if locals()[key] is not None: publication_item[key] = locals()[key] if parent_record is not None: parent_item = {'$ref': parent_record} publication_item['parent_record'] = parent_item if parent_isbn is not None: publication_item['parent_isbn'] = normalize_isbn(parent_isbn) if page_start and page_end: try: self.add_number_of_pages( int(page_end) - int(page_start) + 1 ) except (TypeError, ValueError): pass self._append_to('publication_info', publication_item) if is_citeable(self.record['publication_info']): self.set_citeable(True)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute_operation'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'file1'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'file2'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'display'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'args_z1z2'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'args_bbox'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'args_keystitle'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'args_geometry'},{'id': '13', 'type': 'block', 'children': ['14', '50', '56', '62', '89', '125', '131', '137', '164', '174', '184', '240', '257', '267']},{'id': '14', 'type': 'with_statement', 'children': ['15', '26']},{'id': '15', 'type': 'with_clause', 'children': ['16']},{'id': '16', 'type': 'with_item', 'children': ['17']},{'id': '17', 'type': 'as_pattern', 'children': ['18', '24']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'fits'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'file1'},{'id': '24', 'type': 'as_pattern_target', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'hdulist'},{'id': '26', 'type': 'block', 'children': ['27', '35']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'image_header1'},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'hdulist'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'image1'},{'id': '38', 'type': 'call', 'children': ['39', '46']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'attribute', 'children': ['41', '44']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'hdulist'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'naxis1'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'image_header1'},{'id': '55', 'type': 'string', 'children': [], 'value': "'naxis1'"},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'naxis2'},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'image_header1'},{'id': '61', 'type': 'string', 'children': [], 'value': "'naxis2'"},{'id': '62', 'type': 'if_statement', 'children': ['63', '66']},{'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '=='},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'display'},{'id': '65', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ximshow_file'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74', '77', '80', '83', '86']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'file1'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'args_z1z2'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'args_z1z2'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'args_bbox'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'args_bbox'},{'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'args_keystitle'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'args_keystitle'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'args_geometry'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'args_geometry'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '88', 'type': 'integer', 'children': [], 'value': '12'},{'id': '89', 'type': 'with_statement', 'children': ['90', '101']},{'id': '90', 'type': 'with_clause', 'children': ['91']},{'id': '91', 'type': 'with_item', 'children': ['92']},{'id': '92', 'type': 'as_pattern', 'children': ['93', '99']},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'fits'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'file2'},{'id': '99', 'type': 'as_pattern_target', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'hdulist'},{'id': '101', 'type': 'block', 'children': ['102', '110']},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'image_header2'},{'id': '105', 'type': 'attribute', 'children': ['106', '109']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'hdulist'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'image2'},{'id': '113', 'type': 'call', 'children': ['114', '121']},{'id': '114', 'type': 'attribute', 'children': ['115', '120']},{'id': '115', 'type': 'attribute', 'children': ['116', '119']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'hdulist'},{'id': '118', 'type': 'integer', 'children': [], 'value': '0'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'naxis1_'},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'image_header2'},{'id': '130', 'type': 'string', 'children': [], 'value': "'naxis1'"},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'naxis2_'},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'image_header2'},{'id': '136', 'type': 'string', 'children': [], 'value': "'naxis2'"},{'id': '137', 'type': 'if_statement', 'children': ['138', '141']},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '=='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'display'},{'id': '140', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ximshow_file'},{'id': '145', 'type': 'argument_list', 'children': ['146', '149', '152', '155', '158', '161']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'file2'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'args_z1z2'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'args_z1z2'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'args_bbox'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'args_bbox'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'args_keystitle'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'args_keystitle'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'args_geometry'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'args_geometry'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '163', 'type': 'integer', 'children': [], 'value': '12'},{'id': '164', 'type': 'if_statement', 'children': ['165', '168']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '!='},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'naxis1'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'naxis1_'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'raise_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'string', 'children': [], 'value': '"NAXIS1 values are different."'},{'id': '174', 'type': 'if_statement', 'children': ['175', '178']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '!='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'naxis2'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'naxis2_'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'raise_statement', 'children': ['180']},{'id': '180', 'type': 'call', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'string', 'children': [], 'value': '"NAXIS2 values are different."'},{'id': '184', 'type': 'if_statement', 'children': ['185', '188', '195', '206', '217', '228']},{'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '=='},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '187', 'type': 'string', 'children': [], 'value': '"+"'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '+'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'image1'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'image2'},{'id': '195', 'type': 'elif_clause', 'children': ['196', '199']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '=='},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '198', 'type': 'string', 'children': [], 'value': '"-"'},{'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': 'solution'},{'id': '203', 'type': 'binary_operator', 'children': ['204', '205'], 'value': '-'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'image1'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'image2'},{'id': '206', 'type': 'elif_clause', 'children': ['207', '210']},{'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': '=='},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '209', 'type': 'string', 'children': [], 'value': '"*"'},{'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': 'solution'},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '*'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'image1'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'image2'},{'id': '217', 'type': 'elif_clause', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': '=='},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '220', 'type': 'string', 'children': [], 'value': '"/"'},{'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': 'solution'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '/'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'image1'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'image2'},{'id': '228', 'type': 'else_clause', 'children': ['229']},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'raise_statement', 'children': ['231']},{'id': '231', 'type': 'call', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'binary_operator', 'children': ['235', '236'], 'value': '+'},{'id': '235', 'type': 'string', 'children': [], 'value': '"Unexpected operation="'},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'operation'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'hdu'},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'fits'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'PrimaryHDU'},{'id': '247', 'type': 'argument_list', 'children': ['248', '256']},{'id': '248', 'type': 'call', 'children': ['249', '252']},{'id': '249', 'type': 'attribute', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'solution'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'astype'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'image_header1'},{'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': 'hdu'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'writeto'},{'id': '262', 'type': 'argument_list', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '266', 'type': 'True', 'children': []},{'id': '267', 'type': 'if_statement', 'children': ['268', '273']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': 'in'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'display'},{'id': '270', 'type': 'list', 'children': ['271', '272'], 'value': "['all', 'result']"},{'id': '271', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '272', 'type': 'string', 'children': [], 'value': "'result'"},{'id': '273', 'type': 'block', 'children': ['274']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'ximshow_file'},{'id': '277', 'type': 'argument_list', 'children': ['278', '281', '284', '287', '290', '293']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'args_z1z2'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'args_z1z2'},{'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'args_bbox'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'args_bbox'},{'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'args_keystitle'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'args_keystitle'},{'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'args_geometry'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'args_geometry'},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '295', 'type': 'integer', 'children': [], 'value': '12'}
def compute_operation(file1, file2, operation, output, display, args_z1z2, args_bbox, args_keystitle, args_geometry): with fits.open(file1) as hdulist: image_header1 = hdulist[0].header image1 = hdulist[0].data.astype(np.float) naxis1 = image_header1['naxis1'] naxis2 = image_header1['naxis2'] if display == 'all': ximshow_file(file1.name, args_z1z2=args_z1z2, args_bbox=args_bbox, args_keystitle=args_keystitle, args_geometry=args_geometry, debugplot=12) with fits.open(file2) as hdulist: image_header2 = hdulist[0].header image2 = hdulist[0].data.astype(np.float) naxis1_ = image_header2['naxis1'] naxis2_ = image_header2['naxis2'] if display == 'all': ximshow_file(file2.name, args_z1z2=args_z1z2, args_bbox=args_bbox, args_keystitle=args_keystitle, args_geometry=args_geometry, debugplot=12) if naxis1 != naxis1_: raise ValueError("NAXIS1 values are different.") if naxis2 != naxis2_: raise ValueError("NAXIS2 values are different.") if operation == "+": solution = image1 + image2 elif operation == "-": solution = image1 - image2 elif operation == "*": solution = image1 * image2 elif operation == "/": solution = image1 / image2 else: raise ValueError("Unexpected operation=" + str(operation)) hdu = fits.PrimaryHDU(solution.astype(np.float), image_header1) hdu.writeto(output, overwrite=True) if display in ['all', 'result']: ximshow_file(output.name, args_z1z2=args_z1z2, args_bbox=args_bbox, args_keystitle=args_keystitle, args_geometry=args_geometry, debugplot=12)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'summary'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'rm_nan'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '64', '85', '104', '111', '117', '237', '353']},{'id': '12', 'type': 'if_statement', 'children': ['13', '21', '31']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '18'], 'value': 'is'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'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': 'xx'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'if_statement', 'children': ['34', '40', '50']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], 'value': 'is'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'xx'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'raise_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'binary_operator', 'children': ['57', '63'], 'value': '+'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '+'},{'id': '58', 'type': 'string', 'children': [], 'value': "'x='"},{'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': 'x'},{'id': '63', 'type': 'string', 'children': [], 'value': "' must be a numpy.ndarray'"},{'id': '64', 'type': 'if_statement', 'children': ['65', '70']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': 'is'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'raise_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'binary_operator', 'children': ['76', '84'], 'value': '+'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '+'},{'id': '77', 'type': 'string', 'children': [], 'value': "'xx.dim='"},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '84', 'type': 'string', 'children': [], 'value': "' must be 1'"},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'rm_nan'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '93', 'type': 'call', 'children': ['94', '97']},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'logical_not'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'isnan'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'npoints'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '>'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'npoints'},{'id': '116', 'type': 'integer', 'children': [], 'value': '0'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '120', 'type': 'dictionary', 'children': ['121', '124', '135', '147', '159', '170', '182', '193', '204', '213', '225']},{'id': '121', 'type': 'pair', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'npoints'"},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'npoints'},{'id': '124', 'type': 'pair', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': "'minimum'"},{'id': '126', 'type': 'conditional_expression', 'children': ['127', '133', '134'], 'value': 'if'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'pair', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': "'percentile25'"},{'id': '137', 'type': 'conditional_expression', 'children': ['138', '145', '146'], 'value': 'if'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'percentile'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '144', 'type': 'integer', 'children': [], 'value': '25'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'pair', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': "'median'"},{'id': '149', 'type': 'conditional_expression', 'children': ['150', '157', '158'], 'value': 'if'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'percentile'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '156', 'type': 'integer', 'children': [], 'value': '50'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '158', 'type': 'integer', 'children': [], 'value': '0'},{'id': '159', 'type': 'pair', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': "'mean'"},{'id': '161', 'type': 'conditional_expression', 'children': ['162', '168', '169'], 'value': 'if'},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '169', 'type': 'integer', 'children': [], 'value': '0'},{'id': '170', 'type': 'pair', 'children': ['171', '172']},{'id': '171', 'type': 'string', 'children': [], 'value': "'percentile75'"},{'id': '172', 'type': 'conditional_expression', 'children': ['173', '180', '181'], 'value': 'if'},{'id': '173', 'type': 'call', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'percentile'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '179', 'type': 'integer', 'children': [], 'value': '75'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '181', 'type': 'integer', 'children': [], 'value': '0'},{'id': '182', 'type': 'pair', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': "'maximum'"},{'id': '184', 'type': 'conditional_expression', 'children': ['185', '191', '192'], 'value': 'if'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '192', 'type': 'integer', 'children': [], 'value': '0'},{'id': '193', 'type': 'pair', 'children': ['194', '195']},{'id': '194', 'type': 'string', 'children': [], 'value': "'std'"},{'id': '195', 'type': 'conditional_expression', 'children': ['196', '202', '203'], 'value': 'if'},{'id': '196', 'type': 'call', 'children': ['197', '200']},{'id': '197', 'type': 'attribute', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'std'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '203', 'type': 'integer', 'children': [], 'value': '0'},{'id': '204', 'type': 'pair', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': "'robust_std'"},{'id': '206', 'type': 'conditional_expression', 'children': ['207', '211', '212'], 'value': 'if'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'robust_std'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '212', 'type': 'integer', 'children': [], 'value': '0'},{'id': '213', 'type': 'pair', 'children': ['214', '215']},{'id': '214', 'type': 'string', 'children': [], 'value': "'percentile15'"},{'id': '215', 'type': 'conditional_expression', 'children': ['216', '223', '224'], 'value': 'if'},{'id': '216', 'type': 'call', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'percentile'},{'id': '220', 'type': 'argument_list', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '222', 'type': 'float', 'children': [], 'value': '15.86553'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'pair', 'children': ['226', '227']},{'id': '226', 'type': 'string', 'children': [], 'value': "'percentile84'"},{'id': '227', 'type': 'conditional_expression', 'children': ['228', '235', '236'], 'value': 'if'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'percentile'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'xx'},{'id': '234', 'type': 'float', 'children': [], 'value': '84.13447'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '236', 'type': 'integer', 'children': [], 'value': '0'},{'id': '237', 'type': 'if_statement', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '239', 'type': 'block', 'children': ['240', '245', '250', '255', '263', '271', '279', '287', '295', '303', '311', '316', '324', '332', '340', '348']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'string', 'children': [], 'value': "'>>> ========================================'"},{'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': 'string', 'children': [], 'value': "'>>> STATISTICAL SUMMARY:'"},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'string', 'children': [], 'value': "'>>> ----------------------------------------'"},{'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', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': "'>>> Number of points.........:'"},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '262', 'type': 'string', 'children': [], 'value': "'npoints'"},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268']},{'id': '267', 'type': 'string', 'children': [], 'value': "'>>> Minimum..................:'"},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '270', 'type': 'string', 'children': [], 'value': "'minimum'"},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276']},{'id': '275', 'type': 'string', 'children': [], 'value': "'>>> 1st Quartile.............:'"},{'id': '276', 'type': 'subscript', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '278', 'type': 'string', 'children': [], 'value': "'percentile25'"},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'string', 'children': [], 'value': "'>>> Median...................:'"},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '286', 'type': 'string', 'children': [], 'value': "'median'"},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '290', 'type': 'argument_list', 'children': ['291', '292']},{'id': '291', 'type': 'string', 'children': [], 'value': "'>>> Mean.....................:'"},{'id': '292', 'type': 'subscript', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '294', 'type': 'string', 'children': [], 'value': "'mean'"},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '298', 'type': 'argument_list', 'children': ['299', '300']},{'id': '299', 'type': 'string', 'children': [], 'value': "'>>> 3rd Quartile.............:'"},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '302', 'type': 'string', 'children': [], 'value': "'percentile75'"},{'id': '303', 'type': 'expression_statement', 'children': ['304']},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '306', 'type': 'argument_list', 'children': ['307', '308']},{'id': '307', 'type': 'string', 'children': [], 'value': "'>>> Maximum..................:'"},{'id': '308', 'type': 'subscript', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '310', 'type': 'string', 'children': [], 'value': "'maximum'"},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'string', 'children': [], 'value': "'>>> ----------------------------------------'"},{'id': '316', 'type': 'expression_statement', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '319', 'type': 'argument_list', 'children': ['320', '321']},{'id': '320', 'type': 'string', 'children': [], 'value': "'>>> Standard deviation.......:'"},{'id': '321', 'type': 'subscript', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '323', 'type': 'string', 'children': [], 'value': "'std'"},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '327', 'type': 'argument_list', 'children': ['328', '329']},{'id': '328', 'type': 'string', 'children': [], 'value': "'>>> Robust standard deviation:'"},{'id': '329', 'type': 'subscript', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '331', 'type': 'string', 'children': [], 'value': "'robust_std'"},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'call', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '335', 'type': 'argument_list', 'children': ['336', '337']},{'id': '336', 'type': 'string', 'children': [], 'value': "'>>> 0.1586553 percentile.....:'"},{'id': '337', 'type': 'subscript', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '339', 'type': 'string', 'children': [], 'value': "'percentile15'"},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '343', 'type': 'argument_list', 'children': ['344', '345']},{'id': '344', 'type': 'string', 'children': [], 'value': "'>>> 0.8413447 percentile.....:'"},{'id': '345', 'type': 'subscript', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '347', 'type': 'string', 'children': [], 'value': "'percentile84'"},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'string', 'children': [], 'value': "'>>> ========================================'"},{'id': '353', 'type': 'return_statement', 'children': ['354']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'result'}
def summary(x, rm_nan=False, debug=False): if type(x) is np.ndarray: xx = np.copy(x) else: if type(x) is list: xx = np.array(x) else: raise ValueError('x=' + str(x) + ' must be a numpy.ndarray') if xx.ndim is not 1: raise ValueError('xx.dim=' + str(xx.ndim) + ' must be 1') if rm_nan: xx = xx[np.logical_not(np.isnan(xx))] npoints = len(xx) ok = npoints > 0 result = { 'npoints' : npoints, 'minimum' : np.min(xx) if ok else 0, 'percentile25' : np.percentile(xx, 25) if ok else 0, 'median' : np.percentile(xx, 50) if ok else 0, 'mean' : np.mean(xx) if ok else 0, 'percentile75': np.percentile(xx, 75) if ok else 0, 'maximum' : np.max(xx) if ok else 0, 'std': np.std(xx) if ok else 0, 'robust_std' : robust_std(xx) if ok else 0, 'percentile15': np.percentile(xx, 15.86553) if ok else 0, 'percentile84': np.percentile(xx, 84.13447) if ok else 0 } if debug: print('>>> ========================================') print('>>> STATISTICAL SUMMARY:') print('>>> ----------------------------------------') print('>>> Number of points.........:', result['npoints']) print('>>> Minimum..................:', result['minimum']) print('>>> 1st Quartile.............:', result['percentile25']) print('>>> Median...................:', result['median']) print('>>> Mean.....................:', result['mean']) print('>>> 3rd Quartile.............:', result['percentile75']) print('>>> Maximum..................:', result['maximum']) print('>>> ----------------------------------------') print('>>> Standard deviation.......:', result['std']) print('>>> Robust standard deviation:', result['robust_std']) print('>>> 0.1586553 percentile.....:', result['percentile15']) print('>>> 0.8413447 percentile.....:', result['percentile84']) print('>>> ========================================') return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_peaks_spectrum'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nwinwidth'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '11', 'type': 'integer', 'children': [], 'value': '0'},{'id': '12', 'type': 'block', 'children': ['13', '56', '62', '68', '104', '108', '132', '136', '283', '292', '311']},{'id': '13', 'type': 'if_statement', 'children': ['14', '22', '35']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '19'], 'value': 'is'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'binary_operator', 'children': ['28', '34'], 'value': '+'},{'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '+'},{'id': '29', 'type': 'string', 'children': [], 'value': '"sx="'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '34', 'type': 'string', 'children': [], 'value': '" must be a numpy.ndarray"'},{'id': '35', 'type': 'elif_clause', 'children': ['36', '41']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': 'is'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'ValueError'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'binary_operator', 'children': ['47', '55'], 'value': '+'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'},{'id': '48', 'type': 'string', 'children': [], 'value': '"sx.ndim="'},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'ndim'},{'id': '55', 'type': 'string', 'children': [], 'value': '" must be 1"'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sx_shape'},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '//'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'nwinwidth'},{'id': '67', 'type': 'integer', 'children': [], 'value': '2'},{'id': '68', 'type': 'if_statement', 'children': ['69', '72']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '>='},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '71', 'type': 'integer', 'children': [], 'value': '10'},{'id': '72', 'type': 'block', 'children': ['73', '79', '85', '91', '97']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'string', 'children': [], 'value': "'find_peaks_spectrum> sx shape......:'"},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sx_shape'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '82', 'type': 'argument_list', 'children': ['83', '84']},{'id': '83', 'type': 'string', 'children': [], 'value': "'find_peaks_spectrum> nwinwidth.....:'"},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'nwinwidth'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': "'find_peaks_spectrum> nmed..........:'"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'call', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'find_peaks_spectrum> data_threshold:'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102', '103']},{'id': '101', 'type': 'string', 'children': [], 'value': "'find_peaks_spectrum> the first and last'"},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '103', 'type': 'string', 'children': [], 'value': "'pixels will be ignored'"},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'xpeaks'},{'id': '107', 'type': 'list', 'children': [], 'value': '[]'},{'id': '108', 'type': 'if_statement', 'children': ['109', '114']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '113'], 'value': '<'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sx_shape'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'nwinwidth'},{'id': '114', 'type': 'block', 'children': ['115', '121', '127']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': "'find_peaks_spectrum> sx shape......:'"},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sx_shape'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126']},{'id': '125', 'type': 'string', 'children': [], 'value': "'find_peaks_spectrum> nwinwidth.....:'"},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'nwinwidth'},{'id': '127', 'type': 'raise_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': "'sx.shape < nwinwidth'"},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '136', 'type': 'while_statement', 'children': ['137', '144']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': '<'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '139', 'type': 'binary_operator', 'children': ['140', '143'], 'value': '-'},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'sx_shape'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'if_statement', 'children': ['146', '151', '277']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '>'},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'threshold'},{'id': '151', 'type': 'block', 'children': ['152', '156', '160', '164', '203', '255']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'peak_ok'},{'id': '155', 'type': 'True', 'children': []},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '163', 'type': 'True', 'children': []},{'id': '164', 'type': 'while_statement', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '166', 'type': 'block', 'children': ['167', '190', '194']},{'id': '167', 'type': 'if_statement', 'children': ['168', '185']},{'id': '168', 'type': 'comparison_operator', 'children': ['169', '176'], 'value': '>'},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '175'], 'value': '+'},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '-'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '184'], 'value': '+'},{'id': '179', 'type': 'binary_operator', 'children': ['180', '183'], 'value': '+'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '-'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '184', 'type': 'integer', 'children': [], 'value': '1'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'peak_ok'},{'id': '189', 'type': 'False', 'children': []},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'augmented_assignment', 'children': ['192', '193'], 'value': '+='},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '193', 'type': 'integer', 'children': [], 'value': '1'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '197', 'type': 'boolean_operator', 'children': ['198', '202'], 'value': 'and'},{'id': '198', 'type': '()', 'children': ['199']},{'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': '<'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'peak_ok'},{'id': '203', 'type': 'if_statement', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'peak_ok'},{'id': '205', 'type': 'block', 'children': ['206', '212', '216']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '+'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '211', 'type': 'integer', 'children': [], 'value': '1'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '215', 'type': 'True', 'children': []},{'id': '216', 'type': 'while_statement', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '218', 'type': 'block', 'children': ['219', '242', '246']},{'id': '219', 'type': 'if_statement', 'children': ['220', '237']},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '230'], 'value': '<'},{'id': '221', 'type': 'subscript', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '223', 'type': 'binary_operator', 'children': ['224', '229'], 'value': '-'},{'id': '224', 'type': 'binary_operator', 'children': ['225', '228'], 'value': '+'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '-'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '229', 'type': 'integer', 'children': [], 'value': '1'},{'id': '230', 'type': 'subscript', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'sx'},{'id': '232', 'type': 'binary_operator', 'children': ['233', '236'], 'value': '+'},{'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '-'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'nmed'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'peak_ok'},{'id': '241', 'type': 'False', 'children': []},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'augmented_assignment', 'children': ['244', '245'], 'value': '+='},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '245', 'type': 'integer', 'children': [], 'value': '1'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'loop'},{'id': '249', 'type': 'boolean_operator', 'children': ['250', '254'], 'value': 'and'},{'id': '250', 'type': '()', 'children': ['251']},{'id': '251', 'type': 'comparison_operator', 'children': ['252', '253'], 'value': '<'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'nwinwidth'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'peak_ok'},{'id': '255', 'type': 'if_statement', 'children': ['256', '257', '271']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'peak_ok'},{'id': '257', 'type': 'block', 'children': ['258', '265']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'call', 'children': ['260', '263']},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'xpeaks'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '265', 'type': 'expression_statement', 'children': ['266']},{'id': '266', 'type': 'augmented_assignment', 'children': ['267', '268'], 'value': '+='},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '268', 'type': 'binary_operator', 'children': ['269', '270'], 'value': '-'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'nwinwidth'},{'id': '270', 'type': 'integer', 'children': [], 'value': '1'},{'id': '271', 'type': 'else_clause', 'children': ['272']},{'id': '272', 'type': 'block', 'children': ['273']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'augmented_assignment', 'children': ['275', '276'], 'value': '+='},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '276', 'type': 'integer', 'children': [], 'value': '1'},{'id': '277', 'type': 'else_clause', 'children': ['278']},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'augmented_assignment', 'children': ['281', '282'], 'value': '+='},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '282', 'type': 'integer', 'children': [], 'value': '1'},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'ixpeaks'},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'xpeaks'},{'id': '292', 'type': 'if_statement', 'children': ['293', '296']},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '295'], 'value': '>='},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'debugplot'},{'id': '295', 'type': 'integer', 'children': [], 'value': '10'},{'id': '296', 'type': 'block', 'children': ['297', '306']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '300', 'type': 'argument_list', 'children': ['301', '302']},{'id': '301', 'type': 'string', 'children': [], 'value': "'find_peaks_spectrum> number of peaks found:'"},{'id': '302', 'type': 'call', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '304', 'type': 'argument_list', 'children': ['305']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'ixpeaks'},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'ixpeaks'},{'id': '311', 'type': 'return_statement', 'children': ['312']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'ixpeaks'}
def find_peaks_spectrum(sx, nwinwidth, threshold=0, debugplot=0): if type(sx) is not np.ndarray: raise ValueError("sx=" + str(sx) + " must be a numpy.ndarray") elif sx.ndim is not 1: raise ValueError("sx.ndim=" + str(sx.ndim) + " must be 1") sx_shape = sx.shape nmed = nwinwidth//2 if debugplot >= 10: print('find_peaks_spectrum> sx shape......:', sx_shape) print('find_peaks_spectrum> nwinwidth.....:', nwinwidth) print('find_peaks_spectrum> nmed..........:', nmed) print('find_peaks_spectrum> data_threshold:', threshold) print('find_peaks_spectrum> the first and last', nmed, 'pixels will be ignored') xpeaks = [] if sx_shape[0] < nwinwidth: print('find_peaks_spectrum> sx shape......:', sx_shape) print('find_peaks_spectrum> nwinwidth.....:', nwinwidth) raise ValueError('sx.shape < nwinwidth') i = nmed while i < sx_shape[0] - nmed: if sx[i] > threshold: peak_ok = True j = 0 loop = True while loop: if sx[i - nmed + j] > sx[i - nmed + j + 1]: peak_ok = False j += 1 loop = (j < nmed) and peak_ok if peak_ok: j = nmed + 1 loop = True while loop: if sx[i - nmed + j - 1] < sx[i - nmed + j]: peak_ok = False j += 1 loop = (j < nwinwidth) and peak_ok if peak_ok: xpeaks.append(i) i += nwinwidth - 1 else: i += 1 else: i += 1 ixpeaks = np.array(xpeaks) if debugplot >= 10: print('find_peaks_spectrum> number of peaks found:', len(ixpeaks)) print(ixpeaks) return ixpeaks
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'shortlex'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'excludestart'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '29']},{'id': '10', 'type': 'if_statement', 'children': ['11', '13']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'excludestart'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'yield', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'deque'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'list', 'children': ['26'], 'value': '[(start, other)]'},{'id': '26', 'type': 'tuple', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '29', 'type': 'while_statement', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '31', 'type': 'block', 'children': ['32', '42']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'pattern_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'while_statement', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '44', 'type': 'block', 'children': ['45', '59', '65', '68']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '50', 'type': 'expression_list', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '56', 'type': 'slice', 'children': ['57', '58']},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'colon', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '|'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'yield', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '68', 'type': 'if_statement', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '70', 'type': 'block', 'children': ['71']},{'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': 'queue'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'tuple', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'other'}
def shortlex(start, other, excludestart=False): if not excludestart: yield start queue = collections.deque([(start, other)]) while queue: current, other = queue.popleft() while other: first, other = other[0], other[1:] result = current | first yield result if other: queue.append((result, other))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'reverse_shortlex'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'excludeend'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '17', '29']},{'id': '10', 'type': 'if_statement', 'children': ['11', '13']},{'id': '11', 'type': 'not_operator', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'excludeend'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'yield', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'deque'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'list', 'children': ['26'], 'value': '[(end, other)]'},{'id': '26', 'type': 'tuple', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '29', 'type': 'while_statement', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '31', 'type': 'block', 'children': ['32', '42']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '37']},{'id': '34', 'type': 'pattern_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'queue'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'popleft'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'while_statement', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '44', 'type': 'block', 'children': ['45', '59', '65', '68']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '50']},{'id': '47', 'type': 'pattern_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '50', 'type': 'expression_list', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '56', 'type': 'slice', 'children': ['57', '58']},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'colon', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '&'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'yield', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '68', 'type': 'if_statement', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'other'},{'id': '70', 'type': 'block', 'children': ['71']},{'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': 'queue'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'tuple', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'other'}
def reverse_shortlex(end, other, excludeend=False): if not excludeend: yield end queue = collections.deque([(end, other)]) while queue: current, other = queue.popleft() while other: first, other = other[0], other[1:] result = current & first yield result if other: queue.append((result, other))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gnuplot'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args_dict'},{'id': '7', 'type': 'dictionary', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'silent'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '21', '45', '172', '178', '185', '192']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'''\n Call a Gnuplot script, passing it arguments and\n datasets.\n Args:\n scipt_name(str): The name of the Gnuplot script.\n args_dict(dict): A dictionary of parameters to pass\n to the script. The `key` is the name of the variable\n that the `item` will be passed to the Gnuplot script\n with.\n data(list): A list of lists containing lists to be plotted.\n The lists can be accessed by plotting the variable\n `data` in the Gnuplot script. The first list in the\n list of lists corresponds to the first column in data,\n and so on.\n silent (bool): `True` if Gnuplot stdout should be silenced,\n `False` if not.\n Returns:\n str: The Gnuplot command used to call the script.\n '''"},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '20', 'type': 'string', 'children': [], 'value': "'gnuplot'"},{'id': '21', 'type': 'if_statement', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '23', 'type': 'block', 'children': ['24', '29', '37']},{'id': '24', 'type': 'assert_statement', 'children': ['25', '28']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'not'},{'id': '26', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'args_dict'},{'id': '28', 'type': 'string', 'children': [], 'value': "'Can\\'t use \\'data\\' variable twice.'"},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'data_temp'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_GnuplotDataTemp'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'list_splat', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'},{'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': 'args_dict'},{'id': '41', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'data_temp'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '45', 'type': 'if_statement', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'args_dict'},{'id': '47', 'type': 'block', 'children': ['48', '52', '159', '168']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'augmented_assignment', 'children': ['50', '51'], 'value': '+='},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '51', 'type': 'string', 'children': [], 'value': '\' -e "\''},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '59']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'args_dict'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'block', 'children': ['60', '68', '155']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'augmented_assignment', 'children': ['62', '63'], 'value': '+='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '67'], 'value': '+'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '66', 'type': 'integer', 'children': [], 'value': '0'},{'id': '67', 'type': 'string', 'children': [], 'value': "'='"},{'id': '68', 'type': 'if_statement', 'children': ['69', '76', '87', '113', '144']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '71', 'type': 'argument_list', 'children': ['72', '75']},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'augmented_assignment', 'children': ['79', '80'], 'value': '+='},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '80', 'type': 'binary_operator', 'children': ['81', '86'], 'value': '+'},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '+'},{'id': '82', 'type': 'string', 'children': [], 'value': "'\\''"},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'string', 'children': [], 'value': "'\\''"},{'id': '87', 'type': 'elif_clause', 'children': ['88', '95']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '90', 'type': 'argument_list', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'if_statement', 'children': ['97', '102', '107']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '101'], 'value': 'is'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '100', 'type': 'integer', 'children': [], 'value': '1'},{'id': '101', 'type': 'True', 'children': []},{'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': 'gnuplot_command'},{'id': '106', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '107', 'type': 'else_clause', 'children': ['108']},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'augmented_assignment', 'children': ['111', '112'], 'value': '+='},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '112', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '113', 'type': 'elif_clause', 'children': ['114', '121']},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '116', 'type': 'argument_list', 'children': ['117', '120']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '119', 'type': 'integer', 'children': [], 'value': '1'},{'id': '120', 'type': 'string', 'children': [], 'value': "'__iter__'"},{'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': 'gnuplot_command'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '143'], 'value': '+'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'string', 'children': [], 'value': "'\\''"},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "' '"},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'list_comprehension', 'children': ['134', '138']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '138', 'type': 'for_in_clause', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'string', 'children': [], 'value': "'\\''"},{'id': '144', 'type': 'else_clause', 'children': ['145']},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '154', 'type': 'integer', 'children': [], 'value': '1'},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'augmented_assignment', 'children': ['157', '158'], 'value': '+='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '158', 'type': 'string', 'children': [], 'value': "'; '"},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '164', 'type': 'slice', 'children': ['165', '166']},{'id': '165', 'type': 'colon', 'children': []},{'id': '166', 'type': 'unary_operator', 'children': ['167'], 'value': '-'},{'id': '167', 'type': 'integer', 'children': [], 'value': '1'},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'augmented_assignment', 'children': ['170', '171'], 'value': '+='},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '171', 'type': 'string', 'children': [], 'value': '\'"\''},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'augmented_assignment', 'children': ['174', '175'], 'value': '+='},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '+'},{'id': '176', 'type': 'string', 'children': [], 'value': "' '"},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'script_name'},{'id': '178', 'type': 'if_statement', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'silent'},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'augmented_assignment', 'children': ['183', '184'], 'value': '+='},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '184', 'type': 'string', 'children': [], 'value': "' > /dev/null 2>&1'"},{'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': 'os'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'},{'id': '192', 'type': 'return_statement', 'children': ['193']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'gnuplot_command'}
def gnuplot(script_name, args_dict={}, data=[], silent=True): ''' Call a Gnuplot script, passing it arguments and datasets. Args: scipt_name(str): The name of the Gnuplot script. args_dict(dict): A dictionary of parameters to pass to the script. The `key` is the name of the variable that the `item` will be passed to the Gnuplot script with. data(list): A list of lists containing lists to be plotted. The lists can be accessed by plotting the variable `data` in the Gnuplot script. The first list in the list of lists corresponds to the first column in data, and so on. silent (bool): `True` if Gnuplot stdout should be silenced, `False` if not. Returns: str: The Gnuplot command used to call the script. ''' gnuplot_command = 'gnuplot' if data: assert 'data' not in args_dict, \ 'Can\'t use \'data\' variable twice.' data_temp = _GnuplotDataTemp(*data) args_dict['data'] = data_temp.name if args_dict: gnuplot_command += ' -e "' for arg in args_dict.items(): gnuplot_command += arg[0] + '=' if isinstance(arg[1], str): gnuplot_command += '\'' + arg[1] + '\'' elif isinstance(arg[1], bool): if arg[1] is True: gnuplot_command += '1' else: gnuplot_command += '0' elif hasattr(arg[1], '__iter__'): gnuplot_command += '\'' + ' '.join([str(v) for v in arg[1]]) + '\'' else: gnuplot_command += str(arg[1]) gnuplot_command += '; ' gnuplot_command = gnuplot_command[:-1] gnuplot_command += '"' gnuplot_command += ' ' + script_name if silent: gnuplot_command += ' > /dev/null 2>&1' os.system(gnuplot_command) return gnuplot_command
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '7', 'type': 'list', 'children': [], 'value': '[]'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'goto_metal'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'goto_reaction'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '36', '56', '65', '74', '83', '87']},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'comparison_operator', 'children': ['17', '21'], 'value': '>'},{'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': 'skip'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'for_statement', 'children': ['24', '25', '26']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'skip_f'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'omit_folders'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'skip_f'},{'id': '36', 'type': 'if_statement', 'children': ['37', '49']},{'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': 'os'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'binary_operator', 'children': ['45', '48'], 'value': '+'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'data_base'},{'id': '48', 'type': 'string', 'children': [], 'value': "'/publication.txt'"},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'augmented_assignment', 'children': ['52', '55'], 'value': '-='},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'user_base_level'},{'id': '55', 'type': 'integer', 'children': [], 'value': '1'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "'---------------------- \\n'"},{'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': 'stdout'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'string', 'children': [], 'value': "'Starting folderreader! \\n'"},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'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': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': "'---------------------- \\n'"},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'found_reaction'},{'id': '86', 'type': 'False', 'children': []},{'id': '87', 'type': 'for_statement', 'children': ['88', '92', '100']},{'id': '88', 'type': 'pattern_list', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'walk'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'user_base'},{'id': '100', 'type': 'block', 'children': ['101', '119', '135', '149', '169', '203', '261', '275', '320']},{'id': '101', 'type': 'for_statement', 'children': ['102', '103', '106']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'omit_folder'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'omit_folders'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'if_statement', 'children': ['108', '111']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'omit_folder'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'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': 'dirs'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'omit_folder'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '122', 'type': 'binary_operator', 'children': ['123', '132'], 'value': '-'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'user_base_level'},{'id': '135', 'type': 'if_statement', 'children': ['136', '141']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '=='},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'pub_level'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'read_pub'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '149', 'type': 'if_statement', 'children': ['150', '155']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': '=='},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'DFT_level'},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'DFT_code'},{'id': '161', 'type': 'call', 'children': ['162', '167']},{'id': '162', 'type': 'attribute', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '169', 'type': 'if_statement', 'children': ['170', '175']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '=='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'XC_level'},{'id': '175', 'type': 'block', 'children': ['176', '189', '197']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'DFT_functional'},{'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': 'os'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'gas_folder'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '+'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '196', 'type': 'string', 'children': [], 'value': "'/gas/'"},{'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': 'read_gas'},{'id': '202', 'type': 'argument_list', 'children': []},{'id': '203', 'type': 'if_statement', 'children': ['204', '209']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': '=='},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'reference_level'},{'id': '209', 'type': 'block', 'children': ['210', '223', '254']},{'id': '210', 'type': 'if_statement', 'children': ['211', '221']},{'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'in'},{'id': '212', 'type': 'string', 'children': [], 'value': "'gas'"},{'id': '213', 'type': 'call', 'children': ['214', '219']},{'id': '214', 'type': 'attribute', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'continue_statement', 'children': []},{'id': '223', 'type': 'if_statement', 'children': ['224', '227']},{'id': '224', 'type': 'comparison_operator', 'children': ['225', '226'], 'value': 'is'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'goto_metal'},{'id': '226', 'type': 'None', 'children': []},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'if_statement', 'children': ['229', '239', '244']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '238'], 'value': '=='},{'id': '230', 'type': 'call', 'children': ['231', '236']},{'id': '231', 'type': 'attribute', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'goto_metal'},{'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': 'goto_metal'},{'id': '243', 'type': 'None', 'children': []},{'id': '244', 'type': 'else_clause', 'children': ['245']},{'id': '245', 'type': 'block', 'children': ['246', '253']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '252']},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '250', 'type': 'slice', 'children': ['251']},{'id': '251', 'type': 'colon', 'children': []},{'id': '252', 'type': 'list', 'children': [], 'value': '[]'},{'id': '253', 'type': 'continue_statement', 'children': []},{'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': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'read_bulk'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '261', 'type': 'if_statement', 'children': ['262', '267']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': '=='},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'slab_level'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'read_slab'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '275', 'type': 'if_statement', 'children': ['276', '281']},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '278'], 'value': '=='},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'reaction_level'},{'id': '281', 'type': 'block', 'children': ['282', '313']},{'id': '282', 'type': 'if_statement', 'children': ['283', '286']},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '285'], 'value': 'is'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'goto_reaction'},{'id': '285', 'type': 'None', 'children': []},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'if_statement', 'children': ['288', '298', '303']},{'id': '288', 'type': 'comparison_operator', 'children': ['289', '297'], 'value': '=='},{'id': '289', 'type': 'call', 'children': ['290', '295']},{'id': '290', 'type': 'attribute', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'goto_reaction'},{'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': 'goto_reaction'},{'id': '302', 'type': 'None', 'children': []},{'id': '303', 'type': 'else_clause', 'children': ['304']},{'id': '304', 'type': 'block', 'children': ['305', '312']},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '311']},{'id': '307', 'type': 'subscript', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'dirs'},{'id': '309', 'type': 'slice', 'children': ['310']},{'id': '310', 'type': 'colon', 'children': []},{'id': '311', 'type': 'list', 'children': [], 'value': '[]'},{'id': '312', 'type': 'continue_statement', 'children': []},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'read_reaction'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '320', 'type': 'if_statement', 'children': ['321', '326']},{'id': '321', 'type': 'comparison_operator', 'children': ['322', '323'], 'value': '=='},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'level'},{'id': '323', 'type': 'attribute', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'final_level'},{'id': '326', 'type': 'block', 'children': ['327', '333', '340']},{'id': '327', 'type': 'expression_statement', 'children': ['328']},{'id': '328', 'type': 'assignment', 'children': ['329', '332']},{'id': '329', 'type': 'attribute', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'root'},{'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': 'self'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'read_energies'},{'id': '338', 'type': 'argument_list', 'children': ['339']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'root'},{'id': '340', 'type': 'if_statement', 'children': ['341', '346']},{'id': '341', 'type': 'comparison_operator', 'children': ['342', '345'], 'value': 'is'},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'key_value_pairs_reaction'},{'id': '345', 'type': 'None', 'children': []},{'id': '346', 'type': 'block', 'children': ['347']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'yield', 'children': ['349']},{'id': '349', 'type': 'attribute', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'key_value_pairs_reaction'}
def read(self, skip=[], goto_metal=None, goto_reaction=None): if len(skip) > 0: for skip_f in skip: self.omit_folders.append(skip_f) if os.path.isfile(self.data_base + '/publication.txt'): self.user_base_level -= 1 self.stdout.write('---------------------- \n') self.stdout.write('Starting folderreader! \n') self.stdout.write('---------------------- \n') found_reaction = False for root, dirs, files in os.walk(self.user_base): for omit_folder in self.omit_folders: if omit_folder in dirs: dirs.remove(omit_folder) level = len(root.split("/")) - self.user_base_level if level == self.pub_level: self.read_pub(root) if level == self.DFT_level: self.DFT_code = os.path.basename(root) if level == self.XC_level: self.DFT_functional = os.path.basename(root) self.gas_folder = root + '/gas/' self.read_gas() if level == self.reference_level: if 'gas' in os.path.basename(root): continue if goto_metal is not None: if os.path.basename(root) == goto_metal: goto_metal = None else: dirs[:] = [] continue self.read_bulk(root) if level == self.slab_level: self.read_slab(root) if level == self.reaction_level: if goto_reaction is not None: if os.path.basename(root) == goto_reaction: goto_reaction = None else: dirs[:] = [] continue self.read_reaction(root) if level == self.final_level: self.root = root self.read_energies(root) if self.key_value_pairs_reaction is not None: yield self.key_value_pairs_reaction