sequence
stringlengths 1.27k
35.1k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gather_categories'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'imap'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'categories'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '31', '52', '58', '65', '124', '147', '208', '214', '236', '248', '330']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'categories'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'dictionary', 'children': ['17']}; {'id': '17', 'type': 'pair', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"default"'}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'DataCategory'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '30']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'imap'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'dictionary', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cat_ids'}; {'id': '34', 'type': 'list_comprehension', 'children': ['35', '41', '44']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'categories'}; {'id': '44', 'type': 'if_clause', 'children': ['45']}; {'id': '45', 'type': 'boolean_operator', 'children': ['46', '49'], 'value': 'and'}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'not'}; {'id': '50', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '65', 'type': 'for_statement', 'children': ['66', '69', '73']}; {'id': '66', 'type': 'pattern_list', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'categories'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '89']}; {'id': '75', 'type': 'boolean_operator', 'children': ['76', '79'], 'value': 'and'}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'}; {'id': '77', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '79', 'type': 'comparison_operator', 'children': ['80', '88'], 'value': 'in'}; {'id': '80', 'type': 'subscript', 'children': ['81', '87']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '89', 'type': 'block', 'children': ['90', '108']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'cat_name'}; {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'subscript', 'children': ['101', '107']}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '107', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'cat_name'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'subscript', 'children': ['117', '123']}; {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '130']}; {'id': '125', 'type': 'boolean_operator', 'children': ['126', '128'], 'value': 'and'}; {'id': '126', 'type': 'not_operator', 'children': ['127']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'cat_ids'}; {'id': '128', 'type': 'not_operator', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '130', 'type': 'block', 'children': ['131']}; {'id': '131', 'type': 'return_statement', 'children': ['132']}; {'id': '132', 'type': 'dictionary', 'children': ['133']}; {'id': '133', 'type': 'pair', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"default"'}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'DataCategory'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '146']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'imap'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '145', 'type': 'argument_list', 'children': []}; {'id': '146', 'type': 'dictionary', 'children': []}; {'id': '147', 'type': 'if_statement', 'children': ['148', '152']}; {'id': '148', 'type': 'boolean_operator', 'children': ['149', '150'], 'value': 'and'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cat_ids'}; {'id': '150', 'type': 'not_operator', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '152', 'type': 'block', 'children': ['153', '206']}; {'id': '153', 'type': 'for_statement', 'children': ['154', '157', '162']}; {'id': '154', 'type': 'pattern_list', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'imap'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '161', 'type': 'argument_list', 'children': []}; {'id': '162', 'type': 'block', 'children': ['163', '178', '195']}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'cat_name'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'string', 'children': [], 'value': '"_"'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'list_comprehension', 'children': ['172', '175']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'cid'}; {'id': '175', 'type': 'for_in_clause', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'cid'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'cat_ids'}; {'id': '178', 'type': 'if_statement', 'children': ['179', '182']}; {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'not'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'cat_name'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '182', 'type': 'block', 'children': ['183']}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}; {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'cat_name'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'DataCategory'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '194']}; {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '193', 'type': 'argument_list', 'children': []}; {'id': '194', 'type': 'dictionary', 'children': []}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '204']}; {'id': '197', 'type': 'attribute', 'children': ['198', '203']}; {'id': '198', 'type': 'attribute', 'children': ['199', '202']}; {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'cat_name'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'sids'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '206', 'type': 'return_statement', 'children': ['207']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'cond_ids'}; {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'for_statement', 'children': ['215', '216', '217']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'try_statement', 'children': ['219', '232']}; {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'cond_ids'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '230']}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '232', 'type': 'except_clause', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '234', 'type': 'block', 'children': ['235']}; {'id': '235', 'type': 'continue_statement', 'children': []}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'idx_to_test'}; {'id': '239', 'type': 'call', 'children': ['240', '246']}; {'id': '240', 'type': 'attribute', 'children': ['241', '245']}; {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'cat_ids'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'cond_ids'}; {'id': '248', 'type': 'for_statement', 'children': ['249', '252', '257']}; {'id': '249', 'type': 'pattern_list', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '252', 'type': 'call', 'children': ['253', '256']}; {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'imap'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '256', 'type': 'argument_list', 'children': []}; {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'if_statement', 'children': ['259', '278']}; {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'list_comprehension', 'children': ['263', '275']}; {'id': '263', 'type': 'comparison_operator', 'children': ['264', '272'], 'value': 'in'}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '266', 'type': 'call', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '275', 'type': 'for_in_clause', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'conditions'}; {'id': '278', 'type': 'block', 'children': ['279', '294', '319']}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '282', 'type': 'call', 'children': ['283', '286']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': '"_"'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}; {'id': '287', 'type': 'list_comprehension', 'children': ['288', '291']}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '291', 'type': 'for_in_clause', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'idx_to_test'}; {'id': '294', 'type': 'try_statement', 'children': ['295', '304']}; {'id': '295', 'type': 'block', 'children': ['296']}; {'id': '296', 'type': 'assert_statement', 'children': ['297']}; {'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': 'in'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '299', 'type': 'call', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'except_clause', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}; {'id': '306', 'type': 'block', 'children': ['307']}; {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '312']}; {'id': '309', 'type': 'subscript', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '312', 'type': 'call', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'DataCategory'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '318']}; {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '317', 'type': 'argument_list', 'children': []}; {'id': '318', 'type': 'dictionary', 'children': []}; {'id': '319', 'type': 'expression_statement', 'children': ['320']}; {'id': '320', 'type': 'call', 'children': ['321', '328']}; {'id': '321', 'type': 'attribute', 'children': ['322', '327']}; {'id': '322', 'type': 'attribute', 'children': ['323', '326']}; {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'sids'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '330', 'type': 'try_statement', 'children': ['331', '339', '358']}; {'id': '331', 'type': 'block', 'children': ['332']}; {'id': '332', 'type': 'assert_statement', 'children': ['333']}; {'id': '333', 'type': 'comparison_operator', 'children': ['334', '338'], 'value': '>'}; {'id': '334', 'type': 'call', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '339', 'type': 'except_clause', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'AssertionError'}; {'id': '341', 'type': 'block', 'children': ['342']}; {'id': '342', 'type': 'return_statement', 'children': ['343']}; {'id': '343', 'type': 'dictionary', 'children': ['344']}; {'id': '344', 'type': 'pair', 'children': ['345', '346']}; {'id': '345', 'type': 'string', 'children': [], 'value': '"default"'}; {'id': '346', 'type': 'call', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'DataCategory'}; {'id': '348', 'type': 'argument_list', 'children': ['349', '357']}; {'id': '349', 'type': 'call', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '351', 'type': 'argument_list', 'children': ['352']}; {'id': '352', 'type': 'call', 'children': ['353', '356']}; {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'imap'}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '356', 'type': 'argument_list', 'children': []}; {'id': '357', 'type': 'dictionary', 'children': []}; {'id': '358', 'type': 'else_clause', 'children': ['359']}; {'id': '359', 'type': 'block', 'children': ['360']}; {'id': '360', 'type': 'return_statement', 'children': ['361']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'table'} | def gather_categories(imap, header, categories=None):
if categories is None:
return {"default": DataCategory(set(imap.keys()), {})}
cat_ids = [header.index(cat)
for cat in categories if cat in header and "=" not in cat]
table = OrderedDict()
conditions = defaultdict(set)
for i, cat in enumerate(categories):
if "=" in cat and cat.split("=")[0] in header:
cat_name = header[header.index(cat.split("=")[0])]
conditions[cat_name].add(cat.split("=")[1])
if not cat_ids and not conditions:
return {"default": DataCategory(set(imap.keys()), {})}
if cat_ids and not conditions:
for sid, row in imap.items():
cat_name = "_".join([row[cid] for cid in cat_ids])
if cat_name not in table:
table[cat_name] = DataCategory(set(), {})
table[cat_name].sids.add(sid)
return table
cond_ids = set()
for k in conditions:
try:
cond_ids.add(header.index(k))
except ValueError:
continue
idx_to_test = set(cat_ids).union(cond_ids)
for sid, row in imap.items():
if all([row[header.index(c)] in conditions[c] for c in conditions]):
key = "_".join([row[idx] for idx in idx_to_test])
try:
assert key in table.keys()
except AssertionError:
table[key] = DataCategory(set(), {})
table[key].sids.add(sid)
try:
assert len(table) > 0
except AssertionError:
return {"default": DataCategory(set(imap.keys()), {})}
else:
return table |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'color_mapping'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sample_map'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'group_column'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'color_column'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '17', '27', '99']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'group_colors'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'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': 'group_gather'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'gather_categories'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sample_map'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '25', 'type': 'list', 'children': ['26'], 'value': '[group_column]'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'group_column'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '31', '72']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'color_column'}; {'id': '30', 'type': 'None', 'children': []}; {'id': '31', 'type': 'block', 'children': ['32', '42']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'color_gather'}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'gather_categories'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sample_map'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '40', 'type': 'list', 'children': ['41'], 'value': '[color_column]'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'color_column'}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'group_gather'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'color_gather'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '65']}; {'id': '51', 'type': 'call', 'children': ['52', '59']}; {'id': '52', 'type': 'attribute', 'children': ['53', '58']}; {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'group_gather'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sids'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'color_gather'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sids'}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'group_colors'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}; {'id': '73', 'type': 'block', 'children': ['74', '85']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'bcolors'}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'Set3_12'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'hex_colors'}; {'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'group_gather'}; {'id': '88', 'type': 'block', 'children': ['89']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '94']}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'group_colors'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'bcolors'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '98', 'type': 'argument_list', 'children': []}; {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'group_colors'} | def color_mapping(sample_map, header, group_column, color_column=None):
group_colors = OrderedDict()
group_gather = gather_categories(sample_map, header, [group_column])
if color_column is not None:
color_gather = gather_categories(sample_map, header, [color_column])
for group in group_gather:
for color in color_gather:
if group_gather[group].sids.intersection(color_gather[color].sids):
group_colors[group] = color
else:
bcolors = itertools.cycle(Set3_12.hex_colors)
for group in group_gather:
group_colors[group] = bcolors.next()
return group_colors |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'shuffle_genome'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '12', '15', '16', '19', '22', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fraction'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '10', 'type': 'argument_list', 'children': ['11']}; {'id': '11', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'plot'}; {'id': '14', 'type': 'True', 'children': []}; {'id': '15', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '18', 'type': 'float', 'children': [], 'value': '0.1'}; {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '21', 'type': 'integer', 'children': [], 'value': '100000'}; {'id': '22', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'min_length'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '1000'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'max_length'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '200000'}; {'id': '29', 'type': 'block', 'children': ['30', '39', '60', '67', '71', '152', '159', '242']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'>randomized_%s'"}; {'id': '35', 'type': '()', 'children': ['36']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': "''"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'list_comprehension', 'children': ['51', '54']}; {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'parse_fasta'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'shuffled'}; {'id': '70', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '71', 'type': 'while_statement', 'children': ['72', '75']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '74', 'type': 'False', 'children': []}; {'id': '75', 'type': 'block', 'children': ['76', '89', '99', '126', '134', '146']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'gammavariate'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '89', 'type': 'if_statement', 'children': ['90', '97']}; {'id': '90', 'type': 'boolean_operator', 'children': ['91', '94'], 'value': 'or'}; {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': '<='}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'min_length'}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '>='}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'max_length'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'continue_statement', 'children': []}; {'id': '99', 'type': 'if_statement', 'children': ['100', '106', '115']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '105'], 'value': '<'}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 's'}; {'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': 'seq'}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '112', 'type': 'slice', 'children': ['113', '114']}; {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'colon', 'children': []}; {'id': '115', 'type': 'else_clause', 'children': ['116']}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '122', 'type': 'slice', 'children': ['123', '124', '125']}; {'id': '123', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '124', 'type': 'colon', 'children': []}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '131', 'type': 'slice', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '133', 'type': 'colon', 'children': []}; {'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': 'shuffled'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': "''"}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150']}; {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '=='}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sequence'}; {'id': '149', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'break_statement', 'children': []}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'shuffle'}; {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'shuffled'}; {'id': '159', 'type': 'if_statement', 'children': ['160', '166', '171']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '=='}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'fraction'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '166', 'type': 'block', 'children': ['167']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'subset'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'shuffled'}; {'id': '171', 'type': 'else_clause', 'children': ['172']}; {'id': '172', 'type': 'block', 'children': ['173', '184', '192']}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'max_pieces'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'binary_operator', 'children': ['180', '183'], 'value': '/'}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '*'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'fraction'}; {'id': '183', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'assignment', 'children': ['186', '189']}; {'id': '186', 'type': 'pattern_list', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'subset'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '189', 'type': 'expression_list', 'children': ['190', '191']}; {'id': '190', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '191', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '192', 'type': 'for_statement', 'children': ['193', '194', '195']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'fragment'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'shuffled'}; {'id': '195', 'type': 'block', 'children': ['196', '203']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'fragment'}; {'id': '203', 'type': 'if_statement', 'children': ['204', '209', '221']}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '208'], 'value': '<='}; {'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'max_pieces'}; {'id': '209', 'type': 'block', 'children': ['210', '217']}; {'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': 'subset'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'fragment'}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'augmented_assignment', 'children': ['219', '220'], 'value': '+='}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '221', 'type': 'else_clause', 'children': ['222']}; {'id': '222', 'type': 'block', 'children': ['223', '229', '241']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '-'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'max_pieces'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'subset'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'fragment'}; {'id': '237', 'type': 'slice', 'children': ['238', '239', '240']}; {'id': '238', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '239', 'type': 'colon', 'children': []}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '241', 'type': 'break_statement', 'children': []}; {'id': '242', 'type': 'if_statement', 'children': ['243', '246', '257']}; {'id': '243', 'type': 'comparison_operator', 'children': ['244', '245'], 'value': 'is'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '245', 'type': 'True', 'children': []}; {'id': '246', 'type': 'block', 'children': ['247']}; {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'yield', 'children': ['249']}; {'id': '249', 'type': 'list', 'children': ['250', '251'], 'value': "[header, ''.join(subset)]"}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'string', 'children': [], 'value': "''"}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'subset'}; {'id': '257', 'type': 'else_clause', 'children': ['258']}; {'id': '258', 'type': 'block', 'children': ['259']}; {'id': '259', 'type': 'for_statement', 'children': ['260', '263', '267']}; {'id': '260', 'type': 'pattern_list', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'subset'}; {'id': '267', 'type': 'block', 'children': ['268']}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'yield', 'children': ['270']}; {'id': '270', 'type': 'list', 'children': ['271', '276'], 'value': "['%s fragment:%s' % (header, i), seq]"}; {'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '%'}; {'id': '272', 'type': 'string', 'children': [], 'value': "'%s fragment:%s'"}; {'id': '273', 'type': 'tuple', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'seq'} | def shuffle_genome(genome, cat, fraction = float(100), plot = True, \
alpha = 0.1, beta = 100000, \
min_length = 1000, max_length = 200000):
header = '>randomized_%s' % (genome.name)
sequence = list(''.join([i[1] for i in parse_fasta(genome)]))
length = len(sequence)
shuffled = []
while sequence is not False:
s = int(random.gammavariate(alpha, beta))
if s <= min_length or s >= max_length:
continue
if len(sequence) < s:
seq = sequence[0:]
else:
seq = sequence[0:s]
sequence = sequence[s:]
shuffled.append(''.join(seq))
if sequence == []:
break
random.shuffle(shuffled)
if fraction == float(100):
subset = shuffled
else:
max_pieces = int(length * fraction/100)
subset, total = [], 0
for fragment in shuffled:
length = len(fragment)
if total + length <= max_pieces:
subset.append(fragment)
total += length
else:
diff = max_pieces - total
subset.append(fragment[0:diff])
break
if cat is True:
yield [header, ''.join(subset)]
else:
for i, seq in enumerate(subset):
yield ['%s fragment:%s' % (header, i), seq] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sam2fastq'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'singles'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '20']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'pattern_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '17', 'type': 'expression_list', 'children': ['18', '19']}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '23', 'type': 'block', 'children': ['24', '35', '47', '82', '97', '109', '126', '170', '258']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '33']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '32'], 'value': 'is'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'string', 'children': [], 'value': "'@'"}; {'id': '32', 'type': 'True', 'children': []}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'continue_statement', 'children': []}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '38', 'type': 'call', 'children': ['39', '46']}; {'id': '39', 'type': 'attribute', 'children': ['40', '45']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '50', 'type': 'list_comprehension', 'children': ['51', '57', '58']}; {'id': '51', 'type': 'conditional_expression', 'children': ['52', '53', '56'], 'value': 'if'}; {'id': '52', 'type': 'True', 'children': []}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '55', 'type': 'string', 'children': [], 'value': "'1'"}; {'id': '56', 'type': 'False', 'children': []}; {'id': '57', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '60', 'type': 'subscript', 'children': ['61', '77']}; {'id': '61', 'type': 'subscript', 'children': ['62', '76']}; {'id': '62', 'type': 'call', 'children': ['63', '74']}; {'id': '63', 'type': 'attribute', 'children': ['64', '73']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'bin'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'string', 'children': [], 'value': "'b'"}; {'id': '76', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '77', 'type': 'slice', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'colon', 'children': []}; {'id': '79', 'type': 'colon', 'children': []}; {'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '82', 'type': 'while_statement', 'children': ['83', '89']}; {'id': '83', 'type': 'comparison_operator', 'children': ['84', '88'], 'value': '<'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '89', 'type': 'block', 'children': ['90']}; {'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': 'bit'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'False', 'children': []}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '108']}; {'id': '99', 'type': 'pattern_list', 'children': ['100', '101', '102', '103', '104', '105', '106', '107']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'proper'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'na'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'nap'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'rev'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'mrev'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'right'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '109', 'type': 'if_statement', 'children': ['110', '113']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '112', 'type': 'False', 'children': []}; {'id': '113', 'type': 'block', 'children': ['114', '125']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}; {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'singles'}; {'id': '117', 'type': 'True', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'print_single'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'rev'}; {'id': '125', 'type': 'continue_statement', 'children': []}; {'id': '126', 'type': 'if_statement', 'children': ['127', '130', '156']}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'rev'}; {'id': '129', 'type': 'True', 'children': []}; {'id': '130', 'type': 'block', 'children': ['131', '144']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '134', 'type': 'subscript', 'children': ['135', '143']}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'list', 'children': ['139', '140'], 'value': "['', line[9]]"}; {'id': '139', 'type': 'string', 'children': [], 'value': "''"}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'qual'}; {'id': '147', 'type': 'subscript', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '151', 'type': 'slice', 'children': ['152', '153', '154']}; {'id': '152', 'type': 'colon', 'children': []}; {'id': '153', 'type': 'colon', 'children': []}; {'id': '154', 'type': 'unary_operator', 'children': ['155'], 'value': '-'}; {'id': '155', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '156', 'type': 'else_clause', 'children': ['157']}; {'id': '157', 'type': 'block', 'children': ['158', '164']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '163', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'qual'}; {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174']}; {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'is'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'left'}; {'id': '173', 'type': 'True', 'children': []}; {'id': '174', 'type': 'block', 'children': ['175', '213', '223', '239']}; {'id': '175', 'type': 'if_statement', 'children': ['176', '183']}; {'id': '176', 'type': 'boolean_operator', 'children': ['177', '180'], 'value': 'and'}; {'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'is'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '179', 'type': 'None', 'children': []}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': 'is'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '182', 'type': 'False', 'children': []}; {'id': '183', 'type': 'block', 'children': ['184', '194', '209']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '187', 'type': 'argument_list', 'children': ['188', '189']}; {'id': '188', 'type': 'string', 'children': [], 'value': "'sam file is not sorted'"}; {'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'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', '204']}; {'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '%'}; {'id': '199', 'type': 'string', 'children': [], 'value': "'\\te.g.: %s'"}; {'id': '200', 'type': '()', 'children': ['201']}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '212', 'type': 'argument_list', 'children': []}; {'id': '213', 'type': 'if_statement', 'children': ['214', '217']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'is'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '216', 'type': 'None', 'children': []}; {'id': '217', 'type': 'block', 'children': ['218', '222']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '221', 'type': 'None', 'children': []}; {'id': '222', 'type': 'continue_statement', 'children': []}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '226', 'type': 'list', 'children': ['227', '232', '233', '238'], 'value': "['@%s' % line[0], seq, '+%s' % line[0], qual]"}; {'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '%'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'@%s'"}; {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '231', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '%'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'+%s'"}; {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '237', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'qual'}; {'id': '239', 'type': 'if_statement', 'children': ['240', '243']}; {'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': 'is'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '242', 'type': 'None', 'children': []}; {'id': '243', 'type': 'block', 'children': ['244', '247', '250']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'yield', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'yield', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'assignment', 'children': ['252', '255']}; {'id': '252', 'type': 'pattern_list', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '255', 'type': 'expression_list', 'children': ['256', '257']}; {'id': '256', 'type': 'None', 'children': []}; {'id': '257', 'type': 'None', 'children': []}; {'id': '258', 'type': 'if_statement', 'children': ['259', '262']}; {'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': 'is'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'right'}; {'id': '261', 'type': 'True', 'children': []}; {'id': '262', 'type': 'block', 'children': ['263', '301', '311', '327']}; {'id': '263', 'type': 'if_statement', 'children': ['264', '271']}; {'id': '264', 'type': 'boolean_operator', 'children': ['265', '268'], 'value': 'and'}; {'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'is'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '267', 'type': 'None', 'children': []}; {'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': 'is'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '270', 'type': 'False', 'children': []}; {'id': '271', 'type': 'block', 'children': ['272', '282', '297']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '275', 'type': 'argument_list', 'children': ['276', '277']}; {'id': '276', 'type': 'string', 'children': [], 'value': "'sam file is not sorted'"}; {'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}; {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '285', 'type': 'argument_list', 'children': ['286', '292']}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '%'}; {'id': '287', 'type': 'string', 'children': [], 'value': "'\\te.g.: %s'"}; {'id': '288', 'type': '()', 'children': ['289']}; {'id': '289', 'type': 'subscript', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '291', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '300', 'type': 'argument_list', 'children': []}; {'id': '301', 'type': 'if_statement', 'children': ['302', '305']}; {'id': '302', 'type': 'comparison_operator', 'children': ['303', '304'], 'value': 'is'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '304', 'type': 'None', 'children': []}; {'id': '305', 'type': 'block', 'children': ['306', '310']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}; {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '309', 'type': 'None', 'children': []}; {'id': '310', 'type': 'continue_statement', 'children': []}; {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '314', 'type': 'list', 'children': ['315', '320', '321', '326'], 'value': "['@%s' % line[0], seq, '+%s' % line[0], qual]"}; {'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '%'}; {'id': '316', 'type': 'string', 'children': [], 'value': "'@%s'"}; {'id': '317', 'type': 'subscript', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '319', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '321', 'type': 'binary_operator', 'children': ['322', '323'], 'value': '%'}; {'id': '322', 'type': 'string', 'children': [], 'value': "'+%s'"}; {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '325', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'qual'}; {'id': '327', 'type': 'if_statement', 'children': ['328', '331']}; {'id': '328', 'type': 'comparison_operator', 'children': ['329', '330'], 'value': 'is'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '330', 'type': 'None', 'children': []}; {'id': '331', 'type': 'block', 'children': ['332', '335', '338']}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}; {'id': '333', 'type': 'yield', 'children': ['334']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'yield', 'children': ['337']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '338', 'type': 'expression_statement', 'children': ['339']}; {'id': '339', 'type': 'assignment', 'children': ['340', '343']}; {'id': '340', 'type': 'pattern_list', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '343', 'type': 'expression_list', 'children': ['344', '345']}; {'id': '344', 'type': 'None', 'children': []}; {'id': '345', 'type': 'None', 'children': []} | def sam2fastq(sam, singles = False, force = False):
L, R = None, None
for line in sam:
if line.startswith('@') is True:
continue
line = line.strip().split()
bit = [True if i == '1' else False \
for i in bin(int(line[1])).split('b')[1][::-1]]
while len(bit) < 8:
bit.append(False)
pair, proper, na, nap, rev, mrev, left, right = bit
if pair is False:
if singles is True:
print_single(line, rev)
continue
if rev is True:
seq = rc(['', line[9]])[1]
qual = line[10][::-1]
else:
seq = line[9]
qual = line[10]
if left is True:
if L is not None and force is False:
print('sam file is not sorted', file = sys.stderr)
print('\te.g.: %s' % (line[0]), file = sys.stderr)
exit()
if L is not None:
L = None
continue
L = ['@%s' % line[0], seq, '+%s' % line[0], qual]
if R is not None:
yield L
yield R
L, R = None, None
if right is True:
if R is not None and force is False:
print('sam file is not sorted', file = sys.stderr)
print('\te.g.: %s' % (line[0]), file = sys.stderr)
exit()
if R is not None:
R = None
continue
R = ['@%s' % line[0], seq, '+%s' % line[0], qual]
if L is not None:
yield L
yield R
L, R = None, None |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_sam'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '6', 'type': 'block', 'children': ['7', '29', '141']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tempdir'}; {'id': '10', 'type': 'binary_operator', 'children': ['11', '12'], 'value': '%'}; {'id': '11', 'type': 'string', 'children': [], 'value': "'%s/'"}; {'id': '12', 'type': '()', 'children': ['13']}; {'id': '13', 'type': 'subscript', 'children': ['14', '28']}; {'id': '14', 'type': 'call', 'children': ['15', '25']}; {'id': '15', 'type': 'attribute', 'children': ['16', '24']}; {'id': '16', 'type': 'call', 'children': ['17', '22']}; {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '27', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '33', '119']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '32', 'type': 'True', 'children': []}; {'id': '33', 'type': 'block', 'children': ['34', '49', '112']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'%s.sorted.sam'"}; {'id': '39', 'type': '()', 'children': ['40']}; {'id': '40', 'type': 'subscript', 'children': ['41', '48']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '49', 'type': 'if_statement', 'children': ['50', '53', '79']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '!='}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '65']}; {'id': '55', 'type': 'comparison_operator', 'children': ['56', '64'], 'value': 'is'}; {'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': 'exists'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '64', 'type': 'False', 'children': []}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'system'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '%'}; {'id': '73', 'type': 'string', 'children': [], 'value': '"\\\n sort -k1 --buffer-size=%sG -T %s -o %s %s\\\n "'}; {'id': '74', 'type': 'tuple', 'children': ['75', '76', '77', '78']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sbuffer'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'tempdir'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '79', 'type': 'else_clause', 'children': ['80']}; {'id': '80', 'type': 'block', 'children': ['81', '85', '106']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'stdin-sam.sorted.sam'"}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '98', '103']}; {'id': '91', 'type': 'binary_operator', 'children': ['92', '93', '94'], 'value': '%'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"sort -k1 --buffer-size=%sG -T %s -o %s"'}; {'id': '93', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '94', 'type': 'tuple', 'children': ['95', '96', '97']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sbuffer'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'tempdir'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '105', 'type': 'True', 'children': []}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'communicate'}; {'id': '111', 'type': 'argument_list', 'children': []}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'if_statement', 'children': ['122', '125', '132']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'stdin'}; {'id': '132', 'type': 'else_clause', 'children': ['133']}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'mapping'} | def sort_sam(sam, sort):
tempdir = '%s/' % (os.path.abspath(sam).rsplit('/', 1)[0])
if sort is True:
mapping = '%s.sorted.sam' % (sam.rsplit('.', 1)[0])
if sam != '-':
if os.path.exists(mapping) is False:
os.system("\
sort -k1 --buffer-size=%sG -T %s -o %s %s\
" % (sbuffer, tempdir, mapping, sam))
else:
mapping = 'stdin-sam.sorted.sam'
p = Popen("sort -k1 --buffer-size=%sG -T %s -o %s" \
% (sbuffer, tempdir, mapping), stdin = sys.stdin, shell = True)
p.communicate()
mapping = open(mapping)
else:
if sam == '-':
mapping = sys.stdin
else:
mapping = open(sam)
return mapping |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'crossmap'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fas'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'reads'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'no_shrink'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'keepDB'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'cluster'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '12', 'type': 'block', 'children': ['13', '22', '26', '213']}; {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'cluster'}; {'id': '16', 'type': 'True', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '21', 'type': 'string', 'children': [], 'value': "'48'"}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'btc'}; {'id': '25', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'fa'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'fas'}; {'id': '29', 'type': 'block', 'children': ['30', '38', '45']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'btd'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'bowtiedb'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'fa'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'keepDB'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '44']}; {'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'U'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'reads'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '49', '142']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '48', 'type': 'False', 'children': []}; {'id': '49', 'type': 'block', 'children': ['50', '59']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '54']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'U'}; {'id': '53', 'type': 'False', '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': 'u'}; {'id': '58', 'type': 'False', 'children': []}; {'id': '59', 'type': 'for_statement', 'children': ['60', '63', '67']}; {'id': '60', 'type': 'pattern_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '67', 'type': 'block', 'children': ['68', '74', '85', '125']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}; {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'U'}; {'id': '77', 'type': 'False', 'children': []}; {'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': 'u'}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'U'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'}; {'id': '89', 'type': 'string', 'children': [], 'value': "'%s/%s-vs-%s'"}; {'id': '90', 'type': 'tuple', 'children': ['91', '96', '97', '107']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '97', 'type': 'subscript', 'children': ['98', '105']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'fa'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '107', 'type': 'subscript', 'children': ['108', '124']}; {'id': '108', 'type': 'call', 'children': ['109', '121']}; {'id': '109', 'type': 'attribute', 'children': ['110', '120']}; {'id': '110', 'type': 'subscript', 'children': ['111', '118']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '117', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '118', 'type': 'unary_operator', 'children': ['119'], 'value': '-'}; {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '121', 'type': 'argument_list', 'children': ['122', '123']}; {'id': '122', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '123', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'btc'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'bowtie'}; {'id': '133', 'type': 'argument_list', 'children': ['134', '135', '136', '137', '138', '139', '140', '141']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'btd'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'no_shrink'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '142', 'type': 'else_clause', 'children': ['143']}; {'id': '143', 'type': 'block', 'children': ['144', '148', '152']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '147', 'type': 'False', 'children': []}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '151', 'type': 'False', 'children': []}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '155']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'U'}; {'id': '155', 'type': 'block', 'children': ['156', '196']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '%'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'%s/%s-vs-%s'"}; {'id': '161', 'type': 'tuple', 'children': ['162', '167', '168', '178']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '166', 'type': 'argument_list', 'children': []}; {'id': '167', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '168', 'type': 'subscript', 'children': ['169', '176']}; {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'fa'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '175', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '176', 'type': 'unary_operator', 'children': ['177'], 'value': '-'}; {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'subscript', 'children': ['179', '195']}; {'id': '179', 'type': 'call', 'children': ['180', '192']}; {'id': '180', 'type': 'attribute', 'children': ['181', '191']}; {'id': '181', 'type': 'subscript', 'children': ['182', '189']}; {'id': '182', 'type': 'call', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188']}; {'id': '187', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '189', 'type': 'unary_operator', 'children': ['190'], 'value': '-'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}; {'id': '193', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '194', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '195', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'btc'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'bowtie'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207', '208', '209', '210', '211', '212']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'sam'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'btd'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'options'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'no_shrink'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '213', 'type': 'if_statement', 'children': ['214', '217', '240']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'is'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'cluster'}; {'id': '216', 'type': 'False', 'children': []}; {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'for_statement', 'children': ['219', '220', '221']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'btc'}; {'id': '221', 'type': 'block', 'children': ['222', '234']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '229', 'type': 'argument_list', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '233', 'type': 'True', 'children': []}; {'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': 'p'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'communicate'}; {'id': '239', 'type': 'argument_list', 'children': []}; {'id': '240', 'type': 'else_clause', 'children': ['241']}; {'id': '241', 'type': 'block', 'children': ['242', '273']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'string', 'children': [], 'value': "''"}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '249', 'type': 'generator_expression', 'children': ['250', '267']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}; {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'choice'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}; {'id': '255', 'type': 'list_comprehension', 'children': ['256', '260']}; {'id': '256', 'type': 'call', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '260', 'type': 'for_in_clause', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '264', 'type': 'argument_list', 'children': ['265', '266']}; {'id': '265', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '267', 'type': 'for_in_clause', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '273', 'type': 'for_statement', 'children': ['274', '277', '286']}; {'id': '274', 'type': 'pattern_list', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '279', 'type': 'argument_list', 'children': ['280', '285']}; {'id': '280', 'type': 'call', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'chunks'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'btc'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '285', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '286', 'type': 'block', 'children': ['287', '304', '317', '323', '342']}; {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'bs'}; {'id': '290', 'type': 'call', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '292', 'type': 'argument_list', 'children': ['293', '303']}; {'id': '293', 'type': 'binary_operator', 'children': ['294', '295'], 'value': '%'}; {'id': '294', 'type': 'string', 'children': [], 'value': "'%s/crossmap-qsub.%s.%s.sh'"}; {'id': '295', 'type': 'tuple', 'children': ['296', '301', '302']}; {'id': '296', 'type': 'call', 'children': ['297', '300']}; {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '300', 'type': 'argument_list', 'children': []}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '303', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}; {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '307', 'type': 'argument_list', 'children': ['308', '314']}; {'id': '308', 'type': 'call', 'children': ['309', '312']}; {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '314', 'type': 'keyword_argument', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'bs'}; {'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': 'bs'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '322', 'type': 'argument_list', 'children': []}; {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'assignment', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '326', 'type': 'call', 'children': ['327', '330']}; {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '330', 'type': 'argument_list', 'children': ['331', '338', '339']}; {'id': '331', 'type': 'binary_operator', 'children': ['332', '333', '334'], 'value': '%'}; {'id': '332', 'type': 'string', 'children': [], 'value': "'qsub -V -N crossmap %s'"}; {'id': '333', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '334', 'type': '()', 'children': ['335']}; {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'bs'}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '338', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '339', 'type': 'keyword_argument', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'shell'}; {'id': '341', 'type': 'True', 'children': []}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}; {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'communicate'}; {'id': '347', 'type': 'argument_list', 'children': []} | def crossmap(fas, reads, options, no_shrink, keepDB, threads, cluster, nodes):
if cluster is True:
threads = '48'
btc = []
for fa in fas:
btd = bowtiedb(fa, keepDB)
F, R, U = reads
if F is not False:
if U is False:
u = False
for i, f in enumerate(F):
r = R[i]
if U is not False:
u = U[i]
sam = '%s/%s-vs-%s' % (os.getcwd(), \
fa.rsplit('/', 1)[-1], f.rsplit('/', 1)[-1].rsplit('.', 3)[0])
btc.append(bowtie(sam, btd, f, r, u, options, no_shrink, threads))
else:
f = False
r = False
for u in U:
sam = '%s/%s-vs-%s' % (os.getcwd(), \
fa.rsplit('/', 1)[-1], u.rsplit('/', 1)[-1].rsplit('.', 3)[0])
btc.append(bowtie(sam, btd, f, r, u, options, no_shrink, threads))
if cluster is False:
for i in btc:
p = subprocess.Popen(i, shell = True)
p.communicate()
else:
ID = ''.join(random.choice([str(i) for i in range(0, 9)]) for _ in range(5))
for node, commands in enumerate(chunks(btc, nodes), 1):
bs = open('%s/crossmap-qsub.%s.%s.sh' % (os.getcwd(), ID, node), 'w')
print('\n'.join(commands), file=bs)
bs.close()
p = subprocess.Popen(\
'qsub -V -N crossmap %s' \
% (bs.name), \
shell = True)
p.communicate() |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bit_by_bit'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'in_data'}; {'id': '6', 'type': 'block', 'children': ['7', '25', '31', '97', '135', '152']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'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': 'in_data'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'in_data'}; {'id': '17', 'type': 'list_comprehension', 'children': ['18', '22']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ord'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'in_data'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'NonDirectInit'}; {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'octet'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'in_data'}; {'id': '34', 'type': 'block', 'children': ['35', '50']}; {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ReflectIn'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'octet'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'reflect'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'octet'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '56']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '56', 'type': 'block', 'children': ['57', '65', '88']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'topbit'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '&'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'MSB_Mask'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '78'], 'value': '|'}; {'id': '69', 'type': '()', 'children': ['70']}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '75'], 'value': '&'}; {'id': '71', 'type': '()', 'children': ['72']}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '<<'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'Mask'}; {'id': '78', 'type': '()', 'children': ['79']}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '87'], 'value': '&'}; {'id': '80', 'type': '()', 'children': ['81']}; {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '>>'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'octet'}; {'id': '83', 'type': '()', 'children': ['84']}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '-'}; {'id': '85', 'type': 'integer', 'children': [], 'value': '7'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '0x01'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'topbit'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '^='}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'Poly'}; {'id': '97', 'type': 'for_statement', 'children': ['98', '99', '105']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'Width'}; {'id': '105', 'type': 'block', 'children': ['106', '114', '126']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'topbit'}; {'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '&'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'MSB_Mask'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '117', 'type': '()', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '123'], 'value': '&'}; {'id': '119', 'type': '()', 'children': ['120']}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '<<'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'Mask'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'topbit'}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'augmented_assignment', 'children': ['131', '132'], 'value': '^='}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'Poly'}; {'id': '135', 'type': 'if_statement', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'ReflectOut'}; {'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': 'register'}; {'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': 'reflect'}; {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'Width'}; {'id': '152', 'type': 'return_statement', 'children': ['153']}; {'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '^'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'XorOut'} | def bit_by_bit(self, in_data):
if isinstance(in_data, str):
in_data = [ord(c) for c in in_data]
register = self.NonDirectInit
for octet in in_data:
if self.ReflectIn:
octet = self.reflect(octet, 8)
for i in range(8):
topbit = register & self.MSB_Mask
register = ((register << 1) & self.Mask) | ((octet >> (7 - i)) & 0x01)
if topbit:
register ^= self.Poly
for i in range(self.Width):
topbit = register & self.MSB_Mask
register = ((register << 1) & self.Mask)
if topbit:
register ^= self.Poly
if self.ReflectOut:
register = self.reflect(register, self.Width)
return register ^ self.XorOut |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_ggKbase_tables'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tables'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'id_type'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '232']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '10', 'type': 'dictionary', 'children': []}; {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'tables'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '21']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '21', 'type': 'block', 'children': ['22', '35', '62', '76', '87']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '25', 'type': 'call', 'children': ['26', '33']}; {'id': '26', 'type': 'attribute', 'children': ['27', '32']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '35', 'type': 'if_statement', 'children': ['36', '44']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}; {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '44', 'type': 'block', 'children': ['45', '49', '55', '61']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '54']}; {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'genome size (bp)'"}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '60']}; {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'\n header[13] = '"}; {'id': '61', 'type': 'continue_statement', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '68']}; {'id': '64', 'type': 'pattern_list', 'children': ['65', '66', '67']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '68', 'type': 'expression_list', 'children': ['69', '72', '75']}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '79', 'type': 'list_comprehension', 'children': ['80', '84']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'to_int'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '87', 'type': 'if_statement', 'children': ['88', '91', '167']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'is'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'id_type'}; {'id': '90', 'type': 'False', 'children': []}; {'id': '91', 'type': 'block', 'children': ['92', '105', '144']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '100']}; {'id': '93', 'type': 'boolean_operator', 'children': ['94', '97'], 'value': 'or'}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'}; {'id': '95', 'type': 'string', 'children': [], 'value': "'UNK'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'in'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'unknown'"}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '105', 'type': 'if_statement', 'children': ['106', '117', '143']}; {'id': '106', 'type': 'boolean_operator', 'children': ['107', '111'], 'value': 'and'}; {'id': '107', 'type': '()', 'children': ['108']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '!='}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '111', 'type': '()', 'children': ['112']}; {'id': '112', 'type': 'boolean_operator', 'children': ['113', '114'], 'value': 'and'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'in'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '117', 'type': 'ERROR', 'children': ['118', '123', '130']}; {'id': '118', 'type': 'call', 'children': ['119', '120', '122']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'\n print('"}; {'id': '120', 'type': 'ERROR', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '122', 'type': 'argument_list', 'children': []}; {'id': '123', 'type': 'ERROR', 'children': ['124', '127']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'not'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '130', 'type': 'dictionary_comprehension', 'children': ['131', '134']}; {'id': '131', 'type': 'pair', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '138']}; {'id': '135', 'type': 'pattern_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '143', 'type': 'block', 'children': [], 'value': ''}; {'id': '144', 'type': 'if_statement', 'children': ['145', '148']}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'not'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '154']}; {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '154', 'type': 'dictionary_comprehension', 'children': ['155', '158']}; {'id': '155', 'type': 'pair', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '158', 'type': 'for_in_clause', 'children': ['159', '162']}; {'id': '159', 'type': 'pattern_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '167', 'type': 'else_clause', 'children': ['168']}; {'id': '168', 'type': 'block', 'children': ['169']}; {'id': '169', 'type': 'if_statement', 'children': ['170', '173', '178', '187']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '=='}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'id_type'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '178', 'type': 'elif_clause', 'children': ['179', '182']}; {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '=='}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'id_type'}; {'id': '181', 'type': 'string', 'children': [], 'value': "'code'"}; {'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': 'ID'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '187', 'type': 'else_clause', 'children': ['188', '231']}; {'id': '188', 'type': 'ERROR', 'children': ['189', '204', '217', '230']}; {'id': '189', 'type': 'ERROR', 'children': ['190', '193', '194', '201']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '192', 'type': 'argument_list', 'children': []}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}; {'id': '199', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '200', 'type': 'string', 'children': [], 'value': "''"}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '204', 'type': 'dictionary_comprehension', 'children': ['205', '208']}; {'id': '205', 'type': 'pair', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '208', 'type': 'for_in_clause', 'children': ['209', '212']}; {'id': '209', 'type': 'pattern_list', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '217', 'type': 'ERROR', 'children': ['218', '225']}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '224'], 'value': '=='}; {'id': '219', 'type': 'subscript', 'children': ['220', '223']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '223', 'type': 'string', 'children': [], 'value': "'genome size (bp)'"}; {'id': '224', 'type': 'string', 'children': [], 'value': "''"}; {'id': '225', 'type': 'subscript', 'children': ['226', '229']}; {'id': '226', 'type': 'subscript', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'g2info'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '229', 'type': 'string', 'children': [], 'value': "'genome size (bp)'"}; {'id': '230', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '231', 'type': 'block', 'children': [], 'value': ''}; {'id': '232', 'type': 'return_statement', 'children': ['233']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'g2info'} | def parse_ggKbase_tables(tables, id_type):
g2info = {}
for table in tables:
for line in open(table):
line = line.strip().split('\t')
if line[0].startswith('name'):
header = line
header[4] = 'genome size (bp)'
header[12] = '
header[13] = '
continue
name, code, info = line[0], line[1], line
info = [to_int(i) for i in info]
if id_type is False:
if 'UNK' in code or 'unknown' in code:
code = name
if (name != code) and (name and code in g2info):
print('
print('
exit()
if name not in g2info:
g2info[name] = {item:stat for item, stat in zip(header, info)}
if code not in g2info:
g2info[code] = {item:stat for item, stat in zip(header, info)}
else:
if id_type == 'name':
ID = name
elif id_type == 'code':
ID = code
else:
print('
exit()
ID = ID.replace(' ', '')
g2info[ID] = {item:stat for item, stat in zip(header, info)}
if g2info[ID]['genome size (bp)'] == '':
g2info[ID]['genome size (bp)'] = 0
return g2info |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'top_hits'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '8', 'type': 'block', 'children': ['9', '24']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '21']}; {'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'itemgetter'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '32']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'hit'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '28', 'type': 'slice', 'children': ['29', '30', '31']}; {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'colon', 'children': []}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'yield', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'hit'} | def top_hits(hits, num, column, reverse):
hits.sort(key = itemgetter(column), reverse = reverse)
for hit in hits[0:num]:
yield hit |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'numBlast_sort'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'blast'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'numHits'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '8', 'type': 'block', 'children': ['9', '32', '35', '45', '136', '145']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '12', 'type': 'list', 'children': ['13', '30'], 'value': "['\n 'qstart', 'qend', 'tstart', 'tend', 'evalue', 'bitscore']"}; {'id': '13', 'type': 'concatenated_string', 'children': ['14', '15', '17', '18', '20', '21', '23', '24', '26', '27', '29']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'\n '"}; {'id': '15', 'type': 'ERROR', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'qstart'}; {'id': '17', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '18', 'type': 'ERROR', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'qend'}; {'id': '20', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '21', 'type': 'ERROR', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'tstart'}; {'id': '23', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '24', 'type': 'ERROR', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'tend'}; {'id': '26', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '27', 'type': 'ERROR', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'evalue'}; {'id': '29', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '30', 'type': 'ERROR', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'bitscore'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'yield', 'children': ['34']}; {'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': 'hmm'}; {'id': '38', 'type': 'dictionary_comprehension', 'children': ['39', '42']}; {'id': '39', 'type': 'pair', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '41', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'blast'}; {'id': '48', 'type': 'block', 'children': ['49', '107', '117']}; {'id': '49', 'type': 'if_statement', 'children': ['50', '53', '105']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '53', 'type': 'ERROR', 'children': ['54', '56', '72', '76', '82', '88', '90', '95', '98']}; {'id': '54', 'type': 'ERROR', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'continue'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '58', 'type': 'subscript', 'children': ['59', '69', '71']}; {'id': '59', 'type': 'call', 'children': ['60', '67']}; {'id': '60', 'type': 'attribute', 'children': ['61', '66']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '69', 'type': 'ERROR', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '72', 'type': 'ERROR', 'children': ['73']}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '75', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '88', 'type': 'ERROR', 'children': ['89']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'evalue'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '97', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '98', 'type': 'boolean_operator', 'children': ['99', '102'], 'value': 'and'}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '101', 'type': 'False', 'children': []}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '>'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'evalue'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'continue_statement', 'children': []}; {'id': '107', 'type': 'if_statement', 'children': ['108', '115']}; {'id': '108', 'type': 'boolean_operator', 'children': ['109', '112'], 'value': 'and'}; {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '111', 'type': 'False', 'children': []}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '<'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'continue_statement', 'children': []}; {'id': '117', 'type': 'for_statement', 'children': ['118', '121', '126']}; {'id': '118', 'type': 'pattern_list', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '134']}; {'id': '129', 'type': 'attribute', 'children': ['130', '133']}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'hmm'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'hmm'}; {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'hmm'}; {'id': '145', 'type': 'for_statement', 'children': ['146', '149', '177']}; {'id': '146', 'type': 'pattern_list', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '149', 'type': 'comparison_operator', 'children': ['150', '164', '167'], 'value': 'in'}; {'id': '150', 'type': 'call', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'hmm'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '161']}; {'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'by'}; {'id': '157', 'type': 'list', 'children': ['158', '159'], 'value': "['\n df = df.sort_values(by = ['bitscore']"}; {'id': '158', 'type': 'string', 'children': [], 'value': "'\n df = df.sort_values(by = ['"}; {'id': '159', 'type': 'ERROR', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'bitscore'}; {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'ascending'}; {'id': '163', 'type': 'False', 'children': []}; {'id': '164', 'type': 'ERROR', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'hit'}; {'id': '167', 'type': 'subscript', 'children': ['168', '173']}; {'id': '168', 'type': 'attribute', 'children': ['169', '172']}; {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '173', 'type': 'slice', 'children': ['174', '175', '176']}; {'id': '174', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '175', 'type': 'colon', 'children': []}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'numHits'}; {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'yield', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'hit'} | def numBlast_sort(blast, numHits, evalueT, bitT):
header = ['
'qstart', 'qend', 'tstart', 'tend', 'evalue', 'bitscore']
yield header
hmm = {h:[] for h in header}
for line in blast:
if line.startswith('
continue
line = line.strip().split('\t')
line[10], line[11] = float(line[10]), float(line[11])
evalue, bit = line[10], line[11]
if evalueT is not False and evalue > evalueT:
continue
if bitT is not False and bit < bitT:
continue
for i, h in zip(line, header):
hmm[h].append(i)
hmm = pd.DataFrame(hmm)
for query, df in hmm.groupby(by = ['
df = df.sort_values(by = ['bitscore'], ascending = False)
for hit in df[header].values[0:numHits]:
yield hit |
{'id': '0', 'type': 'module', 'children': ['1', '64', '67', '75', '267']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '47']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'numDomtblout'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'domtblout'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'numHits'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '9', 'type': 'ERROR', 'children': ['10', '29', '30', '40', '42', '43', '44', '45', '46']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '28']}; {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '24']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'hit'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'numDomtblout_sort'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22', '23']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'domtblout'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'numHits'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'yield', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'hit'}; {'id': '28', 'type': 'return_statement', 'children': []}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '30', 'type': 'concatenated_string', 'children': ['31', '32', '35', '36', '39']}; {'id': '31', 'type': 'string', 'children': [], 'value': "'\n '"}; {'id': '32', 'type': 'ERROR', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '35', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '36', 'type': 'ERROR', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'accession'}; {'id': '39', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '40', 'type': 'ERROR', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'qlen'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'full E-value'"}; {'id': '43', 'type': 'string', 'children': [], 'value': "'full score'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'full bias'"}; {'id': '45', 'type': 'ERROR', 'children': []}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'domain'}; {'id': '47', 'type': 'block', 'children': ['48', '53', '60']}; {'id': '48', 'type': 'expression_statement', 'children': ['49', '50', '51', '52']}; {'id': '49', 'type': 'string', 'children': [], 'value': "'domain c-Evalue'"}; {'id': '50', 'type': 'string', 'children': [], 'value': "'domain i-Evalue'"}; {'id': '51', 'type': 'string', 'children': [], 'value': "'domain score'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'domain bias'"}; {'id': '53', 'type': 'expression_statement', 'children': ['54', '55', '56', '57', '58', '59']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'hmm from'"}; {'id': '55', 'type': 'string', 'children': [], 'value': "'hmm to'"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'seq from'"}; {'id': '57', 'type': 'string', 'children': [], 'value': "'seq to'"}; {'id': '58', 'type': 'string', 'children': [], 'value': "'env from'"}; {'id': '59', 'type': 'string', 'children': [], 'value': "'env to'"}; {'id': '60', 'type': 'ERROR', 'children': ['61']}; {'id': '61', 'type': 'expression_statement', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'acc'"}; {'id': '63', 'type': 'string', 'children': [], 'value': "'target description'"}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'yield', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}; {'id': '69', 'type': 'pattern_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'prev'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '72', 'type': 'expression_list', 'children': ['73', '74']}; {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '75', 'type': 'for_statement', 'children': ['76', '77', '78']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'domtblout'}; {'id': '78', 'type': 'block', 'children': ['79', '199', '263']}; {'id': '79', 'type': 'if_statement', 'children': ['80', '83', '173']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '83', 'type': 'ERROR', 'children': ['84', '86', '134', '138', '144', '150', '152', '157', '164', '167', '169', '170']}; {'id': '84', 'type': 'ERROR', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'continue'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88', '123']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '88', 'type': 'ERROR', 'children': ['89', '98', '99', '109', '110', '116', '122']}; {'id': '89', 'type': 'call', 'children': ['90', '97']}; {'id': '90', 'type': 'attribute', 'children': ['91', '96']}; {'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': 'strip'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'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': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '106', 'type': 'slice', 'children': ['107', '108']}; {'id': '107', 'type': 'integer', 'children': [], 'value': '18'}; {'id': '108', 'type': 'colon', 'children': []}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '112', 'type': 'slice', 'children': ['113', '114', '115']}; {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'colon', 'children': []}; {'id': '115', 'type': 'integer', 'children': [], 'value': '18'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '123', 'type': 'binary_operator', 'children': ['124', '127'], 'value': '+'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '127', 'type': 'subscript', 'children': ['128', '131', '133']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '131', 'type': 'ERROR', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '133', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '134', 'type': 'ERROR', 'children': ['135']}; {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '13'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '149', 'type': 'integer', 'children': [], 'value': '13'}; {'id': '150', 'type': 'ERROR', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'evalue'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'bitscore'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '157', 'type': 'subscript', 'children': ['158', '161', '163']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '13'}; {'id': '161', 'type': 'ERROR', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '163', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '13'}; {'id': '167', 'type': 'ERROR', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'evalue'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'bitscore'}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '!='}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'prev'}; {'id': '173', 'type': 'block', 'children': ['174', '195']}; {'id': '174', 'type': 'if_statement', 'children': ['175', '181']}; {'id': '175', 'type': 'comparison_operator', 'children': ['176', '180'], 'value': '>'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '180', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'for_statement', 'children': ['183', '184', '191']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'hit'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'top_hits'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188', '189', '190']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'numHits'}; {'id': '189', 'type': 'integer', 'children': [], 'value': '13'}; {'id': '190', 'type': 'True', 'children': []}; {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'yield', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'hit'}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '198', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '199', 'type': 'if_statement', 'children': ['200', '207', '215', '231', '247']}; {'id': '200', 'type': 'boolean_operator', 'children': ['201', '204'], 'value': 'and'}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '203', 'type': 'False', 'children': []}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': '=='}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '206', 'type': 'False', 'children': []}; {'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': 'hits'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '215', 'type': 'elif_clause', 'children': ['216', '223']}; {'id': '216', 'type': 'boolean_operator', 'children': ['217', '220'], 'value': 'and'}; {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '<='}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'evalue'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': '=='}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '222', 'type': 'False', 'children': []}; {'id': '223', 'type': 'block', 'children': ['224']}; {'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': 'hits'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '231', 'type': 'elif_clause', 'children': ['232', '239']}; {'id': '232', 'type': 'boolean_operator', 'children': ['233', '236'], 'value': 'and'}; {'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '<='}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'evalue'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '>='}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}; {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '247', 'type': 'elif_clause', 'children': ['248', '255']}; {'id': '248', 'type': 'boolean_operator', 'children': ['249', '252'], 'value': 'and'}; {'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': '=='}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'evalueT'}; {'id': '251', 'type': 'False', 'children': []}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': '>='}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'bitT'}; {'id': '255', 'type': 'block', 'children': ['256']}; {'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': 'hits'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'prev'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '267', 'type': 'for_statement', 'children': ['268', '269', '276', '281']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'hit'}; {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'top_hits'}; {'id': '271', 'type': 'argument_list', 'children': ['272', '273', '274', '275']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'numHits'}; {'id': '274', 'type': 'integer', 'children': [], 'value': '13'}; {'id': '275', 'type': 'True', 'children': []}; {'id': '276', 'type': 'ERROR', 'children': ['277']}; {'id': '277', 'type': 'block', 'children': ['278']}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}; {'id': '279', 'type': 'yield', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'hit'}; {'id': '281', 'type': 'block', 'children': [], 'value': ''} | def numDomtblout(domtblout, numHits, evalueT, bitT, sort):
if sort is True:
for hit in numDomtblout_sort(domtblout, numHits, evalueT, bitT):
yield hit
return
header = ['
'query name', 'query accession', 'qlen',
'full E-value', 'full score', 'full bias',
'domain
'domain c-Evalue', 'domain i-Evalue', 'domain score', 'domain bias',
'hmm from', 'hmm to', 'seq from', 'seq to', 'env from', 'env to',
'acc', 'target description']
yield header
prev, hits = None, []
for line in domtblout:
if line.startswith('
continue
line = line.strip().split()
desc = ' '.join(line[18:])
line = line[0:18]
line.append(desc)
ID = line[0] + line[9]
line[11], line[13] = float(line[11]), float(line[13])
evalue, bitscore = line[11], line[13]
line[11], line[13] = evalue, bitscore
if ID != prev:
if len(hits) > 0:
for hit in top_hits(hits, numHits, 13, True):
yield hit
hits = []
if evalueT == False and bitT == False:
hits.append(line)
elif evalue <= evalueT and bitT == False:
hits.append(line)
elif evalue <= evalueT and bit >= bitT:
hits.append(line)
elif evalueT == False and bit >= bitT:
hits.append(line)
prev = ID
for hit in top_hits(hits, numHits, 13, True):
yield hit |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compare_clades'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pw'}; {'id': '5', 'type': 'block', 'children': ['6', '20']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'names'}; {'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', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'list_comprehension', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pw'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '27']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '27', 'type': 'block', 'children': ['28', '36', '218', '260', '264', '310']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'pattern_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'wi'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '33', 'type': 'expression_list', 'children': ['34', '35']}; {'id': '34', 'type': 'dictionary', 'children': []}; {'id': '35', 'type': 'dictionary', 'children': []}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'for_statement', 'children': ['41', '42', '45']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pw'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '45', 'type': 'block', 'children': ['46', '56', '64', '86', '154']}; {'id': '46', 'type': 'if_statement', 'children': ['47', '54']}; {'id': '47', 'type': 'boolean_operator', 'children': ['48', '51'], 'value': 'or'}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'not'}; {'id': '49', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'not'}; {'id': '52', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'continue_statement', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pident'}; {'id': '59', 'type': 'subscript', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pw'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'pattern_list', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '69', 'type': 'expression_list', 'children': ['70', '78']}; {'id': '70', 'type': 'subscript', 'children': ['71', '77']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '78', 'type': 'subscript', 'children': ['79', '85']}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '98', '123']}; {'id': '87', 'type': 'boolean_operator', 'children': ['88', '95'], 'value': 'and'}; {'id': '88', 'type': 'boolean_operator', 'children': ['89', '92'], 'value': 'and'}; {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '91', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'in'}; {'id': '93', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '98', 'type': 'block', 'children': ['99', '111']}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '102', 'type': 'subscript', 'children': ['103', '110']}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '114', 'type': 'subscript', 'children': ['115', '122']}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '123', 'type': 'elif_clause', 'children': ['124', '131']}; {'id': '124', 'type': 'boolean_operator', 'children': ['125', '128'], 'value': 'or'}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'in'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'in'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '131', 'type': 'block', 'children': ['132', '143']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '135', 'type': 'subscript', 'children': ['136', '142']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '142', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '146', 'type': 'subscript', 'children': ['147', '153']}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '153', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '158', '179']}; {'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': '=='}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '158', 'type': 'block', 'children': ['159', '170']}; {'id': '159', 'type': 'if_statement', 'children': ['160', '163']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'not'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'wi'}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '169']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'wi'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '169', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'call', 'children': ['172', '177']}; {'id': '172', 'type': 'attribute', 'children': ['173', '176']}; {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'wi'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'pident'}; {'id': '179', 'type': 'else_clause', 'children': ['180']}; {'id': '180', 'type': 'block', 'children': ['181', '192', '207']}; {'id': '181', 'type': 'if_statement', 'children': ['182', '185']}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'not'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}; {'id': '187', 'type': 'assignment', 'children': ['188', '191']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '191', 'type': 'dictionary', 'children': []}; {'id': '192', 'type': 'if_statement', 'children': ['193', '198']}; {'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'not'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '206']}; {'id': '201', 'type': 'subscript', 'children': ['202', '205']}; {'id': '202', 'type': 'subscript', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '206', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '216']}; {'id': '209', 'type': 'attribute', 'children': ['210', '215']}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}; {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'cA'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'cB'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'pident'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '221', '236']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '221', 'type': 'ERROR', 'children': ['222', '225', '226']}; {'id': '222', 'type': 'ERROR', 'children': ['223', '224']}; {'id': '223', 'type': 'escape_sequence', 'children': [], 'value': '\\n'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'clade'}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': 'in'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'pidents'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'list'}; {'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': 'wi'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '235', 'type': 'argument_list', 'children': []}; {'id': '236', 'type': 'type', 'children': ['237']}; {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}; {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}; {'id': '245', 'type': 'list', 'children': ['246', '252', '253'], 'value': "['wi:%s' % str(i), clade, str(min(pidents))]"}; {'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '%'}; {'id': '247', 'type': 'string', 'children': [], 'value': "'wi:%s'"}; {'id': '248', 'type': 'call', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'clade'}; {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'pidents'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}; {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'comps'}; {'id': '263', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}; {'id': '265', 'type': 'assignment', 'children': ['266', '267', '277', '279']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '267', 'type': 'ERROR', 'children': ['268', '271']}; {'id': '268', 'type': 'ERROR', 'children': ['269', '270']}; {'id': '269', 'type': 'escape_sequence', 'children': [], 'value': '\\n'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '271', 'type': 'comparison_operator', 'children': ['272', '273'], 'value': 'in'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'print_pairwise'}; {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '277', 'type': 'ERROR', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'if'}; {'id': '279', 'type': 'type', 'children': ['280']}; {'id': '280', 'type': 'constrained_type', 'children': ['281', '285']}; {'id': '281', 'type': 'type', 'children': ['282']}; {'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': 'is'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '284', 'type': 'None', 'children': []}; {'id': '285', 'type': 'type', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'binary_operator', 'children': ['295', '302'], 'value': '+'}; {'id': '295', 'type': 'list', 'children': ['296'], 'value': "['bt:%s' % str(i)]"}; {'id': '296', 'type': 'binary_operator', 'children': ['297', '298'], 'value': '%'}; {'id': '297', 'type': 'string', 'children': [], 'value': "'bt:%s'"}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '302', 'type': 'list_comprehension', 'children': ['303', '307']}; {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '307', 'type': 'for_in_clause', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '310', 'type': 'ERROR', 'children': ['311', '314', '315', '316', '320', '322', '323', '338', '340', '343', '367']}; {'id': '311', 'type': 'subscript', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '313', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '314', 'type': 'string', 'children': [], 'value': "'\n comps.extend([j for j in comp[1:] if j != '"}; {'id': '315', 'type': 'ERROR', 'children': []}; {'id': '316', 'type': 'call', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'print_comps'}; {'id': '318', 'type': 'argument_list', 'children': ['319']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'comps'}; {'id': '320', 'type': 'ERROR', 'children': ['321']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'comps'}; {'id': '322', 'type': 'ERROR', 'children': []}; {'id': '323', 'type': 'call', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '325', 'type': 'argument_list', 'children': ['326', '329']}; {'id': '326', 'type': 'ERROR', 'children': ['327', '328']}; {'id': '327', 'type': 'escape_sequence', 'children': [], 'value': '\\n'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '329', 'type': 'comparison_operator', 'children': ['330', '331'], 'value': 'in'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'print_pairwise'}; {'id': '333', 'type': 'argument_list', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'bt'}; {'id': '335', 'type': 'keyword_argument', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'median'}; {'id': '337', 'type': 'True', 'children': []}; {'id': '338', 'type': 'ERROR', 'children': ['339']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'if'}; {'id': '340', 'type': 'comparison_operator', 'children': ['341', '342'], 'value': 'is'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '342', 'type': 'None', 'children': []}; {'id': '343', 'type': 'call', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '345', 'type': 'argument_list', 'children': ['346']}; {'id': '346', 'type': 'call', 'children': ['347', '350']}; {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}; {'id': '351', 'type': 'binary_operator', 'children': ['352', '359'], 'value': '+'}; {'id': '352', 'type': 'list', 'children': ['353'], 'value': "['bt:%s' % str(i)]"}; {'id': '353', 'type': 'binary_operator', 'children': ['354', '355'], 'value': '%'}; {'id': '354', 'type': 'string', 'children': [], 'value': "'bt:%s'"}; {'id': '355', 'type': 'call', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '357', 'type': 'argument_list', 'children': ['358']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '359', 'type': 'list_comprehension', 'children': ['360', '364']}; {'id': '360', 'type': 'call', 'children': ['361', '362']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '362', 'type': 'argument_list', 'children': ['363']}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '364', 'type': 'for_in_clause', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '367', 'type': 'comparison_operator', 'children': ['368', '371'], 'value': '!='}; {'id': '368', 'type': 'subscript', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '370', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '371', 'type': 'binary_operator', 'children': ['372', '373', '374'], 'value': '-'}; {'id': '372', 'type': 'string', 'children': [], 'value': "'\n comps.extend([j for j in comp[1:] if j != '"}; {'id': '373', 'type': 'ERROR', 'children': []}; {'id': '374', 'type': 'call', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'print_comps'}; {'id': '376', 'type': 'argument_list', 'children': ['377']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'comps'} | def compare_clades(pw):
names = sorted(set([i for i in pw]))
for i in range(0, 4):
wi, bt = {}, {}
for a in names:
for b in pw[a]:
if ';' not in a or ';' not in b:
continue
pident = pw[a][b]
cA, cB = a.split(';')[i], b.split(';')[i]
if i == 0 and '_' in cA and '_' in cB:
cA = cA.rsplit('_', 1)[1]
cB = cB.rsplit('_', 1)[1]
elif '>' in cA or '>' in cB:
cA = cA.split('>')[1]
cB = cB.split('>')[1]
if cA == cB:
if cA not in wi:
wi[cA] = []
wi[cA].append(pident)
else:
if cA not in bt:
bt[cA] = {}
if cB not in bt[cA]:
bt[cA][cB] = []
bt[cA][cB].append(pident)
print('\n
for clade, pidents in list(wi.items()):
print('\t'.join(['wi:%s' % str(i), clade, str(min(pidents))]))
comps = []
print('\n
for comp in print_pairwise(bt):
if comp is not None:
print('\t'.join(['bt:%s' % str(i)] + [str(j) for j in comp]))
if comp[0] != '
comps.extend([j for j in comp[1:] if j != '-'])
print_comps(comps)
comps = []
print('\n
for comp in print_pairwise(bt, median = True):
if comp is not None:
print('\t'.join(['bt:%s' % str(i)] + [str(j) for j in comp]))
if comp[0] != '
comps.extend([j for j in comp[1:] if j != '-'])
print_comps(comps) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'searchAccession'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '5', 'type': 'block', 'children': ['6', '16', '91', '101', '176', '186', '261', '292']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'pattern_list', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'entrez'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'genome'"}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '16', 'type': 'for_statement', 'children': ['17', '18', '23']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'splitlines'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'block', 'children': ['24', '37']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '27', 'type': 'call', 'children': ['28', '36']}; {'id': '28', 'type': 'attribute', 'children': ['29', '35']}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'ascii'"}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '36', 'type': 'argument_list', 'children': []}; {'id': '37', 'type': 'if_statement', 'children': ['38', '45']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '42'], 'value': 'or'}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'Assembly_Accession'"}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'}; {'id': '43', 'type': 'string', 'children': [], 'value': "'BioSample'"}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '45', 'type': 'block', 'children': ['46', '78']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '49', 'type': 'subscript', 'children': ['50', '77']}; {'id': '50', 'type': 'call', 'children': ['51', '75']}; {'id': '51', 'type': 'attribute', 'children': ['52', '74']}; {'id': '52', 'type': 'subscript', 'children': ['53', '73']}; {'id': '53', 'type': 'call', 'children': ['54', '71']}; {'id': '54', 'type': 'attribute', 'children': ['55', '70']}; {'id': '55', 'type': 'subscript', 'children': ['56', '69']}; {'id': '56', 'type': 'call', 'children': ['57', '67']}; {'id': '57', 'type': 'attribute', 'children': ['58', '66']}; {'id': '58', 'type': 'subscript', 'children': ['59', '65']}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': "'<'"}; {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "','"}; {'id': '77', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '85']}; {'id': '79', 'type': 'comparison_operator', 'children': ['80', '84'], 'value': '>'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'return_statement', 'children': ['87']}; {'id': '87', 'type': 'tuple', 'children': ['88', '89', '90']}; {'id': '88', 'type': 'True', 'children': []}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}; {'id': '93', 'type': 'pattern_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'entrez'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}; {'id': '99', 'type': 'string', 'children': [], 'value': "'nucleotide'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '101', 'type': 'for_statement', 'children': ['102', '103', '108']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'splitlines'}; {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'block', 'children': ['109', '122']}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '112', 'type': 'call', 'children': ['113', '121']}; {'id': '113', 'type': 'attribute', 'children': ['114', '120']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'ascii'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '121', 'type': 'argument_list', 'children': []}; {'id': '122', 'type': 'if_statement', 'children': ['123', '130']}; {'id': '123', 'type': 'boolean_operator', 'children': ['124', '127'], 'value': 'or'}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'in'}; {'id': '125', 'type': 'string', 'children': [], 'value': "'Assembly_Accession'"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'in'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'BioSample'"}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '130', 'type': 'block', 'children': ['131', '163']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '134', 'type': 'subscript', 'children': ['135', '162']}; {'id': '135', 'type': 'call', 'children': ['136', '160']}; {'id': '136', 'type': 'attribute', 'children': ['137', '159']}; {'id': '137', 'type': 'subscript', 'children': ['138', '158']}; {'id': '138', 'type': 'call', 'children': ['139', '156']}; {'id': '139', 'type': 'attribute', 'children': ['140', '155']}; {'id': '140', 'type': 'subscript', 'children': ['141', '154']}; {'id': '141', 'type': 'call', 'children': ['142', '152']}; {'id': '142', 'type': 'attribute', 'children': ['143', '151']}; {'id': '143', 'type': 'subscript', 'children': ['144', '150']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'string', 'children': [], 'value': "'<'"}; {'id': '154', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '158', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'string', 'children': [], 'value': "','"}; {'id': '162', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '163', 'type': 'if_statement', 'children': ['164', '170']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '169'], 'value': '>'}; {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'block', 'children': ['171']}; {'id': '171', 'type': 'return_statement', 'children': ['172']}; {'id': '172', 'type': 'tuple', 'children': ['173', '174', '175']}; {'id': '173', 'type': 'True', 'children': []}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'pattern_list', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'entrez'}; {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'string', 'children': [], 'value': "'assembly'"}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '186', 'type': 'for_statement', 'children': ['187', '188', '193']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'splitlines'}; {'id': '192', 'type': 'argument_list', 'children': []}; {'id': '193', 'type': 'block', 'children': ['194', '207']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '197', 'type': 'call', 'children': ['198', '206']}; {'id': '198', 'type': 'attribute', 'children': ['199', '205']}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'string', 'children': [], 'value': "'ascii'"}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '206', 'type': 'argument_list', 'children': []}; {'id': '207', 'type': 'if_statement', 'children': ['208', '215']}; {'id': '208', 'type': 'boolean_operator', 'children': ['209', '212'], 'value': 'or'}; {'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': 'in'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'Assembly_Accession'"}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': 'in'}; {'id': '213', 'type': 'string', 'children': [], 'value': "'BioSample'"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '215', 'type': 'block', 'children': ['216', '248']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '219', 'type': 'subscript', 'children': ['220', '247']}; {'id': '220', 'type': 'call', 'children': ['221', '245']}; {'id': '221', 'type': 'attribute', 'children': ['222', '244']}; {'id': '222', 'type': 'subscript', 'children': ['223', '243']}; {'id': '223', 'type': 'call', 'children': ['224', '241']}; {'id': '224', 'type': 'attribute', 'children': ['225', '240']}; {'id': '225', 'type': 'subscript', 'children': ['226', '239']}; {'id': '226', 'type': 'call', 'children': ['227', '237']}; {'id': '227', 'type': 'attribute', 'children': ['228', '236']}; {'id': '228', 'type': 'subscript', 'children': ['229', '235']}; {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '235', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'<'"}; {'id': '239', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '243', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'string', 'children': [], 'value': "','"}; {'id': '247', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '248', 'type': 'if_statement', 'children': ['249', '255']}; {'id': '249', 'type': 'comparison_operator', 'children': ['250', '254'], 'value': '>'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'return_statement', 'children': ['257']}; {'id': '257', 'type': 'tuple', 'children': ['258', '259', '260']}; {'id': '258', 'type': 'True', 'children': []}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'newAcc'}; {'id': '261', 'type': 'for_statement', 'children': ['262', '263', '268']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'splitlines'}; {'id': '267', 'type': 'argument_list', 'children': []}; {'id': '268', 'type': 'block', 'children': ['269', '282']}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '272', 'type': 'call', 'children': ['273', '281']}; {'id': '273', 'type': 'attribute', 'children': ['274', '280']}; {'id': '274', 'type': 'call', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}; {'id': '279', 'type': 'string', 'children': [], 'value': "'ascii'"}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '281', 'type': 'argument_list', 'children': []}; {'id': '282', 'type': 'if_statement', 'children': ['283', '286']}; {'id': '283', 'type': 'comparison_operator', 'children': ['284', '285'], 'value': 'in'}; {'id': '284', 'type': 'string', 'children': [], 'value': "'500 Can'"}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '286', 'type': 'block', 'children': ['287']}; {'id': '287', 'type': 'return_statement', 'children': ['288']}; {'id': '288', 'type': 'tuple', 'children': ['289', '290', '291']}; {'id': '289', 'type': 'False', 'children': []}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '291', 'type': 'string', 'children': [], 'value': "'no network'"}; {'id': '292', 'type': 'return_statement', 'children': ['293']}; {'id': '293', 'type': 'tuple', 'children': ['294', '295', '296']}; {'id': '294', 'type': 'False', 'children': []}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'acc'}; {'id': '296', 'type': 'string', 'children': [], 'value': "'efetch failed'"} | def searchAccession(acc):
out, error = entrez('genome', acc)
for line in out.splitlines():
line = line.decode('ascii').strip()
if 'Assembly_Accession' in line or 'BioSample' in line:
newAcc = line.split('>')[1].split('<')[0].split('.')[0].split(',')[0]
if len(newAcc) > 0:
return (True, acc, newAcc)
out, error = entrez('nucleotide', acc)
for line in out.splitlines():
line = line.decode('ascii').strip()
if 'Assembly_Accession' in line or 'BioSample' in line:
newAcc = line.split('>')[1].split('<')[0].split('.')[0].split(',')[0]
if len(newAcc) > 0:
return (True, acc, newAcc)
out, error = entrez('assembly', acc)
for line in out.splitlines():
line = line.decode('ascii').strip()
if 'Assembly_Accession' in line or 'BioSample' in line:
newAcc = line.split('>')[1].split('<')[0].split('.')[0].split(',')[0]
if len(newAcc) > 0:
return (True, acc, newAcc)
for error in error.splitlines():
error = error.decode('ascii').strip()
if '500 Can' in error:
return (False, acc, 'no network')
return (False, acc, 'efetch failed') |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_configure_logger'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pre_hooks'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'post_hooks'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'metric_grouping_interval'}; {'id': '11', 'type': 'block', 'children': ['12', '24', '26', '30', '57', '63', '77', '87', '96', '102', '125', '141', '157', '164', '178', '182', '194', '210', '218', '236', '245', '272', '280', '289', '296']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'global_statement', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_GLOBAL_LOG_CONFIGURED'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_GLOBAL_LOG_CONFIGURED'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'return_statement', 'children': []}; {'id': '30', 'type': 'function_definition', 'children': ['31', '32', '34']}; {'id': '31', 'type': 'function_name', 'children': [], 'value': 'wrap_hook'}; {'id': '32', 'type': 'parameters', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '34', 'type': 'block', 'children': ['35', '55']}; {'id': '35', 'type': 'decorated_definition', 'children': ['36', '41']}; {'id': '36', 'type': 'decorator', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'wraps'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '41', 'type': 'function_definition', 'children': ['42', '43', '47']}; {'id': '42', 'type': 'function_name', 'children': [], 'value': 'processor'}; {'id': '43', 'type': 'parameters', 'children': ['44', '45', '46']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'method_name'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '47', 'type': 'block', 'children': ['48', '53']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '55', 'type': 'return_statement', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'define_log_processors'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'list_comprehension', 'children': ['70', '74']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'wrap_hook'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'pre_hooks'}; {'id': '77', 'type': 'if_statement', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'metric_grouping_interval'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'metrics_grouping_processor'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'log_renderer'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'define_log_renderer'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94', '95']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'stderr_required'}; {'id': '99', 'type': '()', 'children': ['100']}; {'id': '100', 'type': 'not_operator', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'quiet'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'pretty_to_stderr'}; {'id': '105', 'type': '()', 'children': ['106']}; {'id': '106', 'type': 'boolean_operator', 'children': ['107', '108'], 'value': 'and'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'stderr_required'}; {'id': '108', 'type': '()', 'children': ['109']}; {'id': '109', 'type': 'boolean_operator', 'children': ['110', '113'], 'value': 'or'}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '112', 'type': 'string', 'children': [], 'value': '"pretty"'}; {'id': '113', 'type': '()', 'children': ['114']}; {'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': 'fmt'}; {'id': '117', 'type': 'None', 'children': []}; {'id': '118', 'type': 'call', 'children': ['119', '124']}; {'id': '119', 'type': 'attribute', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'isatty'}; {'id': '124', 'type': 'argument_list', 'children': []}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'should_inject_pretty_renderer'}; {'id': '128', 'type': '()', 'children': ['129']}; {'id': '129', 'type': 'boolean_operator', 'children': ['130', '131'], 'value': 'and'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'pretty_to_stderr'}; {'id': '131', 'type': 'not_operator', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'log_renderer'}; {'id': '136', 'type': 'attribute', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'structlog'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'dev'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ConsoleRenderer'}; {'id': '141', 'type': 'if_statement', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'should_inject_pretty_renderer'}; {'id': '143', 'type': 'block', 'children': ['144', '148']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'stderr_required'}; {'id': '147', 'type': 'False', 'children': []}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'StderrConsoleRenderer'}; {'id': '156', 'type': 'argument_list', 'children': []}; {'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': 'processors'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'log_renderer'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'list_comprehension', 'children': ['171', '175']}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'wrap_hook'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '175', 'type': 'for_in_clause', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'post_hooks'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'streams'}; {'id': '181', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'stderr_required'}; {'id': '184', 'type': 'block', 'children': ['185']}; {'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': 'streams'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '194', 'type': 'if_statement', 'children': ['195', '198']}; {'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': 'is'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '197', 'type': 'None', 'children': []}; {'id': '198', 'type': 'block', 'children': ['199']}; {'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': 'streams'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '207', 'type': 'argument_list', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '209', 'type': 'string', 'children': [], 'value': "'a'"}; {'id': '210', 'type': 'assert_statement', 'children': ['211', '217']}; {'id': '211', 'type': 'comparison_operator', 'children': ['212', '216'], 'value': '!='}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'streams'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '217', 'type': 'string', 'children': [], 'value': '"cannot configure logger for 0 streams"'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '221', 'type': 'conditional_expression', 'children': ['222', '225', '231'], 'value': 'if'}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'streams'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '225', 'type': 'comparison_operator', 'children': ['226', '230'], 'value': '=='}; {'id': '226', 'type': 'call', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'streams'}; {'id': '230', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'Stream'}; {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'list_splat', 'children': ['235']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'streams'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'atexit'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'register'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'close'}; {'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': 'structlog'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'configure'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '254', '257', '266', '269']}; {'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'context_class'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'logger_factory'}; {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'LevelLoggerFactory'}; {'id': '261', 'type': 'argument_list', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'stream'}; {'id': '263', 'type': 'keyword_argument', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '266', 'type': 'keyword_argument', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'wrapper_class'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'BoundLevelLogger'}; {'id': '269', 'type': 'keyword_argument', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'cache_logger_on_first_use'}; {'id': '271', 'type': 'True', 'children': []}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'stdlib_root_log'}; {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '279', 'type': 'argument_list', 'children': []}; {'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': 'stdlib_root_log'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'addHandler'}; {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'StdlibStructlogHandler'}; {'id': '288', 'type': 'argument_list', 'children': []}; {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}; {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'stdlib_root_log'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'setLevel'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}; {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': '_GLOBAL_LOG_CONFIGURED'}; {'id': '299', 'type': 'True', 'children': []} | def _configure_logger(fmt, quiet, level, fpath,
pre_hooks, post_hooks, metric_grouping_interval):
level = getattr(logging, level.upper())
global _GLOBAL_LOG_CONFIGURED
if _GLOBAL_LOG_CONFIGURED:
return
def wrap_hook(fn):
@wraps(fn)
def processor(logger, method_name, event_dict):
fn(event_dict)
return event_dict
return processor
processors = define_log_processors()
processors.extend(
[ wrap_hook(h) for h in pre_hooks ]
)
if metric_grouping_interval:
processors.append(metrics_grouping_processor)
log_renderer = define_log_renderer(fmt, fpath, quiet)
stderr_required = (not quiet)
pretty_to_stderr = (
stderr_required
and (
fmt == "pretty"
or (fmt is None and sys.stderr.isatty())
)
)
should_inject_pretty_renderer = (
pretty_to_stderr
and not isinstance(log_renderer, structlog.dev.ConsoleRenderer)
)
if should_inject_pretty_renderer:
stderr_required = False
processors.append(StderrConsoleRenderer())
processors.append(log_renderer)
processors.extend(
[ wrap_hook(h) for h in post_hooks ]
)
streams = []
if stderr_required:
streams.append(sys.stderr)
if fpath is not None:
streams.append(open(fpath, 'a'))
assert len(streams) != 0, "cannot configure logger for 0 streams"
stream = streams[0] if len(streams) == 1 else Stream(*streams)
atexit.register(stream.close)
structlog.configure(
processors=processors,
context_class=dict,
logger_factory=LevelLoggerFactory(stream, level=level),
wrapper_class=BoundLevelLogger,
cache_logger_on_first_use=True,
)
stdlib_root_log = logging.getLogger()
stdlib_root_log.addHandler(StdlibStructlogHandler())
stdlib_root_log.setLevel(level)
_GLOBAL_LOG_CONFIGURED = True |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'combine_modifiers'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'graphemes'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '15', '22', '203', '213', '217', '221', '278']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '14', 'type': 'string', 'children': [], 'value': '""'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'graphemes'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '28']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'graphemes'}; {'id': '28', 'type': 'block', 'children': ['29', '33', '85', '119', '190', '199']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'augmented_assignment', 'children': ['31', '32'], 'value': '-='}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '60']}; {'id': '34', 'type': 'boolean_operator', 'children': ['35', '50', '51'], 'value': 'and'}; {'id': '35', 'type': 'boolean_operator', 'children': ['36', '42'], 'value': 'and'}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '41'], 'value': '=='}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '49'], 'value': '=='}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'unicodedata'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '49', 'type': 'string', 'children': [], 'value': '"Lm"'}; {'id': '50', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '51', 'type': 'not_operator', 'children': ['52']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '57'], 'value': 'in'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ord'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '57', 'type': 'list', 'children': ['58', '59'], 'value': '[712, 716]'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '712'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '716'}; {'id': '60', 'type': 'block', 'children': ['61', '67', '84']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'count'}; {'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', '78']}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '76', 'type': 'unary_operator', 'children': ['77'], 'value': '-'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '+'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '82', 'type': 'unary_operator', 'children': ['83'], 'value': '-'}; {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'continue_statement', 'children': []}; {'id': '85', 'type': 'if_statement', 'children': ['86', '101']}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '93'], 'value': 'and'}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '92'], 'value': '=='}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '93', 'type': 'comparison_operator', 'children': ['94', '98'], 'value': 'in'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'ord'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '98', 'type': 'list', 'children': ['99', '100'], 'value': '[712, 716]'}; {'id': '99', 'type': 'integer', 'children': [], 'value': '712'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '716'}; {'id': '101', 'type': 'block', 'children': ['102', '114', '118']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '108']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'}; {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '112', 'type': 'unary_operator', 'children': ['113'], 'value': '-'}; {'id': '113', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '117', 'type': 'string', 'children': [], 'value': '""'}; {'id': '118', 'type': 'continue_statement', 'children': []}; {'id': '119', 'type': 'if_statement', 'children': ['120', '135']}; {'id': '120', 'type': 'boolean_operator', 'children': ['121', '127'], 'value': 'and'}; {'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': 'grapheme'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '134'], 'value': '=='}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'unicodedata'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '134', 'type': 'string', 'children': [], 'value': '"Sk"'}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '143', '156']}; {'id': '137', 'type': 'comparison_operator', 'children': ['138', '142'], 'value': '=='}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '143', 'type': 'block', 'children': ['144', '151', '155']}; {'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': 'result'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '154', 'type': 'string', 'children': [], 'value': '""'}; {'id': '155', 'type': 'continue_statement', 'children': []}; {'id': '156', 'type': 'else_clause', 'children': ['157']}; {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'if_statement', 'children': ['159', '172']}; {'id': '159', 'type': 'comparison_operator', 'children': ['160', '171'], 'value': '=='}; {'id': '160', 'type': 'call', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'unicodedata'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'category'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'subscript', 'children': ['166', '170']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '168', 'type': 'unary_operator', 'children': ['169'], 'value': '-'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '171', 'type': 'string', 'children': [], 'value': '"Sk"'}; {'id': '172', 'type': 'block', 'children': ['173', '185', '189']}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '179']}; {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '177', 'type': 'unary_operator', 'children': ['178'], 'value': '-'}; {'id': '178', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '+'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '183', 'type': 'unary_operator', 'children': ['184'], 'value': '-'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '188', 'type': 'string', 'children': [], 'value': '""'}; {'id': '189', 'type': 'continue_statement', 'children': []}; {'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': 'result'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '+'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'grapheme'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'temp'}; {'id': '202', 'type': 'string', 'children': [], 'value': '""'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '206', 'type': 'subscript', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '208', 'type': 'slice', 'children': ['209', '210', '211']}; {'id': '209', 'type': 'colon', 'children': []}; {'id': '210', 'type': 'colon', 'children': []}; {'id': '211', 'type': 'unary_operator', 'children': ['212'], 'value': '-'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '220', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '221', 'type': 'while_statement', 'children': ['222', '228']}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '<'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '228', 'type': 'block', 'children': ['229']}; {'id': '229', 'type': 'if_statement', 'children': ['230', '243', '263']}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '240'], 'value': 'in'}; {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'ord'}; {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'subscript', 'children': ['235', '238']}; {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '238', 'type': 'unary_operator', 'children': ['239'], 'value': '-'}; {'id': '239', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '240', 'type': 'list', 'children': ['241', '242'], 'value': '[865, 860]'}; {'id': '241', 'type': 'integer', 'children': [], 'value': '865'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '860'}; {'id': '243', 'type': 'block', 'children': ['244', '259']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'binary_operator', 'children': ['251', '254'], 'value': '+'}; {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '+'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'augmented_assignment', 'children': ['261', '262'], 'value': '+='}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '263', 'type': 'else_clause', 'children': ['264']}; {'id': '264', 'type': 'block', 'children': ['265', '274']}; {'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': 'r'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'augmented_assignment', 'children': ['276', '277'], 'value': '+='}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '277', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '278', 'type': 'return_statement', 'children': ['279']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'r'} | def combine_modifiers(self, graphemes):
result = []
temp = ""
count = len(graphemes)
for grapheme in reversed(graphemes):
count -= 1
if len(grapheme) == 1 and unicodedata.category(grapheme) == "Lm" \
and not ord(grapheme) in [712, 716]:
temp = grapheme + temp
if count == 0:
result[-1] = temp + result[-1]
continue
if len(grapheme) == 1 and ord(grapheme) in [712, 716]:
result[-1] = grapheme + result[-1]
temp = ""
continue
if len(grapheme) == 1 and unicodedata.category(grapheme) == "Sk":
if len(result) == 0:
result.append(grapheme)
temp = ""
continue
else:
if unicodedata.category(result[-1][0]) == "Sk":
result[-1] = grapheme + result[-1]
temp = ""
continue
result.append(grapheme + temp)
temp = ""
segments = result[::-1]
i = 0
r = []
while i < len(segments):
if ord(segments[i][-1]) in [865, 860]:
r.append(segments[i] + segments[i + 1])
i += 2
else:
r.append(segments[i])
i += 1
return r |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_mismatches'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'mm_option'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'req_map'}; {'id': '9', 'type': 'block', 'children': ['10', '43', '50', '57', '68', '75', '91', '117', '167']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '22', '29', '36']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'mm'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'count_mismatches'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '26']}; {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'mm'}; {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'return_statement', 'children': ['28']}; {'id': '28', 'type': 'False', 'children': []}; {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '32', 'type': 'False', 'children': []}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'return_statement', 'children': ['35']}; {'id': '35', 'type': 'True', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': '<='}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'mm'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'True', 'children': []}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'count_mismatches'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'count_mismatches'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '57', 'type': 'if_statement', 'children': ['58', '65']}; {'id': '58', 'type': 'boolean_operator', 'children': ['59', '62'], 'value': 'and'}; {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '61', 'type': 'False', 'children': []}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '64', 'type': 'False', 'children': []}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}; {'id': '67', 'type': 'False', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}; {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '71', 'type': 'False', 'children': []}; {'id': '72', 'type': 'block', 'children': ['73']}; {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'True', 'children': []}; {'id': '75', 'type': 'if_statement', 'children': ['76', '79']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'req_map'}; {'id': '78', 'type': 'True', 'children': []}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'if_statement', 'children': ['81', '88']}; {'id': '81', 'type': 'boolean_operator', 'children': ['82', '85'], 'value': 'or'}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '84', 'type': 'False', 'children': []}; {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'is'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '87', 'type': 'False', 'children': []}; {'id': '88', 'type': 'block', 'children': ['89']}; {'id': '89', 'type': 'return_statement', 'children': ['90']}; {'id': '90', 'type': 'False', 'children': []}; {'id': '91', 'type': 'if_statement', 'children': ['92', '95']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '=='}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'mm_option'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'one'"}; {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'if_statement', 'children': ['97', '114']}; {'id': '97', 'type': 'boolean_operator', 'children': ['98', '106'], 'value': 'or'}; {'id': '98', 'type': '()', 'children': ['99']}; {'id': '99', 'type': 'boolean_operator', 'children': ['100', '103'], 'value': 'and'}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '102', 'type': 'False', 'children': []}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '<='}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '106', 'type': '()', 'children': ['107']}; {'id': '107', 'type': 'boolean_operator', 'children': ['108', '111'], 'value': 'and'}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '110', 'type': 'False', 'children': []}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': '<='}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'True', 'children': []}; {'id': '117', 'type': 'if_statement', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'mm_option'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'both'"}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'if_statement', 'children': ['123', '126', '134', '146']}; {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'is'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '125', 'type': 'False', 'children': []}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'if_statement', 'children': ['128', '131']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '<='}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'return_statement', 'children': ['133']}; {'id': '133', 'type': 'True', 'children': []}; {'id': '134', 'type': 'elif_clause', 'children': ['135', '138']}; {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'is'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '137', 'type': 'False', 'children': []}; {'id': '138', 'type': 'block', 'children': ['139']}; {'id': '139', 'type': 'if_statement', 'children': ['140', '143']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '<='}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'return_statement', 'children': ['145']}; {'id': '145', 'type': 'True', 'children': []}; {'id': '146', 'type': 'elif_clause', 'children': ['147', '164']}; {'id': '147', 'type': 'boolean_operator', 'children': ['148', '156'], 'value': 'and'}; {'id': '148', 'type': '()', 'children': ['149']}; {'id': '149', 'type': 'boolean_operator', 'children': ['150', '153'], 'value': 'and'}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'is'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '152', 'type': 'False', 'children': []}; {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': '<='}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'r_mm'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '156', 'type': '()', 'children': ['157']}; {'id': '157', 'type': 'boolean_operator', 'children': ['158', '161'], 'value': 'and'}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'is'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '160', 'type': 'False', 'children': []}; {'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': '<='}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'p_mm'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'mismatches'}; {'id': '164', 'type': 'block', 'children': ['165']}; {'id': '165', 'type': 'return_statement', 'children': ['166']}; {'id': '166', 'type': 'True', 'children': []}; {'id': '167', 'type': 'return_statement', 'children': ['168']}; {'id': '168', 'type': 'False', 'children': []} | def check_mismatches(read, pair, mismatches, mm_option, req_map):
if pair is False:
mm = count_mismatches(read)
if mm is False:
return False
if mismatches is False:
return True
if mm <= mismatches:
return True
r_mm = count_mismatches(read)
p_mm = count_mismatches(pair)
if r_mm is False and p_mm is False:
return False
if mismatches is False:
return True
if req_map is True:
if r_mm is False or p_mm is False:
return False
if mm_option == 'one':
if (r_mm is not False and r_mm <= mismatches) or (p_mm is not False and p_mm <= mismatches):
return True
if mm_option == 'both':
if r_mm is False:
if p_mm <= mismatches:
return True
elif p_mm is False:
if r_mm <= mismatches:
return True
elif (r_mm is not False and r_mm <= mismatches) and (p_mm is not False and p_mm <= mismatches):
return True
return False |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_steam'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '25', '33', '47', '61', '84']}; {'id': '5', 'type': 'expression_statement', 'children': ['6']}; {'id': '6', 'type': 'assignment', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '8', 'type': 'lambda', 'children': ['9', '11']}; {'id': '9', 'type': 'lambda_parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'udd'}; {'id': '11', 'type': 'conditional_expression', 'children': ['12', '16', '24'], 'value': 'if'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Steam'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'udd'}; {'id': '16', 'type': 'call', 'children': ['17', '22']}; {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'udd'}; {'id': '24', 'type': 'None', 'children': []}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'plat'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'platform'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'system'}; {'id': '32', 'type': 'argument_list', 'children': []}; {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '=='}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'plat'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'Darwin'"}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'default_osx_userdata_path'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'if_statement', 'children': ['48', '51']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'plat'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'Linux'"}; {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'return_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'default_linux_userdata_path'}; {'id': '60', 'type': 'argument_list', 'children': []}; {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '=='}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'plat'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'Windows'"}; {'id': '65', 'type': 'block', 'children': ['66', '74']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'possible_dir'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'winutils'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'find_userdata_directory'}; {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'return_statement', 'children': ['75']}; {'id': '75', 'type': 'conditional_expression', 'children': ['76', '80', '83'], 'value': 'if'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'helper'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'possible_dir'}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'possible_dir'}; {'id': '82', 'type': 'None', 'children': []}; {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'return_statement', 'children': ['85']}; {'id': '85', 'type': 'None', 'children': []} | def get_steam():
helper = lambda udd: Steam(udd) if os.path.exists(udd) else None
plat = platform.system()
if plat == 'Darwin':
return helper(paths.default_osx_userdata_path())
if plat == 'Linux':
return helper(paths.default_linux_userdata_path())
if plat == 'Windows':
possible_dir = winutils.find_userdata_directory()
return helper(possible_dir) if possible_dir is not None else None
return None |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_barcodes'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'nIds'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'codeLen'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '8', 'type': 'block', 'children': ['9', '39', '54', '75', '87', '112', '116', '192']}; {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '15']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': 'next_code'}; {'id': '11', 'type': 'parameters', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '25'], 'value': '+'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '24'], 'value': '+'}; {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '21', 'type': 'slice', 'children': ['22', '23']}; {'id': '22', 'type': 'colon', 'children': []}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '25', 'type': '()', 'children': ['26']}; {'id': '26', 'type': 'conditional_expression', 'children': ['27', '34', '38'], 'value': 'if'}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '29', 'type': 'slice', 'children': ['30', '33']}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '32'], 'value': '+'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '33', 'type': 'colon', 'children': []}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '<'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'string', 'children': [], 'value': "''"}; {'id': '39', 'type': 'function_definition', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'function_name', 'children': [], 'value': 'rand_base'}; {'id': '41', 'type': 'parameters', 'children': []}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'return_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'choice'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'list', 'children': ['50', '51', '52', '53'], 'value': "['A', 'T', 'C', 'G']"}; {'id': '50', 'type': 'string', 'children': [], 'value': "'A'"}; {'id': '51', 'type': 'string', 'children': [], 'value': "'T'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'C'"}; {'id': '53', 'type': 'string', 'children': [], 'value': "'G'"}; {'id': '54', 'type': 'function_definition', 'children': ['55', '56', '58']}; {'id': '55', 'type': 'function_name', 'children': [], 'value': 'rand_seq'}; {'id': '56', 'type': 'parameters', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'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': 'list_comprehension', 'children': ['66', '69']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'rand_base'}; {'id': '68', 'type': 'argument_list', 'children': []}; {'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'hpf'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}; {'id': '83', 'type': 'string', 'children': [], 'value': "'aaaa|cccc|gggg|tttt'"}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'IGNORECASE'}; {'id': '87', 'type': 'while_statement', 'children': ['88', '89']}; {'id': '88', 'type': 'True', 'children': []}; {'id': '89', 'type': 'block', 'children': ['90', '98']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '93', 'type': 'list', 'children': ['94'], 'value': '[rand_seq(codeLen)]'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'rand_seq'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'codeLen'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '110']}; {'id': '99', 'type': '()', 'children': ['100']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '109'], 'value': 'is'}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'hpf'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '109', 'type': 'None', 'children': []}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'break_statement', 'children': []}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '115', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '116', 'type': 'while_statement', 'children': ['117', '123']}; {'id': '117', 'type': 'comparison_operator', 'children': ['118', '122'], 'value': '<'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'nIds'}; {'id': '123', 'type': 'block', 'children': ['124', '128', '182']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'augmented_assignment', 'children': ['126', '127'], 'value': '-='}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '127', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '133', '149']}; {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': '<'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '131', 'type': 'unary_operator', 'children': ['132'], 'value': '-'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'codeLen'}; {'id': '133', 'type': 'block', 'children': ['134', '139']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '137', 'type': 'unary_operator', 'children': ['138'], 'value': '-'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'codes'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'rand_seq'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'codeLen'}; {'id': '149', 'type': 'else_clause', 'children': ['150']}; {'id': '150', 'type': 'block', 'children': ['151', '165']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'nc'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'next_code'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '160', '164']}; {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'rand_base'}; {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '162', 'type': 'unary_operator', 'children': ['163'], 'value': '-'}; {'id': '163', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '165', 'type': 'if_statement', 'children': ['166', '174']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '173'], 'value': 'is'}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'hpf'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'nc'}; {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'block', 'children': ['175']}; {'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': 'codes'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'nc'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '192', 'type': 'return_statement', 'children': ['193']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'codes'} | def generate_barcodes(nIds, codeLen=12):
def next_code(b, c, i):
return c[:i] + b + (c[i+1:] if i < -1 else '')
def rand_base():
return random.choice(['A', 'T', 'C', 'G'])
def rand_seq(n):
return ''.join([rand_base() for _ in range(n)])
hpf = re.compile('aaaa|cccc|gggg|tttt', re.IGNORECASE)
while True:
codes = [rand_seq(codeLen)]
if (hpf.search(codes[0]) is None):
break
idx = 0
while len(codes) < nIds:
idx -= 1
if idx < -codeLen:
idx = -1
codes.append(rand_seq(codeLen))
else:
nc = next_code(rand_base(), codes[-1], idx)
if hpf.search(nc) is None:
codes.append(nc)
codes = list(set(codes))
return codes |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'ERROR', 'children': ['2']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '8']}; {'id': '3', 'type': 'function_name', 'children': [], 'value': 'parse_fasta_annotations'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6', '7']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'annot_tables'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'trans_table'}; {'id': '8', 'type': 'block', 'children': ['9', '57', '215', '235', '246', '260', '277']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'annot_tables'}; {'id': '12', 'type': 'False', 'children': []}; {'id': '13', 'type': 'block', 'children': ['14', '18']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'annots'}; {'id': '17', 'type': 'dictionary', 'children': []}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'annot_tables'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '28']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cds'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '28', 'type': 'block', 'children': ['29', '45']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '36']}; {'id': '31', 'type': 'pattern_list', 'children': ['32', '33', '34', '35']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '36', 'type': 'call', 'children': ['37', '44']}; {'id': '37', 'type': 'attribute', 'children': ['38', '43']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cds'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'annots'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '50', 'type': 'list', 'children': ['51', '52', '53'], 'value': '[start, end, int(strand)]'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60', '203', '208']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '60', 'type': 'ERROR', 'children': ['61', '160', '179', '180', '182', '183', '185', '191', '197', '200']}; {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '67', '78', '131']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'parse_fasta'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '67', 'type': 'ERROR', 'children': ['68', '73']}; {'id': '68', 'type': 'call', 'children': ['69', '70', '72']}; {'id': '69', 'type': 'string', 'children': [], 'value': "'\n print('"}; {'id': '70', 'type': 'ERROR', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '72', 'type': 'argument_list', 'children': []}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'in'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'ID='"}; {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '78', 'type': 'block', 'children': ['79', '101']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '82', 'type': 'subscript', 'children': ['83', '100']}; {'id': '83', 'type': 'call', 'children': ['84', '97']}; {'id': '84', 'type': 'attribute', 'children': ['85', '96']}; {'id': '85', 'type': 'subscript', 'children': ['86', '95']}; {'id': '86', 'type': 'call', 'children': ['87', '92']}; {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94']}; {'id': '93', 'type': 'string', 'children': [], 'value': "'ID='"}; {'id': '94', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '95', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '104', 'type': 'subscript', 'children': ['105', '130']}; {'id': '105', 'type': 'call', 'children': ['106', '124']}; {'id': '106', 'type': 'attribute', 'children': ['107', '123']}; {'id': '107', 'type': 'subscript', 'children': ['108', '122']}; {'id': '108', 'type': 'call', 'children': ['109', '120']}; {'id': '109', 'type': 'attribute', 'children': ['110', '119']}; {'id': '110', 'type': 'subscript', 'children': ['111', '118']}; {'id': '111', 'type': 'call', 'children': ['112', '117']}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}; {'id': '113', 'type': 'subscript', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '115', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '129']}; {'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '%'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'_%s'"}; {'id': '127', 'type': '()', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'ID'}; {'id': '129', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '131', 'type': 'else_clause', 'children': ['132']}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '136', 'type': 'subscript', 'children': ['137', '159']}; {'id': '137', 'type': 'call', 'children': ['138', '156']}; {'id': '138', 'type': 'attribute', 'children': ['139', '155']}; {'id': '139', 'type': 'subscript', 'children': ['140', '154']}; {'id': '140', 'type': 'call', 'children': ['141', '152']}; {'id': '141', 'type': 'attribute', 'children': ['142', '151']}; {'id': '142', 'type': 'subscript', 'children': ['143', '150']}; {'id': '143', 'type': 'call', 'children': ['144', '149']}; {'id': '144', 'type': 'attribute', 'children': ['145', '148']}; {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}; {'id': '157', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '158', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'locus'}; {'id': '163', 'type': 'subscript', 'children': ['164', '178']}; {'id': '164', 'type': 'call', 'children': ['165', '176']}; {'id': '165', 'type': 'attribute', 'children': ['166', '175']}; {'id': '166', 'type': 'subscript', 'children': ['167', '174']}; {'id': '167', 'type': 'call', 'children': ['168', '173']}; {'id': '168', 'type': 'attribute', 'children': ['169', '172']}; {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '171', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '173', 'type': 'argument_list', 'children': []}; {'id': '174', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}; {'id': '177', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '178', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '179', 'type': 'string', 'children': [], 'value': "'\n info = seq[0].split('"}; {'id': '180', 'type': 'ERROR', 'children': ['181']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '183', 'type': 'ERROR', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'subscript', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '199', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': '=='}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'1'"}; {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}; {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '207', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '208', 'type': 'else_clause', 'children': ['209']}; {'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': 'strand'}; {'id': '213', 'type': 'unary_operator', 'children': ['214'], 'value': '-'}; {'id': '214', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '218', 'type': 'list', 'children': ['219'], 'value': "[''.join(info[4].split()[1:])]"}; {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}; {'id': '221', 'type': 'string', 'children': [], 'value': "''"}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'subscript', 'children': ['225', '232']}; {'id': '225', 'type': 'call', 'children': ['226', '231']}; {'id': '226', 'type': 'attribute', 'children': ['227', '230']}; {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '229', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '231', 'type': 'argument_list', 'children': []}; {'id': '232', 'type': 'slice', 'children': ['233', '234']}; {'id': '233', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '234', 'type': 'colon', 'children': []}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '243']}; {'id': '237', 'type': 'pattern_list', 'children': ['238', '239', '241', '242']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'else'}; {'id': '239', 'type': 'ERROR', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'annots'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'locus'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}; {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '249', 'type': 'subscript', 'children': ['250', '259']}; {'id': '250', 'type': 'call', 'children': ['251', '256']}; {'id': '251', 'type': 'attribute', 'children': ['252', '255']}; {'id': '252', 'type': 'subscript', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '256', 'type': 'argument_list', 'children': ['257', '258']}; {'id': '257', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '258', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '259', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}; {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '263', 'type': 'dictionary', 'children': ['264', '268', '274']}; {'id': '264', 'type': 'pair', 'children': ['265', '266']}; {'id': '265', 'type': 'string', 'children': [], 'value': "'transl_table'"}; {'id': '266', 'type': 'list', 'children': ['267'], 'value': '[trans_table]'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'trans_table'}; {'id': '268', 'type': 'pair', 'children': ['269', '270']}; {'id': '269', 'type': 'string', 'children': [], 'value': "'translation'"}; {'id': '270', 'type': 'list', 'children': ['271'], 'value': '[seq[1]]'}; {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '273', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '274', 'type': 'pair', 'children': ['275', '276']}; {'id': '275', 'type': 'string', 'children': [], 'value': "'product'"}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'yield', 'children': ['279']}; {'id': '279', 'type': 'expression_list', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '281', 'type': 'list', 'children': ['282', '283', '287'], 'value': '[locus, [start, end, strand], info]'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'locus'}; {'id': '283', 'type': 'list', 'children': ['284', '285', '286'], 'value': '[start, end, strand]'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'strand'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'info'} | def parse_fasta_annotations(fastas, annot_tables, trans_table):
if annot_tables is not False:
annots = {}
for table in annot_tables:
for cds in open(table):
ID, start, end, strand = cds.strip().split()
annots[ID] = [start, end, int(strand)]
for fasta in fastas:
for seq in parse_fasta(fasta):
if ('
print('
exit()
if 'ID=' in seq[0]:
ID = seq[0].rsplit('ID=', 1)[1].split(';', 1)[0]
contig = seq[0].split()[0].split('>')[1].rsplit('_%s' % (ID), 1)[0]
else:
contig = seq[0].split()[0].split('>')[1].rsplit('_', 1)[0]
locus = seq[0].split()[0].split('>')[1]
if ('
info = seq[0].split('
start, end, strand = int(info[1]), int(info[2]), info[3]
if strand == '1':
strand = 1
else:
strand = -1
product = [''.join(info[4].split()[1:])]
else:
start, end, strand = annots[locus]
product = seq[0].split(' ', 1)[1]
info = {'transl_table':[trans_table], \
'translation':[seq[1]], \
'product':product}
yield contig, [locus, [start, end, strand], info] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_consensus'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '32', '75', '93', '123', '183', '189', '195']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'nucs'}; {'id': '9', 'type': 'list', 'children': ['10', '11', '12', '13', '14'], 'value': "['A', 'T', 'G', 'C', 'N']"}; {'id': '10', 'type': 'string', 'children': [], 'value': "'A'"}; {'id': '11', 'type': 'string', 'children': [], 'value': "'T'"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'G'"}; {'id': '13', 'type': 'string', 'children': [], 'value': "'C'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'N'"}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'list_comprehension', 'children': ['22', '25', '28']}; {'id': '22', 'type': 'subscript', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '25', 'type': 'for_in_clause', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'nucs'}; {'id': '28', 'type': 'if_clause', 'children': ['29']}; {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'in'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '32', 'type': 'try_statement', 'children': ['33', '51']}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'list_comprehension', 'children': ['41', '44', '47']}; {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '44', 'type': 'for_in_clause', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'nucs'}; {'id': '47', 'type': 'if_clause', 'children': ['48']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'in'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '51', 'type': 'except_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53', '61', '67', '73']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}; {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'consensus'"}; {'id': '58', 'type': 'tuple', 'children': ['59', '60']}; {'id': '59', 'type': 'string', 'children': [], 'value': "'N'"}; {'id': '60', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '66']}; {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '65', 'type': 'string', 'children': [], 'value': "'consensus frequency'"}; {'id': '66', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'reference frequency'"}; {'id': '72', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '78', 'type': 'list_comprehension', 'children': ['79', '84', '87']}; {'id': '79', 'type': 'tuple', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '87', 'type': 'if_clause', 'children': ['88']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': '=='}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'nuc'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '93', 'type': 'if_statement', 'children': ['94', '101', '110']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '100'], 'value': '=='}; {'id': '95', 'type': 'subscript', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'consensus'"}; {'id': '107', 'type': 'tuple', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'id': '109', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'bases'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'consensus'"}; {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'choice'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '123', 'type': 'if_statement', 'children': ['124', '127', '136']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': '=='}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '127', 'type': 'block', 'children': ['128', '132']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'c_freq'}; {'id': '131', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ref_freq'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'id': '136', 'type': 'else_clause', 'children': ['137']}; {'id': '137', 'type': 'block', 'children': ['138', '154']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'c_freq'}; {'id': '141', 'type': 'binary_operator', 'children': ['142', '150'], 'value': '/'}; {'id': '142', 'type': 'call', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'consensus'"}; {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '160', '165']}; {'id': '155', 'type': 'comparison_operator', 'children': ['156', '159'], 'value': 'not'}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'ref'"}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'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': 'ref_freq'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '165', 'type': 'else_clause', 'children': ['166']}; {'id': '166', 'type': 'block', 'children': ['167']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ref_freq'}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '179'], 'value': '/'}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'ref'"}; {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}; {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '187', 'type': 'string', 'children': [], 'value': "'consensus frequency'"}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'c_freq'}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '194']}; {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '193', 'type': 'string', 'children': [], 'value': "'reference frequency'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'ref_freq'}; {'id': '195', 'type': 'return_statement', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'bases'} | def find_consensus(bases):
nucs = ['A', 'T', 'G', 'C', 'N']
total = sum([bases[nuc] for nuc in nucs if nuc in bases])
try:
top = max([bases[nuc] for nuc in nucs if nuc in bases])
except:
bases['consensus'] = ('N', 'n/a')
bases['consensus frequency'] = 'n/a'
bases['reference frequency'] = 'n/a'
return bases
top = [(nuc, bases[nuc]) for nuc in bases if bases[nuc] == top]
if top[0][1] == 0:
bases['consensus'] = ('n/a', 0)
else:
bases['consensus'] = random.choice(top)
if total == 0:
c_freq = 'n/a'
ref_freq = 'n/a'
else:
c_freq = float(bases['consensus'][1]) / float(total)
if bases['ref'] not in bases:
ref_freq = 0
else:
ref_freq = float(bases[bases['ref']]) / float(total)
bases['consensus frequency'] = c_freq
bases['reference frequency'] = ref_freq
return bases |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_consensus'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'genomes'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '128', '204']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'cons'}; {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '14', '22']}; {'id': '11', 'type': 'pattern_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'contigs'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'genomes'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23', '29']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}; {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cons'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '28', 'type': 'dictionary', 'children': []}; {'id': '29', 'type': 'for_statement', 'children': ['30', '33', '41']}; {'id': '30', 'type': 'pattern_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'contigs'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '40', 'type': 'argument_list', 'children': []}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'for_statement', 'children': ['43', '46', '54']}; {'id': '43', 'type': 'pattern_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55', '70', '82']}; {'id': '55', 'type': 'if_statement', 'children': ['56', '61']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'not'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cons'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '69']}; {'id': '64', 'type': 'subscript', 'children': ['65', '68']}; {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'cons'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '69', 'type': 'dictionary', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '73', 'type': 'assignment', 'children': ['74', '81']}; {'id': '74', 'type': 'subscript', 'children': ['75', '80']}; {'id': '75', 'type': 'subscript', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'cons'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '81', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '82', 'type': 'for_statement', 'children': ['83', '86', '93']}; {'id': '83', 'type': 'pattern_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '92']}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '91', 'type': 'string', 'children': [], 'value': "'bp_stats'"}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '93', 'type': 'block', 'children': ['94', '108', '121']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'pattern_list', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '99', 'type': 'expression_list', 'children': ['100', '103']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'ref'"}; {'id': '103', 'type': 'subscript', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'ps'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'consensus'"}; {'id': '107', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '112']}; {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '=='}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '111', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'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': 'seq'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'consensus'}; {'id': '128', 'type': 'for_statement', 'children': ['129', '132', '137']}; {'id': '129', 'type': 'pattern_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'cons'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '136', 'type': 'argument_list', 'children': []}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'for_statement', 'children': ['139', '142', '147']}; {'id': '139', 'type': 'pattern_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'contigs'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '146', 'type': 'argument_list', 'children': []}; {'id': '147', 'type': 'block', 'children': ['148', '156', '164', '198']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '%'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'%s.%s.consensus.fa'"}; {'id': '153', 'type': 'tuple', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '161', 'type': 'argument_list', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '163', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '164', 'type': 'for_statement', 'children': ['165', '168', '173']}; {'id': '165', 'type': 'pattern_list', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'contigs'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '172', 'type': 'argument_list', 'children': []}; {'id': '173', 'type': 'block', 'children': ['174', '185']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '177', 'type': 'argument_list', 'children': ['178', '182']}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '%'}; {'id': '179', 'type': 'string', 'children': [], 'value': "'>%s'"}; {'id': '180', 'type': '()', 'children': ['181']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'contig'}; {'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'f'}; {'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', '195']}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'string', 'children': [], 'value': "''"}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '195', 'type': 'keyword_argument', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '203', 'type': 'argument_list', 'children': []}; {'id': '204', 'type': 'return_statement', 'children': ['205']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'cons'} | def print_consensus(genomes):
cons = {}
for genome, contigs in list(genomes.items()):
cons[genome] = {}
for contig, samples in list(contigs.items()):
for sample, stats in list(samples.items()):
if sample not in cons[genome]:
cons[genome][sample] = {}
seq = cons[genome][sample][contig] = []
for pos, ps in enumerate(stats['bp_stats'], 1):
ref, consensus = ps['ref'], ps['consensus'][0]
if consensus == 'n/a':
consensus = ref.lower()
seq.append(consensus)
for genome, samples in cons.items():
for sample, contigs in samples.items():
fn = '%s.%s.consensus.fa' % (genome, sample)
f = open(fn, 'w')
for contig, seq in contigs.items():
print('>%s' % (contig), file = f)
print(''.join(seq), file = f)
f.close()
return cons |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_cov'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cov_table'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'scaffold2genome'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '15', '179', '195', '255']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '10', 'type': 'dictionary', 'children': []}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '14', 'type': 'dictionary', 'children': []}; {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '21']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cov_table'}; {'id': '21', 'type': 'block', 'children': ['22', '35', '126', '132', '155', '161']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '25', 'type': 'call', 'children': ['26', '33']}; {'id': '26', 'type': 'attribute', 'children': ['27', '32']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '35', 'type': 'if_statement', 'children': ['36', '41', '124']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '41', 'type': 'ERROR', 'children': ['42', '43', '76', '79', '80', '121']}; {'id': '42', 'type': 'ERROR', 'children': []}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '45', 'type': 'subscript', 'children': ['46', '51', '53']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '48', 'type': 'slice', 'children': ['49', '50']}; {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'colon', 'children': []}; {'id': '51', 'type': 'ERROR', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '72', '75'], 'value': 'in'}; {'id': '54', 'type': 'subscript', 'children': ['55', '71']}; {'id': '55', 'type': 'call', 'children': ['56', '68']}; {'id': '56', 'type': 'attribute', 'children': ['57', '67']}; {'id': '57', 'type': 'subscript', 'children': ['58', '65']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'rsplit'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}; {'id': '63', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '65', 'type': 'unary_operator', 'children': ['66'], 'value': '-'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}; {'id': '69', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'ERROR', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '76', 'type': 'ERROR', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'continue'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'scaffold'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '80', 'type': 'subscript', 'children': ['81', '111', '113']}; {'id': '81', 'type': 'subscript', 'children': ['82', '96', '98']}; {'id': '82', 'type': 'call', 'children': ['83', '91', '94']}; {'id': '83', 'type': 'call', 'children': ['84', '89']}; {'id': '84', 'type': 'attribute', 'children': ['85', '88']}; {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': "': '"}; {'id': '91', 'type': 'ERROR', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '96', 'type': 'ERROR', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'covs'}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '103', '106'], 'value': 'in'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '103', 'type': 'ERROR', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '108', 'type': 'slice', 'children': ['109', '110']}; {'id': '109', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '110', 'type': 'colon', 'children': []}; {'id': '111', 'type': 'ERROR', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '113', 'type': 'comparison_operator', 'children': ['114', '117', '120'], 'value': 'in'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '*'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '117', 'type': 'ERROR', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'covs'}; {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'not'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'scaffold'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'scaffold2genome'}; {'id': '124', 'type': 'block', 'children': ['125']}; {'id': '125', 'type': 'continue_statement', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'scaffold2genome'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'scaffold'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}; {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'not'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '136', 'type': 'block', 'children': ['137', '143']}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '142']}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '148']}; {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '148', 'type': 'dictionary_comprehension', 'children': ['149', '152']}; {'id': '149', 'type': 'pair', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '151', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '152', 'type': 'for_in_clause', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'augmented_assignment', 'children': ['157', '160'], 'value': '+='}; {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '161', 'type': 'for_statement', 'children': ['162', '165', '170']}; {'id': '162', 'type': 'pattern_list', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'bases'}; {'id': '170', 'type': 'block', 'children': ['171']}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'augmented_assignment', 'children': ['173', '178'], 'value': '+='}; {'id': '173', 'type': 'subscript', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'coverage'}; {'id': '182', 'type': 'dictionary', 'children': ['183', '186', '189', '192']}; {'id': '183', 'type': 'pair', 'children': ['184', '185']}; {'id': '184', 'type': 'string', 'children': [], 'value': "'genome'"}; {'id': '185', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '186', 'type': 'pair', 'children': ['187', '188']}; {'id': '187', 'type': 'string', 'children': [], 'value': "'genome size (bp)'"}; {'id': '188', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '189', 'type': 'pair', 'children': ['190', '191']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'sample'"}; {'id': '191', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '192', 'type': 'pair', 'children': ['193', '194']}; {'id': '193', 'type': 'string', 'children': [], 'value': "'coverage'"}; {'id': '194', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '195', 'type': 'for_statement', 'children': ['196', '199', '204']}; {'id': '196', 'type': 'pattern_list', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '203', 'type': 'argument_list', 'children': []}; {'id': '204', 'type': 'block', 'children': ['205']}; {'id': '205', 'type': 'for_statement', 'children': ['206', '207', '208']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '208', 'type': 'block', 'children': ['209', '219', '228', '237', '246']}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'cov'}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '218'], 'value': '/'}; {'id': '213', 'type': 'subscript', 'children': ['214', '217']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '226']}; {'id': '221', 'type': 'attribute', 'children': ['222', '225']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'coverage'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'genome'"}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'call', 'children': ['230', '235']}; {'id': '230', 'type': 'attribute', 'children': ['231', '234']}; {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'coverage'}; {'id': '233', 'type': 'string', 'children': [], 'value': "'genome size (bp)'"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'length'}; {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '244']}; {'id': '239', 'type': 'attribute', 'children': ['240', '243']}; {'id': '240', 'type': 'subscript', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'coverage'}; {'id': '242', 'type': 'string', 'children': [], 'value': "'sample'"}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}; {'id': '247', 'type': 'call', 'children': ['248', '253']}; {'id': '248', 'type': 'attribute', 'children': ['249', '252']}; {'id': '249', 'type': 'subscript', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'coverage'}; {'id': '251', 'type': 'string', 'children': [], 'value': "'coverage'"}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'cov'}; {'id': '255', 'type': 'return_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'coverage'} | def parse_cov(cov_table, scaffold2genome):
size = {}
mapped = {}
for line in open(cov_table):
line = line.strip().split('\t')
if line[0].startswith('
samples = line[1:]
samples = [i.rsplit('/', 1)[-1].split('.', 1)[0] for i in samples]
continue
scaffold, length = line[0].split(': ')
length = float(length)
covs = [float(i) for i in line[1:]]
bases = [c * length for c in covs]
if scaffold not in scaffold2genome:
continue
genome = scaffold2genome[scaffold]
if genome not in size:
size[genome] = 0
mapped[genome] = {sample:0 for sample in samples}
size[genome] += length
for sample, count in zip(samples, bases):
mapped[genome][sample] += count
coverage = {'genome':[], 'genome size (bp)':[], 'sample':[], 'coverage':[]}
for genome, length in size.items():
for sample in samples:
cov = mapped[genome][sample] / length
coverage['genome'].append(genome)
coverage['genome size (bp)'].append(length)
coverage['sample'].append(sample)
coverage['coverage'].append(cov)
return pd.DataFrame(coverage) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_genome_matrix'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'id2desc'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '8', 'type': 'block', 'children': ['9', '17', '24', '35', '85', '98', '106', '117', '189']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27', '31', '33']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '27', 'type': 'ERROR', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'\n print('"}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '31', 'type': 'type', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '33', 'type': 'list', 'children': ['34'], 'value': '[fasta]'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '38', 'type': 'block', 'children': ['39', '75']}; {'id': '39', 'type': 'if_statement', 'children': ['40', '43', '48']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': '=='}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'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': 'average'}; {'id': '47', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '48', 'type': 'else_clause', 'children': ['49']}; {'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': 'average'}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'average'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'list_comprehension', 'children': ['59', '68']}; {'id': '59', 'type': 'subscript', 'children': ['60', '67']}; {'id': '60', 'type': 'subscript', 'children': ['61', '66']}; {'id': '61', 'type': 'subscript', 'children': ['62', '65']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '67', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'other'}; {'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': 'line'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'average'}; {'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', '95']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'string', 'children': [], 'value': "''"}; {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109', '113', '115']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '109', 'type': 'ERROR', 'children': ['110', '111', '112']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'\n print('"}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '113', 'type': 'type', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '115', 'type': 'list', 'children': ['116'], 'value': '[fasta]'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'fastas'}; {'id': '120', 'type': 'block', 'children': ['121', '179']}; {'id': '121', 'type': 'if_statement', 'children': ['122', '125', '130']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'percent'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '130', 'type': 'else_clause', 'children': ['131']}; {'id': '131', 'type': 'block', 'children': ['132', '146', '168']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'orthologs'}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'subscript', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'orfs'}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'list_comprehension', 'children': ['156', '157', '160']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '157', 'type': 'for_in_clause', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'id2desc'}; {'id': '160', 'type': 'if_clause', 'children': ['161']}; {'id': '161', 'type': 'comparison_operator', 'children': ['162', '167'], 'value': '=='}; {'id': '162', 'type': 'subscript', 'children': ['163', '166']}; {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'id2desc'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'fasta'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'percent'}; {'id': '171', 'type': 'binary_operator', 'children': ['172', '178'], 'value': '*'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '/'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'orthologs'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'orfs'}; {'id': '178', 'type': 'integer', 'children': [], 'value': '100'}; {'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': 'line'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'percent'}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '199']}; {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'string', 'children': [], 'value': "'\\t'"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'out'} | def print_genome_matrix(hits, fastas, id2desc, file_name):
out = open(file_name, 'w')
fastas = sorted(fastas)
print('
print('
for fasta in fastas:
line = [fasta]
for other in fastas:
if other == fasta:
average = '-'
else:
average = numpy.average([hits[fasta][other][i][3] for i in hits[fasta][other]])
line.append(str(average))
print('\t'.join(line), file=out)
print('', file=out)
print('
print('
for fasta in fastas:
line = [fasta]
for other in fastas:
if other == fasta:
percent = '-'
else:
orthologs = float(len(hits[fasta][other]))
orfs = float(len([i for i in id2desc if id2desc[i][0] == fasta]))
percent = float(orthologs / orfs) * 100
line.append(str(percent))
print('\t'.join(line), file=out) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'ERROR', 'children': ['2', '298', '304']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '17']}; {'id': '3', 'type': 'function_name', 'children': [], 'value': 'calc_thresholds'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6', '7', '14']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rbh'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'thresholds'}; {'id': '9', 'type': 'list', 'children': ['10', '11', '12', '13'], 'value': '[False, False, False, False]'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'False', 'children': []}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'stdevs'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '17', 'type': 'block', 'children': ['18', '25', '29', '70', '78', '84']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'calc_threshold'}; {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'thresholds'}; {'id': '23', 'type': 'unary_operator', 'children': ['24'], 'value': '-'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'norm_threshold'}; {'id': '28', 'type': 'dictionary', 'children': []}; {'id': '29', 'type': 'for_statement', 'children': ['30', '31', '42']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'permutations'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '41']}; {'id': '36', 'type': 'list_comprehension', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '38', 'type': 'for_in_clause', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'rbh'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '42', 'type': 'block', 'children': ['43', '58']}; {'id': '43', 'type': 'if_statement', 'children': ['44', '49']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '48'], 'value': 'not'}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'norm_threshold'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '57']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'norm_threshold'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '57', 'type': 'dictionary', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '69']}; {'id': '60', 'type': 'subscript', 'children': ['61', '66']}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'norm_threshold'}; {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '69', 'type': 'dictionary', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '77', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81', '83']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '81', 'type': 'ERROR', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'comparisons'}; {'id': '83', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'rbh'}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'for_statement', 'children': ['89', '90', '93']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'compare'}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'rbh'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '93', 'type': 'block', 'children': ['94', '108', '114', '121', '140', '170', '179', '188', '197', '206', '215']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'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': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'list', 'children': ['106', '107'], 'value': '[genome, compare]'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'compare'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '112']}; {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'in'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'comparisons'}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'continue_statement', 'children': []}; {'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': 'comparisons'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '124', 'type': 'dictionary', 'children': ['125', '128', '131', '134', '137']}; {'id': '125', 'type': 'pair', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': "'percent identity'"}; {'id': '127', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '128', 'type': 'pair', 'children': ['129', '130']}; {'id': '129', 'type': 'string', 'children': [], 'value': "'e-value'"}; {'id': '130', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '131', 'type': 'pair', 'children': ['132', '133']}; {'id': '132', 'type': 'string', 'children': [], 'value': "'bit score'"}; {'id': '133', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '134', 'type': 'pair', 'children': ['135', '136']}; {'id': '135', 'type': 'string', 'children': [], 'value': "'normalized bit score'"}; {'id': '136', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '137', 'type': 'pair', 'children': ['138', '139']}; {'id': '138', 'type': 'string', 'children': [], 'value': "'alignment length fraction'"}; {'id': '139', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '159']}; {'id': '142', 'type': 'pattern_list', 'children': ['143', '144', '155', '156', '157', '158']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '144', 'type': 'ERROR', 'children': ['145', '147', '154']}; {'id': '145', 'type': 'ERROR', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'in'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '149', 'type': 'subscript', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'rbh'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'compare'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'pident'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'length_fraction'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'norm_bit'}; {'id': '159', 'type': 'subscript', 'children': ['160', '167']}; {'id': '160', 'type': 'subscript', 'children': ['161', '166']}; {'id': '161', 'type': 'subscript', 'children': ['162', '165']}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'rbh'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'compare'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '167', 'type': 'slice', 'children': ['168', '169']}; {'id': '168', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '169', 'type': 'colon', 'children': []}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'call', 'children': ['172', '177']}; {'id': '172', 'type': 'attribute', 'children': ['173', '176']}; {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '175', 'type': 'string', 'children': [], 'value': "'percent identity'"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'pident'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '186']}; {'id': '181', 'type': 'attribute', 'children': ['182', '185']}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '184', 'type': 'string', 'children': [], 'value': "'alignment length fraction'"}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'length_fraction'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'call', 'children': ['190', '195']}; {'id': '190', 'type': 'attribute', 'children': ['191', '194']}; {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '193', 'type': 'string', 'children': [], 'value': "'e-value'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '204']}; {'id': '199', 'type': 'attribute', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'bit score'"}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'bit'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '213']}; {'id': '208', 'type': 'attribute', 'children': ['209', '212']}; {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '211', 'type': 'string', 'children': [], 'value': "'normalized bit score'"}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'norm_bit'}; {'id': '215', 'type': 'if_statement', 'children': ['216', '219', '287']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': 'is'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'calc_threshold'}; {'id': '218', 'type': 'True', 'children': []}; {'id': '219', 'type': 'ERROR', 'children': ['220', '226', '235', '244', '253', '254', '256', '257', '262', '267', '269', '276', '277', '279']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '225', 'type': 'string', 'children': [], 'value': "'normalized bit score'"}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}; {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'average'}; {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'average'}; {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'std'}; {'id': '238', 'type': 'call', 'children': ['239', '242']}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'std'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'norms'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'normal_thresh'}; {'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '-'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'average'}; {'id': '249', 'type': '()', 'children': ['250']}; {'id': '250', 'type': 'binary_operator', 'children': ['251', '252'], 'value': '*'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'std'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'stdevs'}; {'id': '253', 'type': 'string', 'children': [], 'value': "'\n print('"}; {'id': '254', 'type': 'ERROR', 'children': ['255']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '256', 'type': 'ERROR', 'children': []}; {'id': '257', 'type': 'subscript', 'children': ['258', '261']}; {'id': '258', 'type': 'subscript', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'norm_threshold'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'compare'}; {'id': '262', 'type': 'subscript', 'children': ['263', '266']}; {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'norm_threshold'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'compare'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'genome'}; {'id': '267', 'type': 'ERROR', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'normal_thresh'}; {'id': '269', 'type': 'ERROR', 'children': ['270']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '272', '275'], 'value': 'in'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'normal_thresh'}; {'id': '272', 'type': 'ERROR', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'for'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '277', 'type': 'ERROR', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'if'}; {'id': '279', 'type': 'comparison_operator', 'children': ['280', '286'], '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': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '286', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '287', 'type': 'block', 'children': ['288']}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '291', 'type': 'argument_list', 'children': ['292', '295']}; {'id': '292', 'type': 'concatenated_string', 'children': ['293', '294']}; {'id': '293', 'type': 'string', 'children': [], 'value': "'\n print('"}; {'id': '294', 'type': 'string', 'children': [], 'value': "'"}; {'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}; {'id': '299', 'type': 'call', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'if_statement', 'children': ['305', '308', '320']}; {'id': '305', 'type': 'comparison_operator', 'children': ['306', '307'], 'value': 'is'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'calc_threshold'}; {'id': '307', 'type': 'True', 'children': []}; {'id': '308', 'type': 'block', 'children': ['309']}; {'id': '309', 'type': 'return_statement', 'children': ['310']}; {'id': '310', 'type': 'binary_operator', 'children': ['311', '318'], 'value': '+'}; {'id': '311', 'type': 'subscript', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'thresholds'}; {'id': '313', 'type': 'slice', 'children': ['314', '315', '316']}; {'id': '314', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '315', 'type': 'colon', 'children': []}; {'id': '316', 'type': 'unary_operator', 'children': ['317'], 'value': '-'}; {'id': '317', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '318', 'type': 'list', 'children': ['319'], 'value': '[norm_threshold]'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'norm_threshold'}; {'id': '320', 'type': 'else_clause', 'children': ['321']}; {'id': '321', 'type': 'block', 'children': ['322']}; {'id': '322', 'type': 'return_statement', 'children': ['323']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'thresholds'} | def calc_thresholds(rbh, file_name, thresholds = [False, False, False, False], stdevs = 2):
calc_threshold = thresholds[-1]
norm_threshold = {}
for pair in itertools.permutations([i for i in rbh], 2):
if pair[0] not in norm_threshold:
norm_threshold[pair[0]] = {}
norm_threshold[pair[0]][pair[1]] = {}
out = open(file_name, 'w')
print('
comparisons = []
for genome in rbh:
for compare in rbh[genome]:
pair = ''.join(sorted([genome, compare]))
if pair in comparisons:
continue
comparisons.append(pair)
scores = {'percent identity': [], 'e-value': [], 'bit score': [], 'normalized bit score': [], 'alignment length fraction': []}
print('
for id in rbh[genome][compare]:
pident, length_fraction, e, bit, norm_bit = rbh[genome][compare][id][3:]
scores['percent identity'].append(pident)
scores['alignment length fraction'].append(length_fraction)
scores['e-value'].append(e)
scores['bit score'].append(bit)
scores['normalized bit score'].append(norm_bit)
if calc_threshold is True:
norms = scores['normalized bit score']
average = numpy.average(norms)
std = numpy.std(norms)
normal_thresh = average - (std * stdevs)
print('
print('
print('
norm_threshold[genome][compare], norm_threshold[compare][genome] = normal_thresh, normal_thresh
for score in scores:
print('
if len(scores[score]) > 0:
print('
print('', file=out)
out.close()
if calc_threshold is True:
return thresholds[0:-1] + [norm_threshold]
else:
return thresholds |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_property'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree_to_update'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'xpath_root'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'xpaths'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '8', 'type': 'block', 'children': ['9', '234', '241', '248']}; {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '17']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': 'update_element'}; {'id': '11', 'type': 'parameters', 'children': ['12', '13', '14', '15', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '17', 'type': 'block', 'children': ['18', '42', '51', '118', '124', '128', '232']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'has_root'}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '36'], 'value': 'and'}; {'id': '25', 'type': 'boolean_operator', 'children': ['26', '27'], 'value': 'and'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '32'], 'value': '>'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'pattern_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_xpath_tuple'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '51', 'type': 'if_statement', 'children': ['52', '53', '71', '86']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '53', 'type': 'block', 'children': ['54', '63']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '57', 'type': 'list', 'children': ['58'], 'value': '[get_element(elem, path)]'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_element'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'remove_element_attributes'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '70']}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '71', 'type': 'elif_clause', 'children': ['72', '74']}; {'id': '72', 'type': 'not_operator', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'has_root'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'wrap_value'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'remove_element'}; {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '86', 'type': 'else_clause', 'children': ['87']}; {'id': '87', 'type': 'block', 'children': ['88', '96']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get_xpath_branch'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '99', 'type': 'conditional_expression', 'children': ['100', '101', '104'], 'value': 'if'}; {'id': '100', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '!='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '103', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '104', 'type': 'list_comprehension', 'children': ['105', '111']}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'remove_element'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '110', 'type': 'True', 'children': []}; {'id': '111', 'type': 'for_in_clause', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'get_elements'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '118', 'type': 'if_statement', 'children': ['119', '121']}; {'id': '119', 'type': 'not_operator', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'return_statement', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '127', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '128', 'type': 'for_statement', 'children': ['129', '132', '139']}; {'id': '129', 'type': 'pattern_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'wrap_value'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'vals'}; {'id': '139', 'type': 'block', 'children': ['140', '144', '159', '176']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'elem_to_update'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'has_root'}; {'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': 'elem_to_update'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'insert_element'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154', '158']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '154', 'type': '()', 'children': ['155']}; {'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '162', 'type': 'conditional_expression', 'children': ['163', '169', '175'], 'value': 'if'}; {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '169', 'type': 'not_operator', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '176', 'type': 'if_statement', 'children': ['177', '179', '193', '213']}; {'id': '177', 'type': 'not_operator', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'insert_element'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190', '191', '192']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'elem_to_update'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '193', 'type': 'elif_clause', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '195', 'type': 'block', 'children': ['196']}; {'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': 'items'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'insert_element'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207', '208']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'elem_to_update'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '208', 'type': 'dictionary_splat', 'children': ['209']}; {'id': '209', 'type': 'dictionary', 'children': ['210']}; {'id': '210', 'type': 'pair', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '213', 'type': 'else_clause', 'children': ['214']}; {'id': '214', 'type': 'block', 'children': ['215', '225']}; {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'set_element_attributes'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'elem_to_update'}; {'id': '220', 'type': 'dictionary_splat', 'children': ['221']}; {'id': '221', 'type': 'dictionary', 'children': ['222']}; {'id': '222', 'type': 'pair', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'val'}; {'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': 'items'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'elem_to_update'}; {'id': '232', 'type': 'return_statement', 'children': ['233']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}; {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'xpaths'}; {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'reduce_value'}; {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'xpaths'}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'filter_empty'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '248', 'type': 'if_statement', 'children': ['249', '254', '264']}; {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '251', 'type': 'argument_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'xpaths'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '254', 'type': 'block', 'children': ['255']}; {'id': '255', 'type': 'return_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'update_element'}; {'id': '258', 'type': 'argument_list', 'children': ['259', '260', '261', '262', '263']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'tree_to_update'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'xpath_root'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'xpaths'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '264', 'type': 'else_clause', 'children': ['265']}; {'id': '265', 'type': 'block', 'children': ['266', '270', '302']}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'each'}; {'id': '269', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '270', 'type': 'for_statement', 'children': ['271', '274', '278']}; {'id': '271', 'type': 'pattern_list', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'xpath'}; {'id': '274', 'type': 'call', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'xpaths'}; {'id': '278', 'type': 'block', 'children': ['279', '288']}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '282', 'type': 'conditional_expression', 'children': ['283', '286', '287'], 'value': 'if'}; {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '287', 'type': 'None', 'children': []}; {'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': 'each'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'call', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'update_element'}; {'id': '296', 'type': 'argument_list', 'children': ['297', '298', '299', '300', '301']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'tree_to_update'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'xpath_root'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'xpath'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '302', 'type': 'return_statement', 'children': ['303']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'each'} | def _update_property(tree_to_update, xpath_root, xpaths, values):
def update_element(elem, idx, root, path, vals):
has_root = bool(root and len(path) > len(root) and path.startswith(root))
path, attr = get_xpath_tuple(path)
if attr:
removed = [get_element(elem, path)]
remove_element_attributes(removed[0], attr)
elif not has_root:
removed = wrap_value(remove_element(elem, path))
else:
path = get_xpath_branch(root, path)
removed = [] if idx != 0 else [remove_element(e, path, True) for e in get_elements(elem, root)]
if not vals:
return removed
items = []
for i, val in enumerate(wrap_value(vals)):
elem_to_update = elem
if has_root:
elem_to_update = insert_element(elem, (i + idx), root)
val = val.decode('utf-8') if not isinstance(val, string_types) else val
if not attr:
items.append(insert_element(elem_to_update, i, path, val))
elif path:
items.append(insert_element(elem_to_update, i, path, **{attr: val}))
else:
set_element_attributes(elem_to_update, **{attr: val})
items.append(elem_to_update)
return items
xpaths = reduce_value(xpaths)
values = filter_empty(values)
if isinstance(xpaths, string_types):
return update_element(tree_to_update, 0, xpath_root, xpaths, values)
else:
each = []
for index, xpath in enumerate(xpaths):
value = values[index] if values else None
each.extend(update_element(tree_to_update, index, xpath_root, xpath, value))
return each |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_complex_list'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'xpath_map'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '24', '46']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'validate_type'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '21', 'type': 'tuple', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28', '35']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_complex_definitions'}; {'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': 'complex_keys'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_complex_definitions'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '35', 'type': 'else_clause', 'children': ['36']}; {'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': 'complex_keys'}; {'id': '40', 'type': 'conditional_expression', 'children': ['41', '42', '45'], 'value': 'if'}; {'id': '41', 'type': 'dictionary', 'children': []}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'xpath_map'}; {'id': '44', 'type': 'None', 'children': []}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'xpath_map'}; {'id': '46', 'type': 'for_statement', 'children': ['47', '50', '57']}; {'id': '47', 'type': 'pattern_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'complex_struct'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'wrap_value'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '57', 'type': 'block', 'children': ['58', '71', '78']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'cs_idx'}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '70'], 'value': '+'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '66'], 'value': '+'}; {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '+'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '65', 'type': 'string', 'children': [], 'value': "'['"}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '70', 'type': 'string', 'children': [], 'value': "']'"}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'validate_type'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76', '77']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'cs_idx'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'complex_struct'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '78', 'type': 'for_statement', 'children': ['79', '82', '86']}; {'id': '79', 'type': 'pattern_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'cs_prop'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'cs_val'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'complex_struct'}; {'id': '86', 'type': 'block', 'children': ['87', '98', '122']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'cs_key'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'tuple', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'cs_idx'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cs_prop'}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102']}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'not'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'cs_prop'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'complex_keys'}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': '_validation_error'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108', '109', '110']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '108', 'type': 'None', 'children': []}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '110', 'type': '()', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'string', 'children': [], 'value': "'keys: {0}'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': "','"}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'complex_keys'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '129', '139']}; {'id': '123', 'type': 'not_operator', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'cs_val'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'validate_type'}; {'id': '133', 'type': 'argument_list', 'children': ['134', '135', '136']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'cs_key'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'cs_val'}; {'id': '136', 'type': 'tuple', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '139', 'type': 'else_clause', 'children': ['140']}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'for_statement', 'children': ['142', '145', '149']}; {'id': '142', 'type': 'pattern_list', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'list_idx'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'list_val'}; {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'cs_val'}; {'id': '149', 'type': 'block', 'children': ['150', '163']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'list_prop'}; {'id': '153', 'type': 'binary_operator', 'children': ['154', '162'], 'value': '+'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '158'], 'value': '+'}; {'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'cs_key'}; {'id': '157', 'type': 'string', 'children': [], 'value': "'['"}; {'id': '158', 'type': 'call', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'list_idx'}; {'id': '162', 'type': 'string', 'children': [], 'value': "']'"}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'validate_type'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168', '169']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'list_prop'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'list_val'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'string_types'} | def validate_complex_list(prop, value, xpath_map=None):
if value is not None:
validate_type(prop, value, (dict, list))
if prop in _complex_definitions:
complex_keys = _complex_definitions[prop]
else:
complex_keys = {} if xpath_map is None else xpath_map
for idx, complex_struct in enumerate(wrap_value(value)):
cs_idx = prop + '[' + str(idx) + ']'
validate_type(cs_idx, complex_struct, dict)
for cs_prop, cs_val in iteritems(complex_struct):
cs_key = '.'.join((cs_idx, cs_prop))
if cs_prop not in complex_keys:
_validation_error(prop, None, value, ('keys: {0}'.format(','.join(complex_keys))))
if not isinstance(cs_val, list):
validate_type(cs_key, cs_val, (string_types, list))
else:
for list_idx, list_val in enumerate(cs_val):
list_prop = cs_key + '[' + str(list_idx) + ']'
validate_type(list_prop, list_val, string_types) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_dates'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'xpath_map'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '22', '29']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'validate_type'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20', '21']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'date_keys'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '29', 'type': 'if_statement', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'date_keys'}; {'id': '31', 'type': 'block', 'children': ['32', '84', '90', '103', '109', '116', '123', '140', '157', '174', '191']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '40']}; {'id': '33', 'type': 'boolean_operator', 'children': ['34', '37'], 'value': 'or'}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'not'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'DATE_TYPE'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'date_keys'}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'not'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'DATE_VALUES'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'date_keys'}; {'id': '40', 'type': 'block', 'children': ['41', '65']}; {'id': '41', 'type': 'if_statement', 'children': ['42', '45', '52']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_complex_definitions'}; {'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': 'complex_keys'}; {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_complex_definitions'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '52', 'type': 'else_clause', 'children': ['53']}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'complex_keys'}; {'id': '57', 'type': 'conditional_expression', 'children': ['58', '61', '64'], 'value': 'if'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': '_complex_definitions'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'DATES'}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'xpath_map'}; {'id': '63', 'type': 'None', 'children': []}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'xpath_map'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_validation_error'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71', '72']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '70', 'type': 'None', 'children': []}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '72', 'type': '()', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'string', 'children': [], 'value': "'keys: {0}'"}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'string', 'children': [], 'value': "','"}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'complex_keys'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'date_type'}; {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'DATE_TYPE'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94']}; {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'not'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'date_type'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'DATE_TYPES'}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': '_validation_error'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100', '101', '102']}; {'id': '99', 'type': 'string', 'children': [], 'value': "'dates.type'"}; {'id': '100', 'type': 'None', 'children': []}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'date_type'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'DATE_TYPES'}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'date_vals'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'DATE_VALUES'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'validate_type'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114', '115']}; {'id': '113', 'type': 'string', 'children': [], 'value': "'dates.values'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'date_vals'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'date_vals'}; {'id': '123', 'type': 'if_statement', 'children': ['124', '131']}; {'id': '124', 'type': 'boolean_operator', 'children': ['125', '128'], 'value': 'and'}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '=='}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'date_type'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'DATE_TYPE_MISSING'}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '!='}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_validation_error'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '137', '138', '139']}; {'id': '136', 'type': 'string', 'children': [], 'value': "'len(dates.values)'"}; {'id': '137', 'type': 'None', 'children': []}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '139', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '148']}; {'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'and'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '=='}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'date_type'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'DATE_TYPE_SINGLE'}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '!='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '147', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': '_validation_error'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154', '155', '156']}; {'id': '153', 'type': 'string', 'children': [], 'value': "'len(dates.values)'"}; {'id': '154', 'type': 'None', 'children': []}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '157', 'type': 'if_statement', 'children': ['158', '165']}; {'id': '158', 'type': 'boolean_operator', 'children': ['159', '162'], 'value': 'and'}; {'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '=='}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'date_type'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'DATE_TYPE_RANGE'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '!='}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': '_validation_error'}; {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172', '173']}; {'id': '170', 'type': 'string', 'children': [], 'value': "'len(dates.values)'"}; {'id': '171', 'type': 'None', 'children': []}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '173', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '182']}; {'id': '175', 'type': 'boolean_operator', 'children': ['176', '179'], 'value': 'and'}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': '=='}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'date_type'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'DATE_TYPE_MULTIPLE'}; {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '<'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '181', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '182', 'type': 'block', 'children': ['183']}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': '_validation_error'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188', '189', '190']}; {'id': '187', 'type': 'string', 'children': [], 'value': "'len(dates.values)'"}; {'id': '188', 'type': 'None', 'children': []}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'dates_len'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'at least two'"}; {'id': '191', 'type': 'for_statement', 'children': ['192', '195', '199']}; {'id': '192', 'type': 'pattern_list', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'date_vals'}; {'id': '199', 'type': 'block', 'children': ['200', '211']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}; {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'date_key'}; {'id': '203', 'type': 'binary_operator', 'children': ['204', '210'], 'value': '+'}; {'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '+'}; {'id': '205', 'type': 'string', 'children': [], 'value': "'dates.value['"}; {'id': '206', 'type': 'call', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '210', 'type': 'string', 'children': [], 'value': "']'"}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'validate_type'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216', '217']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'date_key'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'string_types'} | def validate_dates(prop, value, xpath_map=None):
if value is not None:
validate_type(prop, value, dict)
date_keys = set(value)
if date_keys:
if DATE_TYPE not in date_keys or DATE_VALUES not in date_keys:
if prop in _complex_definitions:
complex_keys = _complex_definitions[prop]
else:
complex_keys = _complex_definitions[DATES] if xpath_map is None else xpath_map
_validation_error(prop, None, value, ('keys: {0}'.format(','.join(complex_keys))))
date_type = value[DATE_TYPE]
if date_type not in DATE_TYPES:
_validation_error('dates.type', None, date_type, DATE_TYPES)
date_vals = value[DATE_VALUES]
validate_type('dates.values', date_vals, list)
dates_len = len(date_vals)
if date_type == DATE_TYPE_MISSING and dates_len != 0:
_validation_error('len(dates.values)', None, dates_len, 0)
if date_type == DATE_TYPE_SINGLE and dates_len != 1:
_validation_error('len(dates.values)', None, dates_len, 1)
if date_type == DATE_TYPE_RANGE and dates_len != 2:
_validation_error('len(dates.values)', None, dates_len, 2)
if date_type == DATE_TYPE_MULTIPLE and dates_len < 2:
_validation_error('len(dates.values)', None, dates_len, 'at least two')
for idx, date in enumerate(date_vals):
date_key = 'dates.value[' + str(idx) + ']'
validate_type(date_key, date, string_types) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getCharacterSet'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '8', '12', '16', '20', '24', '236']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'string', 'children': [], 'value': "'''Get a character set with individual members or ranges.\n Current index is on '[', the start of the character set.\n '''"}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'chars'}; {'id': '11', 'type': 'string', 'children': [], 'value': "u''"}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '19', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'while_statement', 'children': ['25', '26']}; {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '31', '39', '168', '204', '231']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'escaped_slash'}; {'id': '30', 'type': 'False', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '38', 'type': 'argument_list', 'children': []}; {'id': '39', 'type': 'if_statement', 'children': ['40', '52', '99', '155']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '48'], 'value': 'and'}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '47'], 'value': '=='}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'lookahead'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'string', 'children': [], 'value': "u'-'"}; {'id': '48', 'type': 'not_operator', 'children': ['49']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '=='}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '51', 'type': 'string', 'children': [], 'value': "u'\\\\'"}; {'id': '52', 'type': 'block', 'children': ['53', '57', '63', '71', '89']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'c'}; {'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': 'self'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'c'}; {'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': 'next'}; {'id': '70', 'type': 'argument_list', 'children': []}; {'id': '71', 'type': 'if_statement', 'children': ['72', '81']}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '75'], 'value': 'or'}; {'id': '73', 'type': 'not_operator', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '75', 'type': '()', 'children': ['76']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'meta_chars'}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'raise_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'string', 'children': [], 'value': 'u"unexpected end of class range"'}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'augmented_assignment', 'children': ['91', '92'], 'value': '+='}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'chars'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'getCharacterRange'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '99', 'type': 'elif_clause', 'children': ['100', '103']}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': '=='}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '102', 'type': 'string', 'children': [], 'value': "u'\\\\'"}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'if_statement', 'children': ['105', '114', '128']}; {'id': '105', 'type': 'comparison_operator', 'children': ['106', '111'], 'value': 'in'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'lookahead'}; {'id': '110', 'type': 'argument_list', 'children': []}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'meta_chars'}; {'id': '114', 'type': 'block', 'children': ['115', '123', '127']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '122', 'type': 'argument_list', 'children': []}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'augmented_assignment', 'children': ['125', '126'], 'value': '+='}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'chars'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '127', 'type': 'continue_statement', 'children': []}; {'id': '128', 'type': 'elif_clause', 'children': ['129', '138']}; {'id': '129', 'type': 'comparison_operator', 'children': ['130', '135'], 'value': 'in'}; {'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': 'lookahead'}; {'id': '134', 'type': 'argument_list', 'children': []}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'string_code'}; {'id': '138', 'type': 'block', 'children': ['139', '147']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '146', 'type': 'argument_list', 'children': []}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'augmented_assignment', 'children': ['149', '150'], 'value': '+='}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'chars'}; {'id': '150', 'type': 'subscript', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'string_code'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '155', 'type': 'elif_clause', 'children': ['156', '163']}; {'id': '156', 'type': 'boolean_operator', 'children': ['157', '158'], 'value': 'and'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'not'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'meta_chars'}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'augmented_assignment', 'children': ['166', '167'], 'value': '+='}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'chars'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '168', 'type': 'if_statement', 'children': ['169', '172']}; {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '=='}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '171', 'type': 'string', 'children': [], 'value': "u']'"}; {'id': '172', 'type': 'block', 'children': ['173', '203']}; {'id': '173', 'type': 'if_statement', 'children': ['174', '181', '192']}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '180'], 'value': '=='}; {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'lookahead'}; {'id': '179', 'type': 'argument_list', 'children': []}; {'id': '180', 'type': 'string', 'children': [], 'value': "u'{'"}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '187']}; {'id': '184', 'type': 'list_pattern', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'getQuantifier'}; {'id': '191', 'type': 'argument_list', 'children': []}; {'id': '192', 'type': 'else_clause', 'children': ['193']}; {'id': '193', 'type': 'block', 'children': ['194', '199']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '197', 'type': 'unary_operator', 'children': ['198'], 'value': '-'}; {'id': '198', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '203', 'type': 'break_statement', 'children': []}; {'id': '204', 'type': 'if_statement', 'children': ['205', '221']}; {'id': '205', 'type': 'boolean_operator', 'children': ['206', '213'], 'value': 'and'}; {'id': '206', 'type': 'boolean_operator', 'children': ['207', '208'], 'value': 'and'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': 'in'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'meta_chars'}; {'id': '213', 'type': 'not_operator', 'children': ['214']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '220'], 'value': '=='}; {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '219', 'type': 'argument_list', 'children': []}; {'id': '220', 'type': 'string', 'children': [], 'value': 'u"\\\\"'}; {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'raise_statement', 'children': ['223']}; {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'binary_operator', 'children': ['229', '230'], 'value': '%'}; {'id': '229', 'type': 'string', 'children': [], 'value': 'u"Un-escaped character in class definition: %s"'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '231', 'type': 'if_statement', 'children': ['232', '234']}; {'id': '232', 'type': 'not_operator', 'children': ['233']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '234', 'type': 'block', 'children': ['235']}; {'id': '235', 'type': 'break_statement', 'children': []}; {'id': '236', 'type': 'return_statement', 'children': ['237']}; {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'CharacterSet'}; {'id': '241', 'type': 'argument_list', 'children': ['242', '243', '244']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'chars'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'cnt'} | def getCharacterSet(self):
'''Get a character set with individual members or ranges.
Current index is on '[', the start of the character set.
'''
chars = u''
c = None
cnt = 1
start = 0
while True:
escaped_slash = False
c = self.next()
if self.lookahead() == u'-' and not c == u'\\':
f = c
self.next()
c = self.next()
if not c or (c in self.meta_chars):
raise StringGenerator.SyntaxError(u"unexpected end of class range")
chars += self.getCharacterRange(f, c)
elif c == u'\\':
if self.lookahead() in self.meta_chars:
c = self.next()
chars += c
continue
elif self.lookahead() in self.string_code:
c = self.next()
chars += self.string_code[c]
elif c and c not in self.meta_chars:
chars += c
if c == u']':
if self.lookahead() == u'{':
[start, cnt] = self.getQuantifier()
else:
start = -1
cnt = 1
break
if c and c in self.meta_chars and not self.last() == u"\\":
raise StringGenerator.SyntaxError(u"Un-escaped character in class definition: %s" % c)
if not c:
break
return StringGenerator.CharacterSet(chars, start, cnt) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getSequence'}; {'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': 'level'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '15', '19', '23', '27', '31', '344', '356', '371']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''Get a sequence of nodes.'''"}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '18', 'type': 'string', 'children': [], 'value': "''"}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'left_operand'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'right_operand'}; {'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': 'sequence_closed'}; {'id': '30', 'type': 'False', 'children': []}; {'id': '31', 'type': 'while_statement', 'children': ['32', '33']}; {'id': '32', 'type': 'True', 'children': []}; {'id': '33', 'type': 'block', 'children': ['34', '42', '47', '240']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '45']}; {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'break_statement', 'children': []}; {'id': '47', 'type': 'if_statement', 'children': ['48', '55', '67', '93', '118', '146', '177', '195', '213']}; {'id': '48', 'type': 'boolean_operator', 'children': ['49', '50'], 'value': 'and'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'not'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'meta_chars'}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'getLiteral'}; {'id': '66', 'type': 'argument_list', 'children': []}; {'id': '67', 'type': 'elif_clause', 'children': ['68', '81']}; {'id': '68', 'type': 'boolean_operator', 'children': ['69', '74'], 'value': 'and'}; {'id': '69', 'type': 'boolean_operator', 'children': ['70', '71'], 'value': 'and'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '=='}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '73', 'type': 'string', 'children': [], 'value': "u'$'"}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '80'], 'value': '=='}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'lookahead'}; {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'string', 'children': [], 'value': "u'{'"}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'getSource'}; {'id': '92', 'type': 'argument_list', 'children': []}; {'id': '93', 'type': 'elif_clause', 'children': ['94', '106']}; {'id': '94', 'type': 'boolean_operator', 'children': ['95', '98'], 'value': 'and'}; {'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '=='}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '97', 'type': 'string', 'children': [], 'value': "u'['"}; {'id': '98', 'type': 'not_operator', 'children': ['99']}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '105'], 'value': '=='}; {'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': 'last'}; {'id': '104', 'type': 'argument_list', 'children': []}; {'id': '105', 'type': 'string', 'children': [], 'value': "u'\\\\'"}; {'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': 'seq'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'getCharacterSet'}; {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'elif_clause', 'children': ['119', '131']}; {'id': '119', 'type': 'boolean_operator', 'children': ['120', '123'], 'value': 'and'}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '=='}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '122', 'type': 'string', 'children': [], 'value': "u'('"}; {'id': '123', 'type': 'not_operator', 'children': ['124']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '130'], 'value': '=='}; {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '129', 'type': 'argument_list', 'children': []}; {'id': '130', 'type': 'string', 'children': [], 'value': "u'\\\\'"}; {'id': '131', 'type': 'block', 'children': ['132']}; {'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': 'seq'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '137', 'type': 'argument_list', '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': 'getSequence'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '+'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '145', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '146', 'type': 'elif_clause', 'children': ['147', '159']}; {'id': '147', 'type': 'boolean_operator', 'children': ['148', '151'], 'value': 'and'}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': '=='}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '150', 'type': 'string', 'children': [], 'value': "u')'"}; {'id': '151', 'type': 'not_operator', 'children': ['152']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '158'], 'value': '=='}; {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'string', 'children': [], 'value': "u'\\\\'"}; {'id': '159', 'type': 'block', 'children': ['160', '172', '176']}; {'id': '160', 'type': 'if_statement', 'children': ['161', '164']}; {'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': '=='}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '163', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '164', 'type': 'block', 'children': ['165']}; {'id': '165', 'type': 'raise_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'string', 'children': [], 'value': 'u"Extra closing parenthesis"'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'sequence_closed'}; {'id': '175', 'type': 'True', 'children': []}; {'id': '176', 'type': 'break_statement', 'children': []}; {'id': '177', 'type': 'elif_clause', 'children': ['178', '190']}; {'id': '178', 'type': 'boolean_operator', 'children': ['179', '182'], 'value': 'and'}; {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '=='}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '181', 'type': 'string', 'children': [], 'value': "u'|'"}; {'id': '182', 'type': 'not_operator', 'children': ['183']}; {'id': '183', 'type': 'comparison_operator', 'children': ['184', '189'], 'value': '=='}; {'id': '184', 'type': 'call', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '188', 'type': 'argument_list', 'children': []}; {'id': '189', 'type': 'string', 'children': [], 'value': "u'\\\\'"}; {'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': 'op'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '195', 'type': 'elif_clause', 'children': ['196', '208']}; {'id': '196', 'type': 'boolean_operator', 'children': ['197', '200'], 'value': 'and'}; {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': '=='}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '199', 'type': 'string', 'children': [], 'value': "u'&'"}; {'id': '200', 'type': 'not_operator', 'children': ['201']}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '207'], 'value': '=='}; {'id': '202', 'type': 'call', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '206', 'type': 'argument_list', 'children': []}; {'id': '207', 'type': 'string', 'children': [], 'value': "u'\\\\'"}; {'id': '208', 'type': 'block', 'children': ['209']}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '213', 'type': 'else_clause', 'children': ['214']}; {'id': '214', 'type': 'block', 'children': ['215']}; {'id': '215', 'type': 'if_statement', 'children': ['216', '230']}; {'id': '216', 'type': 'boolean_operator', 'children': ['217', '222'], 'value': 'and'}; {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': 'in'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'meta_chars'}; {'id': '222', 'type': 'not_operator', 'children': ['223']}; {'id': '223', 'type': 'comparison_operator', 'children': ['224', '229'], 'value': '=='}; {'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': 'last'}; {'id': '228', 'type': 'argument_list', 'children': []}; {'id': '229', 'type': 'string', 'children': [], 'value': 'u"\\\\"'}; {'id': '230', 'type': 'block', 'children': ['231']}; {'id': '231', 'type': 'raise_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '236']}; {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}; {'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '%'}; {'id': '238', 'type': 'string', 'children': [], 'value': 'u"Un-escaped special character: %s"'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '240', 'type': 'if_statement', 'children': ['241', '245', '274']}; {'id': '241', 'type': 'boolean_operator', 'children': ['242', '243'], 'value': 'and'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '243', 'type': 'not_operator', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'left_operand'}; {'id': '245', 'type': 'block', 'children': ['246', '266']}; {'id': '246', 'type': 'if_statement', 'children': ['247', '256']}; {'id': '247', 'type': 'boolean_operator', 'children': ['248', '250'], 'value': 'or'}; {'id': '248', 'type': 'not_operator', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '250', 'type': 'comparison_operator', 'children': ['251', '255'], 'value': '<'}; {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '255', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '256', 'type': 'block', 'children': ['257']}; {'id': '257', 'type': 'raise_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '262']}; {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}; {'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '%'}; {'id': '264', 'type': 'string', 'children': [], 'value': 'u"Operator: %s with no left operand"'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'left_operand'}; {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '273', 'type': 'argument_list', 'children': []}; {'id': '274', 'type': 'elif_clause', 'children': ['275', '285']}; {'id': '275', 'type': 'boolean_operator', 'children': ['276', '284'], 'value': 'and'}; {'id': '276', 'type': 'boolean_operator', 'children': ['277', '278'], 'value': 'and'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '278', 'type': 'comparison_operator', 'children': ['279', '283'], 'value': '>='}; {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '283', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'left_operand'}; {'id': '285', 'type': 'block', 'children': ['286', '294', '332', '336', '340']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}; {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'right_operand'}; {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '293', 'type': 'argument_list', 'children': []}; {'id': '294', 'type': 'if_statement', 'children': ['295', '298', '313']}; {'id': '295', 'type': 'comparison_operator', 'children': ['296', '297'], 'value': '=='}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '297', 'type': 'string', 'children': [], 'value': "u'|'"}; {'id': '298', 'type': 'block', 'children': ['299']}; {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'call', 'children': ['301', '304']}; {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}; {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'SequenceOR'}; {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'list', 'children': ['311', '312'], 'value': '[left_operand, right_operand]'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'left_operand'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'right_operand'}; {'id': '313', 'type': 'elif_clause', 'children': ['314', '317']}; {'id': '314', 'type': 'comparison_operator', 'children': ['315', '316'], 'value': '=='}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '316', 'type': 'string', 'children': [], 'value': "u'&'"}; {'id': '317', 'type': 'block', 'children': ['318']}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}; {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'call', 'children': ['325', '328']}; {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'SequenceAND'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}; {'id': '329', 'type': 'list', 'children': ['330', '331'], 'value': '[left_operand, right_operand]'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'left_operand'}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'right_operand'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}; {'id': '333', 'type': 'assignment', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '335', 'type': 'string', 'children': [], 'value': "u''"}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}; {'id': '337', 'type': 'assignment', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'left_operand'}; {'id': '339', 'type': 'None', 'children': []}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}; {'id': '341', 'type': 'assignment', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'right_operand'}; {'id': '343', 'type': 'None', 'children': []}; {'id': '344', 'type': 'if_statement', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '346', 'type': 'block', 'children': ['347']}; {'id': '347', 'type': 'raise_statement', 'children': ['348']}; {'id': '348', 'type': 'call', 'children': ['349', '352']}; {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}; {'id': '353', 'type': 'binary_operator', 'children': ['354', '355'], 'value': '%'}; {'id': '354', 'type': 'string', 'children': [], 'value': 'u"Operator: %s with no right operand"'}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '356', 'type': 'if_statement', 'children': ['357', '363']}; {'id': '357', 'type': 'boolean_operator', 'children': ['358', '361'], 'value': 'and'}; {'id': '358', 'type': 'comparison_operator', 'children': ['359', '360'], 'value': '>'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '360', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '361', 'type': 'not_operator', 'children': ['362']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'sequence_closed'}; {'id': '363', 'type': 'block', 'children': ['364']}; {'id': '364', 'type': 'raise_statement', 'children': ['365']}; {'id': '365', 'type': 'call', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'SyntaxError'}; {'id': '369', 'type': 'argument_list', 'children': ['370']}; {'id': '370', 'type': 'string', 'children': [], 'value': 'u"Missing closing parenthesis"'}; {'id': '371', 'type': 'return_statement', 'children': ['372']}; {'id': '372', 'type': 'call', 'children': ['373', '376']}; {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'StringGenerator'}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'Sequence'}; {'id': '376', 'type': 'argument_list', 'children': ['377']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'seq'} | def getSequence(self, level=0):
'''Get a sequence of nodes.'''
seq = []
op = ''
left_operand = None
right_operand = None
sequence_closed = False
while True:
c = self.next()
if not c:
break
if c and c not in self.meta_chars:
seq.append(self.getLiteral())
elif c and c == u'$' and self.lookahead() == u'{':
seq.append(self.getSource())
elif c == u'[' and not self.last() == u'\\':
seq.append(self.getCharacterSet())
elif c == u'(' and not self.last() == u'\\':
seq.append(self.getSequence(level + 1))
elif c == u')' and not self.last() == u'\\':
if level == 0:
raise StringGenerator.SyntaxError(u"Extra closing parenthesis")
sequence_closed = True
break
elif c == u'|' and not self.last() == u'\\':
op = c
elif c == u'&' and not self.last() == u'\\':
op = c
else:
if c in self.meta_chars and not self.last() == u"\\":
raise StringGenerator.SyntaxError(u"Un-escaped special character: %s" % c)
if op and not left_operand:
if not seq or len(seq) < 1:
raise StringGenerator.SyntaxError(u"Operator: %s with no left operand" % op)
left_operand = seq.pop()
elif op and len(seq) >= 1 and left_operand:
right_operand = seq.pop()
if op == u'|':
seq.append(StringGenerator.SequenceOR([left_operand, right_operand]))
elif op == u'&':
seq.append(StringGenerator.SequenceAND([left_operand, right_operand]))
op = u''
left_operand = None
right_operand = None
if op:
raise StringGenerator.SyntaxError(u"Operator: %s with no right operand" % op)
if level > 0 and not sequence_closed:
raise StringGenerator.SyntaxError(u"Missing closing parenthesis")
return StringGenerator.Sequence(seq) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '8', 'type': 'block', 'children': ['9', '15', '23', '30', '38', '42', '129', '138', '147']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'in'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': []}; {'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': 'type'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'enum'}; {'id': '20', 'type': 'argument_list', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': []}; {'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': 'history'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'resolve'}; {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '48', '53']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'multi_occurrence'}; {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '52', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'if_statement', 'children': ['56', '62']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '61'], 'value': '>'}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'if_statement', 'children': ['64', '69', '93']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'mixed'}; {'id': '68', 'type': 'argument_list', 'children': []}; {'id': '69', 'type': 'block', 'children': ['70', '81', '87']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Factory'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'property'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'md'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': '__metadata__'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'md'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'sxtype'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '93', 'type': 'else_clause', 'children': ['94']}; {'id': '94', 'type': 'block', 'children': ['95', '106', '112', '118']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'Factory'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'object'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'md'}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': '__metadata__'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'md'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'sxtype'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'md'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ordering'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134', '137']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '142']}; {'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': 'is'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '141', 'type': 'None', 'children': []}; {'id': '142', 'type': 'block', 'children': ['143']}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '147', 'type': 'if_statement', 'children': ['148', '154']}; {'id': '148', 'type': 'not_operator', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '154', 'type': 'block', 'children': ['155', '163']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'add_attributes'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '163', 'type': 'for_statement', 'children': ['164', '167', '172']}; {'id': '164', 'type': 'pattern_list', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'ancestry'}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'resolved'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'block', 'children': ['173', '183']}; {'id': '173', 'type': 'if_statement', 'children': ['174', '181']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'skip_child'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'ancestry'}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'continue_statement', 'children': []}; {'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': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190', '191']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '193', 'type': 'slice', 'children': ['194']}; {'id': '194', 'type': 'colon', 'children': []} | def process(self, data, type, history):
if type in history:
return
if type.enum():
return
history.append(type)
resolved = type.resolve()
value = None
if type.multi_occurrence():
value = []
else:
if len(resolved) > 0:
if resolved.mixed():
value = Factory.property(resolved.name)
md = value.__metadata__
md.sxtype = resolved
else:
value = Factory.object(resolved.name)
md = value.__metadata__
md.sxtype = resolved
md.ordering = self.ordering(resolved)
setattr(data, type.name, value)
if value is not None:
data = value
if not isinstance(data, list):
self.add_attributes(data, resolved)
for child, ancestry in resolved.children():
if self.skip_child(child, ancestry):
continue
self.process(data, child, history[:]) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_process_tz'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '8', 'type': 'block', 'children': ['9', '98', '105', '112', '149', '155', '203']}; {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': '_tz'}; {'id': '11', 'type': 'parameters', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '13', 'type': 'block', 'children': ['14', '23', '43', '74', '96']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '20']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '17', 'type': 'tuple', 'children': ['18', '19']}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'string', 'children': [], 'value': "'naive'"}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '=='}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'local'"}; {'id': '27', 'type': 'block', 'children': ['28', '39']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '33']}; {'id': '29', 'type': 'boolean_operator', 'children': ['30', '31'], 'value': 'and'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '__debug__'}; {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'localtz'}; {'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': 'ValueError'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"Requested conversion to local timezone, but `localtz` not installed."'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'localtz'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '50']}; {'id': '44', 'type': 'not_operator', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '50', 'type': 'block', 'children': ['51', '67']}; {'id': '51', 'type': 'if_statement', 'children': ['52', '56']}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '54'], 'value': 'and'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': '__debug__'}; {'id': '54', 'type': 'not_operator', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'localtz'}; {'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': 'ValueError'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '+'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"The `pytz` package must be installed to look up timezone: "'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'get_tz'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '83']}; {'id': '75', 'type': 'boolean_operator', 'children': ['76', '82'], 'value': 'and'}; {'id': '76', 'type': 'not_operator', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '81', 'type': 'string', 'children': [], 'value': "'normalize'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_tz'}; {'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': 't'}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'get_tz'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tzname'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '96', 'type': 'return_statement', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_tz'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': '_tz'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '119']}; {'id': '113', 'type': 'boolean_operator', 'children': ['114', '118'], 'value': 'and'}; {'id': '114', 'type': 'not_operator', 'children': ['115']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'if_statement', 'children': ['121', '126', '136']}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '125', 'type': 'string', 'children': [], 'value': "'localize'"}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'localize'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '136', 'type': 'else_clause', 'children': ['137']}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'naive'}; {'id': '149', 'type': 'if_statement', 'children': ['150', '152']}; {'id': '150', 'type': 'not_operator', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '152', 'type': 'block', 'children': ['153']}; {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '155', 'type': 'if_statement', 'children': ['156', '161', '176', '192']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'normalize'"}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'normalize'}; {'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': 'dt'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'astimezone'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '176', 'type': 'elif_clause', 'children': ['177', '180']}; {'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': '=='}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '179', 'type': 'string', 'children': [], 'value': "'naive'"}; {'id': '180', 'type': 'block', 'children': ['181']}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'tzinfo'}; {'id': '191', 'type': 'None', 'children': []}; {'id': '192', 'type': 'else_clause', 'children': ['193']}; {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'dt'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'astimezone'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'tz'}; {'id': '203', 'type': 'return_statement', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'dt'} | def _process_tz(self, dt, naive, tz):
def _tz(t):
if t in (None, 'naive'):
return t
if t == 'local':
if __debug__ and not localtz:
raise ValueError("Requested conversion to local timezone, but `localtz` not installed.")
t = localtz
if not isinstance(t, tzinfo):
if __debug__ and not localtz:
raise ValueError("The `pytz` package must be installed to look up timezone: " + repr(t))
t = get_tz(t)
if not hasattr(t, 'normalize') and get_tz:
t = get_tz(t.tzname(dt))
return t
naive = _tz(naive)
tz = _tz(tz)
if not dt.tzinfo and naive:
if hasattr(naive, 'localize'):
dt = naive.localize(dt)
else:
dt = dt.replace(tzinfo=naive)
if not tz:
return dt
if hasattr(tz, 'normalize'):
dt = tz.normalize(dt.astimezone(tz))
elif tz == 'naive':
dt = dt.replace(tzinfo=None)
else:
dt = dt.astimezone(tz)
return dt |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__dfs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '8', 'type': 'block', 'children': ['9', '58', '151']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': '=='}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '13', 'type': 'block', 'children': ['14', '19', '47', '56']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '17', 'type': 'list', 'children': ['18'], 'value': '[v]'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '19', 'type': 'while_statement', 'children': ['20', '27']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '26'], 'value': '!='}; {'id': '21', 'type': 'subscript', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': '_dfs_parent'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '27', 'type': 'block', 'children': ['28', '39']}; {'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': 'path'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': '_dfs_parent'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '42', 'type': 'subscript', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': '_dfs_parent'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '47', 'type': 'expression_statement', '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': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_dfs_paths'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'True', 'children': []}; {'id': '58', 'type': 'for_statement', 'children': ['59', '60', '65']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '60', 'type': 'subscript', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': '_graph'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'if_statement', 'children': ['67', '74']}; {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'in'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '-'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'block', 'children': ['75', '83']}; {'id': '75', 'type': 'if_statement', 'children': ['76', '81']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '_dfs_parent'}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'continue_statement', 'children': []}; {'id': '83', 'type': 'if_statement', 'children': ['84', '128']}; {'id': '84', 'type': 'boolean_operator', 'children': ['85', '106', '107'], 'value': 'or'}; {'id': '85', 'type': '()', 'children': ['86']}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '92'], 'value': 'and'}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'in'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': '_left'}; {'id': '92', 'type': '()', 'children': ['93']}; {'id': '93', 'type': 'boolean_operator', 'children': ['94', '99'], 'value': 'or'}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'not'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': '_matching'}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': '!='}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '101', 'type': 'subscript', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '_matching'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '106', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '107', 'type': '()', 'children': ['108']}; {'id': '108', 'type': 'boolean_operator', 'children': ['109', '114'], 'value': 'and'}; {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'in'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': '_right'}; {'id': '114', 'type': '()', 'children': ['115']}; {'id': '115', 'type': 'boolean_operator', 'children': ['116', '121'], 'value': 'and'}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'in'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_matching'}; {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': '=='}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '123', 'type': 'subscript', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': '_matching'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '128', 'type': 'block', 'children': ['129', '137']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '136']}; {'id': '131', 'type': 'subscript', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_dfs_parent'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '137', 'type': 'if_statement', 'children': ['138', '148']}; {'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': '__dfs'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144', '147']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'neighbour'}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '-'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'return_statement', 'children': ['150']}; {'id': '150', 'type': 'True', 'children': []}; {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'False', 'children': []} | def __dfs(self, v, index, layers):
if index == 0:
path = [v]
while self._dfs_parent[v] != v:
path.append(self._dfs_parent[v])
v = self._dfs_parent[v]
self._dfs_paths.append(path)
return True
for neighbour in self._graph[v]:
if neighbour in layers[index - 1]:
if neighbour in self._dfs_parent:
continue
if (neighbour in self._left and (v not in self._matching or neighbour != self._matching[v])) or \
(neighbour in self._right and (v in self._matching and neighbour == self._matching[v])):
self._dfs_parent[neighbour] = v
if self.__dfs(neighbour, index-1, layers):
return True
return False |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'login'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'login_token'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '43', '66', '103']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'login_token'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16', '33']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'token_doc'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '27', '30']}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'query'"}; {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'tokens'"}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '32', 'type': 'string', 'children': [], 'value': "'login'"}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'login_token'}; {'id': '36', 'type': 'subscript', 'children': ['37', '42']}; {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'token_doc'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'query'"}; {'id': '41', 'type': 'string', 'children': [], 'value': "'tokens'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'logintoken'"}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'login_doc'}; {'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': 'post'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '54', '57', '60', '63']}; {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '53', 'type': 'string', 'children': [], 'value': '"clientlogin"'}; {'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'logintoken'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'login_token'}; {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'loginreturnurl'}; {'id': '65', 'type': 'string', 'children': [], 'value': '"http://example.org/"'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '74', '85']}; {'id': '67', 'type': 'comparison_operator', 'children': ['68', '73'], 'value': '=='}; {'id': '68', 'type': 'subscript', 'children': ['69', '72']}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'login_doc'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'clientlogin'"}; {'id': '72', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '73', 'type': 'string', 'children': [], 'value': '"UI"'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'raise_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ClientInteractionRequest'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'from_doc'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'login_token'}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'login_doc'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'clientlogin'"}; {'id': '85', 'type': 'elif_clause', 'children': ['86', '93']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '92'], 'value': '!='}; {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'login_doc'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'clientlogin'"}; {'id': '91', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '92', 'type': 'string', 'children': [], 'value': "'PASS'"}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'raise_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'LoginError'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'from_doc'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'login_doc'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'clientlogin'"}; {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'login_doc'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'clientlogin'"} | def login(self, username, password, login_token=None):
if login_token is None:
token_doc = self.post(action='query', meta='tokens', type='login')
login_token = token_doc['query']['tokens']['logintoken']
login_doc = self.post(
action="clientlogin", username=username, password=password,
logintoken=login_token, loginreturnurl="http://example.org/")
if login_doc['clientlogin']['status'] == "UI":
raise ClientInteractionRequest.from_doc(
login_token, login_doc['clientlogin'])
elif login_doc['clientlogin']['status'] != 'PASS':
raise LoginError.from_doc(login_doc['clientlogin'])
return login_doc['clientlogin'] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cut_levels'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_level'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '15', '146', '162']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'final'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '18', 'type': 'block', 'children': ['19', '34', '52', '112']}; {'id': '19', 'type': 'if_statement', 'children': ['20', '26']}; {'id': '20', 'type': 'not_operator', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'level'"}; {'id': '26', 'type': 'block', 'children': ['27', '33']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '33', 'type': 'continue_statement', 'children': []}; {'id': '34', 'type': 'if_statement', 'children': ['35', '44']}; {'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': 'node'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'soft_root'"}; {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45', '51']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '51', 'type': 'continue_statement', 'children': []}; {'id': '52', 'type': 'if_statement', 'children': ['53', '58', '89', '104']}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': '=='}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'start_level'}; {'id': '58', 'type': 'block', 'children': ['59', '66', '72']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'final'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '82']}; {'id': '73', 'type': 'boolean_operator', 'children': ['74', '78'], 'value': 'and'}; {'id': '74', 'type': 'not_operator', 'children': ['75']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'visible'}; {'id': '78', 'type': 'not_operator', 'children': ['79']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '89', 'type': 'elif_clause', 'children': ['90', '97']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': '=='}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'start_level'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '103', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '104', 'type': 'else_clause', 'children': ['105']}; {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '117']}; {'id': '113', 'type': 'not_operator', 'children': ['114']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'visible'}; {'id': '117', 'type': 'block', 'children': ['118', '122', '136']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'keep_node'}; {'id': '121', 'type': 'False', 'children': []}; {'id': '122', 'type': 'for_statement', 'children': ['123', '124', '127']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'keep_node'}; {'id': '131', 'type': 'boolean_operator', 'children': ['132', '133'], 'value': 'or'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'keep_node'}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'visible'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '139']}; {'id': '137', 'type': 'not_operator', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'keep_node'}; {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '146', 'type': 'for_statement', 'children': ['147', '148', '149']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'removed'}; {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'if_statement', 'children': ['151', '154']}; {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'in'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'final'}; {'id': '154', 'type': 'block', 'children': ['155']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'final'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '162', 'type': 'return_statement', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'final'} | def cut_levels(nodes, start_level):
final = []
removed = []
for node in nodes:
if not hasattr(node, 'level'):
remove(node, removed)
continue
if node.attr.get('soft_root', False):
remove(node, removed)
continue
if node.level == start_level:
final.append(node)
node.parent = None
if not node.visible and not node.children:
remove(node, removed)
elif node.level == start_level + 1:
node.children = []
else:
remove(node, removed)
if not node.visible:
keep_node = False
for child in node.children:
keep_node = keep_node or child.visible
if not keep_node:
remove(node, removed)
for node in removed:
if node in final:
final.remove(node)
return final |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'S'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'Document'}; {'id': '5', 'type': 'list_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '115']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '15']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '15', 'type': 'block', 'children': ['16', '39', '43', '62', '73', '90', '101']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '22']}; {'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': 'field'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '22', 'type': 'block', 'children': ['23', '29', '38']}; {'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': 'field'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'field'}; {'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': 'result'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'tuple', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '38', 'type': 'continue_statement', 'children': []}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '51']}; {'id': '44', 'type': 'not_operator', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'__'"}; {'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': 'field'}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'__'"}; {'id': '61', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '62', 'type': 'if_statement', 'children': ['63', '68']}; {'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': '=='}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '67', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'}; {'id': '73', 'type': 'if_statement', 'children': ['74', '81']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': 'in'}; {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '78', 'type': 'tuple', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'+'"}; {'id': '80', 'type': 'string', 'children': [], 'value': "'-'"}; {'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': 'field'}; {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '87', 'type': 'slice', 'children': ['88', '89']}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '89', 'type': 'colon', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_field'}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'traverse'}; {'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'Document'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '100', 'type': 'None', 'children': []}; {'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': 'result'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'tuple', 'children': ['108', '114']}; {'id': '108', 'type': 'conditional_expression', 'children': ['109', '112', '113'], 'value': 'if'}; {'id': '109', 'type': '()', 'children': ['110']}; {'id': '110', 'type': 'unary_operator', 'children': ['111'], 'value': '~'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': '_field'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '_field'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'direction'}; {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'result'} | def S(Document, *fields):
result = []
for field in fields:
if isinstance(field, tuple):
field, direction = field
result.append((field, direction))
continue
direction = ASCENDING
if not field.startswith('__'):
field = field.replace('__', '.')
if field[0] == '-':
direction = DESCENDING
if field[0] in ('+', '-'):
field = field[1:]
_field = traverse(Document, field, default=None)
result.append(((~_field) if _field else field, direction))
return result |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'valid'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cnpj'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '21', '29', '37', '41', '47', '87', '103', '115', '121', '129', '133', '139', '179', '195', '207']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '14']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '13'], 'value': '!='}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cnpj'}; {'id': '13', 'type': 'integer', 'children': [], 'value': '14'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'False', 'children': []}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cnpj'}; {'id': '26', 'type': 'slice', 'children': ['27', '28']}; {'id': '27', 'type': 'colon', 'children': []}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'digs'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cnpj'}; {'id': '34', 'type': 'slice', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '36', 'type': 'colon', 'children': []}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '-'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '7'}; {'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', '53', '54']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'unary_operator', 'children': ['55'], 'value': '-'}; {'id': '55', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '56', 'type': 'block', 'children': ['57', '72', '78']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '+'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '71'], 'value': '*'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '-'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '-'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}; {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '<'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '2'}; {'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': 'pos'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '90', 'type': 'conditional_expression', 'children': ['91', '92', '97'], 'value': 'if'}; {'id': '91', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '<'}; {'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '%'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '95', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '-'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '99', 'type': '()', 'children': ['100']}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '%'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '103', 'type': 'if_statement', 'children': ['104', '112']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '!='}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'digs'}; {'id': '111', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'return_statement', 'children': ['114']}; {'id': '114', 'type': 'False', 'children': []}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'cnpj'}; {'id': '126', 'type': 'slice', 'children': ['127', '128']}; {'id': '127', 'type': 'colon', 'children': []}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '-'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '7'}; {'id': '139', 'type': 'for_statement', 'children': ['140', '141', '148']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '145', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '146', 'type': 'unary_operator', 'children': ['147'], 'value': '-'}; {'id': '147', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '148', 'type': 'block', 'children': ['149', '164', '170']}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '+'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '163'], 'value': '*'}; {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'nums'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '-'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'tam'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '167', 'type': 'binary_operator', 'children': ['168', '169'], 'value': '-'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174']}; {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': '<'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '173', 'type': 'integer', 'children': [], 'value': '2'}; {'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': 'pos'}; {'id': '178', 'type': 'integer', 'children': [], 'value': '9'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '182', 'type': 'conditional_expression', 'children': ['183', '184', '189'], 'value': 'if'}; {'id': '183', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '188'], 'value': '<'}; {'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '%'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '187', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '-'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '191', 'type': '()', 'children': ['192']}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '%'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'tot'}; {'id': '194', 'type': 'integer', 'children': [], 'value': '11'}; {'id': '195', 'type': 'if_statement', 'children': ['196', '204']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '!='}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'digs'}; {'id': '203', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '204', 'type': 'block', 'children': ['205']}; {'id': '205', 'type': 'return_statement', 'children': ['206']}; {'id': '206', 'type': 'False', 'children': []}; {'id': '207', 'type': 'return_statement', 'children': ['208']}; {'id': '208', 'type': 'True', 'children': []} | def valid(self, cnpj):
if len(cnpj) != 14:
return False
tam = 12
nums = cnpj[:tam]
digs = cnpj[tam:]
tot = 0
pos = tam-7
for i in range(tam, 0, -1):
tot = tot + int(nums[tam-i])*pos
pos = pos - 1
if pos < 2:
pos = 9
res = 0 if tot % 11 < 2 else 11 - (tot % 11)
if res != int(digs[0]):
return False
tam = tam + 1
nums = cnpj[:tam]
tot = 0
pos = tam-7
for i in range(tam, 0, -1):
tot = tot + int(nums[tam-i])*pos
pos = pos - 1
if pos < 2:
pos = 9
res = 0 if tot % 11 < 2 else 11 - (tot % 11)
if res != int(digs[1]):
return False
return True |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'arrayuniqify'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'retainorder'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '17', '23', '45']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'argsort'}; {'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': 'X'}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '33']}; {'id': '31', 'type': 'list', 'children': ['32'], 'value': '[True]'}; {'id': '32', 'type': 'True', 'children': []}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '39'], 'value': '!='}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '36', 'type': 'slice', 'children': ['37', '38']}; {'id': '37', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '38', 'type': 'colon', 'children': []}; {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '41', 'type': 'slice', 'children': ['42', '43']}; {'id': '42', 'type': 'colon', 'children': []}; {'id': '43', 'type': 'unary_operator', 'children': ['44'], 'value': '-'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '47', '105']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'retainorder'}; {'id': '47', 'type': 'block', 'children': ['48', '67', '97', '103']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'DD'}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '63']}; {'id': '56', 'type': 'subscript', 'children': ['57', '62']}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'nonzero'}; {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '70', 'type': 'list_comprehension', 'children': ['71', '84']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '76', 'type': 'slice', 'children': ['77', '78', '79']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '78', 'type': 'colon', 'children': []}; {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'DD'}; {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '+'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '83', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '84', 'type': 'for_in_clause', 'children': ['85', '88']}; {'id': '85', 'type': 'tuple_pattern', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'DD'}; {'id': '93', 'type': 'slice', 'children': ['94', '95']}; {'id': '94', 'type': 'colon', 'children': []}; {'id': '95', 'type': 'unary_operator', 'children': ['96'], 'value': '-'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'ind'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '102', 'type': 'argument_list', 'children': []}; {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ind'}; {'id': '105', 'type': 'else_clause', 'children': ['106']}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'return_statement', 'children': ['108']}; {'id': '108', 'type': 'list', 'children': ['109', '110'], 'value': '[D,s]'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 's'} | def arrayuniqify(X, retainorder=False):
s = X.argsort()
X = X[s]
D = np.append([True],X[1:] != X[:-1])
if retainorder:
DD = np.append(D.nonzero()[0],len(X))
ind = [min(s[x:DD[i+1]]) for (i,x) in enumerate(DD[:-1])]
ind.sort()
return ind
else:
return [D,s] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'equalspairs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'Y'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '37', '58', '75', '84', '100', '116', '127', '143']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Y'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'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': 'R'}; {'id': '18', 'type': 'subscript', 'children': ['19', '36']}; {'id': '19', 'type': 'call', 'children': ['20', '35']}; {'id': '20', 'type': 'attribute', 'children': ['21', '34']}; {'id': '21', 'type': '()', 'children': ['22']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '28'], 'value': '!='}; {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '25', 'type': 'slice', 'children': ['26', '27']}; {'id': '26', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '27', 'type': 'colon', 'children': []}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '30', 'type': 'slice', 'children': ['31', '32']}; {'id': '31', 'type': 'colon', 'children': []}; {'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'}; {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'nonzero'}; {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'list', 'children': ['52'], 'value': '[len(T)-1]'}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '57'], 'value': '-'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'searchsorted'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'searchsorted'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'T'}; {'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': 'array'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'list', 'children': ['99'], 'value': '[0]'}; {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'list', 'children': ['115'], 'value': '[0]'}; {'id': '115', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '119', 'type': 'binary_operator', 'children': ['120', '126'], 'value': '*'}; {'id': '120', 'type': '()', 'children': ['121']}; {'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': '=='}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'B'}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '137'], 'value': '*'}; {'id': '131', 'type': '()', 'children': ['132']}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '136'], 'value': '=='}; {'id': '133', 'type': 'subscript', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '137', 'type': '()', 'children': ['138']}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '142'], 'value': '+'}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '143', 'type': 'return_statement', 'children': ['144']}; {'id': '144', 'type': 'list', 'children': ['145', '146'], 'value': '[A,B]'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'B'} | def equalspairs(X, Y):
T = Y.copy()
R = (T[1:] != T[:-1]).nonzero()[0]
R = np.append(R,np.array([len(T)-1]))
M = R[R.searchsorted(range(len(T)))]
D = T.searchsorted(X)
T = np.append(T,np.array([0]))
M = np.append(M,np.array([0]))
A = (T[D] == X) * D
B = (T[D] == X) * (M[D] + 1)
return [A,B] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'loadSV'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'titles'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'aligned'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'byteorder'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'renamer'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'block', 'children': ['23', '34', '55', '76', '97', '135', '157']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}; {'id': '25', 'type': 'list_pattern', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'loadSVcols'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '32', 'type': 'dictionary_splat', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '42', '49']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'names'"}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '41', 'type': 'argument_list', 'children': []}; {'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': 'names'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'names'"}; {'id': '49', 'type': 'else_clause', 'children': ['50']}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '54', 'type': 'None', 'children': []}; {'id': '55', 'type': 'if_statement', 'children': ['56', '63', '70']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'formats'"}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'formats'"}; {'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': 'formats'}; {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'if_statement', 'children': ['77', '84', '91']}; {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'in'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'dtype'"}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'dtype'"}; {'id': '91', 'type': 'else_clause', 'children': ['92']}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '96', 'type': 'None', 'children': []}; {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'renamer'}; {'id': '100', 'type': 'None', 'children': []}; {'id': '101', 'type': 'block', 'children': ['102', '104', '111']}; {'id': '102', 'type': 'print_statement', 'children': ['103']}; {'id': '103', 'type': 'string', 'children': [], 'value': "'Trying user-given renamer ...'"}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'renamed'}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'renamer'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '111', 'type': 'if_statement', 'children': ['112', '124', '131']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '117'], 'value': '=='}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'renamed'}; {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'uniqify'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'renamed'}; {'id': '124', 'type': 'block', 'children': ['125', '129']}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'renamed'}; {'id': '129', 'type': 'print_statement', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'''... using renamed names (original names will be in return \n metadata)'''"}; {'id': '131', 'type': 'else_clause', 'children': ['132']}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'print_statement', 'children': ['134']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'... renamer failed to produce unique names, not using.'"}; {'id': '135', 'type': 'if_statement', 'children': ['136', '150']}; {'id': '136', 'type': 'boolean_operator', 'children': ['137', '138'], 'value': 'and'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '143'], 'value': '!='}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'uniqify'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '150', 'type': 'block', 'children': ['151', '153']}; {'id': '151', 'type': 'print_statement', 'children': ['152']}; {'id': '152', 'type': 'string', 'children': [], 'value': "'Names are not unique, reverting to default naming scheme.'"}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '156', 'type': 'None', 'children': []}; {'id': '157', 'type': 'return_statement', 'children': ['158']}; {'id': '158', 'type': 'list', 'children': ['159', '191'], 'value': '[utils.fromarrays(columns, type=np.ndarray, dtype=dtype, \n shape=shape, formats=formats, names=names, \n titles=titles, aligned=aligned, \n byteorder=byteorder), metadata]'}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'fromarrays'}; {'id': '163', 'type': 'argument_list', 'children': ['164', '165', '170', '173', '176', '179', '182', '185', '188']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'titles'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'titles'}; {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'aligned'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'aligned'}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'byteorder'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'byteorder'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'metadata'} | def loadSV(fname, shape=None, titles=None, aligned=False, byteorder=None,
renamer=None, **kwargs):
[columns, metadata] = loadSVcols(fname, **kwargs)
if 'names' in metadata.keys():
names = metadata['names']
else:
names = None
if 'formats' in metadata.keys():
formats = metadata['formats']
else:
formats = None
if 'dtype' in metadata.keys():
dtype = metadata['dtype']
else:
dtype = None
if renamer is not None:
print 'Trying user-given renamer ...'
renamed = renamer(names)
if len(renamed) == len(uniqify(renamed)):
names = renamed
print '''... using renamed names (original names will be in return
metadata)'''
else:
print '... renamer failed to produce unique names, not using.'
if names and len(names) != len(uniqify(names)):
print 'Names are not unique, reverting to default naming scheme.'
names = None
return [utils.fromarrays(columns, type=np.ndarray, dtype=dtype,
shape=shape, formats=formats, names=names,
titles=titles, aligned=aligned,
byteorder=byteorder), metadata] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'loadSVrecs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'uselines'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'skiprows'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'linefixer'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'verbosity'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_VERBOSITY'}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '22', 'type': 'block', 'children': ['23', '46', '70', '81', '113', '134', '224', '238', '283', '289', '305']}; {'id': '23', 'type': 'if_statement', 'children': ['24', '33']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '26'], 'value': 'and'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'StringType'}; {'id': '33', 'type': 'block', 'children': ['34', '37']}; {'id': '34', 'type': 'import_statement', 'children': ['35']}; {'id': '35', 'type': 'dotted_name', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '52']}; {'id': '48', 'type': 'list_pattern', 'children': ['49', '50', '51']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'inferedlines'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'WHOLETHING'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'getmetadata'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '59', '62', '65', '68']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'skiprows'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'skiprows'}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'linefixer'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'linefixer'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'verbosity'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'verbosity'}; {'id': '68', 'type': 'dictionary_splat', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'uselines'}; {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'uselines'}; {'id': '78', 'type': 'tuple', 'children': ['79', '80']}; {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'False', 'children': []}; {'id': '81', 'type': 'if_statement', 'children': ['82', '86', '95', '106']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'is_string_like'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'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': 'fh'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'rU'"}; {'id': '95', 'type': 'elif_clause', 'children': ['96', '101']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'readline'"}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'fname'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'raise_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'fname must be a string or file handle'"}; {'id': '113', 'type': 'for_statement', 'children': ['114', '115', '127']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_ind'}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '124'], 'value': '+'}; {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '+'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'skiprows'}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'uselines'}; {'id': '123', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'headerlines'"}; {'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': 'fh'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'readline'}; {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'if_statement', 'children': ['135', '138']}; {'id': '135', 'type': 'boolean_operator', 'children': ['136', '137'], 'value': 'or'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'linefixer'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '138', 'type': 'block', 'children': ['139', '148', '166', '177', '201', '213', '220']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'fh2'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'tempfile'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'TemporaryFile'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'string', 'children': [], 'value': "'w+b'"}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '151', 'type': 'call', 'children': ['152', '164']}; {'id': '152', 'type': 'attribute', 'children': ['153', '163']}; {'id': '153', 'type': 'call', 'children': ['154', '161']}; {'id': '154', 'type': 'attribute', 'children': ['155', '160']}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '166', 'type': 'if_statement', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'linefixer'}; {'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': 'F'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'linefixer'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '177', 'type': 'if_statement', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '185', 'type': 'argument_list', 'children': ['186', '200']}; {'id': '186', 'type': 'lambda', 'children': ['187', '189']}; {'id': '187', 'type': 'lambda_parameters', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'delimiter_regex'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '193', 'type': 'argument_list', 'children': ['194', '199']}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}; {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '197', 'type': 'string', 'children': [], 'value': "'dialect'"}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'delimiter'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'F'}; {'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': 'fh2'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'F'}; {'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': 'fh2'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'seek'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}; {'id': '219', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'fh2'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'csv'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '231', 'type': 'argument_list', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'dialect'}; {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '237', 'type': 'string', 'children': [], 'value': "'dialect'"}; {'id': '238', 'type': 'if_statement', 'children': ['239', '242', '274']}; {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'uselines'}; {'id': '241', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '242', 'type': 'block', 'children': ['243', '247']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'linelist'}; {'id': '246', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '247', 'type': 'for_statement', 'children': ['248', '249', '250']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'ln'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '250', 'type': 'block', 'children': ['251']}; {'id': '251', 'type': 'if_statement', 'children': ['252', '263', '271']}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '256'], 'value': '<='}; {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'line_num'}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '260'], 'value': '-'}; {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'uselines'}; {'id': '259', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'uselines'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'linelist'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'ln'}; {'id': '271', 'type': 'else_clause', 'children': ['272']}; {'id': '272', 'type': 'block', 'children': ['273']}; {'id': '273', 'type': 'break_statement', 'children': []}; {'id': '274', 'type': 'else_clause', 'children': ['275']}; {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'linelist'}; {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'reader'}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'call', 'children': ['285', '288']}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'fh'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '288', 'type': 'argument_list', 'children': []}; {'id': '289', 'type': 'if_statement', 'children': ['290', '296']}; {'id': '290', 'type': 'comparison_operator', 'children': ['291', '295'], 'value': '=='}; {'id': '291', 'type': 'subscript', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'linelist'}; {'id': '293', 'type': 'unary_operator', 'children': ['294'], 'value': '-'}; {'id': '294', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '295', 'type': 'list', 'children': [], 'value': '[]'}; {'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': 'linelist'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}; {'id': '303', 'type': 'unary_operator', 'children': ['304'], 'value': '-'}; {'id': '304', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '305', 'type': 'return_statement', 'children': ['306']}; {'id': '306', 'type': 'list', 'children': ['307', '308'], 'value': '[linelist,metadata]'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'linelist'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'metadata'} | def loadSVrecs(fname, uselines=None, skiprows=0, linefixer=None,
delimiter_regex=None, verbosity=DEFAULT_VERBOSITY, **metadata):
if delimiter_regex and isinstance(delimiter_regex, types.StringType):
import re
delimiter_regex = re.compile(delimiter_regex)
[metadata, inferedlines, WHOLETHING] = getmetadata(fname, skiprows=skiprows,
linefixer=linefixer,
delimiter_regex=delimiter_regex,
verbosity=verbosity, **metadata)
if uselines is None:
uselines = (0,False)
if is_string_like(fname):
fh = file(fname, 'rU')
elif hasattr(fname, 'readline'):
fh = fname
else:
raise ValueError('fname must be a string or file handle')
for _ind in range(skiprows+uselines[0] + metadata['headerlines']):
fh.readline()
if linefixer or delimiter_regex:
fh2 = tempfile.TemporaryFile('w+b')
F = fh.read().strip('\n').split('\n')
if linefixer:
F = map(linefixer,F)
if delimiter_regex:
F = map(lambda line:
delimiter_regex.sub(metadata['dialect'].delimiter, line), F)
fh2.write('\n'.join(F))
fh2.seek(0)
fh = fh2
reader = csv.reader(fh, dialect=metadata['dialect'])
if uselines[1]:
linelist = []
for ln in reader:
if reader.line_num <= uselines[1] - uselines[0]:
linelist.append(ln)
else:
break
else:
linelist = list(reader)
fh.close()
if linelist[-1] == []:
linelist.pop(-1)
return [linelist,metadata] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dflt_interval'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'tuple', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '13', 'type': 'block', 'children': ['14', '21', '25', '29', '82', '107', '113', '121']}; {'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': 'LOGGER'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'RevocationCache.dflt_interval >>>'"}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'fro'}; {'id': '24', 'type': 'None', 'children': []}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'for_statement', 'children': ['30', '31', '32']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'block', 'children': ['33', '42', '48']}; {'id': '33', 'type': 'if_statement', 'children': ['34', '40']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '!='}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'rev_reg_id2cred_def_id'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'continue_statement', 'children': []}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'rr_delta_frames'}; {'id': '52', 'type': 'block', 'children': ['53', '72']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '56', 'type': 'attribute', 'children': ['57', '71']}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'rr_delta_frames'}; {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '65', 'type': 'lambda', 'children': ['66', '68']}; {'id': '66', 'type': 'lambda_parameters', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'fro'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '81']}; {'id': '78', 'type': 'boolean_operator', 'children': ['79', '80'], 'value': 'or'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'fro'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '88']}; {'id': '83', 'type': 'not_operator', 'children': ['84']}; {'id': '84', 'type': '()', 'children': ['85']}; {'id': '85', 'type': 'boolean_operator', 'children': ['86', '87'], 'value': 'and'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fro'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'to'}; {'id': '88', 'type': 'block', 'children': ['89', '97']}; {'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': 'LOGGER'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}; {'id': '95', 'type': 'string', 'children': [], 'value': "'RevocationCache.dflt_interval <!< No data for default non-revoc interval on cred def id %s'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '97', 'type': 'raise_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'CacheIndex'}; {'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': "'No data for default non-revoc interval on cred def id {}'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'rv'}; {'id': '110', 'type': 'tuple', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'fro'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'to'}; {'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': 'LOGGER'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'RevocationCache.dflt_interval <<< %s'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'rv'}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'rv'} | def dflt_interval(self, cd_id: str) -> (int, int):
LOGGER.debug('RevocationCache.dflt_interval >>>')
fro = None
to = None
for rr_id in self:
if cd_id != rev_reg_id2cred_def_id(rr_id):
continue
entry = self[rr_id]
if entry.rr_delta_frames:
to = max(entry.rr_delta_frames, key=lambda f: f.to).to
fro = min(fro or to, to)
if not (fro and to):
LOGGER.debug(
'RevocationCache.dflt_interval <!< No data for default non-revoc interval on cred def id %s',
cd_id)
raise CacheIndex('No data for default non-revoc interval on cred def id {}'.format(cd_id))
rv = (fro, to)
LOGGER.debug('RevocationCache.dflt_interval <<< %s', rv)
return rv |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}; {'id': '3', 'type': 'parameters', 'children': ['4', '8']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'type', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '15', 'type': 'block', 'children': ['16', '25', '48', '100', '111', '135', '178', '249', '393', '401']}; {'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', '23', '24']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'parse >>> base_dir: %s, timestamp: %s'"}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '31']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'id': '31', 'type': 'block', 'children': ['32', '39', '46']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'No cache archives available: not feeding cache'"}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'string', 'children': [], 'value': "'parse <<< None'"}; {'id': '46', 'type': 'return_statement', 'children': ['47']}; {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'if_statement', 'children': ['49', '51']}; {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '51', 'type': 'block', 'children': ['52', '72']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'timestamps'}; {'id': '55', 'type': 'list_comprehension', 'children': ['56', '60', '66']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '60', 'type': 'for_in_clause', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'id': '66', 'type': 'if_clause', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'isdigit'}; {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '74', '82']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'timestamps'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'timestamps'}; {'id': '82', 'type': 'else_clause', 'children': ['83']}; {'id': '83', 'type': 'block', 'children': ['84', '91', '98']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'No cache archives available: not feeding cache'"}; {'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': 'LOGGER'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'string', 'children': [], 'value': "'parse <<< None'"}; {'id': '98', 'type': 'return_statement', 'children': ['99']}; {'id': '99', 'type': 'None', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'timestamp_dir'}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'base_dir'}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '111', 'type': 'if_statement', 'children': ['112', '117']}; {'id': '112', 'type': 'not_operator', 'children': ['113']}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'timestamp_dir'}; {'id': '117', 'type': 'block', 'children': ['118', '126', '133']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'No such archived cache directory: %s'"}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'timestamp_dir'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'string', 'children': [], 'value': "'parse <<< None'"}; {'id': '133', 'type': 'return_statement', 'children': ['134']}; {'id': '134', 'type': 'None', 'children': []}; {'id': '135', 'type': 'with_statement', 'children': ['136', '141']}; {'id': '136', 'type': 'with_clause', 'children': ['137']}; {'id': '137', 'type': 'with_item', 'children': ['138']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'SCHEMA_CACHE'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'with_statement', 'children': ['143', '157']}; {'id': '143', 'type': 'with_clause', 'children': ['144']}; {'id': '144', 'type': 'with_item', 'children': ['145']}; {'id': '145', 'type': 'as_pattern', 'children': ['146', '155']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '154']}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'timestamp_dir'}; {'id': '153', 'type': 'string', 'children': [], 'value': "'schema'"}; {'id': '154', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '155', 'type': 'as_pattern_target', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '157', 'type': 'block', 'children': ['158', '171']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'schemata'}; {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'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': 'archive'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '170', 'type': 'argument_list', 'children': []}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'SCHEMA_CACHE'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'feed'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'schemata'}; {'id': '178', 'type': 'with_statement', 'children': ['179', '184']}; {'id': '179', 'type': 'with_clause', 'children': ['180']}; {'id': '180', 'type': 'with_item', 'children': ['181']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'CRED_DEF_CACHE'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '184', 'type': 'block', 'children': ['185']}; {'id': '185', 'type': 'with_statement', 'children': ['186', '200']}; {'id': '186', 'type': 'with_clause', 'children': ['187']}; {'id': '187', 'type': 'with_item', 'children': ['188']}; {'id': '188', 'type': 'as_pattern', 'children': ['189', '198']}; {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '191', 'type': 'argument_list', 'children': ['192', '197']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'timestamp_dir'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'cred_def'"}; {'id': '197', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '198', 'type': 'as_pattern_target', 'children': ['199']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '200', 'type': 'block', 'children': ['201', '214']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'cred_defs'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'for_statement', 'children': ['215', '216', '217']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'cred_defs'}; {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'if_statement', 'children': ['219', '222', '231']}; {'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': 'in'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'CRED_DEF_CACHE'}; {'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': 'LOGGER'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '230']}; {'id': '229', 'type': 'string', 'children': [], 'value': "'Cred def cache already has cred def on %s: skipping'"}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '231', 'type': 'else_clause', 'children': ['232']}; {'id': '232', 'type': 'block', 'children': ['233', '241']}; {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '238']}; {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'CRED_DEF_CACHE'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '238', 'type': 'subscript', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'cred_defs'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}; {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '248']}; {'id': '247', 'type': 'string', 'children': [], 'value': "'Cred def cache imported cred def for cred def id %s'"}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '249', 'type': 'with_statement', 'children': ['250', '255']}; {'id': '250', 'type': 'with_clause', 'children': ['251']}; {'id': '251', 'type': 'with_item', 'children': ['252']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'REVO_CACHE'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'with_statement', 'children': ['257', '271']}; {'id': '257', 'type': 'with_clause', 'children': ['258']}; {'id': '258', 'type': 'with_item', 'children': ['259']}; {'id': '259', 'type': 'as_pattern', 'children': ['260', '269']}; {'id': '260', 'type': 'call', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '262', 'type': 'argument_list', 'children': ['263', '268']}; {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '265', 'type': 'argument_list', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'timestamp_dir'}; {'id': '267', 'type': 'string', 'children': [], 'value': "'revocation'"}; {'id': '268', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '269', 'type': 'as_pattern_target', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '271', 'type': 'block', 'children': ['272', '285']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'rr_cache_entries'}; {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}; {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'archive'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '284', 'type': 'argument_list', 'children': []}; {'id': '285', 'type': 'for_statement', 'children': ['286', '289', '294']}; {'id': '286', 'type': 'tuple_pattern', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'rr_cache_entries'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '293', 'type': 'argument_list', 'children': []}; {'id': '294', 'type': 'block', 'children': ['295']}; {'id': '295', 'type': 'if_statement', 'children': ['296', '299', '308']}; {'id': '296', 'type': 'comparison_operator', 'children': ['297', '298'], 'value': 'in'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'REVO_CACHE'}; {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}; {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '305', 'type': 'argument_list', 'children': ['306', '307']}; {'id': '306', 'type': 'string', 'children': [], 'value': "'Revocation cache already has entry on %s: skipping'"}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '308', 'type': 'else_clause', 'children': ['309']}; {'id': '309', 'type': 'block', 'children': ['310', '319', '342', '349', '372', '379', '385']}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}; {'id': '311', 'type': 'assignment', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'rr_cache_entry'}; {'id': '313', 'type': 'call', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'RevoCacheEntry'}; {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'subscript', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '318', 'type': 'string', 'children': [], 'value': "'rev_reg_def'"}; {'id': '319', 'type': 'expression_statement', 'children': ['320']}; {'id': '320', 'type': 'assignment', 'children': ['321', '324']}; {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'rr_cache_entry'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'rr_delta_frames'}; {'id': '324', 'type': 'list_comprehension', 'children': ['325', '337']}; {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'RevRegUpdateFrame'}; {'id': '327', 'type': 'argument_list', 'children': ['328', '331', '334']}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '330', 'type': 'string', 'children': [], 'value': "'_to'"}; {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '333', 'type': 'string', 'children': [], 'value': "'_timestamp'"}; {'id': '334', 'type': 'subscript', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '336', 'type': 'string', 'children': [], 'value': "'_rr_update'"}; {'id': '337', 'type': 'for_in_clause', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '339', 'type': 'subscript', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '341', 'type': 'string', 'children': [], 'value': "'rr_delta_frames'"}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}; {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'rr_cache_entry'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'cull'}; {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'True', 'children': []}; {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'assignment', 'children': ['351', '354']}; {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'rr_cache_entry'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'rr_state_frames'}; {'id': '354', 'type': 'list_comprehension', 'children': ['355', '367']}; {'id': '355', 'type': 'call', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'RevRegUpdateFrame'}; {'id': '357', 'type': 'argument_list', 'children': ['358', '361', '364']}; {'id': '358', 'type': 'subscript', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '360', 'type': 'string', 'children': [], 'value': "'_to'"}; {'id': '361', 'type': 'subscript', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '363', 'type': 'string', 'children': [], 'value': "'_timestamp'"}; {'id': '364', 'type': 'subscript', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '366', 'type': 'string', 'children': [], 'value': "'_rr_update'"}; {'id': '367', 'type': 'for_in_clause', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '369', 'type': 'subscript', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '371', 'type': 'string', 'children': [], 'value': "'rr_state_frames'"}; {'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': 'rr_cache_entry'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'cull'}; {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'False', 'children': []}; {'id': '379', 'type': 'expression_statement', 'children': ['380']}; {'id': '380', 'type': 'assignment', 'children': ['381', '384']}; {'id': '381', 'type': 'subscript', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'REVO_CACHE'}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'rr_cache_entry'}; {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'call', 'children': ['387', '390']}; {'id': '387', 'type': 'attribute', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '390', 'type': 'argument_list', 'children': ['391', '392']}; {'id': '391', 'type': 'string', 'children': [], 'value': "'Revocation cache imported entry for rev reg id %s'"}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '393', 'type': 'expression_statement', 'children': ['394']}; {'id': '394', 'type': 'call', 'children': ['395', '398']}; {'id': '395', 'type': 'attribute', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '398', 'type': 'argument_list', 'children': ['399', '400']}; {'id': '399', 'type': 'string', 'children': [], 'value': "'parse <<< %s'"}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '401', 'type': 'return_statement', 'children': ['402']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'timestamp'} | def parse(base_dir: str, timestamp: int = None) -> int:
LOGGER.debug('parse >>> base_dir: %s, timestamp: %s', base_dir, timestamp)
if not isdir(base_dir):
LOGGER.info('No cache archives available: not feeding cache')
LOGGER.debug('parse <<< None')
return None
if not timestamp:
timestamps = [int(t) for t in listdir(base_dir) if t.isdigit()]
if timestamps:
timestamp = max(timestamps)
else:
LOGGER.info('No cache archives available: not feeding cache')
LOGGER.debug('parse <<< None')
return None
timestamp_dir = join(base_dir, str(timestamp))
if not isdir(timestamp_dir):
LOGGER.error('No such archived cache directory: %s', timestamp_dir)
LOGGER.debug('parse <<< None')
return None
with SCHEMA_CACHE.lock:
with open(join(timestamp_dir, 'schema'), 'r') as archive:
schemata = json.loads(archive.read())
SCHEMA_CACHE.feed(schemata)
with CRED_DEF_CACHE.lock:
with open(join(timestamp_dir, 'cred_def'), 'r') as archive:
cred_defs = json.loads(archive.read())
for cd_id in cred_defs:
if cd_id in CRED_DEF_CACHE:
LOGGER.warning('Cred def cache already has cred def on %s: skipping', cd_id)
else:
CRED_DEF_CACHE[cd_id] = cred_defs[cd_id]
LOGGER.info('Cred def cache imported cred def for cred def id %s', cd_id)
with REVO_CACHE.lock:
with open(join(timestamp_dir, 'revocation'), 'r') as archive:
rr_cache_entries = json.loads(archive.read())
for (rr_id, entry) in rr_cache_entries.items():
if rr_id in REVO_CACHE:
LOGGER.warning('Revocation cache already has entry on %s: skipping', rr_id)
else:
rr_cache_entry = RevoCacheEntry(entry['rev_reg_def'])
rr_cache_entry.rr_delta_frames = [
RevRegUpdateFrame(
f['_to'],
f['_timestamp'],
f['_rr_update']) for f in entry['rr_delta_frames']
]
rr_cache_entry.cull(True)
rr_cache_entry.rr_state_frames = [
RevRegUpdateFrame(
f['_to'],
f['_timestamp'],
f['_rr_update']) for f in entry['rr_state_frames']
]
rr_cache_entry.cull(False)
REVO_CACHE[rr_id] = rr_cache_entry
LOGGER.info('Revocation cache imported entry for rev reg id %s', rr_id)
LOGGER.debug('parse <<< %s', timestamp)
return timestamp |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_convert_hbf_meta_val_for_xml'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '6', 'type': 'block', 'children': ['7', '24', '28', '32', '89', '153']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'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': 'val'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': ['15']}; {'id': '15', 'type': 'list_comprehension', 'children': ['16', '21']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '_convert_hbf_meta_val_for_xml'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'is_literal'}; {'id': '27', 'type': 'True', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'if_statement', 'children': ['33', '38', '79']}; {'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': 'val'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '38', 'type': 'block', 'children': ['39', '43']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '47', '52']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'in'}; {'id': '45', 'type': 'string', 'children': [], 'value': "'@href'"}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'val'}; {'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': 'is_literal'}; {'id': '51', 'type': 'False', 'children': []}; {'id': '52', 'type': 'else_clause', 'children': ['53']}; {'id': '53', 'type': 'block', 'children': ['54', '63']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'$'"}; {'id': '63', 'type': 'if_statement', 'children': ['64', '74']}; {'id': '64', 'type': 'boolean_operator', 'children': ['65', '70'], 'value': 'and'}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': '_contains_hbf_meta_keys'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'is_literal'}; {'id': '78', 'type': 'False', 'children': []}; {'id': '79', 'type': 'else_clause', 'children': ['80']}; {'id': '80', 'type': 'block', 'children': ['81', '85']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '84', 'type': 'dictionary', 'children': []}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '89', 'type': 'if_statement', 'children': ['90', '91', '135']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'is_literal'}; {'id': '91', 'type': 'block', 'children': ['92', '100', '108', '124']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'@xsi:type'"}; {'id': '99', 'type': 'string', 'children': [], 'value': "'nex:LiteralMeta'"}; {'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': 'ret'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': "'@property'"}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '112']}; {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '111', 'type': 'None', 'children': []}; {'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': 'ret'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}; {'id': '119', 'type': 'string', 'children': [], 'value': "'@datatype'"}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': '_python_instance_to_nexml_meta_datatype'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128']}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '134']}; {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '133', 'type': 'string', 'children': [], 'value': "'$'"}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '135', 'type': 'else_clause', 'children': ['136']}; {'id': '136', 'type': 'block', 'children': ['137', '145']}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144']}; {'id': '143', 'type': 'string', 'children': [], 'value': "'@xsi:type'"}; {'id': '144', 'type': 'string', 'children': [], 'value': "'nex:ResourceMeta'"}; {'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': 'ret'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}; {'id': '151', 'type': 'string', 'children': [], 'value': "'@rel'"}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ret'} | def _convert_hbf_meta_val_for_xml(key, val):
if isinstance(val, list):
return [_convert_hbf_meta_val_for_xml(key, i) for i in val]
is_literal = True
content = None
if isinstance(val, dict):
ret = val
if '@href' in val:
is_literal = False
else:
content = val.get('$')
if isinstance(content, dict) and _contains_hbf_meta_keys(val):
is_literal = False
else:
ret = {}
content = val
if is_literal:
ret.setdefault('@xsi:type', 'nex:LiteralMeta')
ret.setdefault('@property', key)
if content is not None:
ret.setdefault('@datatype', _python_instance_to_nexml_meta_datatype(content))
if ret is not val:
ret['$'] = content
else:
ret.setdefault('@xsi:type', 'nex:ResourceMeta')
ret.setdefault('@rel', key)
return ret |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_params_match'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '32']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'getargspec'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'default_length'}; {'id': '19', 'type': 'conditional_expression', 'children': ['20', '26', '31'], 'value': 'if'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '30'], 'value': 'is'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '30', 'type': 'None', 'children': []}; {'id': '31', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '38', '87']}; {'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': 'parameters'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '38', 'type': 'block', 'children': ['39', '63', '77']}; {'id': '39', 'type': 'if_statement', 'children': ['40', '57']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '52'], 'value': 'and'}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '46'], 'value': '>'}; {'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': 'parameters'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': 'is'}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'varargs'}; {'id': '56', 'type': 'None', 'children': []}; {'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': 'InvalidParamsError'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"Too many parameters"'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'remaining_parameters'}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '73'], 'value': '-'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '77', 'type': 'if_statement', 'children': ['78', '81']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '>'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'remaining_parameters'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'default_length'}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'raise_statement', 'children': ['83']}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'InvalidParamsError'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'string', 'children': [], 'value': '"Not enough parameters"'}; {'id': '87', 'type': 'elif_clause', 'children': ['88', '93']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '93', 'type': 'block', 'children': ['94', '108', '128', '147', '161']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'missing_parameters'}; {'id': '97', 'type': 'list_comprehension', 'children': ['98', '99', '104']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '104', 'type': 'if_clause', 'children': ['105']}; {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'not'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'default_parameters'}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'subscript', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '118', 'type': 'slice', 'children': ['119', '127']}; {'id': '119', 'type': 'binary_operator', 'children': ['120', '126'], 'value': '-'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'default_length'}; {'id': '127', 'type': 'colon', 'children': []}; {'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'missing_parameters'}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}; {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'not'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'default_parameters'}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'raise_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'InvalidParamsError'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'string', 'children': [], 'value': '"Parameter {} has not been satisfied"'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'extra_params'}; {'id': '150', 'type': 'list_comprehension', 'children': ['151', '152', '155']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '152', 'type': 'for_in_clause', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '155', 'type': 'if_clause', 'children': ['156']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'not'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '161', 'type': 'if_statement', 'children': ['162', '174']}; {'id': '162', 'type': 'boolean_operator', 'children': ['163', '169'], 'value': 'and'}; {'id': '163', 'type': 'comparison_operator', 'children': ['164', '168'], 'value': '>'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'extra_params'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '169', 'type': 'comparison_operator', 'children': ['170', '173'], 'value': 'is'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'keywords'}; {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'block', 'children': ['175']}; {'id': '175', 'type': 'raise_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'InvalidParamsError'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'string', 'children': [], 'value': '"Too many parameters"'} | def validate_params_match(method, parameters):
argspec = inspect.getargspec(method)
default_length = len(argspec.defaults) if argspec.defaults is not None else 0
if isinstance(parameters, list):
if len(parameters) > len(argspec.args) and argspec.varargs is None:
raise InvalidParamsError("Too many parameters")
remaining_parameters = len(argspec.args) - len(parameters)
if remaining_parameters > default_length:
raise InvalidParamsError("Not enough parameters")
elif isinstance(parameters, dict):
missing_parameters = [key for key in argspec.args if key not in parameters]
default_parameters = set(argspec.args[len(argspec.args) - default_length:])
for key in missing_parameters:
if key not in default_parameters:
raise InvalidParamsError("Parameter {} has not been satisfied".format(key))
extra_params = [key for key in parameters if key not in argspec.args]
if len(extra_params) > 0 and argspec.keywords is None:
raise InvalidParamsError("Too many parameters") |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'addcols'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '34', '188', '208', '238']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '16']}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '13', 'type': 'argument_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '20', 'type': 'list_comprehension', 'children': ['21', '26']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'string', 'children': [], 'value': "','"}; {'id': '34', 'type': 'if_statement', 'children': ['35', '40', '151']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'if_statement', 'children': ['42', '69', '120']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'list_comprehension', 'children': ['46', '66']}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '60', '61'], 'value': 'or'}; {'id': '47', 'type': 'boolean_operator', 'children': ['48', '55'], 'value': 'or'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '60', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '69', 'type': 'block', 'children': ['70', '88', '103']}; {'id': '70', 'type': 'assert_statement', 'children': ['71', '87']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'list_comprehension', 'children': ['75', '84']}; {'id': '75', 'type': 'comparison_operator', 'children': ['76', '80'], 'value': '=='}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '87', 'type': 'string', 'children': [], 'value': "'Trying to add columns of wrong length.'"}; {'id': '88', 'type': 'assert_statement', 'children': ['89', '102']}; {'id': '89', 'type': 'boolean_operator', 'children': ['90', '93'], 'value': 'and'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '!='}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '92', 'type': 'None', 'children': []}; {'id': '93', 'type': 'comparison_operator', 'children': ['94', '98'], 'value': '=='}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'Number of columns to add must equal number of new names.'"}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'fromarrays'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112', '117']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '120', 'type': 'else_clause', 'children': ['121']}; {'id': '121', 'type': 'block', 'children': ['122', '133']}; {'id': '122', 'type': 'assert_statement', 'children': ['123', '132']}; {'id': '123', 'type': 'comparison_operator', 'children': ['124', '128'], 'value': '=='}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'Trying to add column of wrong length.'"}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'fromarrays'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '143', '148']}; {'id': '141', 'type': 'list', 'children': ['142'], 'value': '[cols]'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '148', 'type': 'keyword_argument', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '151', 'type': 'else_clause', 'children': ['152']}; {'id': '152', 'type': 'block', 'children': ['153', '161']}; {'id': '153', 'type': 'assert_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '161', 'type': 'if_statement', 'children': ['162', '169']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '168'], 'value': '=='}; {'id': '163', 'type': 'attribute', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '168', 'type': 'None', 'children': []}; {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'fromarrays'}; {'id': '177', 'type': 'argument_list', 'children': ['178', '180', '185']}; {'id': '178', 'type': 'list', 'children': ['179'], 'value': '[cols]'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'Replacements'}; {'id': '191', 'type': 'list_comprehension', 'children': ['192', '193', '200']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '193', 'type': 'for_in_clause', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '200', 'type': 'if_clause', 'children': ['201']}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'in'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '208', 'type': 'if_statement', 'children': ['209', '215']}; {'id': '209', 'type': 'comparison_operator', 'children': ['210', '214'], 'value': '>'}; {'id': '210', 'type': 'call', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'Replacements'}; {'id': '214', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '219', 'type': 'argument_list', 'children': ['220', '221']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'Replacing columns'"}; {'id': '221', 'type': 'list_comprehension', 'children': ['222', '223', '230']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '223', 'type': 'for_in_clause', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '225', 'type': 'attribute', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '230', 'type': 'if_clause', 'children': ['231']}; {'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'in'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '233', 'type': 'attribute', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '238', 'type': 'return_statement', 'children': ['239']}; {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'fromarrays'}; {'id': '243', 'type': 'argument_list', 'children': ['244', '286', '291']}; {'id': '244', 'type': 'binary_operator', 'children': ['245', '267'], 'value': '+'}; {'id': '245', 'type': 'list_comprehension', 'children': ['246', '260']}; {'id': '246', 'type': 'conditional_expression', 'children': ['247', '250', '257'], 'value': 'if'}; {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': 'not'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '252', 'type': 'attribute', 'children': ['253', '256']}; {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '260', 'type': 'for_in_clause', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '262', 'type': 'attribute', 'children': ['263', '266']}; {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '267', 'type': 'list_comprehension', 'children': ['268', '271', '278']}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '271', 'type': 'for_in_clause', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '273', 'type': 'attribute', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '278', 'type': 'if_clause', 'children': ['279']}; {'id': '279', 'type': 'comparison_operator', 'children': ['280', '281'], 'value': 'not'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '281', 'type': 'attribute', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '293', 'type': 'binary_operator', 'children': ['294', '302'], 'value': '+'}; {'id': '294', 'type': 'call', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}; {'id': '297', 'type': 'attribute', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '302', 'type': 'list_comprehension', 'children': ['303', '304', '311']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '304', 'type': 'for_in_clause', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '306', 'type': 'attribute', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '311', 'type': 'if_clause', 'children': ['312']}; {'id': '312', 'type': 'comparison_operator', 'children': ['313', '314'], 'value': 'not'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '314', 'type': 'attribute', 'children': ['315', '318']}; {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'names'} | def addcols(X, cols, names=None):
if isinstance(names,str):
names = [n.strip() for n in names.split(',')]
if isinstance(cols, list):
if any([isinstance(x,np.ndarray) or isinstance(x,list) or \
isinstance(x,tuple) for x in cols]):
assert all([len(x) == len(X) for x in cols]), \
'Trying to add columns of wrong length.'
assert names != None and len(cols) == len(names), \
'Number of columns to add must equal number of new names.'
cols = utils.fromarrays(cols,type=np.ndarray,names = names)
else:
assert len(cols) == len(X), 'Trying to add column of wrong length.'
cols = utils.fromarrays([cols], type=np.ndarray,names=names)
else:
assert isinstance(cols, np.ndarray)
if cols.dtype.names == None:
cols = utils.fromarrays([cols],type=np.ndarray, names=names)
Replacements = [a for a in cols.dtype.names if a in X.dtype.names]
if len(Replacements) > 0:
print('Replacing columns',
[a for a in cols.dtype.names if a in X.dtype.names])
return utils.fromarrays(
[X[a] if a not in cols.dtype.names else cols[a] for a in X.dtype.names] +
[cols[a] for a in cols.dtype.names if a not in X.dtype.names],
type=np.ndarray,
names=list(X.dtype.names) + [a for a in cols.dtype.names
if a not in X.dtype.names]) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'replace'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'old'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '46', '65']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '21', '30']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '=='}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '20', 'type': 'None', 'children': []}; {'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': 'cols'}; {'id': '25', 'type': 'attribute', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '30', 'type': 'elif_clause', 'children': ['31', '36']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'cols'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'string', 'children': [], 'value': "','"}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '64']}; {'id': '59', 'type': 'tuple', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '65', 'type': 'if_statement', 'children': ['66', '67', '127']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '67', 'type': 'block', 'children': ['68', '77']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '77', 'type': 'for_statement', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '80', 'type': 'block', 'children': ['81', '101']}; {'id': '81', 'type': 'if_statement', 'children': ['82', '91']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '88'], 'value': '<'}; {'id': '83', 'type': 'subscript', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98', '99', '100']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'WARNING: dtype of column'"}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'is inferior to dtype of '"}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'which may cause problems.'"}; {'id': '101', 'type': 'try_statement', 'children': ['102', '118']}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '117']}; {'id': '105', 'type': 'subscript', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '109', 'type': 'subscript', 'children': ['110', '116']}; {'id': '110', 'type': '()', 'children': ['111']}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': '=='}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'old'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '118', 'type': 'except_clause', 'children': ['119']}; {'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': 'print'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'Replacement not made on column'"}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'for_statement', 'children': ['130', '131', '132']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '132', 'type': 'block', 'children': ['133', '137']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'QuickRep'}; {'id': '136', 'type': 'True', 'children': []}; {'id': '137', 'type': 'try_statement', 'children': ['138', '152', '162']}; {'id': '138', 'type': 'block', 'children': ['139']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'colstr'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': "''"}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'subscript', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '152', 'type': 'except_clause', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '154', 'type': 'block', 'children': ['155']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160', '161']}; {'id': '159', 'type': 'string', 'children': [], 'value': "'Not replacing in column'"}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '161', 'type': 'string', 'children': [], 'value': "'due to type mismatch.'"}; {'id': '162', 'type': 'else_clause', 'children': ['163']}; {'id': '163', 'type': 'block', 'children': ['164', '184', '199', '269', '326', '345']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'avoid'}; {'id': '167', 'type': 'list_comprehension', 'children': ['168', '172']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ord'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '172', 'type': 'for_in_clause', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '174', 'type': 'call', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'uniqify'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'binary_operator', 'children': ['180', '183'], 'value': '+'}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '+'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'old'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'colstr'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '187', 'type': 'call', 'children': ['188', '197']}; {'id': '188', 'type': 'attribute', 'children': ['189', '196']}; {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'integer', 'children': [], 'value': '256'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'avoid'}; {'id': '199', 'type': 'if_statement', 'children': ['200', '206', '219']}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '205'], 'value': '>'}; {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '205', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '206', 'type': 'block', 'children': ['207']}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '210', 'type': 'call', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'chr'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}; {'id': '213', 'type': 'subscript', 'children': ['214', '218']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '218', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '219', 'type': 'else_clause', 'children': ['220']}; {'id': '220', 'type': 'block', 'children': ['221', '236']}; {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '224', 'type': 'call', 'children': ['225', '234']}; {'id': '225', 'type': 'attribute', 'children': ['226', '233']}; {'id': '226', 'type': 'call', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}; {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'integer', 'children': [], 'value': '65536'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'avoid'}; {'id': '236', 'type': 'if_statement', 'children': ['237', '243', '256']}; {'id': '237', 'type': 'comparison_operator', 'children': ['238', '242'], 'value': '>'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'unichr'}; {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'subscript', 'children': ['251', '255']}; {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '255', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '256', 'type': 'else_clause', 'children': ['257']}; {'id': '257', 'type': 'block', 'children': ['258', '265']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}; {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '261', 'type': 'argument_list', 'children': ['262', '263', '264']}; {'id': '262', 'type': 'string', 'children': [], 'value': "'All unicode characters represented in column'"}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '264', 'type': 'string', 'children': [], 'value': "', can\\t replace quickly.'"}; {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'QuickRep'}; {'id': '268', 'type': 'False', 'children': []}; {'id': '269', 'type': 'if_statement', 'children': ['270', '271', '301']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'QuickRep'}; {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'newrows'}; {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '299']}; {'id': '281', 'type': 'attribute', 'children': ['282', '298']}; {'id': '282', 'type': 'call', 'children': ['283', '295']}; {'id': '283', 'type': 'attribute', 'children': ['284', '294']}; {'id': '284', 'type': 'call', 'children': ['285', '288']}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'subscript', 'children': ['290', '293']}; {'id': '290', 'type': 'subscript', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '295', 'type': 'argument_list', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'old'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '301', 'type': 'else_clause', 'children': ['302']}; {'id': '302', 'type': 'block', 'children': ['303']}; {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'newrows'}; {'id': '306', 'type': 'call', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}; {'id': '311', 'type': 'list_comprehension', 'children': ['312', '319']}; {'id': '312', 'type': 'call', 'children': ['313', '316']}; {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'aa'}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '316', 'type': 'argument_list', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'old'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '319', 'type': 'for_in_clause', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'aa'}; {'id': '321', 'type': 'subscript', 'children': ['322', '325']}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'assignment', 'children': ['328', '333']}; {'id': '328', 'type': 'subscript', 'children': ['329', '332']}; {'id': '329', 'type': 'subscript', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '333', 'type': 'call', 'children': ['334', '343']}; {'id': '334', 'type': 'subscript', 'children': ['335', '338']}; {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'cast'}; {'id': '338', 'type': 'subscript', 'children': ['339', '342']}; {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'newrows'}; {'id': '345', 'type': 'if_statement', 'children': ['346', '355']}; {'id': '346', 'type': 'comparison_operator', 'children': ['347', '350'], 'value': '>'}; {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'newrows'}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '350', 'type': 'subscript', 'children': ['351', '354']}; {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '355', 'type': 'block', 'children': ['356']}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}; {'id': '357', 'type': 'call', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '359', 'type': 'argument_list', 'children': ['360', '361', '362']}; {'id': '360', 'type': 'string', 'children': [], 'value': "'WARNING: dtype of column'"}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '362', 'type': 'concatenated_string', 'children': ['363', '364', '365']}; {'id': '363', 'type': 'string', 'children': [], 'value': "'is inferior to the '"}; {'id': '364', 'type': 'string', 'children': [], 'value': "'dtype of its replacement which may cause problems '"}; {'id': '365', 'type': 'string', 'children': [], 'value': "'(ends of strings might get chopped off).'"} | def replace(X, old, new, strict=True, cols=None, rows=None):
if cols == None:
cols = X.dtype.names
elif isinstance(cols, str):
cols = cols.split(',')
if rows == None:
rows = np.ones((len(X),), bool)
if strict:
new = np.array(new)
for a in cols:
if X.dtype[a] < new.dtype:
print('WARNING: dtype of column', a,
'is inferior to dtype of ', new,
'which may cause problems.')
try:
X[a][(X[a] == old)[rows]] = new
except:
print('Replacement not made on column', a, '.')
else:
for a in cols:
QuickRep = True
try:
colstr = ''.join(X[a][rows])
except TypeError:
print('Not replacing in column', a, 'due to type mismatch.')
else:
avoid = [ord(o) for o in utils.uniqify(old + new + colstr)]
ok = set(range(256)).difference(avoid)
if len(ok) > 0:
sep = chr(list(ok)[0])
else:
ok = set(range(65536)).difference(avoid)
if len(ok) > 0:
sep = unichr(list(ok)[0])
else:
print('All unicode characters represented in column',
a, ', can\t replace quickly.')
QuickRep = False
if QuickRep:
newrows = np.array(sep.join(X[a][rows])
.replace(old, new).split(sep))
else:
newrows = np.array([aa.replace(old,new) for aa in
X[a][rows]])
X[a][rows] = np.cast[X.dtype[a]](newrows)
if newrows.dtype > X.dtype[a]:
print('WARNING: dtype of column', a, 'is inferior to the '
'dtype of its replacement which may cause problems '
'(ends of strings might get chopped off).') |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'rowstack'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'nulls'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'nullvals'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '14', '25']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'string', 'children': [], 'value': "'''\n Vertically stack a sequence of numpy ndarrays with structured dtype\n Analog of numpy.vstack\n Implemented by the tabarray method\n :func:`tabular.tab.tabarray.rowstack` which uses \n :func:`tabular.tabarray.tab_rowstack`.\n **Parameters**\n **seq** : sequence of numpy recarrays\n List, tuple, etc. of numpy recarrays to stack vertically.\n **mode** : string in ['nulls', 'commons', 'abort']\n Denotes how to proceed if the recarrays have different\n dtypes, e.g. different sets of named columns.\n * if `mode` == ``nulls``, the resulting set of columns is\n determined by the union of the dtypes of all recarrays\n to be stacked, and missing data is filled with null \n values as defined by \n :func:`tabular.spreadsheet.nullvalue`; this is the \n default mode.\n * elif `mode` == ``commons``, the resulting set of \n columns is determined by the intersection of the dtypes \n of all recarrays to be stacked, e.g. common columns.\n * elif `mode` == ``abort``, raise an error when the\n recarrays to stack have different dtypes.\n **Returns**\n **out** : numpy ndarray with structured dtype\n Result of vertically stacking the arrays in `seq`.\n **See also:** `numpy.vstack \n <http://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html>`_.\n '''"}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '=='}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'nullvals'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'nullvals'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_NULLVALUEFORMAT'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '32', '333']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '31'], 'value': '>'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'block', 'children': ['33', '43', '88']}; {'id': '33', 'type': 'assert_statement', 'children': ['34', '40', '41']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'in'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '36', 'type': 'list', 'children': ['37', '38', '39'], 'value': "['commons','nulls','abort']"}; {'id': '37', 'type': 'string', 'children': [], 'value': "'commons'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'nulls'"}; {'id': '39', 'type': 'string', 'children': [], 'value': "'abort'"}; {'id': '40', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '41', 'type': '()', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': '\'"mode" argument must either by "commons", "abort", or "nulls".\''}; {'id': '43', 'type': 'if_statement', 'children': ['44', '47']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '=='}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'abort'"}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '76', '82']}; {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'list_comprehension', 'children': ['54', '73']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '63'], 'value': '=='}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'attribute', 'children': ['67', '72']}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'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': 'ValueError'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'string', 'children': [], 'value': "'Some column names are different.'"}; {'id': '82', 'type': 'else_clause', 'children': ['83']}; {'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': 'mode'}; {'id': '87', 'type': 'string', 'children': [], 'value': "'commons'"}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92', '243']}; {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '91', 'type': 'string', 'children': [], 'value': "'nulls'"}; {'id': '92', 'type': 'block', 'children': ['93', '126', '163', '176']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'uniqify'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'listunion'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'list_comprehension', 'children': ['107', '115', '118']}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '118', 'type': 'if_clause', 'children': ['119']}; {'id': '119', 'type': 'comparison_operator', 'children': ['120', '125'], 'value': '!='}; {'id': '120', 'type': 'attribute', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '125', 'type': 'None', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '129', 'type': 'list_comprehension', 'children': ['130', '160']}; {'id': '130', 'type': 'attribute', 'children': ['131', '159']}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'list_comprehension', 'children': ['135', '140', '143']}; {'id': '135', 'type': 'subscript', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'att'}; {'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '143', 'type': 'if_clause', 'children': ['144']}; {'id': '144', 'type': 'boolean_operator', 'children': ['145', '152'], 'value': 'and'}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '151'], 'value': '!='}; {'id': '146', 'type': 'attribute', 'children': ['147', '150']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '151', 'type': 'None', 'children': []}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'in'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'att'}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'att'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '176', 'type': 'return_statement', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'fromarrays'}; {'id': '181', 'type': 'argument_list', 'children': ['182', '235', '240']}; {'id': '182', 'type': 'list_comprehension', 'children': ['183', '226']}; {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'listunion'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'list_comprehension', 'children': ['189', '223']}; {'id': '189', 'type': 'conditional_expression', 'children': ['190', '197', '213'], 'value': 'if'}; {'id': '190', 'type': 'call', 'children': ['191', '196']}; {'id': '191', 'type': 'attribute', 'children': ['192', '195']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'att'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '196', 'type': 'argument_list', 'children': []}; {'id': '197', 'type': '()', 'children': ['198']}; {'id': '198', 'type': 'boolean_operator', 'children': ['199', '206'], 'value': 'and'}; {'id': '199', 'type': 'comparison_operator', 'children': ['200', '205'], 'value': '!='}; {'id': '200', 'type': 'attribute', 'children': ['201', '204']}; {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '205', 'type': 'None', 'children': []}; {'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': 'in'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'att'}; {'id': '208', 'type': 'attribute', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '213', 'type': 'binary_operator', 'children': ['214', '219'], 'value': '*'}; {'id': '214', 'type': 'list', 'children': ['215'], 'value': '[nullvals(format)]'}; {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'nullvals'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '223', 'type': 'for_in_clause', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '226', 'type': 'for_in_clause', 'children': ['227', '230']}; {'id': '227', 'type': 'tuple_pattern', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'att'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '243', 'type': 'elif_clause', 'children': ['244', '247']}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '=='}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'commons'"}; {'id': '247', 'type': 'block', 'children': ['248', '281', '302']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}; {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '251', 'type': 'list_comprehension', 'children': ['252', '253', '262']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '253', 'type': 'for_in_clause', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '255', 'type': 'attribute', 'children': ['256', '261']}; {'id': '256', 'type': 'attribute', 'children': ['257', '260']}; {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '259', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '262', 'type': 'if_clause', 'children': ['263']}; {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'list_comprehension', 'children': ['267', '274']}; {'id': '267', 'type': 'comparison_operator', 'children': ['268', '269'], 'value': 'in'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '269', 'type': 'attribute', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '274', 'type': 'for_in_clause', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '276', 'type': 'subscript', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '278', 'type': 'slice', 'children': ['279', '280']}; {'id': '279', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '280', 'type': 'colon', 'children': []}; {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '284', 'type': 'list_comprehension', 'children': ['285', '299']}; {'id': '285', 'type': 'attribute', 'children': ['286', '298']}; {'id': '286', 'type': 'call', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'list_comprehension', 'children': ['290', '295']}; {'id': '290', 'type': 'subscript', 'children': ['291', '294']}; {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'att'}; {'id': '295', 'type': 'for_in_clause', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '299', 'type': 'for_in_clause', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'att'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '302', 'type': 'return_statement', 'children': ['303']}; {'id': '303', 'type': 'call', 'children': ['304', '307']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'fromrecords'}; {'id': '307', 'type': 'argument_list', 'children': ['308', '322', '327', '330']}; {'id': '308', 'type': 'call', 'children': ['309', '312']}; {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'listunion'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}; {'id': '313', 'type': 'list_comprehension', 'children': ['314', '319']}; {'id': '314', 'type': 'call', 'children': ['315', '318']}; {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'ar'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '318', 'type': 'argument_list', 'children': []}; {'id': '319', 'type': 'for_in_clause', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'ar'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '322', 'type': 'keyword_argument', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '327', 'type': 'keyword_argument', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '330', 'type': 'keyword_argument', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'formats'}; {'id': '333', 'type': 'else_clause', 'children': ['334']}; {'id': '334', 'type': 'block', 'children': ['335']}; {'id': '335', 'type': 'return_statement', 'children': ['336']}; {'id': '336', 'type': 'subscript', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '0'} | def rowstack(seq, mode='nulls', nullvals=None):
'''
Vertically stack a sequence of numpy ndarrays with structured dtype
Analog of numpy.vstack
Implemented by the tabarray method
:func:`tabular.tab.tabarray.rowstack` which uses
:func:`tabular.tabarray.tab_rowstack`.
**Parameters**
**seq** : sequence of numpy recarrays
List, tuple, etc. of numpy recarrays to stack vertically.
**mode** : string in ['nulls', 'commons', 'abort']
Denotes how to proceed if the recarrays have different
dtypes, e.g. different sets of named columns.
* if `mode` == ``nulls``, the resulting set of columns is
determined by the union of the dtypes of all recarrays
to be stacked, and missing data is filled with null
values as defined by
:func:`tabular.spreadsheet.nullvalue`; this is the
default mode.
* elif `mode` == ``commons``, the resulting set of
columns is determined by the intersection of the dtypes
of all recarrays to be stacked, e.g. common columns.
* elif `mode` == ``abort``, raise an error when the
recarrays to stack have different dtypes.
**Returns**
**out** : numpy ndarray with structured dtype
Result of vertically stacking the arrays in `seq`.
**See also:** `numpy.vstack
<http://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html>`_.
'''
if nullvals == None:
nullvals = utils.DEFAULT_NULLVALUEFORMAT
if len(seq) > 1:
assert mode in ['commons','nulls','abort'], \
('"mode" argument must either by "commons", "abort", or "nulls".')
if mode == 'abort':
if not all([set(l.dtype.names) == set(seq[0].dtype.names)
for l in seq]):
raise ValueError('Some column names are different.')
else:
mode = 'commons'
if mode == 'nulls':
names = utils.uniqify(utils.listunion([list(s.dtype.names)
for s in seq if s.dtype.names != None]))
formats = [max([s.dtype[att] for s in seq if s.dtype.names != None
and att in s.dtype.names]).str for att in names]
dtype = np.dtype(zip(names,formats))
return utils.fromarrays([utils.listunion([s[att].tolist()
if (s.dtype.names != None and att in s.dtype.names)
else [nullvals(format)] * len(s) for s in seq])
for (att, format) in zip(names, formats)], type=np.ndarray,
dtype=dtype)
elif mode == 'commons':
names = [x for x in seq[0].dtype.names
if all([x in l.dtype.names for l in seq[1:]])]
formats = [max([a.dtype[att] for a in seq]).str for att in names]
return utils.fromrecords(utils.listunion(
[ar.tolist() for ar in seq]), type=np.ndarray,
names=names, formats=formats)
else:
return seq[0] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'colstack'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'abort'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'returnnaming'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '21', '46', '76', '95', '223']}; {'id': '12', 'type': 'assert_statement', 'children': ['13', '20']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'in'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '15', 'type': 'list', 'children': ['16', '17', '18', '19'], 'value': "['first','drop','abort','rename']"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'first'"}; {'id': '17', 'type': 'string', 'children': [], 'value': "'drop'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'abort'"}; {'id': '19', 'type': 'string', 'children': [], 'value': "'rename'"}; {'id': '20', 'type': 'string', 'children': [], 'value': '\'mode argument must take on value "first","drop", "rename", or "abort".\''}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'AllNames'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'uniqify'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'listunion'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'list_comprehension', 'children': ['35', '43']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'NameList'}; {'id': '49', 'type': 'list_comprehension', 'children': ['50', '73']}; {'id': '50', 'type': 'tuple', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '52', 'type': 'list_comprehension', 'children': ['53', '54', '63']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '63', 'type': 'if_clause', 'children': ['64']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'in'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '66', 'type': 'attribute', 'children': ['67', '72']}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '73', 'type': 'for_in_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'AllNames'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'Commons'}; {'id': '79', 'type': 'list_comprehension', 'children': ['80', '83', '86']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '83', 'type': 'for_in_clause', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'NameList'}; {'id': '86', 'type': 'if_clause', 'children': ['87']}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '94'], 'value': '>'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '95', 'type': 'if_statement', 'children': ['96', '106', '206']}; {'id': '96', 'type': 'boolean_operator', 'children': ['97', '103'], 'value': 'or'}; {'id': '97', 'type': 'comparison_operator', 'children': ['98', '102'], 'value': '>'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'Commons'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '=='}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '105', 'type': 'string', 'children': [], 'value': "'first'"}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'if_statement', 'children': ['108', '111', '119', '143']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '=='}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'abort'"}; {'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': 'ValueError'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '+'}; {'id': '117', 'type': 'string', 'children': [], 'value': "'There are common column names with differing '"}; {'id': '118', 'type': 'string', 'children': [], 'value': "'values in the columns'"}; {'id': '119', 'type': 'elif_clause', 'children': ['120', '123']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '=='}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'drop'"}; {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '127', 'type': 'list_comprehension', 'children': ['128', '134', '139']}; {'id': '128', 'type': 'tuple', 'children': ['129', '132', '133']}; {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '131', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '138']}; {'id': '135', 'type': 'tuple_pattern', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'NameList'}; {'id': '139', 'type': 'if_clause', 'children': ['140']}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'not'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'Commons'}; {'id': '143', 'type': 'elif_clause', 'children': ['144', '147']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': '=='}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'rename'"}; {'id': '147', 'type': 'block', 'children': ['148', '155']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'NameDict'}; {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'NameList'}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'listunion'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'list_comprehension', 'children': ['164', '197', '198']}; {'id': '164', 'type': 'list_comprehension', 'children': ['165', '190']}; {'id': '165', 'type': 'conditional_expression', 'children': ['166', '170', '178', '179'], 'value': 'if'}; {'id': '166', 'type': 'tuple', 'children': ['167', '168', '169']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '177'], 'value': '=='}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'NameDict'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '179', 'type': 'tuple', 'children': ['180', '181', '182']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '186'], 'value': '+'}; {'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '185', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '186', 'type': 'call', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '190', 'type': 'for_in_clause', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '192', 'type': 'attribute', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '197', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '198', 'type': 'for_in_clause', 'children': ['199', '202']}; {'id': '199', 'type': 'tuple_pattern', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '206', 'type': 'else_clause', 'children': ['207']}; {'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': 'Names'}; {'id': '211', 'type': 'list_comprehension', 'children': ['212', '218']}; {'id': '212', 'type': 'tuple', 'children': ['213', '216', '217']}; {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '215', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '218', 'type': 'for_in_clause', 'children': ['219', '222']}; {'id': '219', 'type': 'tuple_pattern', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'NameList'}; {'id': '223', 'type': 'if_statement', 'children': ['224', '225', '260']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'returnnaming'}; {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'return_statement', 'children': ['227']}; {'id': '227', 'type': 'expression_list', 'children': ['228', '259']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'fromarrays'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '245', '250']}; {'id': '233', 'type': 'list_comprehension', 'children': ['234', '239']}; {'id': '234', 'type': 'subscript', 'children': ['235', '238']}; {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '239', 'type': 'for_in_clause', 'children': ['240', '244']}; {'id': '240', 'type': 'tuple_pattern', 'children': ['241', '242', '243']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '252', 'type': 'subscript', 'children': ['253', '258']}; {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'list_splat', 'children': ['257']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '260', 'type': 'else_clause', 'children': ['261']}; {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'return_statement', 'children': ['263']}; {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'fromarrays'}; {'id': '267', 'type': 'argument_list', 'children': ['268', '280', '285']}; {'id': '268', 'type': 'list_comprehension', 'children': ['269', '274']}; {'id': '269', 'type': 'subscript', 'children': ['270', '273']}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'seq'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '274', 'type': 'for_in_clause', 'children': ['275', '279']}; {'id': '275', 'type': 'tuple_pattern', 'children': ['276', '277', '278']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '285', 'type': 'keyword_argument', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '287', 'type': 'subscript', 'children': ['288', '293']}; {'id': '288', 'type': 'call', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}; {'id': '291', 'type': 'list_splat', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '293', 'type': 'integer', 'children': [], 'value': '2'} | def colstack(seq, mode='abort',returnnaming=False):
assert mode in ['first','drop','abort','rename'], \
'mode argument must take on value "first","drop", "rename", or "abort".'
AllNames = utils.uniqify(utils.listunion(
[list(l.dtype.names) for l in seq]))
NameList = [(x, [i for i in range(len(seq)) if x in seq[i].dtype.names])
for x in AllNames]
Commons = [x[0] for x in NameList if len(x[1]) > 1]
if len(Commons) > 0 or mode == 'first':
if mode == 'abort':
raise ValueError('There are common column names with differing ' +
'values in the columns')
elif mode == 'drop':
Names = [(L[0], x,x) for (x, L) in NameList if x not in Commons]
elif mode == 'rename':
NameDict = dict(NameList)
Names = utils.listunion([[(i,n,n) if len(NameDict[n]) == 1 else \
(i,n,n + '_' + str(i)) for n in s.dtype.names] \
for (i,s) in enumerate(seq)])
else:
Names = [(L[0], x,x) for (x, L) in NameList]
if returnnaming:
return utils.fromarrays([seq[i][x] for (i, x,y) in Names],
type= np.ndarray,names=zip(*Names)[2]),Names
else:
return utils.fromarrays([seq[i][x] for (i, x,y) in Names],
type= np.ndarray,names=zip(*Names)[2]) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'getjp2image'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sourceId'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'observatory'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'instrument'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'detector'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'measurement'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '23', '27', '31', '66', '97', '125', '153', '181', '209', '215']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'''\n Helioviewer.org and JHelioviewer operate off of JPEG2000 formatted image data generated from science-quality FITS files. Use the APIs below to interact directly with these intermediary JPEG2000 files.\n Download a JP2 image for the specified datasource that is the closest match in time to the `date` requested.\n Either `sourceId` must be specified, or the combination of `observatory`, `instrument`, `detector`, and `measurement`.\n Request Parameters:\n Parameter\tRequired\tType\tExample\tDescription\n date\tRequired\tstring\t2014-01-01T23:59:59Z\tDesired date/time of the JP2 image. ISO 8601 combined UTC date and time UTC format.\n sourceId\tOptional\tnumber\t14\tUnique image datasource identifier.\n observatory\tOptional\tstring\tSDO\tObservatory name.\n instrument\tOptional\tstring\tAIA\tInstrument name.\n detector\tOptional\tstring\tAIA\tDetector name.\n measurement\tOptional\tstring\t335\tMeasurement name.\n jpip\tOptional\tboolean\tfalse\tOptionally return a JPIP URI instead of the binary data of the image itself.\n json\tOptional\tboolean\tfalse\tOptionally return a JSON object.\n EXAMPLE: http://helioviewer.org/api/v1/getJP2Image/?date=2014-01-01T23:59:59Z&sourceId=14&jpip=true\n '''"}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'http://helioviewer.org/api/v1/getJP2Image/?'"}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'req_url'}; {'id': '30', 'type': 'string', 'children': [], 'value': "''"}; {'id': '31', 'type': 'try_statement', 'children': ['32', '59']}; {'id': '32', 'type': 'block', 'children': ['33', '38', '53']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'validate_iso8601'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '48']}; {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '47'], 'value': '=='}; {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '43', 'type': 'slice', 'children': ['44', '46']}; {'id': '44', 'type': 'unary_operator', 'children': ['45'], 'value': '-'}; {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'colon', 'children': []}; {'id': '47', 'type': 'string', 'children': [], 'value': "'Z'"}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'augmented_assignment', 'children': ['51', '52'], 'value': '+='}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'Z'"}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'augmented_assignment', 'children': ['55', '56'], 'value': '+='}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '+'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'date='"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '59', 'type': 'except_clause', 'children': ['60']}; {'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': 'ValueError'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'string', 'children': [], 'value': '"Your date input is not in iso8601 format. ex: 2014-01-01T23:59:59"'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sourceId'}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'if_statement', 'children': ['70', '76', '84']}; {'id': '70', 'type': 'not_operator', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'sourceId'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'int'}; {'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': 'logger'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'string', 'children': [], 'value': '"The sourceId argument should be an int, ignoring it"'}; {'id': '84', 'type': 'else_clause', 'children': ['85']}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'augmented_assignment', 'children': ['88', '89'], 'value': '+='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '89', 'type': 'binary_operator', 'children': ['90', '96'], 'value': '+'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'}; {'id': '91', 'type': 'string', 'children': [], 'value': '"sourceId="'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sourceId'}; {'id': '96', 'type': 'string', 'children': [], 'value': '"&"'}; {'id': '97', 'type': 'if_statement', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'observatory'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '107', '115']}; {'id': '101', 'type': 'not_operator', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'observatory'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'str'}; {'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': 'logger'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'string', 'children': [], 'value': '"The observatory argument should be a str, ignoring it"'}; {'id': '115', 'type': 'else_clause', 'children': ['116']}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'augmented_assignment', 'children': ['119', '120'], 'value': '+='}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '124'], 'value': '+'}; {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '+'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"observatory="'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'observatory'}; {'id': '124', 'type': 'string', 'children': [], 'value': '"&"'}; {'id': '125', 'type': 'if_statement', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'instrument'}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '135', '143']}; {'id': '129', 'type': 'not_operator', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'instrument'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'string', 'children': [], 'value': '"The instrument argument should be a str, ignoring it"'}; {'id': '143', 'type': 'else_clause', 'children': ['144']}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'augmented_assignment', 'children': ['147', '148'], 'value': '+='}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '152'], 'value': '+'}; {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '+'}; {'id': '150', 'type': 'string', 'children': [], 'value': '"instrument="'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'instrument'}; {'id': '152', 'type': 'string', 'children': [], 'value': '"&"'}; {'id': '153', 'type': 'if_statement', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'detector'}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '163', '171']}; {'id': '157', 'type': 'not_operator', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'detector'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'string', 'children': [], 'value': '"The detector argument should be a str, ignoring it"'}; {'id': '171', 'type': 'else_clause', 'children': ['172']}; {'id': '172', 'type': 'block', 'children': ['173']}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'augmented_assignment', 'children': ['175', '176'], 'value': '+='}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '180'], 'value': '+'}; {'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '+'}; {'id': '178', 'type': 'string', 'children': [], 'value': '"detector="'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'detector'}; {'id': '180', 'type': 'string', 'children': [], 'value': '"&"'}; {'id': '181', 'type': 'if_statement', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'measurement'}; {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'if_statement', 'children': ['185', '191', '199']}; {'id': '185', 'type': 'not_operator', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'measurement'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'string', 'children': [], 'value': '"The measurement argument should be a str, ignoring it"'}; {'id': '199', 'type': 'else_clause', 'children': ['200']}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'augmented_assignment', 'children': ['203', '204'], 'value': '+='}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '204', 'type': 'binary_operator', 'children': ['205', '208'], 'value': '+'}; {'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'}; {'id': '206', 'type': 'string', 'children': [], 'value': '"measurement="'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'detector'}; {'id': '208', 'type': 'string', 'children': [], 'value': '"&"'}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'augmented_assignment', 'children': ['211', '212'], 'value': '+='}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'req_url'}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '+'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '214', 'type': 'string', 'children': [], 'value': '"jpip=true"'}; {'id': '215', 'type': 'return_statement', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'dispatch_http_get'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'req_url'} | def getjp2image(date,
sourceId=None,
observatory=None,
instrument=None,
detector=None,
measurement=None):
'''
Helioviewer.org and JHelioviewer operate off of JPEG2000 formatted image data generated from science-quality FITS files. Use the APIs below to interact directly with these intermediary JPEG2000 files.
Download a JP2 image for the specified datasource that is the closest match in time to the `date` requested.
Either `sourceId` must be specified, or the combination of `observatory`, `instrument`, `detector`, and `measurement`.
Request Parameters:
Parameter Required Type Example Description
date Required string 2014-01-01T23:59:59Z Desired date/time of the JP2 image. ISO 8601 combined UTC date and time UTC format.
sourceId Optional number 14 Unique image datasource identifier.
observatory Optional string SDO Observatory name.
instrument Optional string AIA Instrument name.
detector Optional string AIA Detector name.
measurement Optional string 335 Measurement name.
jpip Optional boolean false Optionally return a JPIP URI instead of the binary data of the image itself.
json Optional boolean false Optionally return a JSON object.
EXAMPLE: http://helioviewer.org/api/v1/getJP2Image/?date=2014-01-01T23:59:59Z&sourceId=14&jpip=true
'''
base_url = 'http://helioviewer.org/api/v1/getJP2Image/?'
req_url = ''
try:
validate_iso8601(date)
if not date[-1:] == 'Z':
date += 'Z'
base_url += 'date=' + date
except:
raise ValueError(
"Your date input is not in iso8601 format. ex: 2014-01-01T23:59:59")
if sourceId:
if not isinstance(sourceId, int):
logger.error("The sourceId argument should be an int, ignoring it")
else:
base_url += "sourceId=" + str(sourceId) + "&"
if observatory:
if not isinstance(observatory, str):
logger.error(
"The observatory argument should be a str, ignoring it")
else:
base_url += "observatory=" + observatory + "&"
if instrument:
if not isinstance(instrument, str):
logger.error(
"The instrument argument should be a str, ignoring it")
else:
base_url += "instrument=" + instrument + "&"
if detector:
if not isinstance(detector, str):
logger.error("The detector argument should be a str, ignoring it")
else:
base_url += "detector=" + detector + "&"
if measurement:
if not isinstance(measurement, str):
logger.error(
"The measurement argument should be a str, ignoring it")
else:
base_url += "measurement=" + detector + "&"
req_url += base_url + "jpip=true"
return dispatch_http_get(req_url) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'loads_loader'}; {'id': '3', 'type': 'parameters', 'children': ['4', '10']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'load_module'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ModuleType'}; {'id': '10', 'type': 'typed_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '12', 'type': 'type', 'children': ['13']}; {'id': '13', 'type': 'generic_type', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '15', 'type': 'type_parameter', 'children': ['16', '18']}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '18', 'type': 'type', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '20', 'type': 'type', 'children': ['21']}; {'id': '21', 'type': 'generic_type', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '23', 'type': 'type_parameter', 'children': ['24']}; {'id': '24', 'type': 'type', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'JSGValidateable'}; {'id': '26', 'type': 'block', 'children': ['27', '33', '48', '64', '73', '143', '167']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cntxt'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'load_module'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_CONTEXT'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'possible_type'}; {'id': '36', 'type': 'conditional_expression', 'children': ['37', '42', '47'], 'value': 'if'}; {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cntxt'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'TYPE'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': 'in'}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'cntxt'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'TYPE'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'target_class'}; {'id': '51', 'type': 'conditional_expression', 'children': ['52', '58', '63'], 'value': 'if'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'load_module'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'possible_type'}; {'id': '57', 'type': 'None', 'children': []}; {'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': 'possible_type'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '63', 'type': 'None', 'children': []}; {'id': '64', 'type': 'if_statement', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'target_class'}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'return_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'target_class'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'dictionary_splat', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '78']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'type_exception'}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'cntxt'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'TYPE_EXCEPTIONS'}; {'id': '78', 'type': 'block', 'children': ['79', '97', '105', '111', '117', '135']}; {'id': '79', 'type': 'if_statement', 'children': ['80', '86']}; {'id': '80', 'type': 'not_operator', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'load_module'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'type_exception'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'raise_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'UNKNOWN_TYPE_EXCEPTION'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'type_exception'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'target_class'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'load_module'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'type_exception'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'target_strict'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'target_class'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_strict'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'target_class'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': '_strict'}; {'id': '116', 'type': 'False', 'children': []}; {'id': '117', 'type': 'try_statement', 'children': ['118', '127']}; {'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': 'rval'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'target_class'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'dictionary_splat', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '127', 'type': 'finally_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'target_class'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': '_strict'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'target_strict'}; {'id': '135', 'type': 'if_statement', 'children': ['136', '140']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'is_valid'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'rval'}; {'id': '140', 'type': 'block', 'children': ['141']}; {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'rval'}; {'id': '143', 'type': 'if_statement', 'children': ['144', '152']}; {'id': '144', 'type': 'boolean_operator', 'children': ['145', '149'], 'value': 'and'}; {'id': '145', 'type': 'not_operator', 'children': ['146']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'cntxt'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'TYPE'}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'cntxt'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'TYPE_EXCEPTIONS'}; {'id': '152', 'type': 'block', 'children': ['153']}; {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '164']}; {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '157', 'type': 'argument_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'load_module'}; {'id': '159', 'type': 'subscript', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'cntxt'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'TYPE_EXCEPTIONS'}; {'id': '163', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'dictionary_splat', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '167', 'type': 'if_statement', 'children': ['168', '173', '179']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '172'], 'value': 'in'}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'cntxt'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'TYPE'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'pairs'}; {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'raise_statement', 'children': ['175']}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'string', 'children': [], 'value': 'f\'Unknown reference type: "{cntxt.TYPE}": "{pairs[cntxt.TYPE]}"\''}; {'id': '179', 'type': 'else_clause', 'children': ['180']}; {'id': '180', 'type': 'block', 'children': ['181']}; {'id': '181', 'type': 'raise_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'string', 'children': [], 'value': 'f\'Missing "{cntxt.TYPE}" element\''} | def loads_loader(load_module: types.ModuleType, pairs: Dict[str, str]) -> Optional[JSGValidateable]:
cntxt = load_module._CONTEXT
possible_type = pairs[cntxt.TYPE] if cntxt.TYPE in pairs else None
target_class = getattr(load_module, possible_type, None) if isinstance(possible_type, str) else None
if target_class:
return target_class(**pairs)
for type_exception in cntxt.TYPE_EXCEPTIONS:
if not hasattr(load_module, type_exception):
raise ValueError(UNKNOWN_TYPE_EXCEPTION.format(type_exception))
target_class = getattr(load_module, type_exception)
target_strict = target_class._strict
target_class._strict = False
try:
rval = target_class(**pairs)
finally:
target_class._strict = target_strict
if is_valid(rval):
return rval
if not cntxt.TYPE and cntxt.TYPE_EXCEPTIONS:
return getattr(load_module, cntxt.TYPE_EXCEPTIONS[0])(**pairs)
if cntxt.TYPE in pairs:
raise ValueError(f'Unknown reference type: "{cntxt.TYPE}": "{pairs[cntxt.TYPE]}"')
else:
raise ValueError(f'Missing "{cntxt.TYPE}" element') |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_cred_def'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '9', 'type': 'type', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '11', 'type': 'block', 'children': ['12', '20', '29', '191', '199']}; {'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': 'debug'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'_BaseAgent.get_cred_def >>> cd_id: %s'"}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'rv_json'}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'dictionary', 'children': []}; {'id': '29', 'type': 'with_statement', 'children': ['30', '35']}; {'id': '30', 'type': 'with_clause', 'children': ['31']}; {'id': '31', 'type': 'with_item', 'children': ['32']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'CRED_DEF_CACHE'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '35', 'type': 'block', 'children': ['36', '70', '83', '93', '102', '137', '172', '183']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'in'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'CRED_DEF_CACHE'}; {'id': '40', 'type': 'block', 'children': ['41', '49', '60', '68']}; {'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': 'LOGGER'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': "'_BaseAgent.get_cred_def: got cred def for %s from cache'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'rv_json'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'CRED_DEF_CACHE'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'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': 'LOGGER'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'_BaseAgent.get_cred_def <<< %s'"}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'rv_json'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'rv_json'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'req_json'}; {'id': '73', 'type': 'await', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ledger'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'build_get_cred_def_request'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'did'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'resp_json'}; {'id': '86', 'type': 'await', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_submit'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'req_json'}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'resp_json'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '118']}; {'id': '103', 'type': 'not_operator', 'children': ['104']}; {'id': '104', 'type': '()', 'children': ['105']}; {'id': '105', 'type': 'boolean_operator', 'children': ['106', '109'], 'value': 'and'}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'in'}; {'id': '107', 'type': 'string', 'children': [], 'value': "'result'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '113', 'type': 'string', 'children': [], 'value': "'result'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '117', 'type': 'None', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119', '127']}; {'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': 'LOGGER'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126']}; {'id': '125', 'type': 'string', 'children': [], 'value': "'_BaseAgent.get_cred_def: <!< no cred def exists on %s'"}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '127', 'type': 'raise_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'AbsentCredDef'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'string', 'children': [], 'value': "'No cred def exists on {}'"}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '137', 'type': 'try_statement', 'children': ['138', '151']}; {'id': '138', 'type': 'block', 'children': ['139']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '144']}; {'id': '141', 'type': 'tuple_pattern', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'rv_json'}; {'id': '144', 'type': 'await', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ledger'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'parse_get_cred_def_response'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'resp_json'}; {'id': '151', 'type': 'except_clause', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'IndyError'}; {'id': '153', 'type': 'block', 'children': ['154', '162']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': "'_BaseAgent.get_cred_def: <!< no cred def exists on %s'"}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '162', 'type': 'raise_statement', 'children': ['163']}; {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'AbsentCredDef'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'string', 'children': [], 'value': "'No cred def exists on {}'"}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'CRED_DEF_CACHE'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'rv_json'}; {'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': 'LOGGER'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190']}; {'id': '189', 'type': 'string', 'children': [], 'value': "'_BaseAgent.get_cred_def: got cred def %s from ledger'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198']}; {'id': '197', 'type': 'string', 'children': [], 'value': "'_BaseAgent.get_cred_def <<< %s'"}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'rv_json'}; {'id': '199', 'type': 'return_statement', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'rv_json'} | async def get_cred_def(self, cd_id: str) -> str:
LOGGER.debug('_BaseAgent.get_cred_def >>> cd_id: %s', cd_id)
rv_json = json.dumps({})
with CRED_DEF_CACHE.lock:
if cd_id in CRED_DEF_CACHE:
LOGGER.info('_BaseAgent.get_cred_def: got cred def for %s from cache', cd_id)
rv_json = json.dumps(CRED_DEF_CACHE[cd_id])
LOGGER.debug('_BaseAgent.get_cred_def <<< %s', rv_json)
return rv_json
req_json = await ledger.build_get_cred_def_request(self.did, cd_id)
resp_json = await self._submit(req_json)
resp = json.loads(resp_json)
if not ('result' in resp and resp['result'].get('data', None)):
LOGGER.debug('_BaseAgent.get_cred_def: <!< no cred def exists on %s', cd_id)
raise AbsentCredDef('No cred def exists on {}'.format(cd_id))
try:
(_, rv_json) = await ledger.parse_get_cred_def_response(resp_json)
except IndyError:
LOGGER.debug('_BaseAgent.get_cred_def: <!< no cred def exists on %s', cd_id)
raise AbsentCredDef('No cred def exists on {}'.format(cd_id))
CRED_DEF_CACHE[cd_id] = json.loads(rv_json)
LOGGER.info('_BaseAgent.get_cred_def: got cred def %s from ledger', cd_id)
LOGGER.debug('_BaseAgent.get_cred_def <<< %s', rv_json)
return rv_json |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'convert_nexson_format'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'remove_old_structs'}; {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pristine_if_invalid'}; {'id': '14', 'type': 'False', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_arbitrary'}; {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '30', '37', '52', '64', '76', '102', '118', '125', '209', '218', '226']}; {'id': '19', 'type': 'if_statement', 'children': ['20', '22']}; {'id': '20', 'type': 'not_operator', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'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': 'current_format'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'detect_nexson_version'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'resolve_nexson_format'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '41', 'type': 'block', 'children': ['42', '50']}; {'id': '42', 'type': 'if_statement', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort_arbitrary'}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sort_arbitrarily_ordered_nexson'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '50', 'type': 'return_statement', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'two2zero'}; {'id': '55', 'type': 'boolean_operator', 'children': ['56', '60'], 'value': 'and'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': '_is_by_id_hbf'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': '_is_badgerfish_version'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'zero2two'}; {'id': '67', 'type': 'boolean_operator', 'children': ['68', '72'], 'value': 'and'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': '_is_by_id_hbf'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': '_is_badgerfish_version'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80']}; {'id': '77', 'type': 'boolean_operator', 'children': ['78', '79'], 'value': 'or'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'two2zero'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'zero2two'}; {'id': '80', 'type': 'block', 'children': ['81', '98']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'convert_nexson_format'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89', '92', '95']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'DIRECT_HONEY_BADGERFISH'}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'remove_old_structs'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'remove_old_structs'}; {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'pristine_if_invalid'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'pristine_if_invalid'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'DIRECT_HONEY_BADGERFISH'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ccdict'}; {'id': '105', 'type': 'dictionary', 'children': ['106', '109', '112', '115']}; {'id': '106', 'type': 'pair', 'children': ['107', '108']}; {'id': '107', 'type': 'string', 'children': [], 'value': "'output_format'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '109', 'type': 'pair', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'input_format'"}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '112', 'type': 'pair', 'children': ['113', '114']}; {'id': '113', 'type': 'string', 'children': [], 'value': "'remove_old_structs'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'remove_old_structs'}; {'id': '115', 'type': 'pair', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': "'pristine_if_invalid'"}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'pristine_if_invalid'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ccfg'}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ConversionConfig'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'ccdict'}; {'id': '125', 'type': 'if_statement', 'children': ['126', '130', '138', '156', '174', '192']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': '_is_badgerfish_version'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'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': 'converter'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'Badgerfish2DirectNexson'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ccfg'}; {'id': '138', 'type': 'elif_clause', 'children': ['139', '143']}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': '_is_badgerfish_version'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '143', 'type': 'block', 'children': ['144', '149']}; {'id': '144', 'type': 'assert_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '_is_direct_hbf'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'Direct2BadgerfishNexson'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ccfg'}; {'id': '156', 'type': 'elif_clause', 'children': ['157', '166']}; {'id': '157', 'type': 'boolean_operator', 'children': ['158', '162'], 'value': 'and'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': '_is_direct_hbf'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '162', 'type': '()', 'children': ['163']}; {'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': '=='}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'BY_ID_HONEY_BADGERFISH'}; {'id': '166', 'type': 'block', 'children': ['167']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '170', 'type': 'call', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'Direct2OptimalNexson'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ccfg'}; {'id': '174', 'type': 'elif_clause', 'children': ['175', '184']}; {'id': '175', 'type': 'boolean_operator', 'children': ['176', '180'], 'value': 'and'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': '_is_direct_hbf'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '180', 'type': '()', 'children': ['181']}; {'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': '=='}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'BY_ID_HONEY_BADGERFISH'}; {'id': '184', 'type': 'block', 'children': ['185']}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'Optimal2DirectNexson'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'ccfg'}; {'id': '192', 'type': 'else_clause', 'children': ['193']}; {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'raise_statement', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'Conversion from {i} to {o}'"}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '206']}; {'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'current_format'}; {'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'out_nexson_format'}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'convert'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'sort_arbitrary'}; {'id': '220', 'type': 'block', 'children': ['221']}; {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'sort_arbitrarily_ordered_nexson'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'blob'}; {'id': '226', 'type': 'return_statement', 'children': ['227']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'blob'} | def convert_nexson_format(blob,
out_nexson_format,
current_format=None,
remove_old_structs=True,
pristine_if_invalid=False,
sort_arbitrary=False):
if not current_format:
current_format = detect_nexson_version(blob)
out_nexson_format = resolve_nexson_format(out_nexson_format)
if current_format == out_nexson_format:
if sort_arbitrary:
sort_arbitrarily_ordered_nexson(blob)
return blob
two2zero = _is_by_id_hbf(out_nexson_format) and _is_badgerfish_version(current_format)
zero2two = _is_by_id_hbf(current_format) and _is_badgerfish_version(out_nexson_format)
if two2zero or zero2two:
blob = convert_nexson_format(blob,
DIRECT_HONEY_BADGERFISH,
current_format=current_format,
remove_old_structs=remove_old_structs,
pristine_if_invalid=pristine_if_invalid)
current_format = DIRECT_HONEY_BADGERFISH
ccdict = {'output_format': out_nexson_format,
'input_format': current_format,
'remove_old_structs': remove_old_structs,
'pristine_if_invalid': pristine_if_invalid}
ccfg = ConversionConfig(ccdict)
if _is_badgerfish_version(current_format):
converter = Badgerfish2DirectNexson(ccfg)
elif _is_badgerfish_version(out_nexson_format):
assert _is_direct_hbf(current_format)
converter = Direct2BadgerfishNexson(ccfg)
elif _is_direct_hbf(current_format) and (out_nexson_format == BY_ID_HONEY_BADGERFISH):
converter = Direct2OptimalNexson(ccfg)
elif _is_direct_hbf(out_nexson_format) and (current_format == BY_ID_HONEY_BADGERFISH):
converter = Optimal2DirectNexson(ccfg)
else:
raise NotImplementedError('Conversion from {i} to {o}'.format(i=current_format, o=out_nexson_format))
blob = converter.convert(blob)
if sort_arbitrary:
sort_arbitrarily_ordered_nexson(blob)
return blob |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_inplace_sort_by_id'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'unsorted_list'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '30', '36', '41']}; {'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': 'unsorted_list'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted_list'}; {'id': '18', 'type': 'list_comprehension', 'children': ['19', '27']}; {'id': '19', 'type': 'tuple', 'children': ['20', '26']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'string', 'children': [], 'value': "'@id'"}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'unsorted_list'}; {'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': 'sorted_list'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'delete_statement', 'children': ['37']}; {'id': '37', 'type': 'subscript', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'unsorted_list'}; {'id': '39', 'type': 'slice', 'children': ['40']}; {'id': '40', 'type': 'colon', 'children': []}; {'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': 'unsorted_list'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'list_comprehension', 'children': ['48', '51']}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '51', 'type': 'for_in_clause', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sorted_list'} | def _inplace_sort_by_id(unsorted_list):
if not isinstance(unsorted_list, list):
return
sorted_list = [(i.get('@id'), i) for i in unsorted_list]
sorted_list.sort()
del unsorted_list[:]
unsorted_list.extend([i[1] for i in sorted_list]) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cull_nonmatching_trees'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'nexson'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'tree_id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'curr_version'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '22', '37', '44', '50', '54', '117', '134']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'curr_version'}; {'id': '13', 'type': 'None', 'children': []}; {'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': 'curr_version'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'detect_nexson_version'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'nexson'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '28']}; {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': '_is_by_id_hbf'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'curr_version'}; {'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': 'nexson'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'convert_nexson_format'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'nexson'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'BY_ID_HONEY_BADGERFISH'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'nexml_el'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'get_nexml_el'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'nexson'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'tree_groups'}; {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'nexml_el'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'treesById'"}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tree_groups_to_del'}; {'id': '53', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '54', 'type': 'for_statement', 'children': ['55', '58', '63']}; {'id': '55', 'type': 'pattern_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'tgi'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tree_group'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'tree_groups'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'block', 'children': ['64', '70']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'tbi'}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tree_group'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'treeById'"}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74', '108']}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'in'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'tree_id'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'tbi'}; {'id': '74', 'type': 'block', 'children': ['75', '91']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'trees_to_del'}; {'id': '78', 'type': 'list_comprehension', 'children': ['79', '80', '87']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '80', 'type': 'for_in_clause', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'tbi'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '86', 'type': 'argument_list', 'children': []}; {'id': '87', 'type': 'if_clause', 'children': ['88']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '!='}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'tree_id'}; {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tid'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'trees_to_del'}; {'id': '94', 'type': 'block', 'children': ['95', '104']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '102']}; {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'tree_group'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'^ot:treeElementOrder'"}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'tid'}; {'id': '104', 'type': 'delete_statement', 'children': ['105']}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'tbi'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'tid'}; {'id': '108', 'type': 'else_clause', 'children': ['109']}; {'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': 'tree_groups_to_del'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'tgi'}; {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'tgid'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'tree_groups_to_del'}; {'id': '120', 'type': 'block', 'children': ['121', '130']}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '128']}; {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'nexml_el'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'^ot:treesElementOrder'"}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'tgid'}; {'id': '130', 'type': 'delete_statement', 'children': ['131']}; {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'tree_groups'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'tgid'}; {'id': '134', 'type': 'return_statement', 'children': ['135']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'nexson'} | def cull_nonmatching_trees(nexson, tree_id, curr_version=None):
if curr_version is None:
curr_version = detect_nexson_version(nexson)
if not _is_by_id_hbf(curr_version):
nexson = convert_nexson_format(nexson, BY_ID_HONEY_BADGERFISH)
nexml_el = get_nexml_el(nexson)
tree_groups = nexml_el['treesById']
tree_groups_to_del = []
for tgi, tree_group in tree_groups.items():
tbi = tree_group['treeById']
if tree_id in tbi:
trees_to_del = [i for i in tbi.keys() if i != tree_id]
for tid in trees_to_del:
tree_group['^ot:treeElementOrder'].remove(tid)
del tbi[tid]
else:
tree_groups_to_del.append(tgi)
for tgid in tree_groups_to_del:
nexml_el['^ot:treesElementOrder'].remove(tgid)
del tree_groups[tgid]
return nexson |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18', '30']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_validate'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '17']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'generic_type', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '14', 'type': 'type_parameter', 'children': ['15']}; {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Logger'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'type', 'children': ['19']}; {'id': '19', 'type': 'generic_type', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Tuple'}; {'id': '21', 'type': 'type_parameter', 'children': ['22', '24']}; {'id': '22', 'type': 'type', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '24', 'type': 'type', 'children': ['25']}; {'id': '25', 'type': 'generic_type', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '27', 'type': 'type_parameter', 'children': ['28']}; {'id': '28', 'type': 'type', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '30', 'type': 'block', 'children': ['31', '35', '133', '147']}; {'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': 'if_statement', 'children': ['36', '42', '50']}; {'id': '36', 'type': 'not_operator', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'string', 'children': [], 'value': 'f"{self._variable_name}: {repr(val)} is not an array"'}; {'id': '50', 'type': 'else_clause', 'children': ['51']}; {'id': '51', 'type': 'block', 'children': ['52', '91', '110']}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '62']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}; {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '62', 'type': 'block', 'children': ['63', '69']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '69', 'type': 'if_statement', 'children': ['70', '83']}; {'id': '70', 'type': 'not_operator', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'conforms'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '75', '78']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': '_type'}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': '_context'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'NAMESPACE'}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': 'f"{self._variable_name} element {i}: {v} is not a {self._type.__name__}"'}; {'id': '91', 'type': 'if_statement', 'children': ['92', '100']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '97'], 'value': '<'}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': '_min'}; {'id': '100', 'type': 'block', 'children': ['101']}; {'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': 'errors'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'concatenated_string', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': 'f"{self._variable_name}: at least {self._min} value{\'s\' if self._min > 1 else \'\'} required - "'}; {'id': '109', 'type': 'string', 'children': [], 'value': 'f"element has {len(val) if len(val) else \'none\'}"'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '125']}; {'id': '111', 'type': 'boolean_operator', 'children': ['112', '117'], 'value': 'and'}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '116'], 'value': 'is'}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': '_max'}; {'id': '116', 'type': 'None', 'children': []}; {'id': '117', 'type': 'comparison_operator', 'children': ['118', '122'], 'value': '>'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': '_max'}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'string', 'children': [], 'value': 'f"{self._variable_name}: no more than {self._max} values permitted - element has {len(val)}"'}; {'id': '133', 'type': 'if_statement', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'for_statement', 'children': ['137', '138', '139']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '139', 'type': 'block', 'children': ['140']}; {'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': 'log'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '147', 'type': 'return_statement', 'children': ['148']}; {'id': '148', 'type': 'expression_list', 'children': ['149', '154']}; {'id': '149', 'type': 'not_operator', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'errors'} | def _validate(self, val: list, log: Optional[Logger] = None) -> Tuple[bool, List[str]]:
errors = []
if not isinstance(val, list):
errors.append(f"{self._variable_name}: {repr(val)} is not an array")
else:
for i in range(0, len(val)):
v = val[i]
if not conforms(v, self._type, self._context.NAMESPACE):
errors.append(f"{self._variable_name} element {i}: {v} is not a {self._type.__name__}")
if len(val) < self._min:
errors.append(
f"{self._variable_name}: at least {self._min} value{'s' if self._min > 1 else ''} required - "
f"element has {len(val) if len(val) else 'none'}")
if self._max is not None and len(val) > self._max:
errors.append(
f"{self._variable_name}: no more than {self._max} values permitted - element has {len(val)}")
if log:
for error in errors:
log.log(error)
return not bool(errors), errors |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_sync_revoc'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'rr_size'}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'type', 'children': ['15']}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '26', '35', '72', '176']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'Issuer._sync_revoc >>> rr_id: %s, rr_size: %s'"}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'rr_size'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '31']}; {'id': '28', 'type': 'tuple_pattern', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'rev_reg_id2cred_def_id__tag'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '35', 'type': 'try_statement', 'children': ['36', '45']}; {'id': '36', 'type': 'block', 'children': ['37']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'await', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'get_cred_def'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '45', 'type': 'except_clause', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'AbsentCredDef'}; {'id': '47', 'type': 'block', 'children': ['48', '59']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'Issuer._sync_revoc: <!< tails tree %s may be for another ledger; no cred def found on %s'"}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': '_dir_tails'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '59', 'type': 'raise_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'AbsentCredDef'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'string', 'children': [], 'value': "'Tails tree {} may be for another ledger; no cred def found on {}'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_dir_tails'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '72', 'type': 'with_statement', 'children': ['73', '78']}; {'id': '73', 'type': 'with_clause', 'children': ['74']}; {'id': '74', 'type': 'with_item', 'children': ['75']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'REVO_CACHE'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '78', 'type': 'block', 'children': ['79', '89', '100']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'revo_cache_entry'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'REVO_CACHE'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '88', 'type': 'None', 'children': []}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '92', 'type': 'conditional_expression', 'children': ['93', '94', '97'], 'value': 'if'}; {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'is'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'revo_cache_entry'}; {'id': '96', 'type': 'None', 'children': []}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'revo_cache_entry'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'block', 'children': ['105', '151']}; {'id': '105', 'type': 'try_statement', 'children': ['106', '123']}; {'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': 'tails'}; {'id': '110', 'type': 'await', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '122']}; {'id': '112', 'type': 'attribute', 'children': ['113', '121']}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'Tails'}; {'id': '115', 'type': 'argument_list', 'children': ['116', '119', '120']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_dir_tails'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '122', 'type': 'argument_list', 'children': []}; {'id': '123', 'type': 'except_clause', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'AbsentTails'}; {'id': '125', 'type': 'block', 'children': ['126', '135']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'await', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': '_create_rev_reg'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'rr_size'}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '138', 'type': 'await', 'children': ['139']}; {'id': '139', 'type': 'call', 'children': ['140', '150']}; {'id': '140', 'type': 'attribute', 'children': ['141', '149']}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'Tails'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '147', '148']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '_dir_tails'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '150', 'type': 'argument_list', 'children': []}; {'id': '151', 'type': 'if_statement', 'children': ['152', '155', '166']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'revo_cache_entry'}; {'id': '154', 'type': 'None', 'children': []}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'REVO_CACHE'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'RevoCacheEntry'}; {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'None', 'children': []}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '166', 'type': 'else_clause', 'children': ['167']}; {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '175']}; {'id': '170', 'type': 'attribute', 'children': ['171', '174']}; {'id': '171', 'type': 'subscript', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'REVO_CACHE'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'rr_id'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'tails'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'string', 'children': [], 'value': "'Issuer._sync_revoc <<<'"} | async def _sync_revoc(self, rr_id: str, rr_size: int = None) -> None:
LOGGER.debug('Issuer._sync_revoc >>> rr_id: %s, rr_size: %s', rr_id, rr_size)
(cd_id, tag) = rev_reg_id2cred_def_id__tag(rr_id)
try:
await self.get_cred_def(cd_id)
except AbsentCredDef:
LOGGER.debug(
'Issuer._sync_revoc: <!< tails tree %s may be for another ledger; no cred def found on %s',
self._dir_tails,
cd_id)
raise AbsentCredDef('Tails tree {} may be for another ledger; no cred def found on {}'.format(
self._dir_tails,
cd_id))
with REVO_CACHE.lock:
revo_cache_entry = REVO_CACHE.get(rr_id, None)
tails = None if revo_cache_entry is None else revo_cache_entry.tails
if tails is None:
try:
tails = await Tails(self._dir_tails, cd_id, tag).open()
except AbsentTails:
await self._create_rev_reg(rr_id, rr_size)
tails = await Tails(self._dir_tails, cd_id, tag).open()
if revo_cache_entry is None:
REVO_CACHE[rr_id] = RevoCacheEntry(None, tails)
else:
REVO_CACHE[rr_id].tails = tails
LOGGER.debug('Issuer._sync_revoc <<<') |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_namespace_uri'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'schema_location'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '15']}; {'id': '13', 'type': 'assert_statement', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '15', 'type': 'if_statement', 'children': ['16', '21', '92']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '__ns_uri_map'}; {'id': '21', 'type': 'block', 'children': ['22', '31', '40', '60', '68', '82']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'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': '__lookup_uri'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'new_ni'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '42', 'type': 'block', 'children': ['43', '51']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': '__check_prefix_conflict'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '58']}; {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'new_ni'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'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': '__merge_schema_locations'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'new_ni'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'schema_location'}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '73']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'new_ni'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '81']}; {'id': '76', 'type': 'subscript', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': '__prefix_map'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'new_ni'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '91']}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': '__ns_uri_map'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'new_ni'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'new_ni'}; {'id': '92', 'type': 'else_clause', 'children': ['93']}; {'id': '93', 'type': 'block', 'children': ['94', '105', '114']}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'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': 'self'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': '__check_prefix_conflict'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': '_NamespaceInfo'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112', '113']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'schema_location'}; {'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': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '__add_namespaceinfo'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ni'} | def add_namespace_uri(self, ns_uri, prefix=None, schema_location=None):
assert ns_uri
if ns_uri in self.__ns_uri_map:
ni = self.__lookup_uri(ns_uri)
new_ni = copy.deepcopy(ni)
if prefix:
self.__check_prefix_conflict(ni, prefix)
new_ni.prefixes.add(prefix)
self.__merge_schema_locations(new_ni, schema_location)
for p in new_ni.prefixes:
self.__prefix_map[p] = new_ni
self.__ns_uri_map[new_ni.uri] = new_ni
else:
if prefix:
self.__check_prefix_conflict(ns_uri, prefix)
ni = _NamespaceInfo(ns_uri, prefix, schema_location)
self.__add_namespaceinfo(ni) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_schemaloc_string'}; {'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': 'ns_uris'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'delim'}; {'id': '13', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '14', 'type': 'block', 'children': ['15', '30', '40', '44', '74', '80']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '18']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ns_uris'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ns_uris'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'iterkeys'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': '__ns_uri_map'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ns_uris'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ns_uris'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'schemalocs'}; {'id': '43', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '44', 'type': 'for_statement', 'children': ['45', '46', '47']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ns_uris'}; {'id': '47', 'type': 'block', 'children': ['48', '57']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '__lookup_uri'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '57', 'type': 'if_statement', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'schema_location'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'schemalocs'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': '"{0.uri} {0.schema_location}"'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '77']}; {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'schemalocs'}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'return_statement', 'children': ['79']}; {'id': '79', 'type': 'string', 'children': [], 'value': '""'}; {'id': '80', 'type': 'return_statement', 'children': ['81']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'string', 'children': [], 'value': '\'xsi:schemaLocation="{0}"\''}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'delim'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'schemalocs'} | def get_schemaloc_string(self, ns_uris=None, sort=False, delim="\n"):
if not ns_uris:
ns_uris = six.iterkeys(self.__ns_uri_map)
if sort:
ns_uris = sorted(ns_uris)
schemalocs = []
for ns_uri in ns_uris:
ni = self.__lookup_uri(ns_uri)
if ni.schema_location:
schemalocs.append("{0.uri} {0.schema_location}".format(ni))
if not schemalocs:
return ""
return 'xsi:schemaLocation="{0}"'.format(delim.join(schemalocs)) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tab_join'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ToMerge'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'keycols'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'nullvals'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'renamer'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'returnrenaming'}; {'id': '16', 'type': 'False', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '23', '49', '76', '103', '168', '172', '235', '244', '250']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': "'''\n Database-join for tabular arrays.\n Wrapper for :func:`tabular.spreadsheet.join` that deals with the coloring \n and returns the result as a tabarray.\n Method calls::\n data = tabular.spreadsheet.join\n '''"}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}; {'id': '25', 'type': 'list_pattern', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Renaming'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'spreadsheet'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34', '37', '40', '43', '46']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ToMerge'}; {'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'keycols'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'keycols'}; {'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'nullvals'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'nullvals'}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'renamer'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'renamer'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'returnrenaming'}; {'id': '45', 'type': 'True', 'children': []}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '49', 'type': 'if_statement', 'children': ['50', '55', '64']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ToMerge'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'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': 'Names'}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ToMerge'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'else_clause', 'children': ['65']}; {'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': 'Names'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ToMerge'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'Colorings'}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'list_comprehension', 'children': ['83', '100']}; {'id': '83', 'type': 'conditional_expression', 'children': ['84', '91', '99'], 'value': 'if'}; {'id': '84', 'type': 'tuple', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}; {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ToMerge'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'coloring'}; {'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': 'in'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'coloring'"}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'dir'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ToMerge'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '99', 'type': 'dictionary', 'children': []}; {'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '103', 'type': 'for_statement', 'children': ['104', '105', '106']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'Names'}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'if_statement', 'children': ['108', '115']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'Renaming'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '114', 'type': 'argument_list', 'children': []}; {'id': '115', 'type': 'block', 'children': ['116', '122']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ToMerge'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '127', '128']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'Colorings'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '127', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'list_comprehension', 'children': ['132', '159']}; {'id': '132', 'type': 'tuple', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '134', 'type': 'list_comprehension', 'children': ['135', '152']}; {'id': '135', 'type': 'conditional_expression', 'children': ['136', '137', '147'], 'value': 'if'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '137', 'type': 'not_operator', 'children': ['138']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'in'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '140', 'type': 'call', 'children': ['141', '146']}; {'id': '141', 'type': 'attribute', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'Renaming'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '146', 'type': 'argument_list', 'children': []}; {'id': '147', 'type': 'subscript', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'Renaming'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '152', 'type': 'for_in_clause', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '154', 'type': 'subscript', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'coloring'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '159', 'type': 'for_in_clause', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '161', 'type': 'call', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}; {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'Colorings'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '167', 'type': 'argument_list', 'children': []}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'Coloring'}; {'id': '171', 'type': 'dictionary', 'children': []}; {'id': '172', 'type': 'for_statement', 'children': ['173', '174', '179']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '174', 'type': 'call', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'Colorings'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '178', 'type': 'argument_list', 'children': []}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'for_statement', 'children': ['181', '182', '189']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '182', 'type': 'call', 'children': ['183', '188']}; {'id': '183', 'type': 'attribute', 'children': ['184', '187']}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'Colorings'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '188', 'type': 'argument_list', 'children': []}; {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'if_statement', 'children': ['191', '198', '218']}; {'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': 'in'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'Coloring'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '197', 'type': 'argument_list', 'children': []}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '204']}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'Coloring'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'uniqify'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'binary_operator', 'children': ['210', '213'], 'value': '+'}; {'id': '210', 'type': 'subscript', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'Coloring'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '213', 'type': 'subscript', 'children': ['214', '217']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'Colorings'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '218', 'type': 'else_clause', 'children': ['219']}; {'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': 'Coloring'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'uniqify'}; {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'subscript', 'children': ['231', '234']}; {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'Colorings'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '238', 'type': 'call', 'children': ['239', '242']}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'tabarray'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'assignment', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'coloring'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'Coloring'}; {'id': '250', 'type': 'if_statement', 'children': ['251', '252', '257']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'returnrenaming'}; {'id': '252', 'type': 'block', 'children': ['253']}; {'id': '253', 'type': 'return_statement', 'children': ['254']}; {'id': '254', 'type': 'list', 'children': ['255', '256'], 'value': '[Result,Renaming]'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'Renaming'}; {'id': '257', 'type': 'else_clause', 'children': ['258']}; {'id': '258', 'type': 'block', 'children': ['259']}; {'id': '259', 'type': 'return_statement', 'children': ['260']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'Result'} | def tab_join(ToMerge, keycols=None, nullvals=None, renamer=None,
returnrenaming=False, Names=None):
'''
Database-join for tabular arrays.
Wrapper for :func:`tabular.spreadsheet.join` that deals with the coloring
and returns the result as a tabarray.
Method calls::
data = tabular.spreadsheet.join
'''
[Result,Renaming] = spreadsheet.join(ToMerge, keycols=keycols,
nullvals=nullvals, renamer=renamer, returnrenaming=True, Names=Names)
if isinstance(ToMerge,dict):
Names = ToMerge.keys()
else:
Names = range(len(ToMerge))
Colorings = dict([(k,ToMerge[k].coloring) if 'coloring' in dir(ToMerge[k])
else {} for k in Names])
for k in Names:
if k in Renaming.keys():
l = ToMerge[k]
Colorings[k] = \
dict([(g, [n if not n in Renaming[k].keys() else Renaming[k][n]
for n in l.coloring[g]]) for g in Colorings[k].keys()])
Coloring = {}
for k in Colorings.keys():
for j in Colorings[k].keys():
if j in Coloring.keys():
Coloring[j] = utils.uniqify(Coloring[j] + Colorings[k][j])
else:
Coloring[j] = utils.uniqify(Colorings[k][j])
Result = Result.view(tabarray)
Result.coloring = Coloring
if returnrenaming:
return [Result,Renaming]
else:
return Result |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'aggregate'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'On'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'AggFuncDict'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'AggFunc'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'AggList'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'returnsort'}; {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'KeepOthers'}; {'id': '22', 'type': 'True', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'keyfuncdict'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '95', '104', '112']}; {'id': '27', 'type': 'if_statement', 'children': ['28', '29', '61']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'returnsort'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'list_pattern', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'spreadsheet'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'aggregate'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '43', '46', '49', '52', '55', '58']}; {'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'On'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'On'}; {'id': '46', 'type': 'keyword_argument', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'AggFuncDict'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'AggFuncDict'}; {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'AggFunc'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'AggFunc'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'AggList'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'AggList'}; {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'returnsort'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'returnsort'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'keyfuncdict'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'keyfuncdict'}; {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'spreadsheet'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'aggregate'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '74', '77', '80', '83', '86', '89', '92']}; {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'On'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'On'}; {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'AggFuncDict'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'AggFuncDict'}; {'id': '80', 'type': 'keyword_argument', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'AggFunc'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'AggFunc'}; {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'AggList'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'AggList'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'returnsort'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'returnsort'}; {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'KeepOthers'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'KeepOthers'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'keyfuncdict'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'keyfuncdict'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'tabarray'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'coloring'}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'coloring'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '114', '119']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'returnsort'}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'list', 'children': ['117', '118'], 'value': '[data, s]'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'data'} | def aggregate(self, On=None, AggFuncDict=None, AggFunc=None, AggList =
None, returnsort=False,KeepOthers=True, keyfuncdict=None):
if returnsort:
[data, s] = spreadsheet.aggregate(X=self,
On=On,
AggFuncDict=AggFuncDict,
AggFunc=AggFunc,
AggList=AggList,
returnsort=returnsort,
keyfuncdict=keyfuncdict)
else:
data = spreadsheet.aggregate(X=self, On=On, AggFuncDict=AggFuncDict,
AggFunc=AggFunc, AggList = AggList, returnsort=returnsort,
KeepOthers=KeepOthers,
keyfuncdict=keyfuncdict)
data = data.view(tabarray)
data.coloring = self.coloring
if returnsort:
return [data, s]
else:
return data |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '7', 'type': 'unary_operator', 'children': ['8'], 'value': '-'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '11', 'type': 'string', 'children': [], 'value': "'quicksort'"}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16', '33', '44']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'index_array'}; {'id': '19', 'type': 'call', 'children': ['20', '27']}; {'id': '20', 'type': 'attribute', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'core'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'fromnumeric'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_wrapit'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29', '30', '31', '32']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'argsort'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'index_array'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'index_array'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'view'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ndarray'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'index_array'} | def argsort(self, axis=-1, kind='quicksort', order=None):
index_array = np.core.fromnumeric._wrapit(self, 'argsort', axis,
kind, order)
index_array = index_array.view(np.ndarray)
return index_array |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_finalize_namespaces'}; {'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': 'ns_dict'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '33', '55', '61', '84', '95']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ns_dict'}; {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'for_statement', 'children': ['13', '16', '22']}; {'id': '13', 'type': 'pattern_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ns_dict'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'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': '_collected_namespaces'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'add_namespace_uri'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '40']}; {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_collected_namespaces'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'add_namespace_uri'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '48']}; {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'idgen'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get_id_namespace'}; {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'idgen'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get_id_namespace_alias'}; {'id': '54', 'type': 'argument_list', 'children': []}; {'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': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': '_fix_example_namespace'}; {'id': '60', 'type': 'argument_list', 'children': []}; {'id': '61', 'type': 'for_statement', 'children': ['62', '65', '73']}; {'id': '62', 'type': 'pattern_list', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'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': '_input_namespaces'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'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': '_collected_namespaces'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'add_namespace_uri'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'call', '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': '_collected_namespaces'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'import_from'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'namespaces'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'XML_NAMESPACES'}; {'id': '95', 'type': 'for_statement', 'children': ['96', '97', '102']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '_collected_namespaces'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'namespace_uris'}; {'id': '102', 'type': 'block', 'children': ['103', '114', '118', '129', '153', '165']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'preferred_prefix'}; {'id': '106', 'type': 'call', 'children': ['107', '112']}; {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_collected_namespaces'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'preferred_prefix_for_namespace'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'preferred_prefix'}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'continue_statement', 'children': []}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'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': 'self'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': '_collected_namespaces'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'get_prefixes'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '129', 'type': 'if_statement', 'children': ['130', '131', '142']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'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': 'prefix'}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'prefixes'}; {'id': '142', 'type': 'else_clause', 'children': ['143']}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'namespaces'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'lookup_name'}; {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'is'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '156', 'type': 'None', 'children': []}; {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'raise_statement', 'children': ['159']}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'namespaces'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'NoPrefixesError'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'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': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': '_collected_namespaces'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'set_preferred_prefix_for_namespace'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '176', '179']}; {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ns_uri'}; {'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'add_if_not_exist'}; {'id': '181', 'type': 'True', 'children': []} | def _finalize_namespaces(self, ns_dict=None):
if ns_dict:
for ns, alias in six.iteritems(ns_dict):
self._collected_namespaces.add_namespace_uri(ns, alias)
self._collected_namespaces.add_namespace_uri(
ns_uri=idgen.get_id_namespace(),
prefix=idgen.get_id_namespace_alias()
)
self._fix_example_namespace()
for prefix, uri in six.iteritems(self._input_namespaces):
self._collected_namespaces.add_namespace_uri(uri, prefix)
self._collected_namespaces.import_from(namespaces.XML_NAMESPACES)
for ns_uri in self._collected_namespaces.namespace_uris:
preferred_prefix = self._collected_namespaces.preferred_prefix_for_namespace(ns_uri)
if preferred_prefix:
continue
prefixes = self._collected_namespaces.get_prefixes(ns_uri)
if prefixes:
prefix = next(iter(prefixes))
else:
prefix = namespaces.lookup_name(ns_uri)
if prefix is None:
raise namespaces.NoPrefixesError(ns_uri)
self._collected_namespaces.set_preferred_prefix_for_namespace(
ns_uri=ns_uri,
prefix=prefix,
add_if_not_exist=True
) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_empty_fields'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '26', '44', '62', '93', '111', '127', '144', '162']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14']}; {'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'is'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_is_deprecated'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': '_is_deprecated'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'string', 'children': [], 'value': "'is_deprecated'"}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '31'], 'value': 'is'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': '_is_dubious'}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': '_is_dubious'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'string', 'children': [], 'value': "'is_dubious'"}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': 'is'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_is_synonym'}; {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '_is_synonym'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'string', 'children': [], 'value': "'is_synonym'"}; {'id': '62', 'type': 'if_statement', 'children': ['63', '68']}; {'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': 'is'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_synonyms'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_EMPTY_TUPLE'}; {'id': '68', 'type': 'block', 'children': ['69', '80']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': '_synonyms'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'synonyms'"}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86']}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': 'is'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_synonyms'}; {'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': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': '_synonyms'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_EMPTY_TUPLE'}; {'id': '93', 'type': 'if_statement', 'children': ['94', '99']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': 'is'}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'rank'}; {'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': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '_rank'}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'rank'"}; {'id': '111', 'type': 'if_statement', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_nomenclature_code'}; {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_nomenclature_code'}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'string', 'children': [], 'value': "'nomenclature_code'"}; {'id': '127', 'type': 'if_statement', 'children': ['128', '132']}; {'id': '128', 'type': 'not_operator', 'children': ['129']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': '_unique_name'}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': '_unique_name'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'string', 'children': [], 'value': "'unique_name'"}; {'id': '144', 'type': 'if_statement', 'children': ['145', '150']}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': 'is'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_taxonomic_lineage'}; {'id': '149', 'type': 'None', 'children': []}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '156']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': '_taxonomic_lineage'}; {'id': '156', 'type': 'call', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'string', 'children': [], 'value': "'taxonomic_lineage'"}; {'id': '162', 'type': 'if_statement', 'children': ['163', '168']}; {'id': '163', 'type': 'comparison_operator', 'children': ['164', '167'], 'value': 'is'}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': '_parent'}; {'id': '167', 'type': 'None', 'children': []}; {'id': '168', 'type': 'block', 'children': ['169', '180']}; {'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': 'self'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': '_parent'}; {'id': '174', 'type': 'call', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'string', 'children': [], 'value': "'parent'"}; {'id': '180', 'type': 'if_statement', 'children': ['181', '196']}; {'id': '181', 'type': 'boolean_operator', 'children': ['182', '193'], 'value': 'and'}; {'id': '182', 'type': 'boolean_operator', 'children': ['183', '188'], 'value': 'and'}; {'id': '183', 'type': 'comparison_operator', 'children': ['184', '187'], 'value': 'is'}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': '_parent'}; {'id': '187', 'type': 'None', 'children': []}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '192'], 'value': 'is'}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': '_taxomachine_wrapper'}; {'id': '192', 'type': 'None', 'children': []}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': '_taxonomic_lineage'}; {'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': '_fill_parent_attr'}; {'id': '202', 'type': 'argument_list', 'children': []} | def update_empty_fields(self, **kwargs):
if self._is_deprecated is None:
self._is_deprecated = kwargs.get('is_deprecated')
if self._is_dubious is None:
self._is_dubious = kwargs.get('is_dubious')
if self._is_synonym is None:
self._is_synonym = kwargs.get('is_synonym')
if self._synonyms is _EMPTY_TUPLE:
self._synonyms = kwargs.get('synonyms')
if self._synonyms is None:
self._synonyms = _EMPTY_TUPLE
if self.rank is None:
self._rank = kwargs.get('rank')
if self._nomenclature_code:
self._nomenclature_code = kwargs.get('nomenclature_code')
if not self._unique_name:
self._unique_name = kwargs.get('unique_name')
if self._taxonomic_lineage is None:
self._taxonomic_lineage = kwargs.get('taxonomic_lineage')
if self._parent is None:
self._parent = kwargs.get('parent')
if self._parent is None and self._taxomachine_wrapper is not None and self._taxonomic_lineage:
self._fill_parent_attr() |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_creds'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'proof_req_json'}; {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'typed_default_parameter', 'children': ['15', '16', '18']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'filt_dflt_incl'}; {'id': '16', 'type': 'type', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '18', 'type': 'False', 'children': []}; {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'tuple', 'children': ['21', '24']}; {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Set'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '25', 'type': 'block', 'children': ['26', '35', '44', '48', '63', '72', '78', '118', '305', '321', '332', '340']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'HolderProver.get_creds >>> proof_req_json: %s, filt: %s'"}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'proof_req_json'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '35', 'type': 'if_statement', 'children': ['36', '39']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'is'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '38', 'type': 'None', 'children': []}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '43', 'type': 'dictionary', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'rv'}; {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'creds_json'}; {'id': '51', 'type': 'await', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'anoncreds'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'prover_get_credentials_for_proof_req'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '62']}; {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'wallet'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'handle'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'proof_req_json'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'creds'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'creds_json'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'cred_ids'}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'if_statement', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'for_statement', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'try_statement', 'children': ['86', '100']}; {'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': 'json'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'await', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'get_cred_def'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '100', 'type': 'except_clause', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'AbsentCredDef'}; {'id': '102', 'type': 'block', 'children': ['103', '111']}; {'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': 'LOGGER'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}; {'id': '109', 'type': 'string', 'children': [], 'value': "'HolderProver.get_creds: ignoring filter criterion, no cred def on %s'"}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'cd_id'}; {'id': '118', 'type': 'for_statement', 'children': ['119', '120', '133']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'inner_creds'}; {'id': '120', 'type': 'call', 'children': ['121', '132']}; {'id': '121', 'type': 'attribute', 'children': ['122', '131']}; {'id': '122', 'type': 'dictionary', 'children': ['123', '127']}; {'id': '123', 'type': 'dictionary_splat', 'children': ['124']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'creds'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'attrs'"}; {'id': '127', 'type': 'dictionary_splat', 'children': ['128']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'creds'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'predicates'"}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '132', 'type': 'argument_list', 'children': []}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'for_statement', 'children': ['135', '136', '137']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'cred'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'inner_creds'}; {'id': '137', 'type': 'block', 'children': ['138', '144']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'cred_info'}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'cred'}; {'id': '143', 'type': 'string', 'children': [], 'value': "'cred_info'"}; {'id': '144', 'type': 'if_statement', 'children': ['145', '146', '294']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '146', 'type': 'block', 'children': ['147', '153', '171', '225', '285']}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cred_cd_id'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'cred_info'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'cred_def_id'"}; {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'not'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'cred_cd_id'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '157', 'type': 'block', 'children': ['158', '170']}; {'id': '158', 'type': 'if_statement', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'filt_dflt_incl'}; {'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': 'cred_ids'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'cred_info'}; {'id': '169', 'type': 'string', 'children': [], 'value': "'referent'"}; {'id': '170', 'type': 'continue_statement', 'children': []}; {'id': '171', 'type': 'if_statement', 'children': ['172', '180']}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': 'in'}; {'id': '173', 'type': 'string', 'children': [], 'value': "'attr-match'"}; {'id': '174', 'type': '()', 'children': ['175']}; {'id': '175', 'type': 'boolean_operator', 'children': ['176', '179'], 'value': 'or'}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'cred_cd_id'}; {'id': '179', 'type': 'dictionary', 'children': []}; {'id': '180', 'type': 'block', 'children': ['181']}; {'id': '181', 'type': 'if_statement', 'children': ['182', '223']}; {'id': '182', 'type': 'not_operator', 'children': ['183']}; {'id': '183', 'type': 'comparison_operator', 'children': ['184', '216'], 'value': '<='}; {'id': '184', 'type': 'call', 'children': ['185', '215']}; {'id': '185', 'type': 'attribute', 'children': ['186', '214']}; {'id': '186', 'type': 'dictionary_comprehension', 'children': ['187', '203']}; {'id': '187', 'type': 'pair', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'subscript', 'children': ['193', '202']}; {'id': '193', 'type': 'call', 'children': ['194', '199']}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}; {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'cred_cd_id'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '199', 'type': 'argument_list', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'attr-match'"}; {'id': '201', 'type': 'dictionary', 'children': []}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '203', 'type': 'for_in_clause', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'k'}; {'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': 'filt'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'cred_cd_id'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '211', 'type': 'argument_list', 'children': ['212', '213']}; {'id': '212', 'type': 'string', 'children': [], 'value': "'attr-match'"}; {'id': '213', 'type': 'dictionary', 'children': []}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '215', 'type': 'argument_list', 'children': []}; {'id': '216', 'type': 'call', 'children': ['217', '222']}; {'id': '217', 'type': 'attribute', 'children': ['218', '221']}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'cred_info'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'attrs'"}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '222', 'type': 'argument_list', 'children': []}; {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'continue_statement', 'children': []}; {'id': '225', 'type': 'if_statement', 'children': ['226', '234']}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': 'in'}; {'id': '227', 'type': 'string', 'children': [], 'value': "'minima'"}; {'id': '228', 'type': '()', 'children': ['229']}; {'id': '229', 'type': 'boolean_operator', 'children': ['230', '233'], 'value': 'or'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'cred_cd_id'}; {'id': '233', 'type': 'dictionary', 'children': []}; {'id': '234', 'type': 'block', 'children': ['235', '247']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'minima'}; {'id': '238', 'type': 'call', 'children': ['239', '244']}; {'id': '239', 'type': 'attribute', 'children': ['240', '243']}; {'id': '240', 'type': 'subscript', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'cred_cd_id'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '244', 'type': 'argument_list', 'children': ['245', '246']}; {'id': '245', 'type': 'string', 'children': [], 'value': "'minima'"}; {'id': '246', 'type': 'dictionary', 'children': []}; {'id': '247', 'type': 'try_statement', 'children': ['248', '281']}; {'id': '248', 'type': 'block', 'children': ['249']}; {'id': '249', 'type': 'if_statement', 'children': ['250', '279']}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '252', 'type': 'generator_expression', 'children': ['253', '276']}; {'id': '253', 'type': 'boolean_operator', 'children': ['254', '260'], 'value': 'or'}; {'id': '254', 'type': '()', 'children': ['255']}; {'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': 'not'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'cred_info'}; {'id': '259', 'type': 'string', 'children': [], 'value': "'attrs'"}; {'id': '260', 'type': '()', 'children': ['261']}; {'id': '261', 'type': 'comparison_operator', 'children': ['262', '270'], 'value': '<'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'subscript', 'children': ['266', '269']}; {'id': '266', 'type': 'subscript', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'cred_info'}; {'id': '268', 'type': 'string', 'children': [], 'value': "'attrs'"}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '270', 'type': 'call', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}; {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'minima'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '276', 'type': 'for_in_clause', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'minima'}; {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'continue_statement', 'children': []}; {'id': '281', 'type': 'except_clause', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'continue_statement', 'children': []}; {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '290']}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'cred_ids'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '290', 'type': 'argument_list', 'children': ['291']}; {'id': '291', 'type': 'subscript', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'cred_info'}; {'id': '293', 'type': 'string', 'children': [], 'value': "'referent'"}; {'id': '294', 'type': 'else_clause', 'children': ['295']}; {'id': '295', 'type': 'block', 'children': ['296']}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}; {'id': '297', 'type': 'call', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'cred_ids'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'subscript', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'cred_info'}; {'id': '304', 'type': 'string', 'children': [], 'value': "'referent'"}; {'id': '305', 'type': 'if_statement', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'filt'}; {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}; {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'creds'}; {'id': '311', 'type': 'call', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'loads'}; {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'prune_creds_json'}; {'id': '318', 'type': 'argument_list', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'creds'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'cred_ids'}; {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'rv'}; {'id': '324', 'type': 'tuple', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'cred_ids'}; {'id': '326', 'type': 'call', 'children': ['327', '330']}; {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'creds'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}; {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'LOGGER'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '337', 'type': 'argument_list', 'children': ['338', '339']}; {'id': '338', 'type': 'string', 'children': [], 'value': "'HolderProver.get_creds <<< %s'"}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'rv'}; {'id': '340', 'type': 'return_statement', 'children': ['341']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'rv'} | async def get_creds(self, proof_req_json: str, filt: dict = None, filt_dflt_incl: bool = False) -> (Set[str], str):
LOGGER.debug('HolderProver.get_creds >>> proof_req_json: %s, filt: %s', proof_req_json, filt)
if filt is None:
filt = {}
rv = None
creds_json = await anoncreds.prover_get_credentials_for_proof_req(self.wallet.handle, proof_req_json)
creds = json.loads(creds_json)
cred_ids = set()
if filt:
for cd_id in filt:
try:
json.loads(await self.get_cred_def(cd_id))
except AbsentCredDef:
LOGGER.warning('HolderProver.get_creds: ignoring filter criterion, no cred def on %s', cd_id)
filt.pop(cd_id)
for inner_creds in {**creds['attrs'], **creds['predicates']}.values():
for cred in inner_creds:
cred_info = cred['cred_info']
if filt:
cred_cd_id = cred_info['cred_def_id']
if cred_cd_id not in filt:
if filt_dflt_incl:
cred_ids.add(cred_info['referent'])
continue
if 'attr-match' in (filt[cred_cd_id] or {}):
if not {k: str(filt[cred_cd_id].get('attr-match', {})[k])
for k in filt[cred_cd_id].get('attr-match', {})}.items() <= cred_info['attrs'].items():
continue
if 'minima' in (filt[cred_cd_id] or {}):
minima = filt[cred_cd_id].get('minima', {})
try:
if any((attr not in cred_info['attrs'])
or (int(cred_info['attrs'][attr]) < int(minima[attr]))
for attr in minima):
continue
except ValueError:
continue
cred_ids.add(cred_info['referent'])
else:
cred_ids.add(cred_info['referent'])
if filt:
creds = json.loads(prune_creds_json(creds, cred_ids))
rv = (cred_ids, json.dumps(creds))
LOGGER.debug('HolderProver.get_creds <<< %s', rv)
return rv |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'summary'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '7', 'type': 'block', 'children': ['8', '42', '76', '114', '118', '199', '206', '243', '248', '255', '264', '296', '305']}; {'id': '8', 'type': 'function_definition', 'children': ['9', '10', '18']}; {'id': '9', 'type': 'function_name', 'children': [], 'value': 'display_header'}; {'id': '10', 'type': 'parameters', 'children': ['11', '12', '15']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '14', 'type': 'string', 'children': [], 'value': "''"}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '17', 'type': 'string', 'children': [], 'value': "''"}; {'id': '18', 'type': 'block', 'children': ['19', '27', '37']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '26', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '30']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'display_header'}; {'id': '36', 'type': 'argument_list', 'children': []}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '42', 'type': 'function_definition', 'children': ['43', '44', '52']}; {'id': '43', 'type': 'function_name', 'children': [], 'value': 'display_separator'}; {'id': '44', 'type': 'parameters', 'children': ['45', '46', '49']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '46', 'type': 'default_parameter', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '48', 'type': 'string', 'children': [], 'value': "''"}; {'id': '49', 'type': 'default_parameter', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '51', 'type': 'string', 'children': [], 'value': "''"}; {'id': '52', 'type': 'block', 'children': ['53', '61', '71']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '60', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'display_separator'}; {'id': '70', 'type': 'argument_list', 'children': []}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '76', 'type': 'function_definition', 'children': ['77', '78', '89']}; {'id': '77', 'type': 'function_name', 'children': [], 'value': 'display_metrics'}; {'id': '78', 'type': 'parameters', 'children': ['79', '80', '83', '86']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '80', 'type': 'default_parameter', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '82', 'type': 'string', 'children': [], 'value': "''"}; {'id': '83', 'type': 'default_parameter', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '85', 'type': 'string', 'children': [], 'value': "''"}; {'id': '86', 'type': 'default_parameter', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '88', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '89', 'type': 'block', 'children': ['90', '98', '109']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '97', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '98', 'type': 'for_statement', 'children': ['99', '100', '101']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'display_metrics'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'after'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '117', 'type': 'dictionary', 'children': []}; {'id': '118', 'type': 'for_statement', 'children': ['119', '120', '121']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '121', 'type': 'block', 'children': ['122', '130', '136', '152', '160']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'language'"}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'in'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '139']}; {'id': '137', 'type': 'not_operator', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '145', 'type': 'dictionary', 'children': ['146', '149']}; {'id': '146', 'type': 'pair', 'children': ['147', '148']}; {'id': '147', 'type': 'string', 'children': [], 'value': "'file_count'"}; {'id': '148', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '149', 'type': 'pair', 'children': ['150', '151']}; {'id': '150', 'type': 'string', 'children': [], 'value': "'language'"}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'augmented_assignment', 'children': ['154', '159'], 'value': '+='}; {'id': '154', 'type': 'subscript', 'children': ['155', '158']}; {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'file_count'"}; {'id': '159', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '160', 'type': 'for_statement', 'children': ['161', '162', '165']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '165', 'type': 'block', 'children': ['166', '175', '187']}; {'id': '166', 'type': 'if_statement', 'children': ['167', '173']}; {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'not'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '169', 'type': 'list', 'children': ['170', '171', '172'], 'value': "['sloc', 'comments', 'mccabe']"}; {'id': '170', 'type': 'string', 'children': [], 'value': "'sloc'"}; {'id': '171', 'type': 'string', 'children': [], 'value': "'comments'"}; {'id': '172', 'type': 'string', 'children': [], 'value': "'mccabe'"}; {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'continue_statement', 'children': []}; {'id': '175', 'type': 'if_statement', 'children': ['176', '178']}; {'id': '176', 'type': 'not_operator', 'children': ['177']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '178', 'type': 'block', 'children': ['179']}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '186']}; {'id': '181', 'type': 'subscript', 'children': ['182', '185']}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'augmented_assignment', 'children': ['189', '194'], 'value': '+='}; {'id': '189', 'type': 'subscript', 'children': ['190', '193']}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '194', 'type': 'subscript', 'children': ['195', '198']}; {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '202', 'type': 'dictionary', 'children': ['203']}; {'id': '203', 'type': 'pair', 'children': ['204', '205']}; {'id': '204', 'type': 'string', 'children': [], 'value': "'language'"}; {'id': '205', 'type': 'string', 'children': [], 'value': "'Total'"}; {'id': '206', 'type': 'for_statement', 'children': ['207', '208', '209']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'for_statement', 'children': ['211', '212', '215']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '215', 'type': 'block', 'children': ['216', '222', '233']}; {'id': '216', 'type': 'if_statement', 'children': ['217', '220']}; {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '=='}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '219', 'type': 'string', 'children': [], 'value': "'language'"}; {'id': '220', 'type': 'block', 'children': ['221']}; {'id': '221', 'type': 'continue_statement', 'children': []}; {'id': '222', 'type': 'if_statement', 'children': ['223', '226']}; {'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': 'not'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '226', 'type': 'block', 'children': ['227']}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '232']}; {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'augmented_assignment', 'children': ['235', '238'], 'value': '+='}; {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '238', 'type': 'subscript', 'children': ['239', '242']}; {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'i'}; {'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': "'Metrics Summary:'"}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}; {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'display_header'}; {'id': '251', 'type': 'argument_list', 'children': ['252', '253', '254']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '253', 'type': 'string', 'children': [], 'value': "'Files'"}; {'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': 'display_separator'}; {'id': '258', 'type': 'argument_list', 'children': ['259', '260', '263']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '260', 'type': 'binary_operator', 'children': ['261', '262'], 'value': '*'}; {'id': '261', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '262', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '263', 'type': 'string', 'children': [], 'value': "''"}; {'id': '264', 'type': 'for_statement', 'children': ['265', '266', '279']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '266', 'type': 'call', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '274']}; {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '273', 'type': 'argument_list', 'children': []}; {'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}; {'id': '281', 'type': 'call', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'display_metrics'}; {'id': '283', 'type': 'argument_list', 'children': ['284', '285', '292', '293']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '285', 'type': 'binary_operator', 'children': ['286', '287'], 'value': '%'}; {'id': '286', 'type': 'string', 'children': [], 'value': "'%5d'"}; {'id': '287', 'type': 'subscript', 'children': ['288', '291']}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '291', 'type': 'string', 'children': [], 'value': "'file_count'"}; {'id': '292', 'type': 'string', 'children': [], 'value': "''"}; {'id': '293', 'type': 'subscript', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'summary'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}; {'id': '297', 'type': 'call', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'display_separator'}; {'id': '299', 'type': 'argument_list', 'children': ['300', '301', '304']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '301', 'type': 'binary_operator', 'children': ['302', '303'], 'value': '*'}; {'id': '302', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '303', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '304', 'type': 'string', 'children': [], 'value': "''"}; {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'call', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'display_metrics'}; {'id': '308', 'type': 'argument_list', 'children': ['309', '310', '315', '316']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'processors'}; {'id': '310', 'type': 'binary_operator', 'children': ['311', '312'], 'value': '%'}; {'id': '311', 'type': 'string', 'children': [], 'value': "'%5d'"}; {'id': '312', 'type': 'subscript', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '314', 'type': 'string', 'children': [], 'value': "'file_count'"}; {'id': '315', 'type': 'string', 'children': [], 'value': "''"}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'total'} | def summary(processors, metrics, context):
def display_header(processors, before='', after=''):
print(before, end=' ')
for processor in processors:
processor.display_header()
print(after)
def display_separator(processors, before='', after=''):
print(before, end=' ')
for processor in processors:
processor.display_separator()
print(after)
def display_metrics(processors, before='', after='', metrics=[]):
print(before, end=' ')
for processor in processors:
processor.display_metrics(metrics)
print(after)
summary = {}
for m in metrics:
lang = metrics[m]['language']
has_key = lang in summary
if not has_key:
summary[lang] = {'file_count': 0, 'language': lang}
summary[lang]['file_count'] += 1
for i in metrics[m]:
if i not in ['sloc', 'comments', 'mccabe']:
continue
if not has_key:
summary[lang][i] = 0
summary[lang][i] += metrics[m][i]
total = {'language': 'Total'}
for m in summary:
for i in summary[m]:
if i == 'language':
continue
if i not in total:
total[i] = 0
total[i] += summary[m][i]
print('Metrics Summary:')
display_header(processors, 'Files', '')
display_separator(processors, '-'*5, '')
for k in sorted(summary.keys(), key=str.lower):
display_metrics(processors, '%5d' %
summary[k]['file_count'], '', summary[k])
display_separator(processors, '-'*5, '')
display_metrics(processors, '%5d' % total['file_count'],
'', total) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_experiment'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'roleouts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'episodes'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'in_cloud'}; {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'dynProfile'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'block', 'children': ['14', '396', '441']}; {'id': '14', 'type': 'function_definition', 'children': ['15', '16', '17']}; {'id': '15', 'type': 'function_name', 'children': [], 'value': 'run'}; {'id': '16', 'type': 'parameters', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18', '42', '51', '59', '68', '77', '86', '93', '391']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22', '32']}; {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dynProfile'}; {'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': 'maxsteps'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '32', 'type': 'else_clause', 'children': ['33']}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'maxsteps'}; {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'dynProfile'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'na'}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'agents'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '58'], 'value': '*'}; {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '*'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'roleouts'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'episodes'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'maxsteps'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'all_action'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'tuple', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'na'}; {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'all_reward'}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'tuple', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'na'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'tuple', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'na'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ni'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'vmarkup'}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'vectorize'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get_markup'}; {'id': '93', 'type': 'for_statement', 'children': ['94', '95', '99']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'roleout'}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'roleouts'}; {'id': '99', 'type': 'block', 'children': ['100', '126', '133', '139', '148', '157', '377', '384']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dynProfile'}; {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'block', 'children': ['105', '111']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '*'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'roleout'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'episodes'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '116', 'type': 'subscript', 'children': ['117', '118', '124']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'dynProfile'}; {'id': '118', 'type': 'slice', 'children': ['119', '120', '121']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '120', 'type': 'colon', 'children': []}; {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '+'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'episodes'}; {'id': '124', 'type': 'slice', 'children': ['125']}; {'id': '125', 'type': 'colon', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'doEpisodes'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'episodes'}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'nei'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '*'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'episodes'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'maxsteps'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'epi_action'}; {'id': '142', 'type': 'call', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'tuple', 'children': ['146', '147']}; {'id': '146', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'nei'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'epi_reward'}; {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'tuple', 'children': ['155', '156']}; {'id': '155', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'nei'}; {'id': '157', 'type': 'for_statement', 'children': ['158', '163', '164', '176']}; {'id': '158', 'type': 'pattern_list', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '160', 'type': 'tuple_pattern', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '163', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '169', 'type': 'argument_list', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'tasks'}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'experiment'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'agents'}; {'id': '176', 'type': 'block', 'children': ['177', '188', '199', '317', '336', '351', '365', '371']}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'subscript', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '187', 'type': 'string', 'children': [], 'value': '"action"'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'reward'}; {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'subscript', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'history'}; {'id': '198', 'type': 'string', 'children': [], 'value': '"reward"'}; {'id': '199', 'type': 'for_statement', 'children': ['200', '201', '205']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'nei'}; {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'if_statement', 'children': ['207', '214', '258', '307']}; {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '209', 'type': 'argument_list', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'learner'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'DirectSearchLearner'}; {'id': '214', 'type': 'block', 'children': ['215', '232', '238']}; {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '222']}; {'id': '217', 'type': 'subscript', 'children': ['218', '219', '220']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '220', 'type': 'slice', 'children': ['221']}; {'id': '221', 'type': 'colon', 'children': []}; {'id': '222', 'type': 'call', 'children': ['223', '226']}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'denormalize'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'subscript', 'children': ['228', '229', '230']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '230', 'type': 'slice', 'children': ['231']}; {'id': '231', 'type': 'colon', 'children': []}; {'id': '232', 'type': 'expression_statement', 'children': ['233']}; {'id': '233', 'type': 'assignment', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '*'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'nei'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'roleout'}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'assignment', 'children': ['240', '249']}; {'id': '240', 'type': 'subscript', 'children': ['241', '242', '243']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '243', 'type': 'slice', 'children': ['244', '245', '246']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '245', 'type': 'colon', 'children': []}; {'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '+'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'nei'}; {'id': '249', 'type': 'subscript', 'children': ['250', '257']}; {'id': '250', 'type': 'attribute', 'children': ['251', '256']}; {'id': '251', 'type': 'attribute', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'learner'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'explorer'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '257', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '258', 'type': 'elif_clause', 'children': ['259', '266']}; {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '261', 'type': 'argument_list', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'learner'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'ValueBasedLearner'}; {'id': '266', 'type': 'block', 'children': ['267', '283', '289']}; {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '274']}; {'id': '269', 'type': 'subscript', 'children': ['270', '271', '272']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '272', 'type': 'slice', 'children': ['273']}; {'id': '273', 'type': 'colon', 'children': []}; {'id': '274', 'type': 'call', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'vmarkup'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '282']}; {'id': '277', 'type': 'subscript', 'children': ['278', '279', '280']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '280', 'type': 'slice', 'children': ['281']}; {'id': '281', 'type': 'colon', 'children': []}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '*'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'nei'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'roleout'}; {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '300']}; {'id': '291', 'type': 'subscript', 'children': ['292', '293', '294']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '294', 'type': 'slice', 'children': ['295', '296', '297']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '296', 'type': 'colon', 'children': []}; {'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '+'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'nei'}; {'id': '300', 'type': 'attribute', 'children': ['301', '306']}; {'id': '301', 'type': 'attribute', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'learner'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'explorer'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '307', 'type': 'else_clause', 'children': ['308']}; {'id': '308', 'type': 'block', 'children': ['309']}; {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '312', 'type': 'call', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'vmarkup'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'task'}; {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'epi_action'}; {'id': '320', 'type': 'attribute', 'children': ['321', '335']}; {'id': '321', 'type': 'subscript', 'children': ['322', '323', '326']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'epi_action'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '326', 'type': 'call', 'children': ['327', '334']}; {'id': '327', 'type': 'attribute', 'children': ['328', '333']}; {'id': '328', 'type': 'subscript', 'children': ['329', '330', '332']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '330', 'type': 'slice', 'children': ['331']}; {'id': '331', 'type': 'colon', 'children': []}; {'id': '332', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '334', 'type': 'argument_list', 'children': []}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}; {'id': '337', 'type': 'assignment', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'epi_reward'}; {'id': '339', 'type': 'attribute', 'children': ['340', '350']}; {'id': '340', 'type': 'subscript', 'children': ['341', '342', '345']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'epi_reward'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'reward'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'flatten'}; {'id': '349', 'type': 'argument_list', 'children': []}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '351', 'type': 'if_statement', 'children': ['352', '357']}; {'id': '352', 'type': 'call', 'children': ['353', '354']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '354', 'type': 'argument_list', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '356', 'type': 'string', 'children': [], 'value': '"module"'}; {'id': '357', 'type': 'block', 'children': ['358']}; {'id': '358', 'type': 'print_statement', 'children': ['359', '360']}; {'id': '359', 'type': 'string', 'children': [], 'value': '"PARAMS:"'}; {'id': '360', 'type': 'attribute', 'children': ['361', '364']}; {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '365', 'type': 'expression_statement', 'children': ['366']}; {'id': '366', 'type': 'call', 'children': ['367', '370']}; {'id': '367', 'type': 'attribute', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'learn'}; {'id': '370', 'type': 'argument_list', 'children': []}; {'id': '371', 'type': 'expression_statement', 'children': ['372']}; {'id': '372', 'type': 'call', 'children': ['373', '376']}; {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'reset'}; {'id': '376', 'type': 'argument_list', 'children': []}; {'id': '377', 'type': 'expression_statement', 'children': ['378']}; {'id': '378', 'type': 'assignment', 'children': ['379', '380']}; {'id': '379', 'type': 'identifier', 'children': [], 'value': 'all_action'}; {'id': '380', 'type': 'subscript', 'children': ['381', '382', '383']}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'all_action'}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'epi_action'}; {'id': '384', 'type': 'expression_statement', 'children': ['385']}; {'id': '385', 'type': 'assignment', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'all_reward'}; {'id': '387', 'type': 'subscript', 'children': ['388', '389', '390']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'all_reward'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'epi_reward'}; {'id': '391', 'type': 'return_statement', 'children': ['392']}; {'id': '392', 'type': 'expression_list', 'children': ['393', '394', '395']}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'all_action'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'all_reward'}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '396', 'type': 'if_statement', 'children': ['397', '398', '430']}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'in_cloud'}; {'id': '398', 'type': 'block', 'children': ['399', '402', '414', '423']}; {'id': '399', 'type': 'import_statement', 'children': ['400']}; {'id': '400', 'type': 'dotted_name', 'children': ['401']}; {'id': '401', 'type': 'identifier', 'children': [], 'value': 'cloud'}; {'id': '402', 'type': 'expression_statement', 'children': ['403']}; {'id': '403', 'type': 'assignment', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'job_id'}; {'id': '405', 'type': 'call', 'children': ['406', '409']}; {'id': '406', 'type': 'attribute', 'children': ['407', '408']}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'cloud'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'call'}; {'id': '409', 'type': 'argument_list', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '411', 'type': 'keyword_argument', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': '_high_cpu'}; {'id': '413', 'type': 'False', 'children': []}; {'id': '414', 'type': 'expression_statement', 'children': ['415']}; {'id': '415', 'type': 'assignment', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '417', 'type': 'call', 'children': ['418', '421']}; {'id': '418', 'type': 'attribute', 'children': ['419', '420']}; {'id': '419', 'type': 'identifier', 'children': [], 'value': 'cloud'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '421', 'type': 'argument_list', 'children': ['422']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'job_id'}; {'id': '423', 'type': 'expression_statement', 'children': ['424']}; {'id': '424', 'type': 'assignment', 'children': ['425', '429']}; {'id': '425', 'type': 'pattern_list', 'children': ['426', '427', '428']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'all_action'}; {'id': '427', 'type': 'identifier', 'children': [], 'value': 'all_reward'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '429', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '430', 'type': 'else_clause', 'children': ['431']}; {'id': '431', 'type': 'block', 'children': ['432']}; {'id': '432', 'type': 'expression_statement', 'children': ['433']}; {'id': '433', 'type': 'assignment', 'children': ['434', '438']}; {'id': '434', 'type': 'pattern_list', 'children': ['435', '436', '437']}; {'id': '435', 'type': 'identifier', 'children': [], 'value': 'all_action'}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'all_reward'}; {'id': '437', 'type': 'identifier', 'children': [], 'value': 'epsilon'}; {'id': '438', 'type': 'call', 'children': ['439', '440']}; {'id': '439', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '440', 'type': 'argument_list', 'children': []}; {'id': '441', 'type': 'return_statement', 'children': ['442']}; {'id': '442', 'type': 'expression_list', 'children': ['443', '444', '445']}; {'id': '443', 'type': 'identifier', 'children': [], 'value': 'all_action'}; {'id': '444', 'type': 'identifier', 'children': [], 'value': 'all_reward'}; {'id': '445', 'type': 'identifier', 'children': [], 'value': 'epsilon'} | def run_experiment(experiment, roleouts, episodes, in_cloud=False,
dynProfile=None):
def run():
if dynProfile is None:
maxsteps = len(experiment.profile)
else:
maxsteps = dynProfile.shape[1]
na = len(experiment.agents)
ni = roleouts * episodes * maxsteps
all_action = zeros((na, 0))
all_reward = zeros((na, 0))
epsilon = zeros((na, ni))
vmarkup = vectorize(get_markup)
for roleout in range(roleouts):
if dynProfile is not None:
i = roleout * episodes
experiment.profile = dynProfile[i:i + episodes, :]
experiment.doEpisodes(episodes)
nei = episodes * maxsteps
epi_action = zeros((0, nei))
epi_reward = zeros((0, nei))
for i, (task, agent) in \
enumerate(zip(experiment.tasks, experiment.agents)):
action = copy(agent.history["action"])
reward = copy(agent.history["reward"])
for j in range(nei):
if isinstance(agent.learner, DirectSearchLearner):
action[j, :] = task.denormalize(action[j, :])
k = nei * roleout
epsilon[i, k:k + nei] = agent.learner.explorer.sigma[0]
elif isinstance(agent.learner, ValueBasedLearner):
action[j, :] = vmarkup(action[j, :], task)
k = nei * roleout
epsilon[i, k:k + nei] = agent.learner.explorer.epsilon
else:
action = vmarkup(action, task)
epi_action = c_[epi_action.T, action[:, 0].flatten()].T
epi_reward = c_[epi_reward.T, reward.flatten()].T
if hasattr(agent, "module"):
print "PARAMS:", agent.module.params
agent.learn()
agent.reset()
all_action = c_[all_action, epi_action]
all_reward = c_[all_reward, epi_reward]
return all_action, all_reward, epsilon
if in_cloud:
import cloud
job_id = cloud.call(run, _high_cpu=False)
result = cloud.result(job_id)
all_action, all_reward, epsilon = result
else:
all_action, all_reward, epsilon = run()
return all_action, all_reward, epsilon |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'total_cost'}; {'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': 'p'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '26', '37', '48', '58', '175']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '18', 'type': 'conditional_expression', 'children': ['19', '22', '25'], 'value': 'if'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '24', 'type': 'None', 'children': []}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '29', 'type': 'conditional_expression', 'children': ['30', '33', '36'], 'value': 'if'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '40', 'type': 'conditional_expression', 'children': ['41', '44', '47'], 'value': 'if'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '46', 'type': 'None', 'children': []}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '51', 'type': 'conditional_expression', 'children': ['52', '53', '57'], 'value': 'if'}; {'id': '52', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '53', 'type': 'not_operator', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'online'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '62', '158', '171']}; {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': '=='}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'id': '62', 'type': 'block', 'children': ['63', '72']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'n_segments'}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '71'], 'value': '-'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '78', '132']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'}; {'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': 'n_segments'}; {'id': '78', 'type': 'block', 'children': ['79', '87', '97', '109', '117']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}; {'id': '81', 'type': 'pattern_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'x1'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'y1'}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}; {'id': '89', 'type': 'pattern_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'x2'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'y2'}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '105'], 'value': '/'}; {'id': '101', 'type': '()', 'children': ['102']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '-'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'y2'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'y1'}; {'id': '105', 'type': '()', 'children': ['106']}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '-'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'x2'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'x1'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '-'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'y1'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '*'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'x1'}; {'id': '117', 'type': 'if_statement', 'children': ['118', '122']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120', '121'], 'value': '<='}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'x1'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'x2'}; {'id': '122', 'type': 'block', 'children': ['123', '131']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '130'], 'value': '+'}; {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '*'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '131', 'type': 'break_statement', 'children': []}; {'id': '132', 'type': 'else_clause', 'children': ['133']}; {'id': '133', 'type': 'block', 'children': ['134', '150']}; {'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': 'logger'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '%'}; {'id': '141', 'type': 'string', 'children': [], 'value': '"Value [%f] outside pwl cost curve [%s]."'}; {'id': '142', 'type': 'tuple', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '144', 'type': 'subscript', 'children': ['145', '149']}; {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '147', 'type': 'unary_operator', 'children': ['148'], 'value': '-'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '153', 'type': 'binary_operator', 'children': ['154', '157'], 'value': '+'}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '*'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '158', 'type': 'elif_clause', 'children': ['159', '162']}; {'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '=='}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'POLYNOMIAL'}; {'id': '162', 'type': 'block', 'children': ['163']}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'polyval'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '171', 'type': 'else_clause', 'children': ['172']}; {'id': '172', 'type': 'block', 'children': ['173']}; {'id': '173', 'type': 'raise_statement', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '175', 'type': 'if_statement', 'children': ['176', '179', '183']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'is_load'}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'return_statement', 'children': ['181']}; {'id': '181', 'type': 'unary_operator', 'children': ['182'], 'value': '-'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '183', 'type': 'else_clause', 'children': ['184']}; {'id': '184', 'type': 'block', 'children': ['185']}; {'id': '185', 'type': 'return_statement', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'result'} | def total_cost(self, p=None, p_cost=None, pcost_model=None):
p = self.p if p is None else p
p_cost = self.p_cost if p_cost is None else p_cost
pcost_model = self.pcost_model if pcost_model is None else pcost_model
p = 0.0 if not self.online else p
if pcost_model == PW_LINEAR:
n_segments = len(p_cost) - 1
for i in range(n_segments):
x1, y1 = p_cost[i]
x2, y2 = p_cost[i + 1]
m = (y2 - y1) / (x2 - x1)
c = y1 - m * x1
if x1 <= p <= x2:
result = m*p + c
break
else:
logger.error("Value [%f] outside pwl cost curve [%s]." %
(p, p_cost[-1][0]))
result = m*p + c
elif pcost_model == POLYNOMIAL:
result = polyval(p_cost, p)
else:
raise ValueError
if self.is_load:
return -result
else:
return result |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'offers_to_pwl'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'offers'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '26', '44', '57', '70', '82', '159', '193', '223']}; {'id': '7', 'type': 'assert_statement', 'children': ['8']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'is_load'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'g_offers'}; {'id': '15', 'type': 'list_comprehension', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'offers'}; {'id': '20', 'type': 'if_clause', 'children': ['21']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '=='}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'generator'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'gt_zero'}; {'id': '29', 'type': 'list_comprehension', 'children': ['30', '31', '34']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'offr'}; {'id': '31', 'type': 'for_in_clause', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'offr'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'g_offers'}; {'id': '34', 'type': 'if_clause', 'children': ['35']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '43'], 'value': '>'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'round'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'offr'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'quantity'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '43', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '47', 'type': 'list_comprehension', 'children': ['48', '49', '52']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '49', 'type': 'for_in_clause', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'gt_zero'}; {'id': '52', 'type': 'if_clause', 'children': ['53']}; {'id': '53', 'type': 'not_operator', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'withheld'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'p_offers'}; {'id': '60', 'type': 'list_comprehension', 'children': ['61', '62', '65']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '65', 'type': 'if_clause', 'children': ['66']}; {'id': '66', 'type': 'not_operator', 'children': ['67']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'reactive'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'q_offers'}; {'id': '73', 'type': 'list_comprehension', 'children': ['74', '75', '78']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '78', 'type': 'if_clause', 'children': ['79']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'reactive'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '84', '108']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'p_offers'}; {'id': '84', 'type': 'block', 'children': ['85', '96', '102']}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': '_offbids_to_points'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'p_offers'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'online'}; {'id': '107', 'type': 'True', 'children': []}; {'id': '108', 'type': 'else_clause', 'children': ['109']}; {'id': '109', 'type': 'block', 'children': ['110', '124', '130']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '115', 'type': 'list', 'children': ['116', '119'], 'value': '[(0.0, 0.0), (self.p_max, 0.0)]'}; {'id': '116', 'type': 'tuple', 'children': ['117', '118']}; {'id': '117', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '118', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '119', 'type': 'tuple', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'p_max'}; {'id': '123', 'type': 'float', 'children': [], 'value': '0.0'}; {'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': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'id': '130', 'type': 'if_statement', 'children': ['131', '132', '151']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'q_offers'}; {'id': '132', 'type': 'block', 'children': ['133', '139', '145']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'p_min'}; {'id': '138', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'p_max'}; {'id': '144', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '150']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'online'}; {'id': '150', 'type': 'True', 'children': []}; {'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', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'online'}; {'id': '158', 'type': 'False', 'children': []}; {'id': '159', 'type': 'if_statement', 'children': ['160', '161', '179']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'q_offers'}; {'id': '161', 'type': 'block', 'children': ['162', '173']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'assignment', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'q_cost'}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': '_offbids_to_points'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'q_offers'}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'qcost_model'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'id': '179', 'type': 'else_clause', 'children': ['180']}; {'id': '180', 'type': 'block', 'children': ['181', '187']}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'q_cost'}; {'id': '186', 'type': 'None', 'children': []}; {'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': 'qcost_model'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'id': '193', 'type': 'if_statement', 'children': ['194', '205']}; {'id': '194', 'type': 'boolean_operator', 'children': ['195', '200'], 'value': 'and'}; {'id': '195', 'type': 'not_operator', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'p_offers'}; {'id': '200', 'type': 'not_operator', 'children': ['201']}; {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'q_offers'}; {'id': '205', 'type': 'block', 'children': ['206', '217']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '%'}; {'id': '213', 'type': 'string', 'children': [], 'value': '"No valid offers for generator [%s], shutting down."'}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'name'}; {'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': 'self'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'online'}; {'id': '222', 'type': 'False', 'children': []}; {'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': '_adjust_limits'}; {'id': '228', 'type': 'argument_list', 'children': []} | def offers_to_pwl(self, offers):
assert not self.is_load
g_offers = [offer for offer in offers if offer.generator == self]
gt_zero = [offr for offr in g_offers if round(offr.quantity, 4) > 0.0]
valid = [offer for offer in gt_zero if not offer.withheld]
p_offers = [v for v in valid if not v.reactive]
q_offers = [v for v in valid if v.reactive]
if p_offers:
self.p_cost = self._offbids_to_points(p_offers)
self.pcost_model = PW_LINEAR
self.online = True
else:
self.p_cost = [(0.0, 0.0), (self.p_max, 0.0)]
self.pcost_model = PW_LINEAR
if q_offers:
self.p_min = 0.0
self.p_max = 0.0
self.online = True
else:
self.online = False
if q_offers:
self.q_cost = self._offbids_to_points(q_offers)
self.qcost_model = PW_LINEAR
else:
self.q_cost = None
self.qcost_model = PW_LINEAR
if not len(p_offers) and not len(q_offers):
logger.info("No valid offers for generator [%s], shutting down." %
self.name)
self.online = False
self._adjust_limits() |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'bids_to_pwl'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bids'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '25', '43', '56', '69', '81', '149', '203']}; {'id': '7', 'type': 'assert_statement', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'is_load'}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'vl_bids'}; {'id': '14', 'type': 'list_comprehension', 'children': ['15', '16', '19']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'bids'}; {'id': '19', 'type': 'if_clause', 'children': ['20']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': '=='}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'vLoad'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'gt_zero'}; {'id': '28', 'type': 'list_comprehension', 'children': ['29', '30', '33']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'vl_bids'}; {'id': '33', 'type': 'if_clause', 'children': ['34']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '42'], 'value': '>'}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'round'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'quantity'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '42', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'valid_bids'}; {'id': '46', 'type': 'list_comprehension', 'children': ['47', '48', '51']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'gt_zero'}; {'id': '51', 'type': 'if_clause', 'children': ['52']}; {'id': '52', 'type': 'not_operator', 'children': ['53']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'withheld'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'p_bids'}; {'id': '59', 'type': 'list_comprehension', 'children': ['60', '61', '64']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'valid_bids'}; {'id': '64', 'type': 'if_clause', 'children': ['65']}; {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'reactive'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'q_bids'}; {'id': '72', 'type': 'list_comprehension', 'children': ['73', '74', '77']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'valid_bids'}; {'id': '77', 'type': 'if_clause', 'children': ['78']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'reactive'}; {'id': '81', 'type': 'if_statement', 'children': ['82', '83', '108']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'p_bids'}; {'id': '83', 'type': 'block', 'children': ['84', '96', '102']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'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': '_offbids_to_points'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'p_bids'}; {'id': '95', 'type': 'True', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'online'}; {'id': '107', 'type': 'True', 'children': []}; {'id': '108', 'type': 'else_clause', 'children': ['109']}; {'id': '109', 'type': 'block', 'children': ['110', '124', '130', '143']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '115', 'type': 'list', 'children': ['116', '119'], 'value': '[(0.0, 0.0), (self.p_max, 0.0)]'}; {'id': '116', 'type': 'tuple', 'children': ['117', '118']}; {'id': '117', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '118', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '119', 'type': 'tuple', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'p_max'}; {'id': '123', 'type': 'float', 'children': [], 'value': '0.0'}; {'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': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'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': 'logger'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '140'], 'value': '%'}; {'id': '137', 'type': 'concatenated_string', 'children': ['138', '139']}; {'id': '138', 'type': 'string', 'children': [], 'value': '"No valid active power bids for dispatchable load "'}; {'id': '139', 'type': 'string', 'children': [], 'value': '"[%s], shutting down."'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'}; {'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': 'self'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'online'}; {'id': '148', 'type': 'False', 'children': []}; {'id': '149', 'type': 'if_statement', 'children': ['150', '151', '176']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'q_bids'}; {'id': '151', 'type': 'block', 'children': ['152', '164', '170']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'q_cost'}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '_offbids_to_points'}; {'id': '161', 'type': 'argument_list', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'q_bids'}; {'id': '163', 'type': 'True', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'qcost_model'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'online'}; {'id': '175', 'type': 'True', 'children': []}; {'id': '176', 'type': 'else_clause', 'children': ['177']}; {'id': '177', 'type': 'block', 'children': ['178', '197']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'assignment', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'q_cost'}; {'id': '183', 'type': 'list', 'children': ['184', '189', '192'], 'value': '[(self.q_min, 0.0), (0.0, 0.0), (self.q_max, 0.0)]'}; {'id': '184', 'type': 'tuple', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'q_min'}; {'id': '188', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '189', 'type': 'tuple', 'children': ['190', '191']}; {'id': '190', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '191', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '192', 'type': 'tuple', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'q_max'}; {'id': '196', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'qcost_model'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'PW_LINEAR'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': '_adjust_limits'}; {'id': '208', 'type': 'argument_list', 'children': []} | def bids_to_pwl(self, bids):
assert self.is_load
vl_bids = [bid for bid in bids if bid.vLoad == self]
gt_zero = [bid for bid in vl_bids if round(bid.quantity, 4) > 0.0]
valid_bids = [bid for bid in gt_zero if not bid.withheld]
p_bids = [v for v in valid_bids if not v.reactive]
q_bids = [v for v in valid_bids if v.reactive]
if p_bids:
self.p_cost = self._offbids_to_points(p_bids, True)
self.pcost_model = PW_LINEAR
self.online = True
else:
self.p_cost = [(0.0, 0.0), (self.p_max, 0.0)]
self.pcost_model = PW_LINEAR
logger.info("No valid active power bids for dispatchable load "
"[%s], shutting down." % self.name)
self.online = False
if q_bids:
self.q_cost = self._offbids_to_points(q_bids, True)
self.qcost_model = PW_LINEAR
self.online = True
else:
self.q_cost = [(self.q_min, 0.0), (0.0, 0.0), (self.q_max, 0.0)]
self.qcost_model = PW_LINEAR
self._adjust_limits() |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'DoxyfileParse'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_contents'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '13', '27', '33', '47', '53', '59', '67', '71', '75', '79', '83', '87', '127', '274', '325']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'import_statement', 'children': ['11']}; {'id': '11', 'type': 'dotted_name', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'shlex'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'lex'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'shlex'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'shlex'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '24']}; {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'instream'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'file_contents'}; {'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'posix'}; {'id': '26', 'type': 'True', 'children': []}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'augmented_assignment', 'children': ['29', '32'], 'value': '+='}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'lex'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'wordchars'}; {'id': '32', 'type': 'string', 'children': [], 'value': '"*+./-:"'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'lex'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'whitespace'}; {'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': 'lex'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'whitespace'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}; {'id': '45', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '46', 'type': 'string', 'children': [], 'value': '""'}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'lex'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'escape'}; {'id': '52', 'type': 'string', 'children': [], 'value': '""'}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'lineno'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'lex'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'lineno'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'lex'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'get_token'}; {'id': '66', 'type': 'argument_list', 'children': []}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'last_token'}; {'id': '74', 'type': 'string', 'children': [], 'value': '""'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'key_token'}; {'id': '78', 'type': 'False', 'children': []}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'next_key'}; {'id': '82', 'type': 'False', 'children': []}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '86', 'type': 'True', 'children': []}; {'id': '87', 'type': 'function_definition', 'children': ['88', '89', '94']}; {'id': '88', 'type': 'function_name', 'children': [], 'value': 'append_data'}; {'id': '89', 'type': 'parameters', 'children': ['90', '91', '92', '93']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'if_statement', 'children': ['96', '106', '116']}; {'id': '96', 'type': 'boolean_operator', 'children': ['97', '98'], 'value': 'or'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '105'], 'value': '=='}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '105', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '114']}; {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '116', 'type': 'else_clause', 'children': ['117']}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'augmented_assignment', 'children': ['120', '126'], 'value': '+='}; {'id': '120', 'type': 'subscript', 'children': ['121', '124']}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '124', 'type': 'unary_operator', 'children': ['125'], 'value': '-'}; {'id': '125', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '127', 'type': 'while_statement', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '129', 'type': 'block', 'children': ['130', '241', '245', '253']}; {'id': '130', 'type': 'if_statement', 'children': ['131', '135', '146', '153', '164']}; {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'in'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '133', 'type': 'list', 'children': ['134'], 'value': "['\\n']"}; {'id': '134', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '141']}; {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'not'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'last_token'}; {'id': '139', 'type': 'list', 'children': ['140'], 'value': "['\\\\']"}; {'id': '140', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'key_token'}; {'id': '145', 'type': 'True', 'children': []}; {'id': '146', 'type': 'elif_clause', 'children': ['147', '151']}; {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'in'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '149', 'type': 'list', 'children': ['150'], 'value': "['\\\\']"}; {'id': '150', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'pass_statement', 'children': []}; {'id': '153', 'type': 'elif_clause', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'key_token'}; {'id': '155', 'type': 'block', 'children': ['156', '160']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'key_token'}; {'id': '163', 'type': 'False', 'children': []}; {'id': '164', 'type': 'else_clause', 'children': ['165']}; {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'if_statement', 'children': ['167', '170', '188', '227']}; {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '=='}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '169', 'type': 'string', 'children': [], 'value': '"+="'}; {'id': '170', 'type': 'block', 'children': ['171']}; {'id': '171', 'type': 'if_statement', 'children': ['172', '179']}; {'id': '172', 'type': 'not_operator', 'children': ['173']}; {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': 'data'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '187', 'type': 'argument_list', 'children': []}; {'id': '188', 'type': 'elif_clause', 'children': ['189', '192']}; {'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': '=='}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '191', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '192', 'type': 'block', 'children': ['193']}; {'id': '193', 'type': 'if_statement', 'children': ['194', '204', '217']}; {'id': '194', 'type': 'boolean_operator', 'children': ['195', '198'], 'value': 'and'}; {'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '=='}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '197', 'type': 'string', 'children': [], 'value': '"TAGFILES"'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '204', 'type': 'block', 'children': ['205', '213']}; {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'append_data'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '210', '211', '212']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '211', 'type': 'False', 'children': []}; {'id': '212', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '216', 'type': 'False', 'children': []}; {'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', '224']}; {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '226', 'type': 'argument_list', 'children': []}; {'id': '227', 'type': 'else_clause', 'children': ['228']}; {'id': '228', 'type': 'block', 'children': ['229', '237']}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'append_data'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234', '235', '236']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '240', 'type': 'True', 'children': []}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'last_token'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '248', 'type': 'call', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'lex'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'get_token'}; {'id': '252', 'type': 'argument_list', 'children': []}; {'id': '253', 'type': 'if_statement', 'children': ['254', '261']}; {'id': '254', 'type': 'boolean_operator', 'children': ['255', '258'], 'value': 'and'}; {'id': '255', 'type': 'comparison_operator', 'children': ['256', '257'], 'value': '=='}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'last_token'}; {'id': '257', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '258', 'type': 'comparison_operator', 'children': ['259', '260'], 'value': '!='}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '260', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '261', 'type': 'block', 'children': ['262', '266']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}; {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '265', 'type': 'False', 'children': []}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'append_data'}; {'id': '269', 'type': 'argument_list', 'children': ['270', '271', '272', '273']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'new_data'}; {'id': '273', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '274', 'type': 'for_statement', 'children': ['275', '278', '283']}; {'id': '275', 'type': 'tuple_pattern', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '278', 'type': 'call', 'children': ['279', '282']}; {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '282', 'type': 'argument_list', 'children': []}; {'id': '283', 'type': 'block', 'children': ['284', '299', '309']}; {'id': '284', 'type': 'if_statement', 'children': ['285', '291']}; {'id': '285', 'type': 'comparison_operator', 'children': ['286', '290'], 'value': '=='}; {'id': '286', 'type': 'call', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '290', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'data'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '299', 'type': 'if_statement', 'children': ['300', '307']}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': 'in'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '302', 'type': 'list', 'children': ['303', '304', '305', '306'], 'value': '["INPUT", "FILE_PATTERNS", "EXCLUDE_PATTERNS", "TAGFILES"]'}; {'id': '303', 'type': 'string', 'children': [], 'value': '"INPUT"'}; {'id': '304', 'type': 'string', 'children': [], 'value': '"FILE_PATTERNS"'}; {'id': '305', 'type': 'string', 'children': [], 'value': '"EXCLUDE_PATTERNS"'}; {'id': '306', 'type': 'string', 'children': [], 'value': '"TAGFILES"'}; {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'continue_statement', 'children': []}; {'id': '309', 'type': 'if_statement', 'children': ['310', '316']}; {'id': '310', 'type': 'comparison_operator', 'children': ['311', '315'], 'value': '=='}; {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '315', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '316', 'type': 'block', 'children': ['317']}; {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '322']}; {'id': '319', 'type': 'subscript', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '324', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '325', 'type': 'return_statement', 'children': ['326']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'data'} | def DoxyfileParse(file_contents):
data = {}
import shlex
lex = shlex.shlex(instream = file_contents, posix = True)
lex.wordchars += "*+./-:"
lex.whitespace = lex.whitespace.replace("\n", "")
lex.escape = ""
lineno = lex.lineno
token = lex.get_token()
key = token
last_token = ""
key_token = False
next_key = False
new_data = True
def append_data(data, key, new_data, token):
if new_data or len(data[key]) == 0:
data[key].append(token)
else:
data[key][-1] += token
while token:
if token in ['\n']:
if last_token not in ['\\']:
key_token = True
elif token in ['\\']:
pass
elif key_token:
key = token
key_token = False
else:
if token == "+=":
if not data.has_key(key):
data[key] = list()
elif token == "=":
if key == "TAGFILES" and data.has_key(key):
append_data( data, key, False, "=" )
new_data=False
else:
data[key] = list()
else:
append_data( data, key, new_data, token )
new_data = True
last_token = token
token = lex.get_token()
if last_token == '\\' and token != '\n':
new_data = False
append_data( data, key, new_data, '\\' )
for (k, v) in data.items():
if len(v) == 0:
data.pop(k)
if k in ["INPUT", "FILE_PATTERNS", "EXCLUDE_PATTERNS", "TAGFILES"]:
continue
if len(v) == 1:
data[k] = v[0]
return data |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'DoxySourceScan'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '7', 'type': 'block', 'children': ['8', '37', '42', '46', '57', '78', '88', '98', '112', '282', '333', '393', '398', '403', '408', '424']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'default_file_patterns'}; {'id': '11', 'type': 'list', 'children': ['12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36'], 'value': "[\n '*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx',\n '*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++',\n '*.idl', '*.odl', '*.cs', '*.php', '*.php3', '*.inc', '*.m', '*.mm',\n '*.py',\n ]"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'*.c'"}; {'id': '13', 'type': 'string', 'children': [], 'value': "'*.cc'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'*.cxx'"}; {'id': '15', 'type': 'string', 'children': [], 'value': "'*.cpp'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'*.c++'"}; {'id': '17', 'type': 'string', 'children': [], 'value': "'*.java'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'*.ii'"}; {'id': '19', 'type': 'string', 'children': [], 'value': "'*.ixx'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'*.ipp'"}; {'id': '21', 'type': 'string', 'children': [], 'value': "'*.i++'"}; {'id': '22', 'type': 'string', 'children': [], 'value': "'*.inl'"}; {'id': '23', 'type': 'string', 'children': [], 'value': "'*.h'"}; {'id': '24', 'type': 'string', 'children': [], 'value': "'*.hh '"}; {'id': '25', 'type': 'string', 'children': [], 'value': "'*.hxx'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'*.hpp'"}; {'id': '27', 'type': 'string', 'children': [], 'value': "'*.h++'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'*.idl'"}; {'id': '29', 'type': 'string', 'children': [], 'value': "'*.odl'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'*.cs'"}; {'id': '31', 'type': 'string', 'children': [], 'value': "'*.php'"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'*.php3'"}; {'id': '33', 'type': 'string', 'children': [], 'value': "'*.inc'"}; {'id': '34', 'type': 'string', 'children': [], 'value': "'*.m'"}; {'id': '35', 'type': 'string', 'children': [], 'value': "'*.mm'"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'*.py'"}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'default_exclude_patterns'}; {'id': '40', 'type': 'list', 'children': ['41'], 'value': "[\n '*~',\n ]"}; {'id': '41', 'type': 'string', 'children': [], 'value': "'*~'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '45', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'DoxyfileParse'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_contents'}; {'id': '56', 'type': 'argument_list', 'children': []}; {'id': '57', 'type': 'if_statement', 'children': ['58', '67', '72']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '66'], 'value': '=='}; {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': '"RECURSIVE"'}; {'id': '65', 'type': 'string', 'children': [], 'value': '"NO"'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"YES"'}; {'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': 'recursive'}; {'id': '71', 'type': 'True', 'children': []}; {'id': '72', 'type': 'else_clause', 'children': ['73']}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'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': 'file_patterns'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': '"FILE_PATTERNS"'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'default_file_patterns'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': '"EXCLUDE_PATTERNS"'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'default_exclude_patterns'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'conf_dir'}; {'id': '101', 'type': 'call', 'children': ['102', '107']}; {'id': '102', 'type': 'attribute', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '112', 'type': 'for_statement', 'children': ['113', '114', '121']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}; {'id': '119', 'type': 'string', 'children': [], 'value': '"INPUT"'}; {'id': '120', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '121', 'type': 'block', 'children': ['122', '145']}; {'id': '122', 'type': 'if_statement', 'children': ['123', '132']}; {'id': '123', 'type': 'not_operator', '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': 'isabs'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '132', 'type': 'block', 'children': ['133']}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '136', 'type': 'call', 'children': ['137', '142']}; {'id': '137', 'type': 'attribute', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'conf_dir'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '145', 'type': 'if_statement', 'children': ['146', '154', '162']}; {'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': 'isfile'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '154', 'type': 'block', 'children': ['155']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '162', 'type': 'elif_clause', 'children': ['163', '171']}; {'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': 'isdir'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'if_statement', 'children': ['173', '174', '257']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '174', 'type': 'block', 'children': ['175']}; {'id': '175', 'type': 'for_statement', 'children': ['176', '180', '186']}; {'id': '176', 'type': 'pattern_list', 'children': ['177', '178', '179']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'walk'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'for_statement', 'children': ['188', '189', '190']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '190', 'type': 'block', 'children': ['191', '203', '225', '244']}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '194', 'type': 'call', 'children': ['195', '200']}; {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'pattern_check'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'reduce'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '223', '224']}; {'id': '209', 'type': 'lambda', 'children': ['210', '213']}; {'id': '210', 'type': 'lambda_parameters', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '213', 'type': 'boolean_operator', 'children': ['214', '215'], 'value': 'or'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'file_patterns'}; {'id': '224', 'type': 'False', 'children': []}; {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'exclude_check'}; {'id': '228', 'type': 'call', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'reduce'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '242', '243']}; {'id': '231', 'type': 'lambda', 'children': ['232', '235']}; {'id': '232', 'type': 'lambda_parameters', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '235', 'type': 'boolean_operator', 'children': ['236', '237'], 'value': 'and'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '239', 'type': 'argument_list', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'exclude_patterns'}; {'id': '243', 'type': 'True', 'children': []}; {'id': '244', 'type': 'if_statement', 'children': ['245', '249']}; {'id': '245', 'type': 'boolean_operator', 'children': ['246', '247'], 'value': 'and'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'pattern_check'}; {'id': '247', 'type': 'not_operator', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'exclude_check'}; {'id': '249', 'type': 'block', 'children': ['250']}; {'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': 'sources'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '257', 'type': 'else_clause', 'children': ['258']}; {'id': '258', 'type': 'block', 'children': ['259']}; {'id': '259', 'type': 'for_statement', 'children': ['260', '261', '262']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'file_patterns'}; {'id': '262', 'type': 'block', 'children': ['263']}; {'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': 'sources'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}; {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}; {'id': '279', 'type': 'list', 'children': ['280', '281'], 'value': '[node, pattern]'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '282', 'type': 'for_statement', 'children': ['283', '284', '291']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '284', 'type': 'call', 'children': ['285', '288']}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '288', 'type': 'argument_list', 'children': ['289', '290']}; {'id': '289', 'type': 'string', 'children': [], 'value': '"TAGFILES"'}; {'id': '290', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '291', 'type': 'block', 'children': ['292', '303', '326']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}; {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '295', 'type': 'subscript', 'children': ['296', '302']}; {'id': '296', 'type': 'call', 'children': ['297', '300']}; {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '302', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '303', 'type': 'if_statement', 'children': ['304', '313']}; {'id': '304', 'type': 'not_operator', 'children': ['305']}; {'id': '305', 'type': 'call', 'children': ['306', '311']}; {'id': '306', 'type': 'attribute', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'isabs'}; {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'file'}; {'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': 'file'}; {'id': '317', 'type': 'call', 'children': ['318', '323']}; {'id': '318', 'type': 'attribute', 'children': ['319', '322']}; {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '323', 'type': 'argument_list', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'conf_dir'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '333', 'type': 'function_definition', 'children': ['334', '335', '337']}; {'id': '334', 'type': 'function_name', 'children': [], 'value': 'append_additional_source'}; {'id': '335', 'type': 'parameters', 'children': ['336']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '337', 'type': 'block', 'children': ['338', '348']}; {'id': '338', 'type': 'expression_statement', 'children': ['339']}; {'id': '339', 'type': 'assignment', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '341', 'type': 'call', 'children': ['342', '345']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '345', 'type': 'argument_list', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'option'}; {'id': '347', 'type': 'string', 'children': [], 'value': '""'}; {'id': '348', 'type': 'if_statement', 'children': ['349', '352']}; {'id': '349', 'type': 'comparison_operator', 'children': ['350', '351'], 'value': '!='}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '351', 'type': 'string', 'children': [], 'value': '""'}; {'id': '352', 'type': 'block', 'children': ['353', '376']}; {'id': '353', 'type': 'if_statement', 'children': ['354', '363']}; {'id': '354', 'type': 'not_operator', 'children': ['355']}; {'id': '355', 'type': 'call', 'children': ['356', '361']}; {'id': '356', 'type': 'attribute', 'children': ['357', '360']}; {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'isabs'}; {'id': '361', 'type': 'argument_list', 'children': ['362']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '363', 'type': 'block', 'children': ['364']}; {'id': '364', 'type': 'expression_statement', 'children': ['365']}; {'id': '365', 'type': 'assignment', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '367', 'type': 'call', 'children': ['368', '373']}; {'id': '368', 'type': 'attribute', 'children': ['369', '372']}; {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '373', 'type': 'argument_list', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'conf_dir'}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '376', 'type': 'if_statement', 'children': ['377', '385']}; {'id': '377', 'type': 'call', 'children': ['378', '383']}; {'id': '378', 'type': 'attribute', 'children': ['379', '382']}; {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '383', 'type': 'argument_list', 'children': ['384']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '385', 'type': 'block', 'children': ['386']}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}; {'id': '387', 'type': 'call', 'children': ['388', '391']}; {'id': '388', 'type': 'attribute', 'children': ['389', '390']}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '391', 'type': 'argument_list', 'children': ['392']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '393', 'type': 'expression_statement', 'children': ['394']}; {'id': '394', 'type': 'call', 'children': ['395', '396']}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'append_additional_source'}; {'id': '396', 'type': 'argument_list', 'children': ['397']}; {'id': '397', 'type': 'string', 'children': [], 'value': '"HTML_STYLESHEET"'}; {'id': '398', 'type': 'expression_statement', 'children': ['399']}; {'id': '399', 'type': 'call', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'append_additional_source'}; {'id': '401', 'type': 'argument_list', 'children': ['402']}; {'id': '402', 'type': 'string', 'children': [], 'value': '"HTML_HEADER"'}; {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'call', 'children': ['405', '406']}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'append_additional_source'}; {'id': '406', 'type': 'argument_list', 'children': ['407']}; {'id': '407', 'type': 'string', 'children': [], 'value': '"HTML_FOOTER"'}; {'id': '408', 'type': 'expression_statement', 'children': ['409']}; {'id': '409', 'type': 'assignment', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '411', 'type': 'call', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '413', 'type': 'argument_list', 'children': ['414', '423']}; {'id': '414', 'type': 'lambda', 'children': ['415', '417']}; {'id': '415', 'type': 'lambda_parameters', 'children': ['416']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '417', 'type': 'call', 'children': ['418', '421']}; {'id': '418', 'type': 'attribute', 'children': ['419', '420']}; {'id': '419', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'File'}; {'id': '421', 'type': 'argument_list', 'children': ['422']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '423', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '424', 'type': 'return_statement', 'children': ['425']}; {'id': '425', 'type': 'identifier', 'children': [], 'value': 'sources'} | def DoxySourceScan(node, env, path):
default_file_patterns = [
'*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx',
'*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++',
'*.idl', '*.odl', '*.cs', '*.php', '*.php3', '*.inc', '*.m', '*.mm',
'*.py',
]
default_exclude_patterns = [
'*~',
]
sources = []
data = DoxyfileParse(node.get_contents())
if data.get("RECURSIVE", "NO") == "YES":
recursive = True
else:
recursive = False
file_patterns = data.get("FILE_PATTERNS", default_file_patterns)
exclude_patterns = data.get("EXCLUDE_PATTERNS", default_exclude_patterns)
conf_dir = os.path.dirname(str(node))
for node in data.get("INPUT", []):
if not os.path.isabs(node):
node = os.path.join(conf_dir, node)
if os.path.isfile(node):
sources.append(node)
elif os.path.isdir(node):
if recursive:
for root, dirs, files in os.walk(node):
for f in files:
filename = os.path.join(root, f)
pattern_check = reduce(lambda x, y: x or bool(fnmatch(filename, y)), file_patterns, False)
exclude_check = reduce(lambda x, y: x and fnmatch(filename, y), exclude_patterns, True)
if pattern_check and not exclude_check:
sources.append(filename)
else:
for pattern in file_patterns:
sources.extend(glob.glob("/".join([node, pattern])))
for node in data.get("TAGFILES", []):
file = node.split("=")[0]
if not os.path.isabs(file):
file = os.path.join(conf_dir, file)
sources.append(file)
def append_additional_source(option):
file = data.get(option, "")
if file != "":
if not os.path.isabs(file):
file = os.path.join(conf_dir, file)
if os.path.isfile(file):
sources.append(file)
append_additional_source("HTML_STYLESHEET")
append_additional_source("HTML_HEADER")
append_additional_source("HTML_FOOTER")
sources = map( lambda path: env.File(path), sources )
return sources |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_quadratic_costs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ipol'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'nxyz'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '9', 'type': 'block', 'children': ['10', '17', '24', '38', '61', '89', '117', '126', '316']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ipol'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'rnpol'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'gpol'}; {'id': '27', 'type': 'list_comprehension', 'children': ['28', '29', '32']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '32', 'type': 'if_clause', 'children': ['33']}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '37'], 'value': '=='}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'POLYNOMIAL'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '53']}; {'id': '39', 'type': 'list_comprehension', 'children': ['40', '41', '44']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'gpol'}; {'id': '44', 'type': 'if_clause', 'children': ['45']}; {'id': '45', 'type': 'comparison_operator', 'children': ['46', '52'], 'value': '>'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"Order of polynomial cost greater than quadratic."'}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'iqdr'}; {'id': '64', 'type': 'list_comprehension', 'children': ['65', '66', '74']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '70']}; {'id': '67', 'type': 'pattern_list', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '74', 'type': 'if_clause', 'children': ['75']}; {'id': '75', 'type': 'boolean_operator', 'children': ['76', '81'], 'value': 'and'}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': '=='}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'POLYNOMIAL'}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '88'], 'value': '=='}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ilin'}; {'id': '92', 'type': 'list_comprehension', 'children': ['93', '94', '102']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '94', 'type': 'for_in_clause', 'children': ['95', '98']}; {'id': '95', 'type': 'pattern_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '98', 'type': 'call', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '102', 'type': 'if_clause', 'children': ['103']}; {'id': '103', 'type': 'boolean_operator', 'children': ['104', '109'], 'value': 'and'}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '=='}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'pcost_model'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'POLYNOMIAL'}; {'id': '109', 'type': 'comparison_operator', 'children': ['110', '116'], 'value': '=='}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'polycf'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'tuple', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '125', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '130', '292']}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': '>'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '129', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '130', 'type': 'block', 'children': ['131', '159', '192', '206', '217', '241', '261', '269']}; {'id': '131', 'type': 'if_statement', 'children': ['132', '138']}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '137'], 'value': '>'}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'iqdr'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '138', 'type': 'block', 'children': ['139']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '146']}; {'id': '141', 'type': 'subscript', 'children': ['142', '143', '144']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'polycf'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'iqdr'}; {'id': '144', 'type': 'slice', 'children': ['145']}; {'id': '145', 'type': 'colon', 'children': []}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'list_comprehension', 'children': ['150', '156']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '156', 'type': 'for_in_clause', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '159', 'type': 'if_statement', 'children': ['160', '166']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '165'], 'value': '>'}; {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ilin'}; {'id': '165', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '166', 'type': 'block', 'children': ['167']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '175']}; {'id': '169', 'type': 'subscript', 'children': ['170', '171', '172']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'polycf'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'ilin'}; {'id': '172', 'type': 'slice', 'children': ['173', '174']}; {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'colon', 'children': []}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'list_comprehension', 'children': ['179', '189']}; {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'subscript', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'p_cost'}; {'id': '186', 'type': 'slice', 'children': ['187', '188']}; {'id': '187', 'type': 'colon', 'children': []}; {'id': '188', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '189', 'type': 'for_in_clause', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'polycf'}; {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '*'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'polycf'}; {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'list', 'children': ['201', '204', '205'], 'value': '[base_mva**2, base_mva, 1]'}; {'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '**'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '203', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '205', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'Pg'}; {'id': '209', 'type': 'call', 'children': ['210', '215']}; {'id': '210', 'type': 'attribute', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'om'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'get_var'}; {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'string', 'children': [], 'value': '"Pg"'}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'Npol'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '238']}; {'id': '223', 'type': 'tuple', 'children': ['224', '228']}; {'id': '224', 'type': 'call', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '228', 'type': 'tuple', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'rnpol'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '234'], 'value': '+'}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'Pg'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'i1'}; {'id': '234', 'type': 'call', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'ipol'}; {'id': '238', 'type': 'tuple', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'nxyz'}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'Hpol'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '258']}; {'id': '247', 'type': 'tuple', 'children': ['248', '255']}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '*'}; {'id': '249', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '250', 'type': 'subscript', 'children': ['251', '252', '254']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'polycf'}; {'id': '252', 'type': 'slice', 'children': ['253']}; {'id': '253', 'type': 'colon', 'children': []}; {'id': '254', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '255', 'type': 'tuple', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'rnpol'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'rnpol'}; {'id': '258', 'type': 'tuple', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'Cpol'}; {'id': '264', 'type': 'subscript', 'children': ['265', '266', '268']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'polycf'}; {'id': '266', 'type': 'slice', 'children': ['267']}; {'id': '267', 'type': 'colon', 'children': []}; {'id': '268', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'fparm_pol'}; {'id': '272', 'type': 'attribute', 'children': ['273', '291']}; {'id': '273', 'type': '()', 'children': ['274']}; {'id': '274', 'type': 'binary_operator', 'children': ['275', '279'], 'value': '*'}; {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'npol'}; {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'list', 'children': ['283', '285', '287', '289'], 'value': '[[1], [0], [0], [1]]'}; {'id': '283', 'type': 'list', 'children': ['284'], 'value': '[1]'}; {'id': '284', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '285', 'type': 'list', 'children': ['286'], 'value': '[0]'}; {'id': '286', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '287', 'type': 'list', 'children': ['288'], 'value': '[0]'}; {'id': '288', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '289', 'type': 'list', 'children': ['290'], 'value': '[1]'}; {'id': '290', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '292', 'type': 'else_clause', 'children': ['293']}; {'id': '293', 'type': 'block', 'children': ['294', '300', '307']}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'Npol'}; {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'Hpol'}; {'id': '299', 'type': 'None', 'children': []}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}; {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'Cpol'}; {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'fparm_pol'}; {'id': '310', 'type': 'call', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}; {'id': '313', 'type': 'tuple', 'children': ['314', '315']}; {'id': '314', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '315', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '316', 'type': 'return_statement', 'children': ['317']}; {'id': '317', 'type': 'expression_list', 'children': ['318', '319', '320', '321', '322', '323']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'Npol'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'Hpol'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'Cpol'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'fparm_pol'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'polycf'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'npol'} | def _quadratic_costs(self, generators, ipol, nxyz, base_mva):
npol = len(ipol)
rnpol = range(npol)
gpol = [g for g in generators if g.pcost_model == POLYNOMIAL]
if [g for g in gpol if len(g.p_cost) > 3]:
logger.error("Order of polynomial cost greater than quadratic.")
iqdr = [i for i, g in enumerate(generators)
if g.pcost_model == POLYNOMIAL and len(g.p_cost) == 3]
ilin = [i for i, g in enumerate(generators)
if g.pcost_model == POLYNOMIAL and len(g.p_cost) == 2]
polycf = zeros((npol, 3))
if npol > 0:
if len(iqdr) > 0:
polycf[iqdr, :] = array([list(g.p_cost)
for g in generators])
if len(ilin) > 0:
polycf[ilin, 1:] = array([list(g.p_cost[:2])
for g in generators])
polycf = polycf * array([base_mva**2, base_mva, 1])
Pg = self.om.get_var("Pg")
Npol = csr_matrix((ones(npol), (rnpol, Pg.i1 + array(ipol))),
(npol, nxyz))
Hpol = csr_matrix((2 * polycf[:, 0], (rnpol, rnpol)), (npol, npol))
Cpol = polycf[:, 1]
fparm_pol = (ones(npol) * array([[1], [0], [0], [1]])).T
else:
Npol = Hpol = None
Cpol = array([])
fparm_pol = zeros((0, 4))
return Npol, Hpol, Cpol, fparm_pol, polycf, npol |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_gh'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'block', 'children': ['7', '26', '45', '80', '95', '114', '133', '144', '159', '170', '192', '212', '384']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'Pgen'}; {'id': '10', 'type': 'subscript', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '12', 'type': 'slice', 'children': ['13', '18', '19']}; {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_Pg'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'i1'}; {'id': '18', 'type': 'colon', 'children': []}; {'id': '19', 'type': 'binary_operator', 'children': ['20', '25'], 'value': '+'}; {'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': '_Pg'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'iN'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Qgen'}; {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '31', 'type': 'slice', 'children': ['32', '37', '38']}; {'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': '_Qg'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'i1'}; {'id': '37', 'type': 'colon', 'children': []}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '44'], 'value': '+'}; {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_Qg'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'iN'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '45', 'type': 'for_statement', 'children': ['46', '49', '55']}; {'id': '46', 'type': 'pattern_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'gen'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_gn'}; {'id': '55', 'type': 'block', 'children': ['56', '68']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'gen'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '61', 'type': 'binary_operator', 'children': ['62', '65'], 'value': '*'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'Pgen'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': '_base_mva'}; {'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': 'gen'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '73', 'type': 'binary_operator', 'children': ['74', '77'], 'value': '*'}; {'id': '74', 'type': 'subscript', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'Qgen'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': '_base_mva'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'Sbus'}; {'id': '83', 'type': 'call', 'children': ['84', '91']}; {'id': '84', 'type': 'attribute', 'children': ['85', '90']}; {'id': '85', 'type': 'attribute', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'om'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'getSbus'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '_bs'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'Vang'}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '100', 'type': 'slice', 'children': ['101', '106', '107']}; {'id': '101', 'type': 'attribute', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '_Va'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'i1'}; {'id': '106', 'type': 'colon', 'children': []}; {'id': '107', 'type': 'binary_operator', 'children': ['108', '113'], 'value': '+'}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': '_Va'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'iN'}; {'id': '113', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'Vmag'}; {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '119', 'type': 'slice', 'children': ['120', '125', '126']}; {'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': '_Vm'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'i1'}; {'id': '125', 'type': 'colon', 'children': []}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '132'], 'value': '+'}; {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': '_Vm'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'iN'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '*'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'Vmag'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '*'}; {'id': '142', 'type': 'integer', 'children': [], 'value': '1j'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'Vang'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'mis'}; {'id': '147', 'type': 'binary_operator', 'children': ['148', '158'], 'value': '-'}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '*'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'conj'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'binary_operator', 'children': ['154', '157'], 'value': '*'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_Ybus'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'Sbus'}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164', '167']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'r_'}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'mis'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'mis'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'imag'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'list_comprehension', 'children': ['177', '187']}; {'id': '177', 'type': 'binary_operator', 'children': ['178', '186'], 'value': '**'}; {'id': '178', 'type': '()', 'children': ['179']}; {'id': '179', 'type': 'binary_operator', 'children': ['180', '183'], 'value': '/'}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'rate_a'}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': '_base_mva'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '187', 'type': 'for_in_clause', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': '_ln'}; {'id': '192', 'type': 'for_statement', 'children': ['193', '196', '200']}; {'id': '193', 'type': 'pattern_list', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '196', 'type': 'call', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'if_statement', 'children': ['202', '205']}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': '=='}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '204', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '211']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'Inf'}; {'id': '212', 'type': 'if_statement', 'children': ['213', '218', '258']}; {'id': '213', 'type': 'comparison_operator', 'children': ['214', '217'], 'value': '=='}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'flow_lim'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'IFLOW'}; {'id': '218', 'type': 'block', 'children': ['219', '227', '235']}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'If'}; {'id': '222', 'type': 'binary_operator', 'children': ['223', '226'], 'value': '*'}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': '_Yf'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'It'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '234'], 'value': '*'}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': '_Yt'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '238', 'type': 'subscript', 'children': ['239', '240', '249']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'r_'}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '248'], 'value': '-'}; {'id': '241', 'type': '()', 'children': ['242']}; {'id': '242', 'type': 'binary_operator', 'children': ['243', '244'], 'value': '*'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'If'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'conj'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'If'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '249', 'type': 'binary_operator', 'children': ['250', '257'], 'value': '-'}; {'id': '250', 'type': '()', 'children': ['251']}; {'id': '251', 'type': 'binary_operator', 'children': ['252', '253'], 'value': '*'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'It'}; {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'conj'}; {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'It'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '258', 'type': 'else_clause', 'children': ['259']}; {'id': '259', 'type': 'block', 'children': ['260', '274', '288', '303', '318']}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}; {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'i_fbus'}; {'id': '263', 'type': 'list_comprehension', 'children': ['264', '269']}; {'id': '264', 'type': 'attribute', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'from_bus'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': '_i'}; {'id': '269', 'type': 'for_in_clause', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': '_ln'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'i_tbus'}; {'id': '277', 'type': 'list_comprehension', 'children': ['278', '283']}; {'id': '278', 'type': 'attribute', 'children': ['279', '282']}; {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'to_bus'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': '_i'}; {'id': '283', 'type': 'for_in_clause', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': '_ln'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}; {'id': '289', 'type': 'assignment', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'Sf'}; {'id': '291', 'type': 'binary_operator', 'children': ['292', '295'], 'value': '*'}; {'id': '292', 'type': 'subscript', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'i_fbus'}; {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'conj'}; {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'binary_operator', 'children': ['299', '302'], 'value': '*'}; {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': '_Yf'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'St'}; {'id': '306', 'type': 'binary_operator', 'children': ['307', '310'], 'value': '*'}; {'id': '307', 'type': 'subscript', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'i_tbus'}; {'id': '310', 'type': 'call', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'conj'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}; {'id': '313', 'type': 'binary_operator', 'children': ['314', '317'], 'value': '*'}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': '_Yt'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'V'}; {'id': '318', 'type': 'if_statement', 'children': ['319', '324', '348', '380']}; {'id': '319', 'type': 'comparison_operator', 'children': ['320', '323'], 'value': '=='}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'flow_lim'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'PFLOW'}; {'id': '324', 'type': 'block', 'children': ['325']}; {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'assignment', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '328', 'type': 'subscript', 'children': ['329', '330', '339']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'r_'}; {'id': '330', 'type': 'binary_operator', 'children': ['331', '338'], 'value': '-'}; {'id': '331', 'type': 'binary_operator', 'children': ['332', '337'], 'value': '**'}; {'id': '332', 'type': 'call', 'children': ['333', '336']}; {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'Sf'}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '336', 'type': 'argument_list', 'children': []}; {'id': '337', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '339', 'type': 'binary_operator', 'children': ['340', '347'], 'value': '-'}; {'id': '340', 'type': 'binary_operator', 'children': ['341', '346'], 'value': '**'}; {'id': '341', 'type': 'call', 'children': ['342', '345']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'St'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '345', 'type': 'argument_list', 'children': []}; {'id': '346', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '348', 'type': 'elif_clause', 'children': ['349', '354']}; {'id': '349', 'type': 'comparison_operator', 'children': ['350', '353'], 'value': '=='}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'flow_lim'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'SFLOW'}; {'id': '354', 'type': 'block', 'children': ['355']}; {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'assignment', 'children': ['357', '358']}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '358', 'type': 'attribute', 'children': ['359', '379']}; {'id': '359', 'type': 'subscript', 'children': ['360', '361', '370']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'r_'}; {'id': '361', 'type': 'binary_operator', 'children': ['362', '369'], 'value': '-'}; {'id': '362', 'type': '()', 'children': ['363']}; {'id': '363', 'type': 'binary_operator', 'children': ['364', '365'], 'value': '*'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'Sf'}; {'id': '365', 'type': 'call', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'conj'}; {'id': '367', 'type': 'argument_list', 'children': ['368']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'Sf'}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '370', 'type': 'binary_operator', 'children': ['371', '378'], 'value': '-'}; {'id': '371', 'type': '()', 'children': ['372']}; {'id': '372', 'type': 'binary_operator', 'children': ['373', '374'], 'value': '*'}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'St'}; {'id': '374', 'type': 'call', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'conj'}; {'id': '376', 'type': 'argument_list', 'children': ['377']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'St'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'flow_max'}; {'id': '379', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '380', 'type': 'else_clause', 'children': ['381']}; {'id': '381', 'type': 'block', 'children': ['382']}; {'id': '382', 'type': 'raise_statement', 'children': ['383']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '384', 'type': 'return_statement', 'children': ['385']}; {'id': '385', 'type': 'expression_list', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'g'} | def _gh(self, x):
Pgen = x[self._Pg.i1:self._Pg.iN + 1]
Qgen = x[self._Qg.i1:self._Qg.iN + 1]
for i, gen in enumerate(self._gn):
gen.p = Pgen[i] * self._base_mva
gen.q = Qgen[i] * self._base_mva
Sbus = self.om.case.getSbus(self._bs)
Vang = x[self._Va.i1:self._Va.iN + 1]
Vmag = x[self._Vm.i1:self._Vm.iN + 1]
V = Vmag * exp(1j * Vang)
mis = V * conj(self._Ybus * V) - Sbus
g = r_[mis.real,
mis.imag]
flow_max = array([(l.rate_a / self._base_mva)**2 for l in self._ln])
for i, v in enumerate(flow_max):
if v == 0.0:
flow_max[i] = Inf
if self.flow_lim == IFLOW:
If = self._Yf * V
It = self._Yt * V
h = r_[(If * conj(If)) - flow_max,
(It * conj(It)) - flow_max]
else:
i_fbus = [e.from_bus._i for e in self._ln]
i_tbus = [e.to_bus._i for e in self._ln]
Sf = V[i_fbus] * conj(self._Yf * V)
St = V[i_tbus] * conj(self._Yt * V)
if self.flow_lim == PFLOW:
h = r_[Sf.real()**2 - flow_max,
St.real()**2 - flow_max]
elif self.flow_lim == SFLOW:
h = r_[(Sf * conj(Sf)) - flow_max,
(St * conj(St)) - flow_max].real
else:
raise ValueError
return h, g |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'performAction'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '6', 'type': 'block', 'children': ['7', '27', '37', '49', '66', '80', '102', '163', '169']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'gs'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '12', '19']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '12', 'type': 'for_in_clause', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'online_generators'}; {'id': '19', 'type': 'if_clause', 'children': ['20']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '26'], 'value': '!='}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'bus'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'REFERENCE'}; {'id': '27', 'type': 'assert_statement', 'children': ['28']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '33'], 'value': '=='}; {'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': 'action'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'gs'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '%'}; {'id': '44', 'type': 'string', 'children': [], 'value': '"Action: %s"'}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '49', 'type': 'for_statement', 'children': ['50', '53', '57']}; {'id': '50', 'type': 'pattern_list', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'gs'}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '79']}; {'id': '68', 'type': 'attribute', 'children': ['69', '78']}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'NewtonPF'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '77', 'type': 'False', 'children': []}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'solve'}; {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '91']}; {'id': '82', 'type': 'subscript', 'children': ['83', '86', '88']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': '_Pg'}; {'id': '86', 'type': 'slice', 'children': ['87']}; {'id': '87', 'type': 'colon', 'children': []}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_step'}; {'id': '91', 'type': 'list_comprehension', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'online_generators'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '115']}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '107'], 'value': '!='}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': '_step'}; {'id': '107', 'type': 'binary_operator', 'children': ['108', '114'], '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': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '115', 'type': 'block', 'children': ['116', '134']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'pq_buses'}; {'id': '119', 'type': 'list_comprehension', 'children': ['120', '121', '128']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'buses'}; {'id': '128', 'type': 'if_clause', 'children': ['129']}; {'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '=='}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'PQ'}; {'id': '134', 'type': 'for_statement', 'children': ['135', '138', '142']}; {'id': '135', 'type': 'pattern_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'pq_buses'}; {'id': '142', 'type': 'block', 'children': ['143']}; {'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': 'b'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'p_demand'}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '154'], 'value': '*'}; {'id': '149', 'type': 'subscript', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': '_Pd0'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '154', 'type': 'subscript', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '162'], 'value': '+'}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': '_step'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'augmented_assignment', 'children': ['165', '168'], 'value': '+='}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': '_step'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'logger'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '%'}; {'id': '176', 'type': 'string', 'children': [], 'value': '"Entering step %d."'}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': '_step'} | def performAction(self, action):
gs = [g for g in self.case.online_generators if g.bus.type !=REFERENCE]
assert len(action) == len(gs)
logger.info("Action: %s" % list(action))
for i, g in enumerate(gs):
g.p = action[i]
NewtonPF(self.case, verbose=False).solve()
self._Pg[:, self._step] = [g.p for g in self.case.online_generators]
if self._step != len(self.profile) - 1:
pq_buses = [b for b in self.case.buses if b.type == PQ]
for i, b in enumerate(pq_buses):
b.p_demand = self._Pd0[i] * self.profile[self._step + 1]
self._step += 1
logger.info("Entering step %d." % self._step) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'blt'}; {'id': '3', 'type': 'parameters', 'children': ['4', '12']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '6', 'type': 'type', 'children': ['7']}; {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '9', 'type': 'type_parameter', 'children': ['10']}; {'id': '10', 'type': 'type', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'SYM'}; {'id': '12', 'type': 'typed_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '14', 'type': 'type', 'children': ['15']}; {'id': '15', 'type': 'generic_type', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '17', 'type': 'type_parameter', 'children': ['18']}; {'id': '18', 'type': 'type', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'SYM'}; {'id': '20', 'type': 'type', 'children': ['21']}; {'id': '21', 'type': 'generic_type', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '23', 'type': 'type_parameter', 'children': ['24', '26']}; {'id': '24', 'type': 'type', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '26', 'type': 'type', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'Any'}; {'id': '28', 'type': 'block', 'children': ['29', '39', '58']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'J'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ca'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'jacobian'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '49']}; {'id': '41', 'type': 'pattern_list', 'children': ['42', '43', '44', '45', '46', '47', '48']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'nblock'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'rowperm'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'colperm'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'rowblock'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'colblock'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'coarserow'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'coarsecol'}; {'id': '49', 'type': 'call', 'children': ['50', '57']}; {'id': '50', 'type': 'attribute', 'children': ['51', '56']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'J'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sparsity'}; {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'btf'}; {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': 'dictionary', 'children': ['60', '63', '66', '69', '72', '75', '78', '81']}; {'id': '60', 'type': 'pair', 'children': ['61', '62']}; {'id': '61', 'type': 'string', 'children': [], 'value': "'J'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'J'}; {'id': '63', 'type': 'pair', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'nblock'"}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'nblock'}; {'id': '66', 'type': 'pair', 'children': ['67', '68']}; {'id': '67', 'type': 'string', 'children': [], 'value': "'rowperm'"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'rowperm'}; {'id': '69', 'type': 'pair', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'colperm'"}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'colperm'}; {'id': '72', 'type': 'pair', 'children': ['73', '74']}; {'id': '73', 'type': 'string', 'children': [], 'value': "'rowblock'"}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'rowblock'}; {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'colblock'"}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'colblock'}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'coarserow'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'coarserow'}; {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'coarsecol'"}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'coarsecol'} | def blt(f: List[SYM], x: List[SYM]) -> Dict[str, Any]:
J = ca.jacobian(f, x)
nblock, rowperm, colperm, rowblock, colblock, coarserow, coarsecol = J.sparsity().btf()
return {
'J': J,
'nblock': nblock,
'rowperm': rowperm,
'colperm': colperm,
'rowblock': rowblock,
'colblock': colblock,
'coarserow': coarserow,
'coarsecol': coarsecol
} |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_generators'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'call', 'children': ['8', '13']}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}; {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '16', 'type': 'lambda', 'children': ['17', '19']}; {'id': '17', 'type': 'lambda_parameters', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'gn'}; {'id': '19', 'type': 'attribute', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'gn'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'bus'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_i'} | def sort_generators(self):
self.generators.sort(key=lambda gn: gn.bus._i) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dotdata'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'prog'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"dot"'}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '11', 'type': 'string', 'children': [], 'value': '"xdot"'}; {'id': '12', 'type': 'block', 'children': ['13', '18', '24', '30', '44', '71', '81', '88', '96', '103', '109', '120', '149', '155', '161', '167', '190', '196', '208', '261', '269', '299', '306']}; {'id': '13', 'type': 'import_statement', 'children': ['14', '16']}; {'id': '14', 'type': 'dotted_name', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '16', 'type': 'dotted_name', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tempfile'}; {'id': '18', 'type': 'import_from_statement', 'children': ['19', '22']}; {'id': '19', 'type': 'dotted_name', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dot2tex'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dotparsing'}; {'id': '22', 'type': 'dotted_name', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'find_graphviz'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'progs'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'find_graphviz'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'is'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'progs'}; {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35', '42']}; {'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': 'logger'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"GraphViz executables not found."'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '52']}; {'id': '45', 'type': 'not_operator', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'progs'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'prog'}; {'id': '52', 'type': 'block', 'children': ['53', '69']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'binary_operator', 'children': ['60', '61', '62'], 'value': '%'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'Invalid program [%s]. Available programs are: %s'"}; {'id': '61', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '62', 'type': 'tuple', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'prog'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'progs'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '68', 'type': 'argument_list', 'children': []}; {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'None', 'children': []}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}; {'id': '73', 'type': 'pattern_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'tmp_fd'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'tmp_name'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'tempfile'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'mkstemp'}; {'id': '80', 'type': 'argument_list', 'children': []}; {'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': 'os'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'tmp_fd'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'dot_fd'}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'tmp_name'}; {'id': '95', 'type': 'string', 'children': [], 'value': '"w+b"'}; {'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': 'dot_fd'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dotdata'}; {'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': 'dot_fd'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '108', 'type': 'argument_list', 'children': []}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '112', 'type': 'call', 'children': ['113', '118']}; {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'tmp_name'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '127', 'type': 'argument_list', 'children': ['128', '136', '139', '144']}; {'id': '128', 'type': 'tuple', 'children': ['129', '132', '135']}; {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'progs'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'prog'}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'}; {'id': '133', 'type': 'string', 'children': [], 'value': "'-T'"}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'tmp_name'}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'cwd'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'stdout_output'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '166', 'type': 'argument_list', 'children': []}; {'id': '167', 'type': 'while_statement', 'children': ['168', '169']}; {'id': '168', 'type': 'True', 'children': []}; {'id': '169', 'type': 'block', 'children': ['170', '178', '183']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'if_statement', 'children': ['179', '181']}; {'id': '179', 'type': 'not_operator', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'break_statement', 'children': []}; {'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': 'stdout_output'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'data'}; {'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': 'stdout'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '195', 'type': 'argument_list', 'children': []}; {'id': '196', 'type': 'if_statement', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'stdout_output'}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'stdout_output'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'string', 'children': [], 'value': "''"}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'stdout_output'}; {'id': '208', 'type': 'if_statement', 'children': ['209', '213']}; {'id': '209', 'type': 'not_operator', 'children': ['210']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'closed'}; {'id': '213', 'type': 'block', 'children': ['214', '220', '243', '249']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'stderr_output'}; {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '219', 'type': 'argument_list', 'children': []}; {'id': '220', 'type': 'while_statement', 'children': ['221', '222']}; {'id': '221', 'type': 'True', 'children': []}; {'id': '222', 'type': 'block', 'children': ['223', '231', '236']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '226', 'type': 'call', 'children': ['227', '230']}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '230', 'type': 'argument_list', 'children': []}; {'id': '231', 'type': 'if_statement', 'children': ['232', '234']}; {'id': '232', 'type': 'not_operator', 'children': ['233']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '234', 'type': 'block', 'children': ['235']}; {'id': '235', 'type': 'break_statement', 'children': []}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'stderr_output'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '248', 'type': 'argument_list', 'children': []}; {'id': '249', 'type': 'if_statement', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'stderr_output'}; {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}; {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'stderr_output'}; {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}; {'id': '257', 'type': 'string', 'children': [], 'value': "''"}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'stderr_output'}; {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '264', 'type': 'call', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'wait'}; {'id': '268', 'type': 'argument_list', 'children': []}; {'id': '269', 'type': 'if_statement', 'children': ['270', '273', '288']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '272'], 'value': '!='}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '272', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'binary_operator', 'children': ['281', '284'], 'value': '%'}; {'id': '281', 'type': 'concatenated_string', 'children': ['282', '283']}; {'id': '282', 'type': 'string', 'children': [], 'value': '"Program [%s] terminated with status: %d. stderr "'}; {'id': '283', 'type': 'string', 'children': [], 'value': '"follows: %s"'}; {'id': '284', 'type': 'tuple', 'children': ['285', '286', '287']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'prog'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'stderr_output'}; {'id': '288', 'type': 'elif_clause', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'stderr_output'}; {'id': '290', 'type': 'block', 'children': ['291']}; {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '296']}; {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '296', 'type': 'argument_list', 'children': ['297', '298']}; {'id': '297', 'type': 'string', 'children': [], 'value': '"%s"'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'stderr_output'}; {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'call', 'children': ['301', '304']}; {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'unlink'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'tmp_name'}; {'id': '306', 'type': 'return_statement', 'children': ['307']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'stdout_output'} | def create(self, dotdata, prog="dot", format="xdot"):
import os, tempfile
from dot2tex.dotparsing import find_graphviz
progs = find_graphviz()
if progs is None:
logger.warning("GraphViz executables not found.")
return None
if not progs.has_key(prog):
logger.warning('Invalid program [%s]. Available programs are: %s' % \
(prog, progs.keys()))
return None
tmp_fd, tmp_name = tempfile.mkstemp()
os.close(tmp_fd)
dot_fd = file(tmp_name, "w+b")
dot_fd.write(dotdata)
dot_fd.close()
tmp_dir = os.path.dirname(tmp_name)
p = subprocess.Popen((progs[prog], '-T'+format, tmp_name),
cwd=tmp_dir, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
stderr = p.stderr
stdout = p.stdout
stdout_output = list()
while True:
data = stdout.read()
if not data:
break
stdout_output.append(data)
stdout.close()
if stdout_output:
stdout_output = ''.join(stdout_output)
if not stderr.closed:
stderr_output = list()
while True:
data = stderr.read()
if not data:
break
stderr_output.append(data)
stderr.close()
if stderr_output:
stderr_output = ''.join(stderr_output)
status = p.wait()
if status != 0 :
logger.error("Program [%s] terminated with status: %d. stderr " \
"follows: %s" % ( prog, status, stderr_output ) )
elif stderr_output:
logger.error( "%s", stderr_output )
os.unlink(tmp_name)
return stdout_output |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'format'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_metrics'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'build_metrics'}; {'id': '6', 'type': 'block', 'children': ['7', '132', '141', '150', '157', '226', '245', '250', '276']}; {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '14']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': 'indent'}; {'id': '9', 'type': 'parameters', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'block', 'children': ['15', '23']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '+'}; {'id': '19', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '*'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '22', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '23', 'type': 'if_statement', 'children': ['24', '28', '106']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '28', 'type': 'block', 'children': ['29', '52', '73', '85']}; {'id': '29', 'type': 'if_statement', 'children': ['30', '43']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '35'], 'value': 'or'}; {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '35', 'type': 'not_operator', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}; {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '51', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '66']}; {'id': '53', 'type': 'boolean_operator', 'children': ['54', '58'], 'value': 'or'}; {'id': '54', 'type': 'not_operator', 'children': ['55']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '58', 'type': 'not_operator', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '+'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '85', 'type': 'if_statement', 'children': ['86', '99']}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '91'], 'value': 'or'}; {'id': '87', 'type': 'not_operator', 'children': ['88']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '91', 'type': 'not_operator', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '98']}; {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '98', 'type': 'argument_list', 'children': []}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'if_statement', 'children': ['109', '125']}; {'id': '109', 'type': 'boolean_operator', 'children': ['110', '111'], 'value': 'and'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '111', 'type': '()', 'children': ['112']}; {'id': '112', 'type': 'boolean_operator', 'children': ['113', '117'], 'value': 'or'}; {'id': '113', 'type': 'not_operator', 'children': ['114']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '117', 'type': 'not_operator', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '124']}; {'id': '119', 'type': 'attribute', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '124', 'type': 'argument_list', 'children': []}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'tail'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'Element'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'metrics'"}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '144', 'type': 'call', 'children': ['145', '148']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'Element'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'string', 'children': [], 'value': "'files'"}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '157', 'type': 'for_statement', 'children': ['158', '159', '164']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'file_metrics'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '163', 'type': 'argument_list', 'children': []}; {'id': '164', 'type': 'block', 'children': ['165', '186']}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'tmp_file'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'SubElement'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174', '175']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '174', 'type': 'string', 'children': [], 'value': '"file"'}; {'id': '175', 'type': 'dictionary', 'children': ['176', '179']}; {'id': '176', 'type': 'pair', 'children': ['177', '178']}; {'id': '177', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '179', 'type': 'pair', 'children': ['180', '181']}; {'id': '180', 'type': 'string', 'children': [], 'value': "'language'"}; {'id': '181', 'type': 'subscript', 'children': ['182', '185']}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'file_metrics'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '185', 'type': 'string', 'children': [], 'value': "'language'"}; {'id': '186', 'type': 'for_statement', 'children': ['187', '188', '195']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '188', 'type': 'call', 'children': ['189', '194']}; {'id': '189', 'type': 'attribute', 'children': ['190', '193']}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'file_metrics'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '194', 'type': 'argument_list', 'children': []}; {'id': '195', 'type': 'block', 'children': ['196', '202']}; {'id': '196', 'type': 'if_statement', 'children': ['197', '200']}; {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': '=='}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '199', 'type': 'string', 'children': [], 'value': "'language'"}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'continue_statement', 'children': []}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}; {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'tmp_metric'}; {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'SubElement'}; {'id': '209', 'type': 'argument_list', 'children': ['210', '211', '212']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'tmp_file'}; {'id': '211', 'type': 'string', 'children': [], 'value': '"metric"'}; {'id': '212', 'type': 'dictionary', 'children': ['213', '216']}; {'id': '213', 'type': 'pair', 'children': ['214', '215']}; {'id': '214', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '216', 'type': 'pair', 'children': ['217', '218']}; {'id': '217', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '218', 'type': 'call', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}; {'id': '221', 'type': 'subscript', 'children': ['222', '225']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'file_metrics'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '226', 'type': 'if_statement', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'build_metrics'}; {'id': '228', 'type': 'block', 'children': ['229', '238']}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'build'}; {'id': '232', 'type': 'call', 'children': ['233', '236']}; {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'Element'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}; {'id': '237', 'type': 'string', 'children': [], 'value': "'build'"}; {'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': 'root'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'build'}; {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '250', 'type': 'if_statement', 'children': ['251', '252', '265']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'PY3'}; {'id': '252', 'type': 'block', 'children': ['253']}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'tostring'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '262', 'type': 'keyword_argument', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '264', 'type': 'string', 'children': [], 'value': "'unicode'"}; {'id': '265', 'type': 'else_clause', 'children': ['266']}; {'id': '266', 'type': 'block', 'children': ['267']}; {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '270', 'type': 'call', 'children': ['271', '274']}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'tostring'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '276', 'type': 'return_statement', 'children': ['277']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'body'} | def format(file_metrics, build_metrics):
def indent(elem, level=0):
i = "\n" + level*" "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
root = ET.Element('metrics')
files = ET.Element('files')
root.append(files)
for key in file_metrics.keys():
tmp_file = ET.SubElement(files, "file",
{'name': key, 'language': file_metrics[key]['language']})
for name in file_metrics[key].keys():
if name == 'language':
continue
tmp_metric = ET.SubElement(tmp_file, "metric",
{'name': name, 'value': str(file_metrics[key][name])})
if build_metrics:
build = ET.Element('build')
root.append(build)
indent(root)
if PY3:
body = ET.tostring(root, encoding='unicode')
else:
body = ET.tostring(root)
return body |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'governor'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'Vgov'}; {'id': '8', 'type': 'block', 'children': ['9', '15', '25', '34', '52', '70', '77', '84', '91', '98', '105', '112', '119', '126', '133', '140', '147', '154', '161', '168', '175', '199', '216', '229', '233', '269', '305', '309', '313', '349', '385', '398']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'governors'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'governors'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'omegas'}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '22'], 'value': '*'}; {'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '*'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '37', 'type': 'list_comprehension', 'children': ['38', '43', '46']}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'generator'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_i'}; {'id': '43', 'type': 'for_in_clause', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'governors'}; {'id': '46', 'type': 'if_clause', 'children': ['47']}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '=='}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'CONST_POWER'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '55', 'type': 'list_comprehension', 'children': ['56', '61', '64']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'generator'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_i'}; {'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'governors'}; {'id': '64', 'type': 'if_clause', 'children': ['65']}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': '=='}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'GENERAL_IEEE'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '76']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74', '75']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'Pm'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82', '83']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '83', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'P'}; {'id': '87', 'type': 'subscript', 'children': ['88', '89', '90']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '94', 'type': 'subscript', 'children': ['95', '96', '97']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '97', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '101', 'type': 'subscript', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '108', 'type': 'subscript', 'children': ['109', '110', '111']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'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': 'T1'}; {'id': '115', 'type': 'subscript', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'T2'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124', '125']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '125', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'T3'}; {'id': '129', 'type': 'subscript', 'children': ['130', '131', '132']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'Pup'}; {'id': '136', 'type': 'subscript', 'children': ['137', '138', '139']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '139', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'Pdown'}; {'id': '143', 'type': 'subscript', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'Pmax'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152', '153']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '153', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'Pmin'}; {'id': '157', 'type': 'subscript', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '160', 'type': 'integer', 'children': [], 'value': '7'}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'P0'}; {'id': '164', 'type': 'subscript', 'children': ['165', '166', '167']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'Pgov'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '167', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '171', 'type': 'subscript', 'children': ['172', '173', '174']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'Vgov'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'dx'}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '*'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'K'}; {'id': '180', 'type': '()', 'children': ['181']}; {'id': '181', 'type': 'binary_operator', 'children': ['182', '188'], 'value': '+'}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '187'], 'value': '*'}; {'id': '183', 'type': 'binary_operator', 'children': ['184', '186'], 'value': '/'}; {'id': '184', 'type': 'unary_operator', 'children': ['185'], 'value': '-'}; {'id': '185', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'T1'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '188', 'type': 'binary_operator', 'children': ['189', '195'], 'value': '*'}; {'id': '189', 'type': '()', 'children': ['190']}; {'id': '190', 'type': 'binary_operator', 'children': ['191', '192'], 'value': '-'}; {'id': '191', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '/'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'T2'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'T1'}; {'id': '195', 'type': '()', 'children': ['196']}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '-'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'omegas'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'dP'}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '208'], 'value': '+'}; {'id': '203', 'type': 'binary_operator', 'children': ['204', '207'], 'value': '*'}; {'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '/'}; {'id': '205', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'T1'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '208', 'type': 'binary_operator', 'children': ['209', '212'], 'value': '*'}; {'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '/'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'T2'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'T1'}; {'id': '212', 'type': '()', 'children': ['213']}; {'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '-'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'omegas'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '219', 'type': 'binary_operator', 'children': ['220', '223'], 'value': '*'}; {'id': '220', 'type': 'binary_operator', 'children': ['221', '222'], 'value': '/'}; {'id': '221', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'T3'}; {'id': '223', 'type': '()', 'children': ['224']}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '228'], 'value': '-'}; {'id': '225', 'type': 'binary_operator', 'children': ['226', '227'], 'value': '-'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'P0'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'P'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'Pm'}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'y2'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '233', 'type': 'if_statement', 'children': ['234', '245']}; {'id': '234', 'type': 'comparison_operator', 'children': ['235', '244'], 'value': '>='}; {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}; {'id': '241', 'type': 'comparison_operator', 'children': ['242', '243'], 'value': '>'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'Pup'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}; {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'y2'}; {'id': '249', 'type': 'binary_operator', 'children': ['250', '261'], 'value': '+'}; {'id': '250', 'type': 'binary_operator', 'children': ['251', '260'], 'value': '*'}; {'id': '251', 'type': '()', 'children': ['252']}; {'id': '252', 'type': 'binary_operator', 'children': ['253', '254'], 'value': '-'}; {'id': '253', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '254', 'type': 'call', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}; {'id': '257', 'type': 'comparison_operator', 'children': ['258', '259'], 'value': '>'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'Pup'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'y2'}; {'id': '261', 'type': 'binary_operator', 'children': ['262', '268'], 'value': '*'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': '>'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'Pup'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'Pup'}; {'id': '269', 'type': 'if_statement', 'children': ['270', '281']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '280'], 'value': '>='}; {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}; {'id': '277', 'type': 'comparison_operator', 'children': ['278', '279'], 'value': '<'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'Pdown'}; {'id': '280', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'y2'}; {'id': '285', 'type': 'binary_operator', 'children': ['286', '297'], 'value': '+'}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '296'], 'value': '*'}; {'id': '287', 'type': '()', 'children': ['288']}; {'id': '288', 'type': 'binary_operator', 'children': ['289', '290'], 'value': '-'}; {'id': '289', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '290', 'type': 'call', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}; {'id': '293', 'type': 'comparison_operator', 'children': ['294', '295'], 'value': '<'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'Pdown'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'y2'}; {'id': '297', 'type': 'binary_operator', 'children': ['298', '304'], 'value': '*'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'comparison_operator', 'children': ['302', '303'], 'value': '<'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'Pdown'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'Pdown'}; {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'dz'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'y2'}; {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'dPm'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'y2'}; {'id': '313', 'type': 'if_statement', 'children': ['314', '325']}; {'id': '314', 'type': 'comparison_operator', 'children': ['315', '324'], 'value': '>='}; {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '317', 'type': 'argument_list', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}; {'id': '321', 'type': 'comparison_operator', 'children': ['322', '323'], 'value': '>'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'Pmax'}; {'id': '324', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'dPm'}; {'id': '329', 'type': 'binary_operator', 'children': ['330', '341'], 'value': '+'}; {'id': '330', 'type': 'binary_operator', 'children': ['331', '340'], 'value': '*'}; {'id': '331', 'type': '()', 'children': ['332']}; {'id': '332', 'type': 'binary_operator', 'children': ['333', '334'], 'value': '-'}; {'id': '333', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '334', 'type': 'call', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}; {'id': '337', 'type': 'comparison_operator', 'children': ['338', '339'], 'value': '>'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'Pmax'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'dPm'}; {'id': '341', 'type': 'binary_operator', 'children': ['342', '348'], 'value': '*'}; {'id': '342', 'type': 'call', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}; {'id': '345', 'type': 'comparison_operator', 'children': ['346', '347'], 'value': '>'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'Pmax'}; {'id': '348', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '349', 'type': 'if_statement', 'children': ['350', '361']}; {'id': '350', 'type': 'comparison_operator', 'children': ['351', '360'], 'value': '>='}; {'id': '351', 'type': 'call', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '353', 'type': 'argument_list', 'children': ['354']}; {'id': '354', 'type': 'call', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '356', 'type': 'argument_list', 'children': ['357']}; {'id': '357', 'type': 'comparison_operator', 'children': ['358', '359'], 'value': '<'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'Pmin'}; {'id': '360', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '361', 'type': 'block', 'children': ['362']}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}; {'id': '363', 'type': 'assignment', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'dPm'}; {'id': '365', 'type': 'binary_operator', 'children': ['366', '377'], 'value': '+'}; {'id': '366', 'type': 'binary_operator', 'children': ['367', '376'], 'value': '*'}; {'id': '367', 'type': '()', 'children': ['368']}; {'id': '368', 'type': 'binary_operator', 'children': ['369', '370'], 'value': '-'}; {'id': '369', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '370', 'type': 'call', 'children': ['371', '372']}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '372', 'type': 'argument_list', 'children': ['373']}; {'id': '373', 'type': 'comparison_operator', 'children': ['374', '375'], 'value': '<'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'Pmin'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'dPm'}; {'id': '377', 'type': 'binary_operator', 'children': ['378', '384'], 'value': '*'}; {'id': '378', 'type': 'call', 'children': ['379', '380']}; {'id': '379', 'type': 'identifier', 'children': [], 'value': 'flatnonzero'}; {'id': '380', 'type': 'argument_list', 'children': ['381']}; {'id': '381', 'type': 'comparison_operator', 'children': ['382', '383'], 'value': '<'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'z'}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'Pmin'}; {'id': '384', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'assignment', 'children': ['387', '392']}; {'id': '387', 'type': 'subscript', 'children': ['388', '389', '390']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '390', 'type': 'slice', 'children': ['391']}; {'id': '391', 'type': 'colon', 'children': []}; {'id': '392', 'type': 'subscript', 'children': ['393', '394', '395', '396', '397']}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'dPm'}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'dP'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'dx'}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'dz'}; {'id': '398', 'type': 'return_statement', 'children': ['399']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'F'} | def governor(self, Xgov, Pgov, Vgov):
governors = self.governors
omegas = 2 * pi * self.freq
F = zeros(Xgov.shape)
typ1 = [g.generator._i for g in governors if g.model == CONST_POWER]
typ2 = [g.generator._i for g in governors if g.model == GENERAL_IEEE]
F[typ1, 0] = 0
Pm = Xgov[typ2, 0]
P = Xgov[typ2, 1]
x = Xgov[typ2, 2]
z = Xgov[typ2, 3]
K = Pgov[typ2, 0]
T1 = Pgov[typ2, 1]
T2 = Pgov[typ2, 2]
T3 = Pgov[typ2, 3]
Pup = Pgov[typ2, 4]
Pdown = Pgov[typ2, 5]
Pmax = Pgov[typ2, 6]
Pmin = Pgov[typ2, 7]
P0 = Pgov[typ2, 8]
omega = Vgov[typ2, 0]
dx = K * (-1 / T1 * x + (1 - T2 / T1) * (omega - omegas))
dP = 1 / T1 * x + T2 / T1 * (omega - omegas)
y = 1 / T3 * (P0 - P - Pm)
y2 = y
if sum(flatnonzero(y > Pup)) >= 1:
y2 = (1 - flatnonzero(y > Pup)) * y2 + flatnonzero(y > Pup) * Pup
if sum(flatnonzero(y < Pdown)) >= 1:
y2 = (1 - flatnonzero(y<Pdown)) * y2 + flatnonzero(y<Pdown) * Pdown
dz = y2
dPm = y2
if sum(flatnonzero(z > Pmax)) >= 1:
dPm = (1 - flatnonzero(z > Pmax)) * dPm + flatnonzero(z > Pmax) * 0
if sum(flatnonzero(z < Pmin)) >= 1:
dPm = (1 - flatnonzero(z < Pmin)) * dPm + flatnonzero(z < Pmin) * 0
F[typ2, :] = c_[dPm, dP, dx, dz]
return F |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generator'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'Xgen'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'Xexc'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Vgen'}; {'id': '9', 'type': 'block', 'children': ['10', '16', '26', '35', '51', '67', '74', '81', '96', '111', '118', '124', '147', '157', '169', '176', '183', '190', '203', '216', '229', '242', '255', '268', '281', '294', '301', '308', '315', '322', '329', '335', '358', '376', '393', '406']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dyn_generators'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'omegas'}; {'id': '19', 'type': 'binary_operator', 'children': ['20', '23'], 'value': '*'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '22'], 'value': '*'}; {'id': '21', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Xgen'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '38', 'type': 'list_comprehension', 'children': ['39', '42', '45']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '_i'}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '45', 'type': 'if_clause', 'children': ['46']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': '=='}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'CLASSICAL'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '58', '61']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': '_i'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '61', 'type': 'if_clause', 'children': ['62']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '66'], 'value': '=='}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'FOURTH_ORDER'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '70', 'type': 'subscript', 'children': ['71', '72', '73']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'Xgen'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'Pm0'}; {'id': '77', 'type': 'subscript', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'H'}; {'id': '84', 'type': 'subscript', 'children': ['85', '95']}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'list_comprehension', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '99', 'type': 'subscript', 'children': ['100', '110']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'list_comprehension', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '107', 'type': 'for_in_clause', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'Pe'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116', '117']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'Vgen'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '117', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ddelta'}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'omegas'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'domega'}; {'id': '127', 'type': 'binary_operator', 'children': ['128', '135'], 'value': '*'}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '134'], 'value': '/'}; {'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '*'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'H'}; {'id': '135', 'type': '()', 'children': ['136']}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '146'], 'value': '-'}; {'id': '137', 'type': 'binary_operator', 'children': ['138', '145'], 'value': '+'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '141'], 'value': '*'}; {'id': '139', 'type': 'unary_operator', 'children': ['140'], 'value': '-'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '141', 'type': '()', 'children': ['142']}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '-'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'omegas'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'Pm0'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'Pe'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'dEq'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '164']}; {'id': '159', 'type': 'subscript', 'children': ['160', '161', '162']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'typ1'}; {'id': '162', 'type': 'slice', 'children': ['163']}; {'id': '163', 'type': 'colon', 'children': []}; {'id': '164', 'type': 'subscript', 'children': ['165', '166', '167', '168']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'ddelta'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'domega'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dEq'}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '172', 'type': 'subscript', 'children': ['173', '174', '175']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'Xgen'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '175', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'Eq_tr'}; {'id': '179', 'type': 'subscript', 'children': ['180', '181', '182']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'Xgen'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'Ed_tr'}; {'id': '186', 'type': 'subscript', 'children': ['187', '188', '189']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'Xgen'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '189', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}; {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'H'}; {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'list_comprehension', 'children': ['197', '200']}; {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '200', 'type': 'for_in_clause', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'list_comprehension', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '213', 'type': 'for_in_clause', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'xd'}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'list_comprehension', 'children': ['223', '226']}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'xd'}; {'id': '226', 'type': 'for_in_clause', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'xq'}; {'id': '232', 'type': 'call', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'list_comprehension', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'xq'}; {'id': '239', 'type': 'for_in_clause', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'xd_tr'}; {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'list_comprehension', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'xd_tr'}; {'id': '252', 'type': 'for_in_clause', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'xq_tr'}; {'id': '258', 'type': 'call', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}; {'id': '261', 'type': 'list_comprehension', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'xq_tr'}; {'id': '265', 'type': 'for_in_clause', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'Td0_tr'}; {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'list_comprehension', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'td'}; {'id': '278', 'type': 'for_in_clause', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'Tq0_tr'}; {'id': '284', 'type': 'call', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}; {'id': '287', 'type': 'list_comprehension', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'tq'}; {'id': '291', 'type': 'for_in_clause', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'Id'}; {'id': '297', 'type': 'subscript', 'children': ['298', '299', '300']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'Vgen'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '300', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'Iq'}; {'id': '304', 'type': 'subscript', 'children': ['305', '306', '307']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'Vgen'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '307', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}; {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'Pe'}; {'id': '311', 'type': 'subscript', 'children': ['312', '313', '314']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'Vgen'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '314', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'Efd'}; {'id': '318', 'type': 'subscript', 'children': ['319', '320', '321']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'Xexc'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '321', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}; {'id': '323', 'type': 'assignment', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'Pm'}; {'id': '325', 'type': 'subscript', 'children': ['326', '327', '328']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'Xgov'}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '328', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'ddelta'}; {'id': '332', 'type': 'binary_operator', 'children': ['333', '334'], 'value': '-'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'omegas'}; {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'domega'}; {'id': '338', 'type': 'binary_operator', 'children': ['339', '346'], 'value': '*'}; {'id': '339', 'type': 'binary_operator', 'children': ['340', '345'], 'value': '/'}; {'id': '340', 'type': 'binary_operator', 'children': ['341', '342'], 'value': '*'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'H'}; {'id': '346', 'type': '()', 'children': ['347']}; {'id': '347', 'type': 'binary_operator', 'children': ['348', '357'], 'value': '-'}; {'id': '348', 'type': 'binary_operator', 'children': ['349', '356'], 'value': '+'}; {'id': '349', 'type': 'binary_operator', 'children': ['350', '352'], 'value': '*'}; {'id': '350', 'type': 'unary_operator', 'children': ['351'], 'value': '-'}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'D'}; {'id': '352', 'type': '()', 'children': ['353']}; {'id': '353', 'type': 'binary_operator', 'children': ['354', '355'], 'value': '-'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'omega'}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'omegas'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'Pm'}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'Pe'}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}; {'id': '359', 'type': 'assignment', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'dEq'}; {'id': '361', 'type': 'binary_operator', 'children': ['362', '365'], 'value': '*'}; {'id': '362', 'type': 'binary_operator', 'children': ['363', '364'], 'value': '/'}; {'id': '363', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'Td0_tr'}; {'id': '365', 'type': '()', 'children': ['366']}; {'id': '366', 'type': 'binary_operator', 'children': ['367', '370'], 'value': '+'}; {'id': '367', 'type': 'binary_operator', 'children': ['368', '369'], 'value': '-'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'Efd'}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'Eq_tr'}; {'id': '370', 'type': 'binary_operator', 'children': ['371', '375'], 'value': '*'}; {'id': '371', 'type': '()', 'children': ['372']}; {'id': '372', 'type': 'binary_operator', 'children': ['373', '374'], 'value': '-'}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'xd'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'xd_tr'}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'Id'}; {'id': '376', 'type': 'expression_statement', 'children': ['377']}; {'id': '377', 'type': 'assignment', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'dEd'}; {'id': '379', 'type': 'binary_operator', 'children': ['380', '383'], 'value': '*'}; {'id': '380', 'type': 'binary_operator', 'children': ['381', '382'], 'value': '/'}; {'id': '381', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'Tq0_tr'}; {'id': '383', 'type': '()', 'children': ['384']}; {'id': '384', 'type': 'binary_operator', 'children': ['385', '387'], 'value': '-'}; {'id': '385', 'type': 'unary_operator', 'children': ['386'], 'value': '-'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'Ed_tr'}; {'id': '387', 'type': 'binary_operator', 'children': ['388', '392'], 'value': '*'}; {'id': '388', 'type': '()', 'children': ['389']}; {'id': '389', 'type': 'binary_operator', 'children': ['390', '391'], 'value': '-'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'xq'}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'xq_tr'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'Iq'}; {'id': '393', 'type': 'expression_statement', 'children': ['394']}; {'id': '394', 'type': 'assignment', 'children': ['395', '400']}; {'id': '395', 'type': 'subscript', 'children': ['396', '397', '398']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'typ2'}; {'id': '398', 'type': 'slice', 'children': ['399']}; {'id': '399', 'type': 'colon', 'children': []}; {'id': '400', 'type': 'subscript', 'children': ['401', '402', '403', '404', '405']}; {'id': '401', 'type': 'identifier', 'children': [], 'value': 'c_'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'ddelta'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'domega'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'dEq'}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'dEd'}; {'id': '406', 'type': 'return_statement', 'children': ['407']}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'F'} | def generator(self, Xgen, Xexc, Xgov, Vgen):
generators = self.dyn_generators
omegas = 2 * pi * self.freq
F = zeros(Xgen.shape)
typ1 = [g._i for g in generators if g.model == CLASSICAL]
typ2 = [g._i for g in generators if g.model == FOURTH_ORDER]
omega = Xgen[typ1, 1]
Pm0 = Xgov[typ1, 0]
H = array([g.h for g in generators])[typ1]
D = array([g.d for g in generators])[typ1]
Pe = Vgen[typ1, 2]
ddelta = omega = omegas
domega = pi * self.freq / H * (-D * (omega - omegas) + Pm0 - Pe)
dEq = zeros(len(typ1))
F[typ1, :] = c_[ddelta, domega, dEq]
omega = Xgen[typ2, 1]
Eq_tr = Xgen[typ2, 2]
Ed_tr = Xgen[typ2, 3]
H = array([g.h for g in generators])
D = array([g.d for g in generators])
xd = array([g.xd for g in generators])
xq = array([g.xq for g in generators])
xd_tr = array([g.xd_tr for g in generators])
xq_tr = array([g.xq_tr for g in generators])
Td0_tr = array([g.td for g in generators])
Tq0_tr = array([g.tq for g in generators])
Id = Vgen[typ2, 0]
Iq = Vgen[typ2, 1]
Pe = Vgen[typ2, 2]
Efd = Xexc[typ2, 0]
Pm = Xgov[typ2, 0]
ddelta = omega - omegas
domega = pi * self.freq / H * (-D * (omega - omegas) + Pm - Pe)
dEq = 1 / Td0_tr * (Efd - Eq_tr + (xd - xd_tr) * Id)
dEd = 1 / Tq0_tr * (-Ed_tr - (xq - xq_tr) * Iq)
F[typ2, :] = c_[ddelta, domega, dEq, dEd]
return F |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_const_pf_constraints'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'gn'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '7', 'type': 'block', 'children': ['8', '41', '51', '58', '65', '80', '95', '110', '125', '140', '166', '182', '209', '325']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ivl'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'list_comprehension', 'children': ['15', '16', '24']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '20']}; {'id': '17', 'type': 'pattern_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'gn'}; {'id': '24', 'type': 'if_clause', 'children': ['25']}; {'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'and'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'is_load'}; {'id': '29', 'type': '()', 'children': ['30']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '36'], 'value': 'or'}; {'id': '31', 'type': 'comparison_operator', 'children': ['32', '35'], 'value': '!='}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'q_min'}; {'id': '35', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': '!='}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'q_max'}; {'id': '40', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'vl'}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '48']}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'gn'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ivl'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'nvl'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'vl'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ng'}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'gn'}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Pg'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '79'], 'value': '/'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'list_comprehension', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'vl'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'Qg'}; {'id': '83', 'type': 'binary_operator', 'children': ['84', '94'], 'value': '/'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'list_comprehension', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '91', 'type': 'for_in_clause', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'vl'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'Pmin'}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '109'], 'value': '/'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'list_comprehension', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'p_min'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'vl'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'Qmin'}; {'id': '113', 'type': 'binary_operator', 'children': ['114', '124'], 'value': '/'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}; {'id': '117', 'type': 'list_comprehension', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'q_min'}; {'id': '121', 'type': 'for_in_clause', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'vl'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'Qmax'}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '139'], 'value': '/'}; {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'list_comprehension', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'q_max'}; {'id': '136', 'type': 'for_in_clause', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'vl'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'base_mva'}; {'id': '140', 'type': 'for_statement', 'children': ['141', '142', '143']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'vl'}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'if_statement', 'children': ['145', '156']}; {'id': '145', 'type': 'boolean_operator', 'children': ['146', '151'], 'value': 'and'}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '!='}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'qmin'}; {'id': '150', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '151', 'type': 'comparison_operator', 'children': ['152', '155'], 'value': '!='}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'q_max'}; {'id': '155', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '156', 'type': 'block', 'children': ['157']}; {'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': 'logger'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'concatenated_string', 'children': ['164', '165']}; {'id': '164', 'type': 'string', 'children': [], 'value': '"Either Qmin or Qmax must be equal to zero for "'}; {'id': '165', 'type': 'string', 'children': [], 'value': '"each dispatchable load."'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'Qlim'}; {'id': '169', 'type': 'binary_operator', 'children': ['170', '176'], 'value': '+'}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '175'], 'value': '*'}; {'id': '171', 'type': '()', 'children': ['172']}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': '=='}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'Qmin'}; {'id': '174', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'Qmax'}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '181'], 'value': '*'}; {'id': '177', 'type': '()', 'children': ['178']}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': '=='}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'Qmax'}; {'id': '180', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'Qmin'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '198']}; {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'comparison_operator', 'children': ['187', '197'], 'value': '>'}; {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'binary_operator', 'children': ['191', '192'], 'value': '-'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'Qg'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '196'], 'value': '/'}; {'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '*'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'Pg'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'Qlim'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'Pmin'}; {'id': '197', 'type': 'float', 'children': [], 'value': '1e-6'}; {'id': '198', 'type': 'block', 'children': ['199']}; {'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': 'logger'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'concatenated_string', 'children': ['206', '207', '208']}; {'id': '206', 'type': 'string', 'children': [], 'value': '"For a dispatchable load, PG and QG must be "'}; {'id': '207', 'type': 'string', 'children': [], 'value': '"consistent with the power factor defined by "'}; {'id': '208', 'type': 'string', 'children': [], 'value': '"PMIN and the Q limits."'}; {'id': '209', 'type': 'if_statement', 'children': ['210', '213', '298']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': '>'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'nvl'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '213', 'type': 'block', 'children': ['214', '218', '222', '230', '237', '245', '260', '269', '287', '294']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'xx'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'Pmin'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'yy'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'Qlim'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'pftheta'}; {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'arctan2'}; {'id': '227', 'type': 'argument_list', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'yy'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'xx'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}; {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'pc'}; {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'sin'}; {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'pftheta'}; {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'qc'}; {'id': '240', 'type': 'unary_operator', 'children': ['241'], 'value': '-'}; {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'cos'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'pftheta'}; {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ii'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}; {'id': '251', 'type': 'list', 'children': ['252', '256'], 'value': '[range(nvl), range(nvl)]'}; {'id': '252', 'type': 'call', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'nvl'}; {'id': '256', 'type': 'call', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'nvl'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}; {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'jj'}; {'id': '263', 'type': 'subscript', 'children': ['264', '265', '266']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'r_'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'ivl'}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '268'], 'value': '+'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'ivl'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'ng'}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'Avl'}; {'id': '272', 'type': 'call', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '279', '282']}; {'id': '275', 'type': 'subscript', 'children': ['276', '277', '278']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'r_'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'pc'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'qc'}; {'id': '279', 'type': 'tuple', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'ii'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'jj'}; {'id': '282', 'type': 'tuple', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'nvl'}; {'id': '284', 'type': 'binary_operator', 'children': ['285', '286'], 'value': '*'}; {'id': '285', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'ng'}; {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '290', 'type': 'call', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'nvl'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'uvl'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '298', 'type': 'else_clause', 'children': ['299']}; {'id': '299', 'type': 'block', 'children': ['300', '311', '318']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}; {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'Avl'}; {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'tuple', 'children': ['307', '308']}; {'id': '307', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '308', 'type': 'binary_operator', 'children': ['309', '310'], 'value': '*'}; {'id': '309', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'ng'}; {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '314', 'type': 'call', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}; {'id': '317', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}; {'id': '319', 'type': 'assignment', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'uvl'}; {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '325', 'type': 'return_statement', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'LinearConstraint'}; {'id': '328', 'type': 'argument_list', 'children': ['329', '330', '331', '332', '333']}; {'id': '329', 'type': 'string', 'children': [], 'value': '"vl"'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'Avl'}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'lvl'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'uvl'}; {'id': '333', 'type': 'list', 'children': ['334', '335'], 'value': '["Pg", "Qg"]'}; {'id': '334', 'type': 'string', 'children': [], 'value': '"Pg"'}; {'id': '335', 'type': 'string', 'children': [], 'value': '"Qg"'} | def _const_pf_constraints(self, gn, base_mva):
ivl = array([i for i, g in enumerate(gn)
if g.is_load and (g.q_min != 0.0 or g.q_max != 0.0)])
vl = [gn[i] for i in ivl]
nvl = len(vl)
ng = len(gn)
Pg = array([g.p for g in vl]) / base_mva
Qg = array([g.q for g in vl]) / base_mva
Pmin = array([g.p_min for g in vl]) / base_mva
Qmin = array([g.q_min for g in vl]) / base_mva
Qmax = array([g.q_max for g in vl]) / base_mva
for g in vl:
if g.qmin != 0.0 and g.q_max != 0.0:
logger.error("Either Qmin or Qmax must be equal to zero for "
"each dispatchable load.")
Qlim = (Qmin == 0.0) * Qmax + (Qmax == 0.0) * Qmin
if any( abs(Qg - Pg * Qlim / Pmin) > 1e-6 ):
logger.error("For a dispatchable load, PG and QG must be "
"consistent with the power factor defined by "
"PMIN and the Q limits.")
if nvl > 0:
xx = Pmin
yy = Qlim
pftheta = arctan2(yy, xx)
pc = sin(pftheta)
qc = -cos(pftheta)
ii = array([range(nvl), range(nvl)])
jj = r_[ivl, ivl + ng]
Avl = csr_matrix(r_[pc, qc], (ii, jj), (nvl, 2 * ng))
lvl = zeros(nvl)
uvl = lvl
else:
Avl = zeros((0, 2 * ng))
lvl = array([])
uvl = array([])
return LinearConstraint("vl", Avl, lvl, uvl, ["Pg", "Qg"]) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_voltage_angle_diff_limit'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'buses'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '7', 'type': 'block', 'children': ['8', '15', '300']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'nb'}; {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'buses'}; {'id': '15', 'type': 'if_statement', 'children': ['16', '20', '275']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ignore_ang_lim'}; {'id': '20', 'type': 'block', 'children': ['21', '59', '83', '107', '114']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'iang'}; {'id': '24', 'type': 'list_comprehension', 'children': ['25', '26', '34']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '30']}; {'id': '27', 'type': 'pattern_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '34', 'type': 'if_clause', 'children': ['35']}; {'id': '35', 'type': 'boolean_operator', 'children': ['36', '48'], 'value': 'or'}; {'id': '36', 'type': '()', 'children': ['37']}; {'id': '37', 'type': 'boolean_operator', 'children': ['38', '41'], 'value': 'and'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ang_min'}; {'id': '41', 'type': '()', 'children': ['42']}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': '>'}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ang_min'}; {'id': '46', 'type': 'unary_operator', 'children': ['47'], 'value': '-'}; {'id': '47', 'type': 'float', 'children': [], 'value': '360.0'}; {'id': '48', 'type': '()', 'children': ['49']}; {'id': '49', 'type': 'boolean_operator', 'children': ['50', '53'], 'value': 'and'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ang_max'}; {'id': '53', 'type': '()', 'children': ['54']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '<'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ang_max'}; {'id': '58', 'type': 'float', 'children': [], 'value': '360.0'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'iangl'}; {'id': '62', 'type': 'subscript', 'children': ['63', '82']}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'list_comprehension', 'children': ['67', '68', '76']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '68', 'type': 'for_in_clause', 'children': ['69', '72']}; {'id': '69', 'type': 'pattern_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '76', 'type': 'if_clause', 'children': ['77']}; {'id': '77', 'type': 'comparison_operator', 'children': ['78', '81'], 'value': 'is'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ang_min'}; {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'iang'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'iangh'}; {'id': '86', 'type': 'subscript', 'children': ['87', '106']}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'list_comprehension', 'children': ['91', '92', '100']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '92', 'type': 'for_in_clause', 'children': ['93', '96']}; {'id': '93', 'type': 'pattern_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '100', 'type': 'if_clause', 'children': ['101']}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': 'is'}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ang_max'}; {'id': '105', 'type': 'None', 'children': []}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'iang'}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'nang'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'iang'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118', '250']}; {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '>'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'nang'}; {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'block', 'children': ['119', '131', '148', '165', '172', '192', '201', '206', '228']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'ii'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '127'], 'value': '+'}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'nang'}; {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'nang'}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'jjf'}; {'id': '134', 'type': 'subscript', 'children': ['135', '147']}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'list_comprehension', 'children': ['139', '144']}; {'id': '139', 'type': 'attribute', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'from_bus'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': '_i'}; {'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'iang'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'jjt'}; {'id': '151', 'type': 'subscript', 'children': ['152', '164']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'list_comprehension', 'children': ['156', '161']}; {'id': '156', 'type': 'attribute', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'to_bus'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '_i'}; {'id': '161', 'type': 'for_in_clause', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'iang'}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'jj'}; {'id': '168', 'type': 'subscript', 'children': ['169', '170', '171']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'r_'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'jjf'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'jjt'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'Aang'}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'csr_matrix'}; {'id': '177', 'type': 'argument_list', 'children': ['178', '189']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180', '184']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'r_'}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'nang'}; {'id': '184', 'type': 'unary_operator', 'children': ['185'], 'value': '-'}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'nang'}; {'id': '189', 'type': 'tuple', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'ii'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'jj'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'uang'}; {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '*'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'Inf'}; {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'nang'}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '204', 'type': 'unary_operator', 'children': ['205'], 'value': '-'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'uang'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '211']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'iangl'}; {'id': '211', 'type': 'subscript', 'children': ['212', '227']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}; {'id': '215', 'type': 'list_comprehension', 'children': ['216', '224']}; {'id': '216', 'type': 'binary_operator', 'children': ['217', '220'], 'value': '*'}; {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ang_min'}; {'id': '220', 'type': '()', 'children': ['221']}; {'id': '221', 'type': 'binary_operator', 'children': ['222', '223'], 'value': '/'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '223', 'type': 'float', 'children': [], 'value': '180.0'}; {'id': '224', 'type': 'for_in_clause', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'iangl'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'assignment', 'children': ['230', '233']}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'uang'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'iangh'}; {'id': '233', 'type': 'subscript', 'children': ['234', '249']}; {'id': '234', 'type': 'call', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}; {'id': '237', 'type': 'list_comprehension', 'children': ['238', '246']}; {'id': '238', 'type': 'binary_operator', 'children': ['239', '242'], 'value': '*'}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'ang_max'}; {'id': '242', 'type': '()', 'children': ['243']}; {'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '/'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '245', 'type': 'float', 'children': [], 'value': '180.0'}; {'id': '246', 'type': 'for_in_clause', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'branches'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'iangh'}; {'id': '250', 'type': 'else_clause', 'children': ['251']}; {'id': '251', 'type': 'block', 'children': ['252', '261', '268']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}; {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'Aang'}; {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'tuple', 'children': ['259', '260']}; {'id': '259', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'nb'}; {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '264', 'type': 'call', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}; {'id': '267', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'uang'}; {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '275', 'type': 'else_clause', 'children': ['276']}; {'id': '276', 'type': 'block', 'children': ['277', '286', '293']}; {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'Aang'}; {'id': '280', 'type': 'call', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}; {'id': '283', 'type': 'tuple', 'children': ['284', '285']}; {'id': '284', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'nb'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}; {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'uang'}; {'id': '296', 'type': 'call', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}; {'id': '299', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '300', 'type': 'return_statement', 'children': ['301']}; {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'LinearConstraint'}; {'id': '303', 'type': 'argument_list', 'children': ['304', '305', '306', '307', '308']}; {'id': '304', 'type': 'string', 'children': [], 'value': '"ang"'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'Aang'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'lang'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'uang'}; {'id': '308', 'type': 'list', 'children': ['309'], 'value': '["Va"]'}; {'id': '309', 'type': 'string', 'children': [], 'value': '"Va"'} | def _voltage_angle_diff_limit(self, buses, branches):
nb = len(buses)
if not self.ignore_ang_lim:
iang = [i for i, b in enumerate(branches)
if (b.ang_min and (b.ang_min > -360.0))
or (b.ang_max and (b.ang_max < 360.0))]
iangl = array([i for i, b in enumerate(branches)
if b.ang_min is not None])[iang]
iangh = array([i for i, b in enumerate(branches)
if b.ang_max is not None])[iang]
nang = len(iang)
if nang > 0:
ii = range(nang) + range(nang)
jjf = array([b.from_bus._i for b in branches])[iang]
jjt = array([b.to_bus._i for b in branches])[iang]
jj = r_[jjf, jjt]
Aang = csr_matrix(r_[ones(nang), -ones(nang)], (ii, jj))
uang = Inf * ones(nang)
lang = -uang
lang[iangl] = array([b.ang_min * (pi / 180.0)
for b in branches])[iangl]
uang[iangh] = array([b.ang_max * (pi / 180.0)
for b in branches])[iangh]
else:
Aang = zeros((0, nb))
lang = array([])
uang = array([])
else:
Aang = zeros((0, nb))
lang = array([])
uang = array([])
return LinearConstraint("ang", Aang, lang, uang, ["Va"]) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_clipPrices'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '38', '70', '107', '144']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'guaranteeOfferPrice'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'offers'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '29']}; {'id': '18', 'type': 'boolean_operator', 'children': ['19', '22'], 'value': 'and'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'accepted'}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '26'], 'value': '<'}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'price'}; {'id': '29', 'type': 'block', 'children': ['30']}; {'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': 'offer'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'price'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'guaranteeBidPrice'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '48']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'bids'}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'if_statement', 'children': ['50', '61']}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '54'], 'value': 'and'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'accepted'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '>'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'price'}; {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'price'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '79']}; {'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': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'limits'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"maxClearedOffer"'}; {'id': '79', 'type': 'block', 'children': ['80', '88']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'maxClearedOffer'}; {'id': '83', 'type': 'subscript', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'limits'}; {'id': '87', 'type': 'string', 'children': [], 'value': '"maxClearedOffer"'}; {'id': '88', 'type': 'for_statement', 'children': ['89', '90', '93']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'offers'}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'if_statement', 'children': ['95', '100']}; {'id': '95', 'type': 'comparison_operator', 'children': ['96', '99'], 'value': '>'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'maxClearedOffer'}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'offer'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'maxClearedOffer'}; {'id': '107', 'type': 'if_statement', 'children': ['108', '116']}; {'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': 'limits'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'has_key'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'string', 'children': [], 'value': '"minClearedBid"'}; {'id': '116', 'type': 'block', 'children': ['117', '125']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'minClearedBid'}; {'id': '120', 'type': 'subscript', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'limits'}; {'id': '124', 'type': 'string', 'children': [], 'value': '"minClearedBid"'}; {'id': '125', 'type': 'for_statement', 'children': ['126', '127', '130']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'bids'}; {'id': '130', 'type': 'block', 'children': ['131']}; {'id': '131', 'type': 'if_statement', 'children': ['132', '137']}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '136'], 'value': '<'}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'minClearedBid'}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'minClearedBid'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '150']}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': '!='}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'auctionType'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'DISCRIMINATIVE'}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'for_statement', 'children': ['152', '153', '158']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '153', 'type': 'attribute', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '158', 'type': 'block', 'children': ['159', '175', '201', '217']}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'gOffers'}; {'id': '162', 'type': 'list_comprehension', 'children': ['163', '164', '169']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '164', 'type': 'for_in_clause', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'offers'}; {'id': '169', 'type': 'if_clause', 'children': ['170']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '=='}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'generator'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '175', 'type': 'if_statement', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'gOffers'}; {'id': '177', 'type': 'block', 'children': ['178', '191']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'uniformPrice'}; {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'list_comprehension', 'children': ['185', '188']}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '188', 'type': 'for_in_clause', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'gOffers'}; {'id': '191', 'type': 'for_statement', 'children': ['192', '193', '194']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'gOffers'}; {'id': '194', 'type': 'block', 'children': ['195']}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}; {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'uniformPrice'}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'gBids'}; {'id': '204', 'type': 'list_comprehension', 'children': ['205', '206', '211']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '206', 'type': 'for_in_clause', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'bids'}; {'id': '211', 'type': 'if_clause', 'children': ['212']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '216'], 'value': '=='}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'vLoad'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '217', 'type': 'if_statement', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'gBids'}; {'id': '219', 'type': 'block', 'children': ['220', '233']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'uniformPrice'}; {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'list_comprehension', 'children': ['227', '230']}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'cleared_price'}; {'id': '230', 'type': 'for_in_clause', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'gBids'}; {'id': '233', 'type': 'for_statement', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'gBids'}; {'id': '236', 'type': 'block', 'children': ['237']}; {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '242']}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'bid'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'clearedPrice'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'uniformPrice'} | def _clipPrices(self):
if self.guaranteeOfferPrice:
for offer in self.offers:
if offer.accepted and offer.clearedPrice < offer.price:
offer.clearedPrice = offer.price
if self.guaranteeBidPrice:
for bid in self.bids:
if bid.accepted and bid.clearedPrice > bid.price:
bid.clearedPrice = bid.price
if self.limits.has_key("maxClearedOffer"):
maxClearedOffer = self.limits["maxClearedOffer"]
for offer in self.offers:
if offer.clearedPrice > maxClearedOffer:
offer.clearedPrice = maxClearedOffer
if self.limits.has_key("minClearedBid"):
minClearedBid = self.limits["minClearedBid"]
for bid in self.bids:
if bid.clearedPrice < minClearedBid:
bid.clearedPrice = minClearedBid
if self.auctionType != DISCRIMINATIVE:
for g in self.case.generators:
gOffers = [of for of in self.offers if of.generator == g]
if gOffers:
uniformPrice = max([of.clearedPrice for of in gOffers])
for of in gOffers:
of.clearedPrice = uniformPrice
gBids = [bid for bid in self.bids if bid.vLoad == g]
if gBids:
uniformPrice = min([bid.cleared_price for bid in gBids])
for bid in gBids:
bid.clearedPrice = uniformPrice |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gpu_iuwt_decomposition'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'store_smoothed'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'store_on_gpu'}; {'id': '9', 'type': 'block', 'children': ['10', '16', '40', '49', '74', '98', '107', '116', '125', '138', '151', '155', '163', '172', '185', '198', '261', '381']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'ker'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'SourceModule'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '*'}; {'id': '20', 'type': '()', 'children': ['21']}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '/'}; {'id': '22', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '35']}; {'id': '29', 'type': 'list', 'children': ['30', '31', '32', '33', '34'], 'value': '[1,4,6,4,1]'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '33', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'float32'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'to_gpu_async'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'detail_coeffs'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '71']}; {'id': '57', 'type': 'list', 'children': ['58', '61', '66'], 'value': '[scale_count-scale_adjust, in1.shape[0], in1.shape[1]]'}; {'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '-'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '61', 'type': 'subscript', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'subscript', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'float32'}; {'id': '74', 'type': 'try_statement', 'children': ['75', '92']}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'to_gpu_async'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'float32'}; {'id': '92', 'type': 'except_clause', 'children': ['93']}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'empty_like'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'gpu_out1'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'empty_like'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'gpu_out2'}; {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'empty_like'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '135']}; {'id': '133', 'type': 'list', 'children': ['134'], 'value': '[1]'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'int32'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'gpu_adjust'}; {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '145', 'type': 'argument_list', 'children': ['146', '148']}; {'id': '146', 'type': 'list', 'children': ['147'], 'value': '[1]'}; {'id': '147', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'int32'}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'augmented_assignment', 'children': ['153', '154'], 'value': '+='}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'gpu_adjust'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}; {'id': '157', 'type': 'pattern_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_row_kernel'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_col_kernel'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous'}; {'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': 'gpu_store_detail_coeffs'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'ker'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'get_function'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'string', 'children': [], 'value': '"gpu_store_detail_coeffs"'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '184'], 'value': '//'}; {'id': '179', 'type': 'subscript', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '183', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'binary_operator', 'children': ['192', '197'], 'value': '//'}; {'id': '192', 'type': 'subscript', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '197', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '198', 'type': 'if_statement', 'children': ['199', '202']}; {'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': '>'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '201', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '202', 'type': 'block', 'children': ['203']}; {'id': '203', 'type': 'for_statement', 'children': ['204', '205', '210']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '207', 'type': 'argument_list', 'children': ['208', '209']}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '210', 'type': 'block', 'children': ['211', '230', '249', '257']}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_row_kernel'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216', '217', '218', '219', '225']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '221', 'type': 'tuple', 'children': ['222', '223', '224']}; {'id': '222', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '223', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '227', 'type': 'tuple', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}; {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_col_kernel'}; {'id': '233', 'type': 'argument_list', 'children': ['234', '235', '236', '237', '238', '244']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'gpu_out1'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '240', 'type': 'tuple', 'children': ['241', '242', '243']}; {'id': '241', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '242', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '243', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '246', 'type': 'tuple', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '254']}; {'id': '251', 'type': 'pattern_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'gpu_out1'}; {'id': '254', 'type': 'expression_list', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'gpu_out1'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'augmented_assignment', 'children': ['259', '260'], 'value': '+='}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '261', 'type': 'for_statement', 'children': ['262', '263', '268']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '265', 'type': 'argument_list', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '268', 'type': 'block', 'children': ['269', '288', '307', '326', '345', '369', '377']}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_row_kernel'}; {'id': '272', 'type': 'argument_list', 'children': ['273', '274', '275', '276', '277', '283']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '279', 'type': 'tuple', 'children': ['280', '281', '282']}; {'id': '280', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '281', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '285', 'type': 'tuple', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_col_kernel'}; {'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294', '295', '296', '302']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'gpu_out1'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '298', 'type': 'tuple', 'children': ['299', '300', '301']}; {'id': '299', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '300', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '301', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '304', 'type': 'tuple', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'call', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_row_kernel'}; {'id': '310', 'type': 'argument_list', 'children': ['311', '312', '313', '314', '315', '321']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'gpu_out1'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '317', 'type': 'tuple', 'children': ['318', '319', '320']}; {'id': '318', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '319', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '320', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '321', 'type': 'keyword_argument', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '323', 'type': 'tuple', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'call', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_col_kernel'}; {'id': '329', 'type': 'argument_list', 'children': ['330', '331', '332', '333', '334', '340']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'gpu_out2'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '334', 'type': 'keyword_argument', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '336', 'type': 'tuple', 'children': ['337', '338', '339']}; {'id': '337', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '338', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '339', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '342', 'type': 'tuple', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'call', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'gpu_store_detail_coeffs'}; {'id': '348', 'type': 'argument_list', 'children': ['349', '350', '351', '352', '353', '354', '360']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'gpu_out2'}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'detail_coeffs'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'gpu_adjust'}; {'id': '354', 'type': 'keyword_argument', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '356', 'type': 'tuple', 'children': ['357', '358', '359']}; {'id': '357', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '358', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '359', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '360', 'type': 'keyword_argument', 'children': ['361', '362']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '362', 'type': 'tuple', 'children': ['363', '364', '365']}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '365', 'type': 'call', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '367', 'type': 'argument_list', 'children': ['368']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '369', 'type': 'expression_statement', 'children': ['370']}; {'id': '370', 'type': 'assignment', 'children': ['371', '374']}; {'id': '371', 'type': 'pattern_list', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'gpu_out1'}; {'id': '374', 'type': 'expression_list', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'gpu_out1'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '377', 'type': 'expression_statement', 'children': ['378']}; {'id': '378', 'type': 'augmented_assignment', 'children': ['379', '380'], 'value': '+='}; {'id': '379', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '380', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '381', 'type': 'if_statement', 'children': ['382', '383', '386', '401']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'store_on_gpu'}; {'id': '383', 'type': 'block', 'children': ['384']}; {'id': '384', 'type': 'return_statement', 'children': ['385']}; {'id': '385', 'type': 'identifier', 'children': [], 'value': 'detail_coeffs'}; {'id': '386', 'type': 'elif_clause', 'children': ['387', '388']}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'store_smoothed'}; {'id': '388', 'type': 'block', 'children': ['389']}; {'id': '389', 'type': 'return_statement', 'children': ['390']}; {'id': '390', 'type': 'expression_list', 'children': ['391', '396']}; {'id': '391', 'type': 'call', 'children': ['392', '395']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'detail_coeffs'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '395', 'type': 'argument_list', 'children': []}; {'id': '396', 'type': 'call', 'children': ['397', '400']}; {'id': '397', 'type': 'attribute', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '400', 'type': 'argument_list', 'children': []}; {'id': '401', 'type': 'else_clause', 'children': ['402']}; {'id': '402', 'type': 'block', 'children': ['403']}; {'id': '403', 'type': 'return_statement', 'children': ['404']}; {'id': '404', 'type': 'call', 'children': ['405', '408']}; {'id': '405', 'type': 'attribute', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'detail_coeffs'}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '408', 'type': 'argument_list', 'children': []} | def gpu_iuwt_decomposition(in1, scale_count, scale_adjust, store_smoothed, store_on_gpu):
ker = SourceModule(
)
wavelet_filter = (1./16)*np.array([1,4,6,4,1], dtype=np.float32)
wavelet_filter = gpuarray.to_gpu_async(wavelet_filter)
detail_coeffs = gpuarray.empty([scale_count-scale_adjust, in1.shape[0], in1.shape[1]], np.float32)
try:
gpu_in1 = gpuarray.to_gpu_async(in1.astype(np.float32))
except:
gpu_in1 = in1
gpu_tmp = gpuarray.empty_like(gpu_in1)
gpu_out1 = gpuarray.empty_like(gpu_in1)
gpu_out2 = gpuarray.empty_like(gpu_in1)
gpu_scale = gpuarray.zeros([1], np.int32)
gpu_adjust = gpuarray.zeros([1], np.int32)
gpu_adjust += scale_adjust
gpu_a_trous_row_kernel, gpu_a_trous_col_kernel = gpu_a_trous()
gpu_store_detail_coeffs = ker.get_function("gpu_store_detail_coeffs")
grid_rows = int(in1.shape[0]//32)
grid_cols = int(in1.shape[1]//32)
if scale_adjust>0:
for i in range(0, scale_adjust):
gpu_a_trous_row_kernel(gpu_in1, gpu_tmp, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_a_trous_col_kernel(gpu_tmp, gpu_out1, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_in1, gpu_out1 = gpu_out1, gpu_in1
gpu_scale += 1
for i in range(scale_adjust, scale_count):
gpu_a_trous_row_kernel(gpu_in1, gpu_tmp, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_a_trous_col_kernel(gpu_tmp, gpu_out1, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_a_trous_row_kernel(gpu_out1, gpu_tmp, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_a_trous_col_kernel(gpu_tmp, gpu_out2, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_store_detail_coeffs(gpu_in1, gpu_out2, detail_coeffs, gpu_scale, gpu_adjust,
block=(32,32,1), grid=(grid_cols, grid_rows, int(scale_count)))
gpu_in1, gpu_out1 = gpu_out1, gpu_in1
gpu_scale += 1
if store_on_gpu:
return detail_coeffs
elif store_smoothed:
return detail_coeffs.get(), gpu_in1.get()
else:
return detail_coeffs.get() |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gpu_iuwt_recomposition'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'store_on_gpu'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'smoothed_array'}; {'id': '8', 'type': 'block', 'children': ['9', '33', '42', '52', '97', '121', '130', '143', '149', '157', '170', '183', '258', '318']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '12', 'type': 'binary_operator', 'children': ['13', '17'], 'value': '*'}; {'id': '13', 'type': '()', 'children': ['14']}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '16'], 'value': '/'}; {'id': '15', 'type': 'float', 'children': [], 'value': '1.'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '28']}; {'id': '22', 'type': 'list', 'children': ['23', '24', '25', '26', '27'], 'value': '[1,4,6,4,1]'}; {'id': '23', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'float32'}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'to_gpu_async'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'max_scale'}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '51'], 'value': '+'}; {'id': '46', 'type': 'subscript', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56', '79']}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'smoothed_array'}; {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '76']}; {'id': '65', 'type': 'list', 'children': ['66', '71'], 'value': '[in1.shape[1], in1.shape[2]]'}; {'id': '66', 'type': 'subscript', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '75', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'float32'}; {'id': '79', 'type': 'else_clause', 'children': ['80']}; {'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': 'recomposition'}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'to_gpu'}; {'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': 'smoothed_array'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'float32'}; {'id': '97', 'type': 'try_statement', 'children': ['98', '115']}; {'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': 'gpu_in1'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'to_gpu_async'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'float32'}; {'id': '115', 'type': 'except_clause', 'children': ['116']}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '124', 'type': 'call', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'empty_like'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'gpuarray'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '140']}; {'id': '138', 'type': 'list', 'children': ['139'], 'value': '[1]'}; {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'int32'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'augmented_assignment', 'children': ['145', '146'], 'value': '+='}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '-'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'max_scale'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '154']}; {'id': '151', 'type': 'pattern_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_row_kernel'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_col_kernel'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous'}; {'id': '156', 'type': 'argument_list', 'children': []}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'binary_operator', 'children': ['164', '169'], 'value': '//'}; {'id': '164', 'type': 'subscript', 'children': ['165', '168']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '182'], 'value': '//'}; {'id': '177', 'type': 'subscript', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'in1'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '181', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '183', 'type': 'for_statement', 'children': ['184', '185', '196']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '187', 'type': 'argument_list', 'children': ['188', '191', '194']}; {'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '-'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'max_scale'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '191', 'type': 'binary_operator', 'children': ['192', '193'], 'value': '-'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '193', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '194', 'type': 'unary_operator', 'children': ['195'], 'value': '-'}; {'id': '195', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '196', 'type': 'block', 'children': ['197', '216', '235', '254']}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_row_kernel'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '202', '203', '204', '205', '211']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '207', 'type': 'tuple', 'children': ['208', '209', '210']}; {'id': '208', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '209', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '210', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '213', 'type': 'tuple', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_col_kernel'}; {'id': '219', 'type': 'argument_list', 'children': ['220', '221', '222', '223', '224', '230']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '226', 'type': 'tuple', 'children': ['227', '228', '229']}; {'id': '227', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '228', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '229', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '232', 'type': 'tuple', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '238', 'type': 'binary_operator', 'children': ['239', '245'], 'value': '+'}; {'id': '239', 'type': 'subscript', 'children': ['240', '241', '243']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '241', 'type': 'slice', 'children': ['242']}; {'id': '242', 'type': 'colon', 'children': []}; {'id': '243', 'type': 'slice', 'children': ['244']}; {'id': '244', 'type': 'colon', 'children': []}; {'id': '245', 'type': 'subscript', 'children': ['246', '247', '250', '252']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'gpu_in1'}; {'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '-'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '250', 'type': 'slice', 'children': ['251']}; {'id': '251', 'type': 'colon', 'children': []}; {'id': '252', 'type': 'slice', 'children': ['253']}; {'id': '253', 'type': 'colon', 'children': []}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}; {'id': '255', 'type': 'augmented_assignment', 'children': ['256', '257'], 'value': '-='}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '257', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '258', 'type': 'if_statement', 'children': ['259', '262']}; {'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': '>'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '261', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '262', 'type': 'block', 'children': ['263']}; {'id': '263', 'type': 'for_statement', 'children': ['264', '265', '275']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '267', 'type': 'argument_list', 'children': ['268', '271', '273']}; {'id': '268', 'type': 'binary_operator', 'children': ['269', '270'], 'value': '-'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'scale_adjust'}; {'id': '270', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '271', 'type': 'unary_operator', 'children': ['272'], 'value': '-'}; {'id': '272', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '273', 'type': 'unary_operator', 'children': ['274'], 'value': '-'}; {'id': '274', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '275', 'type': 'block', 'children': ['276', '295', '314']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_row_kernel'}; {'id': '279', 'type': 'argument_list', 'children': ['280', '281', '282', '283', '284', '290']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '286', 'type': 'tuple', 'children': ['287', '288', '289']}; {'id': '287', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '288', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '289', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '292', 'type': 'tuple', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'call', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'gpu_a_trous_col_kernel'}; {'id': '298', 'type': 'argument_list', 'children': ['299', '300', '301', '302', '303', '309']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'gpu_tmp'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'wavelet_filter'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '303', 'type': 'keyword_argument', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'block'}; {'id': '305', 'type': 'tuple', 'children': ['306', '307', '308']}; {'id': '306', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '307', 'type': 'integer', 'children': [], 'value': '32'}; {'id': '308', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'grid'}; {'id': '311', 'type': 'tuple', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'grid_cols'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'grid_rows'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}; {'id': '315', 'type': 'augmented_assignment', 'children': ['316', '317'], 'value': '-='}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'gpu_scale'}; {'id': '317', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '318', 'type': 'if_statement', 'children': ['319', '320', '323']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'store_on_gpu'}; {'id': '320', 'type': 'block', 'children': ['321']}; {'id': '321', 'type': 'return_statement', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '323', 'type': 'else_clause', 'children': ['324']}; {'id': '324', 'type': 'block', 'children': ['325']}; {'id': '325', 'type': 'return_statement', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '330']}; {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'recomposition'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '330', 'type': 'argument_list', 'children': []} | def gpu_iuwt_recomposition(in1, scale_adjust, store_on_gpu, smoothed_array):
wavelet_filter = (1./16)*np.array([1,4,6,4,1], dtype=np.float32)
wavelet_filter = gpuarray.to_gpu_async(wavelet_filter)
max_scale = in1.shape[0] + scale_adjust
if smoothed_array is None:
recomposition = gpuarray.zeros([in1.shape[1], in1.shape[2]], np.float32)
else:
recomposition = gpuarray.to_gpu(smoothed_array.astype(np.float32))
try:
gpu_in1 = gpuarray.to_gpu_async(in1.astype(np.float32))
except:
gpu_in1 = in1
gpu_tmp = gpuarray.empty_like(recomposition)
gpu_scale = gpuarray.zeros([1], np.int32)
gpu_scale += max_scale-1
gpu_a_trous_row_kernel, gpu_a_trous_col_kernel = gpu_a_trous()
grid_rows = int(in1.shape[1]//32)
grid_cols = int(in1.shape[2]//32)
for i in range(max_scale-1, scale_adjust-1, -1):
gpu_a_trous_row_kernel(recomposition, gpu_tmp, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_a_trous_col_kernel(gpu_tmp, recomposition, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
recomposition = recomposition[:,:] + gpu_in1[i-scale_adjust,:,:]
gpu_scale -= 1
if scale_adjust>0:
for i in range(scale_adjust-1, -1, -1):
gpu_a_trous_row_kernel(recomposition, gpu_tmp, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_a_trous_col_kernel(gpu_tmp, recomposition, wavelet_filter, gpu_scale,
block=(32,32,1), grid=(grid_cols, grid_rows))
gpu_scale -= 1
if store_on_gpu:
return recomposition
else:
return recomposition.get() |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_config'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '18', '172']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'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': 'variables'}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '29']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'list_splat', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '28', 'type': 'argument_list', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30', '41', '45', '108']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'combination'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '44', 'type': 'True', 'children': []}; {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '52']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'combination'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'reducer'}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'reducers'}; {'id': '58', 'type': 'block', 'children': ['59', '95']}; {'id': '59', 'type': 'if_statement', 'children': ['60', '65', '77']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': '=='}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'reducer'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'-'"}; {'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': 'match'}; {'id': '69', 'type': 'not_operator', 'children': ['70']}; {'id': '70', 'type': 'attribute', 'children': ['71', '76']}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'combination'}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'reducer'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'value'}; {'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': 'match'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '92']}; {'id': '85', 'type': 'attribute', 'children': ['86', '91']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'combination'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'reducer'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'reducer'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '95', 'type': 'if_statement', 'children': ['96', '103']}; {'id': '96', 'type': 'conditional_expression', 'children': ['97', '98', '101'], 'value': 'if'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'reducer'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'is_exclude'}; {'id': '101', 'type': 'not_operator', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '107', 'type': 'False', 'children': []}; {'id': '108', 'type': 'if_statement', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'include'}; {'id': '110', 'type': 'block', 'children': ['111', '129', '146', '166']}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '118', 'type': 'generator_expression', 'children': ['119', '122', '125']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '122', 'type': 'for_in_clause', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '125', 'type': 'if_clause', 'children': ['126']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '139', 'type': 'generator_expression', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '143', 'type': 'for_in_clause', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '156']}; {'id': '147', 'type': 'boolean_operator', 'children': ['148', '151'], 'value': 'and'}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'in'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '!='}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '156', 'type': 'block', 'children': ['157']}; {'id': '157', 'type': 'raise_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'DuplicateEnvironment'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162', '163']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'assignment', 'children': ['168', '171']}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'matrix'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '172', 'type': 'return_statement', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'matrix'} | def from_config(config):
matrix = {}
variables = config.keys()
for entries in product(*config.values()):
combination = dict(zip(variables, entries))
include = True
for value in combination.values():
for reducer in value.reducers:
if reducer.pattern == '-':
match = not combination[reducer.variable].value
else:
match = fnmatch(combination[reducer.variable].value, reducer.pattern)
if match if reducer.is_exclude else not match:
include = False
if include:
key = '-'.join(entry.alias for entry in entries if entry.alias)
data = dict(
zip(variables, (entry.value for entry in entries))
)
if key in matrix and data != matrix[key]:
raise DuplicateEnvironment(key, data, matrix[key])
matrix[key] = data
return matrix |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '71']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'moresane_by_scale'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41', '44', '47', '50', '53', '56', '59', '62', '65', '68']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'start_scale'}; {'id': '7', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stop_scale'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'subregion'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'sigma_level'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'loop_gain'}; {'id': '19', 'type': 'float', 'children': [], 'value': '0.1'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tolerance'}; {'id': '22', 'type': 'float', 'children': [], 'value': '0.75'}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'accuracy'}; {'id': '25', 'type': 'float', 'children': [], 'value': '1e-6'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'major_loop_miter'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'minor_loop_miter'}; {'id': '31', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'all_on_gpu'}; {'id': '34', 'type': 'False', 'children': []}; {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'decom_mode'}; {'id': '37', 'type': 'string', 'children': [], 'value': '"ser"'}; {'id': '38', 'type': 'default_parameter', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'core_count'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '41', 'type': 'default_parameter', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'conv_device'}; {'id': '43', 'type': 'string', 'children': [], 'value': "'cpu'"}; {'id': '44', 'type': 'default_parameter', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'conv_mode'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'linear'"}; {'id': '47', 'type': 'default_parameter', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'extraction_mode'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'cpu'"}; {'id': '50', 'type': 'default_parameter', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'enforce_positivity'}; {'id': '52', 'type': 'False', 'children': []}; {'id': '53', 'type': 'default_parameter', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'edge_suppression'}; {'id': '55', 'type': 'False', 'children': []}; {'id': '56', 'type': 'default_parameter', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'edge_offset'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '59', 'type': 'default_parameter', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'flux_threshold'}; {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'default_parameter', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'neg_comp'}; {'id': '64', 'type': 'False', 'children': []}; {'id': '65', 'type': 'default_parameter', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'edge_excl'}; {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'default_parameter', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'int_excl'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '71', 'type': 'block', 'children': ['72', '78', '82', '224', '230']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'dirty_data'}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dirty_data'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'start_scale'}; {'id': '82', 'type': 'while_statement', 'children': ['83', '88']}; {'id': '83', 'type': 'not_operator', 'children': ['84']}; {'id': '84', 'type': '()', 'children': ['85']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'complete'}; {'id': '88', 'type': 'block', 'children': ['89', '101', '170', '178', '182', '210']}; {'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': 'logger'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'string', 'children': [], 'value': '"MORESANE at scale {}"'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'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': 'self'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'moresane'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '110', '113', '116', '119', '122', '125', '128', '131', '134', '137', '140', '143', '146', '149', '152', '155', '158', '161', '164', '167']}; {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'subregion'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'subregion'}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sigma_level'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sigma_level'}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'loop_gain'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'loop_gain'}; {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'tolerance'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'tolerance'}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'accuracy'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'accuracy'}; {'id': '125', 'type': 'keyword_argument', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'major_loop_miter'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'major_loop_miter'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'minor_loop_miter'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'minor_loop_miter'}; {'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'all_on_gpu'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'all_on_gpu'}; {'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'decom_mode'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'decom_mode'}; {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'core_count'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'core_count'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'conv_device'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'conv_device'}; {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'conv_mode'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'conv_mode'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'extraction_mode'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'extraction_mode'}; {'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'enforce_positivity'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'enforce_positivity'}; {'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'edge_suppression'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'edge_suppression'}; {'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'edge_offset'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'edge_offset'}; {'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'flux_threshold'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'flux_threshold'}; {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'neg_comp'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'neg_comp'}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'edge_excl'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'edge_excl'}; {'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'int_excl'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'int_excl'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'dirty_data'}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'residual'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'augmented_assignment', 'children': ['180', '181'], 'value': '+='}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '181', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '201']}; {'id': '183', 'type': '()', 'children': ['184']}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': '>'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '186', 'type': 'binary_operator', 'children': ['187', '200'], 'value': '-'}; {'id': '187', 'type': '()', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'log2'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}; {'id': '193', 'type': 'subscript', 'children': ['194', '199']}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'dirty_data'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '199', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'logger'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'string', 'children': [], 'value': '"Maximum scale reached - finished."'}; {'id': '209', 'type': 'break_statement', 'children': []}; {'id': '210', 'type': 'if_statement', 'children': ['211', '215']}; {'id': '211', 'type': '()', 'children': ['212']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': '>'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'scale_count'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'stop_scale'}; {'id': '215', 'type': 'block', 'children': ['216', '223']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'string', 'children': [], 'value': '"Maximum scale reached - finished."'}; {'id': '223', 'type': 'break_statement', 'children': []}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'dirty_data'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'dirty_data'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}; {'id': '231', 'type': 'assignment', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'complete'}; {'id': '235', 'type': 'False', 'children': []} | def moresane_by_scale(self, start_scale=1, stop_scale=20, subregion=None, sigma_level=4, loop_gain=0.1,
tolerance=0.75, accuracy=1e-6, major_loop_miter=100, minor_loop_miter=30, all_on_gpu=False,
decom_mode="ser", core_count=1, conv_device='cpu', conv_mode='linear', extraction_mode='cpu',
enforce_positivity=False, edge_suppression=False,
edge_offset=0, flux_threshold=0, neg_comp=False, edge_excl=0, int_excl=0):
dirty_data = self.dirty_data
scale_count = start_scale
while not (self.complete):
logger.info("MORESANE at scale {}".format(scale_count))
self.moresane(subregion=subregion, scale_count=scale_count, sigma_level=sigma_level, loop_gain=loop_gain,
tolerance=tolerance, accuracy=accuracy, major_loop_miter=major_loop_miter,
minor_loop_miter=minor_loop_miter, all_on_gpu=all_on_gpu, decom_mode=decom_mode,
core_count=core_count, conv_device=conv_device, conv_mode=conv_mode,
extraction_mode=extraction_mode, enforce_positivity=enforce_positivity,
edge_suppression=edge_suppression, edge_offset=edge_offset,
flux_threshold=flux_threshold, neg_comp=neg_comp,
edge_excl=edge_excl, int_excl=int_excl)
self.dirty_data = self.residual
scale_count += 1
if (scale_count>(np.log2(self.dirty_data.shape[0]))-1):
logger.info("Maximum scale reached - finished.")
break
if (scale_count>stop_scale):
logger.info("Maximum scale reached - finished.")
break
self.dirty_data = dirty_data
self.complete = False |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_or_create'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'no_input'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'create_new'}; {'id': '13', 'type': 'False', 'children': []}; {'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '16', 'type': 'block', 'children': ['17', '25', '35', '45', '53', '67', '85', '119', '158', '193', '238']}; {'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', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'argparse'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ArgumentParser'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'string', 'children': [], 'value': "'--no_input'"}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'store_true'"}; {'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': 'parser'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'add_argument'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'--create_new'"}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'store_true'"}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'parse_args'}; {'id': '52', 'type': 'argument_list', 'children': []}; {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'no_input'}; {'id': '57', 'type': 'block', 'children': ['58', '63']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'Parameter --no_input was given'"}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'no_input'}; {'id': '66', 'type': 'True', 'children': []}; {'id': '67', 'type': 'if_statement', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'create_new'}; {'id': '71', 'type': 'block', 'children': ['72', '77', '81']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'Parameter --create_new was given'"}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'create_new'}; {'id': '80', 'type': 'True', 'children': []}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'no_input'}; {'id': '84', 'type': 'True', 'children': []}; {'id': '85', 'type': 'function_definition', 'children': ['86', '87', '88']}; {'id': '86', 'type': 'function_name', 'children': [], 'value': 'savefile_more_recent'}; {'id': '87', 'type': 'parameters', 'children': []}; {'id': '88', 'type': 'block', 'children': ['89', '100', '115']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'time_savefile'}; {'id': '92', 'type': 'call', 'children': ['93', '98']}; {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'getmtime'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'time_program'}; {'id': '103', 'type': 'call', 'children': ['104', '109']}; {'id': '104', 'type': 'attribute', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'getmtime'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'argv'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '>'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'time_savefile'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'time_program'}; {'id': '119', 'type': 'function_definition', 'children': ['120', '121', '122']}; {'id': '120', 'type': 'function_name', 'children': [], 'value': 'load_pickle'}; {'id': '121', 'type': 'parameters', 'children': []}; {'id': '122', 'type': 'block', 'children': ['123', '146', '156']}; {'id': '123', 'type': 'with_statement', 'children': ['124', '134']}; {'id': '124', 'type': 'with_clause', 'children': ['125']}; {'id': '125', 'type': 'with_item', 'children': ['126']}; {'id': '126', 'type': 'as_pattern', 'children': ['127', '132']}; {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '131', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '132', 'type': 'as_pattern_target', 'children': ['133']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '134', 'type': 'block', 'children': ['135']}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '140']}; {'id': '137', 'type': 'pattern_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'statefile_version'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'of'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150']}; {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '!='}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'statefile_version'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'STATEFILE_VERSION'}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'raise_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'string', 'children': [], 'value': "f'Wrong statefile version, please remove state file {filename}'"}; {'id': '156', 'type': 'return_statement', 'children': ['157']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '158', 'type': 'function_definition', 'children': ['159', '160', '161']}; {'id': '159', 'type': 'function_name', 'children': [], 'value': 'load'}; {'id': '160', 'type': 'parameters', 'children': []}; {'id': '161', 'type': 'block', 'children': ['162', '169', '177', '191']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'binary_operator', 'children': ['167', '168'], 'value': '%'}; {'id': '167', 'type': 'string', 'children': [], 'value': "'Loading %s'"}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '174']}; {'id': '171', 'type': 'pattern_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'obj_list'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '174', 'type': 'call', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'load_pickle'}; {'id': '176', 'type': 'argument_list', 'children': []}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'system'}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'System'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '186', '189']}; {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'load_state'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'obj_list'}; {'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '189', 'type': 'dictionary_splat', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '191', 'type': 'return_statement', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'system'}; {'id': '193', 'type': 'function_definition', 'children': ['194', '195', '196']}; {'id': '194', 'type': 'function_name', 'children': [], 'value': 'create'}; {'id': '195', 'type': 'parameters', 'children': []}; {'id': '196', 'type': 'block', 'children': ['197', '202', '206', '226']}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}; {'id': '201', 'type': 'string', 'children': [], 'value': "'Creating new system'"}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}; {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '205', 'type': 'None', 'children': []}; {'id': '206', 'type': 'if_statement', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '208', 'type': 'block', 'children': ['209']}; {'id': '209', 'type': 'try_statement', 'children': ['210', '219']}; {'id': '210', 'type': 'block', 'children': ['211']}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '216']}; {'id': '213', 'type': 'pattern_list', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'obj_list'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'load_pickle'}; {'id': '218', 'type': 'argument_list', 'children': []}; {'id': '219', 'type': 'except_clause', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'FileNotFoundError'}; {'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': 'config'}; {'id': '225', 'type': 'None', 'children': []}; {'id': '226', 'type': 'return_statement', 'children': ['227']}; {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '229', 'type': 'argument_list', 'children': ['230', '233', '236']}; {'id': '230', 'type': 'keyword_argument', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'load_config'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '236', 'type': 'dictionary_splat', 'children': ['237']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '238', 'type': 'if_statement', 'children': ['239', '249', '304']}; {'id': '239', 'type': 'boolean_operator', 'children': ['240', '241'], 'value': 'and'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'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': 'os'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'if_statement', 'children': ['251', '257', '262']}; {'id': '251', 'type': 'boolean_operator', 'children': ['252', '255'], 'value': 'and'}; {'id': '252', 'type': 'call', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'savefile_more_recent'}; {'id': '254', 'type': 'argument_list', 'children': []}; {'id': '255', 'type': 'not_operator', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'create_new'}; {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'return_statement', 'children': ['259']}; {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '261', 'type': 'argument_list', 'children': []}; {'id': '262', 'type': 'else_clause', 'children': ['263']}; {'id': '263', 'type': 'block', 'children': ['264', '276']}; {'id': '264', 'type': 'if_statement', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'no_input'}; {'id': '266', 'type': 'block', 'children': ['267', '272']}; {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'call', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'string', 'children': [], 'value': "'Program file more recent. Loading that instead.'"}; {'id': '272', 'type': 'return_statement', 'children': ['273']}; {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '275', 'type': 'argument_list', 'children': []}; {'id': '276', 'type': 'while_statement', 'children': ['277', '278']}; {'id': '277', 'type': 'True', 'children': []}; {'id': '278', 'type': 'block', 'children': ['279', '286']}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'input'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}; {'id': '285', 'type': 'string', 'children': [], 'value': "'Program file more recent. Do you want to load it? (y/n) '"}; {'id': '286', 'type': 'if_statement', 'children': ['287', '290', '295']}; {'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': '=='}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '289', 'type': 'string', 'children': [], 'value': "'y'"}; {'id': '290', 'type': 'block', 'children': ['291']}; {'id': '291', 'type': 'return_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '294', 'type': 'argument_list', 'children': []}; {'id': '295', 'type': 'elif_clause', 'children': ['296', '299']}; {'id': '296', 'type': 'comparison_operator', 'children': ['297', '298'], 'value': '=='}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'answer'}; {'id': '298', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'return_statement', 'children': ['301']}; {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '303', 'type': 'argument_list', 'children': []}; {'id': '304', 'type': 'else_clause', 'children': ['305']}; {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'return_statement', 'children': ['307']}; {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'create'}; {'id': '309', 'type': 'argument_list', 'children': []} | def load_or_create(cls, filename=None, no_input=False, create_new=False, **kwargs):
parser = argparse.ArgumentParser()
parser.add_argument('--no_input', action='store_true')
parser.add_argument('--create_new', action='store_true')
args = parser.parse_args()
if args.no_input:
print('Parameter --no_input was given')
no_input = True
if args.create_new:
print('Parameter --create_new was given')
create_new = True
no_input = True
def savefile_more_recent():
time_savefile = os.path.getmtime(filename)
time_program = os.path.getmtime(sys.argv[0])
return time_savefile > time_program
def load_pickle():
with open(filename, 'rb') as of:
statefile_version, data = pickle.load(of)
if statefile_version != STATEFILE_VERSION:
raise RuntimeError(f'Wrong statefile version, please remove state file {filename}')
return data
def load():
print('Loading %s' % filename)
obj_list, config = load_pickle()
system = System(load_state=obj_list, filename=filename, **kwargs)
return system
def create():
print('Creating new system')
config = None
if filename:
try:
obj_list, config = load_pickle()
except FileNotFoundError:
config = None
return cls(filename=filename, load_config=config, **kwargs)
if filename and os.path.isfile(filename):
if savefile_more_recent() and not create_new:
return load()
else:
if no_input:
print('Program file more recent. Loading that instead.')
return create()
while True:
answer = input('Program file more recent. Do you want to load it? (y/n) ')
if answer == 'y':
return create()
elif answer == 'n':
return load()
else:
return create() |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cleanup'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '24', '45', '54', '66', '75', '97', '106', '123', '132', '154', '163', '190']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'pre_exit_trigger'}; {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': '"Shutting down %s, please wait a moment."'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '31']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'threading'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'block', 'children': ['32']}; {'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': 't'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'TimerClass'}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'cancel'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', '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': 'logger'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'string', 'children': [], 'value': "'Timers cancelled'"}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '59']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'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': 'i'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'cleanup'}; {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'expression_statement', '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': 'self'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'Sensors etc cleanups done'"}; {'id': '75', 'type': 'for_statement', 'children': ['76', '77', '90']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ser'}; {'id': '77', 'type': 'generator_expression', 'children': ['78', '79', '84']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '79', 'type': 'for_in_clause', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '84', 'type': 'if_clause', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'AbstractUserService'}; {'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': 'ser'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cleanup_system'}; {'id': '96', 'type': 'argument_list', 'children': []}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'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': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'string', 'children': [], 'value': "'User services cleaned up'"}; {'id': '106', 'type': 'if_statement', 'children': ['107', '114']}; {'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': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'worker_thread'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'is_alive'}; {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'block', 'children': ['115']}; {'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': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'worker_thread'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'stop'}; {'id': '122', 'type': 'argument_list', 'children': []}; {'id': '123', 'type': 'expression_statement', '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': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'string', 'children': [], 'value': "'Worker thread really stopped'"}; {'id': '132', 'type': 'for_statement', 'children': ['133', '134', '147']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'ser'}; {'id': '134', 'type': 'generator_expression', 'children': ['135', '136', '141']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '136', 'type': 'for_in_clause', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '141', 'type': 'if_clause', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'AbstractSystemService'}; {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'ser'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'cleanup_system'}; {'id': '153', 'type': 'argument_list', 'children': []}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'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': 'self'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'string', 'children': [], 'value': "'System services cleaned up'"}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '168', 'type': 'generator_expression', 'children': ['169', '172', '179']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '172', 'type': 'for_in_clause', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '174', 'type': 'call', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'threading'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '178', 'type': 'argument_list', 'children': []}; {'id': '179', 'type': 'if_clause', 'children': ['180']}; {'id': '180', 'type': 'boolean_operator', 'children': ['181', '186'], 'value': 'and'}; {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'is_alive'}; {'id': '185', 'type': 'argument_list', 'children': []}; {'id': '186', 'type': 'not_operator', 'children': ['187']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'daemon'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'threads'}; {'id': '192', 'type': 'block', 'children': ['193']}; {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '200']}; {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '204']}; {'id': '201', 'type': 'concatenated_string', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': "'After cleanup, we have still the following threads '"}; {'id': '203', 'type': 'string', 'children': [], 'value': "'running: %s'"}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'threads'} | def cleanup(self):
self.pre_exit_trigger = True
self.logger.info("Shutting down %s, please wait a moment.", self.name)
for t in threading.enumerate():
if isinstance(t, TimerClass):
t.cancel()
self.logger.debug('Timers cancelled')
for i in self.objects:
i.cleanup()
self.logger.debug('Sensors etc cleanups done')
for ser in (i for i in self.services if isinstance(i, AbstractUserService)):
ser.cleanup_system()
self.logger.debug('User services cleaned up')
if self.worker_thread.is_alive():
self.worker_thread.stop()
self.logger.debug('Worker thread really stopped')
for ser in (i for i in self.services if isinstance(i, AbstractSystemService)):
ser.cleanup_system()
self.logger.debug('System services cleaned up')
threads = list(t.name for t in threading.enumerate() if t.is_alive() and not t.daemon)
if threads:
self.logger.info('After cleanup, we have still the following threads '
'running: %s', ', '.join(threads)) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_puml'}; {'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': 'filename'}; {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'block', 'children': ['9', '42', '63', '70', '77', '103', '110', '333', '340']}; {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': 'get_type'}; {'id': '11', 'type': 'parameters', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '13', 'type': 'block', 'children': ['14', '18', '40']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'program'"}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24', '29']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'AbstractSensor'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'sensor'"}; {'id': '29', 'type': 'elif_clause', 'children': ['30', '35']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'AbstractActuator'}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '39', 'type': 'string', 'children': [], 'value': "'actuator'"}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '44', '53']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'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': 's'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'StringIO'}; {'id': '62', 'type': 'argument_list', 'children': []}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'string', 'children': [], 'value': "'@startuml\\n'"}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'skinparam state {\\n'"}; {'id': '77', 'type': 'for_statement', 'children': ['78', '81', '91']}; {'id': '78', 'type': 'pattern_list', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '90']}; {'id': '85', 'type': 'attribute', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'background_colors'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '90', 'type': 'argument_list', 'children': []}; {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '%'}; {'id': '99', 'type': 'string', 'children': [], 'value': "'BackGroundColor<<%s>> %s\\n'"}; {'id': '100', 'type': 'tuple', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'v'}; {'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': 's'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'string', 'children': [], 'value': "'}\\n'"}; {'id': '110', 'type': 'for_statement', 'children': ['111', '112', '117']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'system'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '117', 'type': 'block', 'children': ['118', '130']}; {'id': '118', 'type': 'if_statement', 'children': ['119', '128']}; {'id': '119', 'type': 'boolean_operator', 'children': ['120', '125'], 'value': 'or'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'DefaultProgram'}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'hide_in_uml'}; {'id': '128', 'type': 'block', 'children': ['129']}; {'id': '129', 'type': 'continue_statement', 'children': []}; {'id': '130', 'type': 'if_statement', 'children': ['131', '136']}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ProgrammableSystemObject'}; {'id': '136', 'type': 'block', 'children': ['137', '152', '165', '221', '242', '276']}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '%'}; {'id': '144', 'type': 'string', 'children': [], 'value': '\'state "%s" as %s <<%s>>\\n\''}; {'id': '145', 'type': 'tuple', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'get_type'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '%'}; {'id': '159', 'type': 'string', 'children': [], 'value': "'%s: %s\\n'"}; {'id': '160', 'type': 'tuple', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'class_name'}; {'id': '165', 'type': 'if_statement', 'children': ['166', '171', '201']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'AbstractActuator'}; {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'for_statement', 'children': ['173', '174', '180']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '174', 'type': 'call', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'program_stack'}; {'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': 's'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}; {'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '%'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'%s: %s :: %s\\n'"}; {'id': '189', 'type': 'tuple', 'children': ['190', '191', '192']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '192', 'type': 'call', 'children': ['193', '198']}; {'id': '193', 'type': 'attribute', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'program_status'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '201', 'type': 'elif_clause', 'children': ['202', '207']}; {'id': '202', 'type': 'call', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '206', 'type': 'string', 'children': [], 'value': "'status'"}; {'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': 's'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '%'}; {'id': '215', 'type': 'string', 'children': [], 'value': "'%s: Status: %s\\n'"}; {'id': '216', 'type': 'tuple', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '221', 'type': 'if_statement', 'children': ['222', '228']}; {'id': '222', 'type': 'call', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226', '227']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '226', 'type': 'string', 'children': [], 'value': "'is_program'"}; {'id': '227', 'type': 'False', 'children': []}; {'id': '228', 'type': 'block', 'children': ['229']}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '%'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'%s: Priority: %s\\n'"}; {'id': '237', 'type': 'tuple', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'priority'}; {'id': '242', 'type': 'for_statement', 'children': ['243', '244', '247']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'actual_triggers'}; {'id': '247', 'type': 'block', 'children': ['248', '260']}; {'id': '248', 'type': 'if_statement', 'children': ['249', '258']}; {'id': '249', 'type': 'boolean_operator', 'children': ['250', '255'], 'value': 'or'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'DefaultProgram'}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'hide_in_uml'}; {'id': '258', 'type': 'block', 'children': ['259']}; {'id': '259', 'type': 'continue_statement', 'children': []}; {'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': 's'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '268'], 'value': '%'}; {'id': '267', 'type': 'string', 'children': [], 'value': "'%s -[%s]-> %s\\n'"}; {'id': '268', 'type': 'tuple', 'children': ['269', '270', '275']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '270', 'type': 'subscript', 'children': ['271', '274']}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'arrow_colors'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'trigger'"}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '276', 'type': 'for_statement', 'children': ['277', '278', '281']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'actual_targets'}; {'id': '281', 'type': 'block', 'children': ['282', '288', '303', '317']}; {'id': '282', 'type': 'if_statement', 'children': ['283', '286']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'hide_in_uml'}; {'id': '286', 'type': 'block', 'children': ['287']}; {'id': '287', 'type': 'continue_statement', 'children': []}; {'id': '288', 'type': 'if_statement', 'children': ['289', '292', '297']}; {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'active'}; {'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': 'color'}; {'id': '296', 'type': 'string', 'children': [], 'value': "'active_target'"}; {'id': '297', 'type': 'else_clause', 'children': ['298']}; {'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': 'color'}; {'id': '302', 'type': 'string', 'children': [], 'value': "'inactive_target'"}; {'id': '303', 'type': 'if_statement', 'children': ['304', '312']}; {'id': '304', 'type': 'comparison_operator', 'children': ['305', '311'], 'value': '=='}; {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '307', 'type': 'argument_list', 'children': ['308', '309', '310']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '309', 'type': 'string', 'children': [], 'value': "'program'"}; {'id': '310', 'type': 'None', 'children': []}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '312', 'type': 'block', 'children': ['313']}; {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '316', 'type': 'string', 'children': [], 'value': "'controlled_target'"}; {'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': 's'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '322', 'type': 'argument_list', 'children': ['323']}; {'id': '323', 'type': 'binary_operator', 'children': ['324', '325'], 'value': '%'}; {'id': '324', 'type': 'string', 'children': [], 'value': "'%s -[%s]-> %s\\n'"}; {'id': '325', 'type': 'tuple', 'children': ['326', '327', '332']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'o'}; {'id': '327', 'type': 'subscript', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'arrow_colors'}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 't'}; {'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': 's'}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}; {'id': '339', 'type': 'string', 'children': [], 'value': "'@enduml\\n'"}; {'id': '340', 'type': 'if_statement', 'children': ['341', '342', '349']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '342', 'type': 'block', 'children': ['343']}; {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '348']}; {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '348', 'type': 'argument_list', 'children': []}; {'id': '349', 'type': 'else_clause', 'children': ['350']}; {'id': '350', 'type': 'block', 'children': ['351']}; {'id': '351', 'type': 'return_statement', 'children': ['352']}; {'id': '352', 'type': 'call', 'children': ['353', '356']}; {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '356', 'type': 'argument_list', 'children': []} | def write_puml(self, filename=''):
def get_type(o):
type = 'program'
if isinstance(o, AbstractSensor):
type = 'sensor'
elif isinstance(o, AbstractActuator):
type = 'actuator'
return type
if filename:
s = open(filename, 'w')
else:
s = io.StringIO()
s.write('@startuml\n')
s.write('skinparam state {\n')
for k, v in list(self.background_colors.items()):
s.write('BackGroundColor<<%s>> %s\n' % (k, v))
s.write('}\n')
for o in self.system.objects:
if isinstance(o, DefaultProgram) or o.hide_in_uml:
continue
if isinstance(o, ProgrammableSystemObject):
s.write('state "%s" as %s <<%s>>\n' % (o, o, get_type(o)))
s.write('%s: %s\n' % (o, o.class_name))
if isinstance(o, AbstractActuator):
for p in reversed(o.program_stack):
s.write('%s: %s :: %s\n' % (o, p, o.program_status.get(p, '-')))
elif hasattr(o, 'status'):
s.write('%s: Status: %s\n' % (o, o.status))
if getattr(o, 'is_program', False):
s.write('%s: Priority: %s\n' % (o, o.priority))
for t in o.actual_triggers:
if isinstance(t, DefaultProgram) or t.hide_in_uml:
continue
s.write('%s -[%s]-> %s\n' % (t, self.arrow_colors['trigger'], o))
for t in o.actual_targets:
if t.hide_in_uml:
continue
if o.active:
color = 'active_target'
else:
color = 'inactive_target'
if getattr(t, 'program', None) == o:
color = 'controlled_target'
s.write('%s -[%s]-> %s\n' % (o, self.arrow_colors[color], t))
s.write('@enduml\n')
if filename:
s.close()
else:
return s.getvalue() |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '18', '32', '44', '52', '63', '89', '106', '118', '170', '187', '191', '203', '225', '263']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '13', 'type': 'subscript', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}; {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'y'}; {'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': 'y'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'classes'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'classes'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'n_classes'}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'classes'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '68']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '68', 'type': 'block', 'children': ['69', '78']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'median_kneighbour_distance'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '83', 'type': 'binary_operator', 'children': ['84', '87'], 'value': '**'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '89', 'type': 'if_statement', 'children': ['90', '94']}; {'id': '90', 'type': 'not_operator', 'children': ['91']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '104'], 'value': '**'}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '104', 'type': 'unary_operator', 'children': ['105'], 'value': '-'}; {'id': '105', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '111']}; {'id': '107', 'type': 'not_operator', 'children': ['108']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rho'}; {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'rho'}; {'id': '117', 'type': 'float', 'children': [], 'value': '0.1'}; {'id': '118', 'type': 'if_statement', 'children': ['119', '124', '158']}; {'id': '119', 'type': 'comparison_operator', 'children': ['120', '123'], 'value': 'is'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'kernel_pos'}; {'id': '123', 'type': 'None', 'children': []}; {'id': '124', 'type': 'block', 'children': ['125', '135', '146']}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'B'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'n_kernels_max'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'kernel_idx'}; {'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': 'np'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'permutation'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'kernel_pos'}; {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'kernel_idx'}; {'id': '155', 'type': 'slice', 'children': ['156', '157']}; {'id': '156', 'type': 'colon', 'children': []}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'B'}; {'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': 'B'}; {'id': '163', 'type': 'subscript', 'children': ['164', '169']}; {'id': '164', 'type': 'attribute', 'children': ['165', '168']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'kernel_pos'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'Phi'}; {'id': '173', 'type': 'call', 'children': ['174', '179']}; {'id': '174', 'type': 'attribute', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'pairwise'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'rbf_kernel'}; {'id': '179', 'type': 'argument_list', 'children': ['180', '181', '184']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'kernel_pos'}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'theta'}; {'id': '190', 'type': 'dictionary', 'children': []}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'Phi_PhiT'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'Phi'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'Phi'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'inverse_term'}; {'id': '206', 'type': 'call', 'children': ['207', '212']}; {'id': '207', 'type': 'attribute', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'linalg'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'inv'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}; {'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '+'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'Phi_PhiT'}; {'id': '215', 'type': 'binary_operator', 'children': ['216', '219'], 'value': '*'}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'rho'}; {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'eye'}; {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'B'}; {'id': '225', 'type': 'for_statement', 'children': ['226', '227', '230']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'classes'}; {'id': '230', 'type': 'block', 'children': ['231', '243']}; {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '234', 'type': 'call', 'children': ['235', '241']}; {'id': '235', 'type': 'attribute', 'children': ['236', '240']}; {'id': '236', 'type': '()', 'children': ['237']}; {'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': '=='}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '248']}; {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'theta'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '248', 'type': 'call', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'inverse_term'}; {'id': '254', 'type': 'call', 'children': ['255', '258']}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '258', 'type': 'argument_list', 'children': ['259', '262']}; {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'Phi'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'theta'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'theta'} | def fit(self, X, y=None):
N = X.shape[0]
if y is None:
y = np.zeros(N)
self.classes = list(set(y))
self.classes.sort()
self.n_classes = len(self.classes)
if not self.sigma:
self.sigma = median_kneighbour_distance(X)
self.gamma = self.sigma**-2
if not self.gamma:
self.gamma = self.sigma**-2
if not self.rho:
self.rho = 0.1
if self.kernel_pos is None:
B = min(self.n_kernels_max, N)
kernel_idx = np.random.permutation(N)
self.kernel_pos = X[kernel_idx[:B]]
else:
B = self.kernel_pos.shape[0]
Phi = metrics.pairwise.rbf_kernel(X, self.kernel_pos, self.gamma)
theta = {}
Phi_PhiT = np.dot(Phi.T, Phi)
inverse_term = np.linalg.inv(Phi_PhiT + self.rho*np.eye(B))
for c in self.classes:
m = (y == c).astype(int)
theta[c] = np.dot(inverse_term, np.dot(Phi.T, m))
self.theta = theta |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'predict_sequence'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'inference'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'smoothing'"}; {'id': '11', 'type': 'block', 'children': ['12', '21', '29', '40', '48', '114']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'obsll'}; {'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': 'predict_proba'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'X'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '26']}; {'id': '23', 'type': 'pattern_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'obsll'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'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': 'zeros'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'tuple', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '47']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44', '45']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '45', 'type': 'slice', 'children': ['46']}; {'id': '46', 'type': 'colon', 'children': []}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '55']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}; {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '55', 'type': 'block', 'children': ['56', '76', '93']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '63']}; {'id': '58', 'type': 'subscript', 'children': ['59', '60', '61']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '61', 'type': 'slice', 'children': ['62']}; {'id': '62', 'type': 'colon', 'children': []}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'dot'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '75']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70', '73']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '-'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '73', 'type': 'slice', 'children': ['74']}; {'id': '74', 'type': 'colon', 'children': []}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '82']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'augmented_assignment', 'children': ['85', '89'], 'value': '*='}; {'id': '85', 'type': 'subscript', 'children': ['86', '87', '88']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '89', 'type': 'subscript', 'children': ['90', '91', '92']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'obsll'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '100']}; {'id': '95', 'type': 'subscript', 'children': ['96', '97', '98']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '98', 'type': 'slice', 'children': ['99']}; {'id': '99', 'type': 'colon', 'children': []}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '106'], 'value': '/'}; {'id': '101', 'type': 'subscript', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '104', 'type': 'slice', 'children': ['105']}; {'id': '105', 'type': 'colon', 'children': []}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'subscript', 'children': ['110', '111', '112']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '112', 'type': 'slice', 'children': ['113']}; {'id': '113', 'type': 'colon', 'children': []}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118', '121']}; {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '=='}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'inference'}; {'id': '117', 'type': 'string', 'children': [], 'value': "'filtering'"}; {'id': '118', 'type': 'block', 'children': ['119']}; {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '121', 'type': 'else_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123', '134', '145', '160', '232', '278']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'tuple', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'tuple', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '154']}; {'id': '147', 'type': 'subscript', 'children': ['148', '149', '152']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '-'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'slice', 'children': ['153']}; {'id': '153', 'type': 'colon', 'children': []}; {'id': '154', 'type': 'call', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '160', 'type': 'for_statement', 'children': ['161', '162', '172']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '168', '170']}; {'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '-'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '167', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '168', 'type': 'unary_operator', 'children': ['169'], 'value': '-'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'unary_operator', 'children': ['171'], 'value': '-'}; {'id': '171', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '172', 'type': 'block', 'children': ['173', '211']}; {'id': '173', 'type': 'for_statement', 'children': ['174', '175', '179']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'for_statement', 'children': ['181', '182', '186']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'S'}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'augmented_assignment', 'children': ['189', '193'], 'value': '+='}; {'id': '189', 'type': 'subscript', 'children': ['190', '191', '192']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '193', 'type': 'binary_operator', 'children': ['194', '205'], 'value': '*'}; {'id': '194', 'type': 'binary_operator', 'children': ['195', '199'], 'value': '*'}; {'id': '195', 'type': 'subscript', 'children': ['196', '197', '198']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '199', 'type': 'subscript', 'children': ['200', '201', '204']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'obsll'}; {'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '+'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '203', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '205', 'type': 'subscript', 'children': ['206', '207', '210']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '+'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '209', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '218']}; {'id': '213', 'type': 'subscript', 'children': ['214', '215', '216']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '216', 'type': 'slice', 'children': ['217']}; {'id': '217', 'type': 'colon', 'children': []}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '224'], 'value': '/'}; {'id': '219', 'type': 'subscript', 'children': ['220', '221', '222']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '222', 'type': 'slice', 'children': ['223']}; {'id': '223', 'type': 'colon', 'children': []}; {'id': '224', 'type': 'call', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'subscript', 'children': ['228', '229', '230']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '230', 'type': 'slice', 'children': ['231']}; {'id': '231', 'type': 'colon', 'children': []}; {'id': '232', 'type': 'for_statement', 'children': ['233', '234', '238']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '234', 'type': 'call', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '238', 'type': 'block', 'children': ['239', '257']}; {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '246']}; {'id': '241', 'type': 'subscript', 'children': ['242', '243', '244']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '244', 'type': 'slice', 'children': ['245']}; {'id': '245', 'type': 'colon', 'children': []}; {'id': '246', 'type': 'binary_operator', 'children': ['247', '252'], 'value': '*'}; {'id': '247', 'type': 'subscript', 'children': ['248', '249', '250']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'alpha'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '250', 'type': 'slice', 'children': ['251']}; {'id': '251', 'type': 'colon', 'children': []}; {'id': '252', 'type': 'subscript', 'children': ['253', '254', '255']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'beta'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '255', 'type': 'slice', 'children': ['256']}; {'id': '256', 'type': 'colon', 'children': []}; {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '264']}; {'id': '259', 'type': 'subscript', 'children': ['260', '261', '262']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '262', 'type': 'slice', 'children': ['263']}; {'id': '263', 'type': 'colon', 'children': []}; {'id': '264', 'type': 'binary_operator', 'children': ['265', '270'], 'value': '/'}; {'id': '265', 'type': 'subscript', 'children': ['266', '267', '268']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '268', 'type': 'slice', 'children': ['269']}; {'id': '269', 'type': 'colon', 'children': []}; {'id': '270', 'type': 'call', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}; {'id': '273', 'type': 'subscript', 'children': ['274', '275', '276']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'gamma'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '276', 'type': 'slice', 'children': ['277']}; {'id': '277', 'type': 'colon', 'children': []}; {'id': '278', 'type': 'return_statement', 'children': ['279']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'gamma'} | def predict_sequence(self, X, A, pi, inference='smoothing'):
obsll = self.predict_proba(X)
T, S = obsll.shape
alpha = np.zeros((T, S))
alpha[0, :] = pi
for t in range(1, T):
alpha[t, :] = np.dot(alpha[t-1, :], A)
for s in range(S):
alpha[t, s] *= obsll[t, s]
alpha[t, :] = alpha[t, :]/sum(alpha[t, :])
if inference == 'filtering':
return alpha
else:
beta = np.zeros((T, S))
gamma = np.zeros((T, S))
beta[T-1, :] = np.ones(S)
for t in range(T-2, -1, -1):
for i in range(S):
for j in range(S):
beta[t, i] += A[i, j]*obsll[t+1, j]*beta[t+1, j]
beta[t, :] = beta[t, :]/sum(beta[t, :])
for t in range(T):
gamma[t, :] = alpha[t, :]*beta[t, :]
gamma[t, :] = gamma[t, :]/sum(gamma[t, :])
return gamma |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_bgcolor'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'colname'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'copper'"}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '11', 'type': 'string', 'children': [], 'value': "'absmax'"}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '15', 'type': 'block', 'children': ['16', '28', '38', '47', '148', '164', '179', '189', '216', '227', '231']}; {'id': '16', 'type': 'try_statement', 'children': ['17', '25']}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'cmap_builder'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '25', 'type': 'except_clause', 'children': ['26']}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'pass_statement', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}; {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '31', 'type': 'attribute', 'children': ['32', '37']}; {'id': '32', 'type': 'subscript', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'colname'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '45']}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '44'], 'value': '=='}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'return_statement', 'children': []}; {'id': '47', 'type': 'if_statement', 'children': ['48', '51', '69', '121']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '=='}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'clip'"}; {'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': 'data'}; {'id': '55', 'type': 'list_comprehension', 'children': ['56', '66']}; {'id': '56', 'type': 'binary_operator', 'children': ['57', '62'], 'value': '/'}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'threshold'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '69', 'type': 'elif_clause', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '=='}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'absmax'"}; {'id': '73', 'type': 'block', 'children': ['74', '85', '96', '105']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '84', 'type': 'argument_list', 'children': []}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'list', 'children': ['103', '104'], 'value': '[m, M]'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '!='}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'data'}; {'id': '113', 'type': 'binary_operator', 'children': ['114', '120'], 'value': '/'}; {'id': '114', 'type': '()', 'children': ['115']}; {'id': '115', 'type': 'binary_operator', 'children': ['116', '119'], 'value': '+'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '/'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'float', 'children': [], 'value': '2.'}; {'id': '121', 'type': 'elif_clause', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'max'"}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'if_statement', 'children': ['127', '134']}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '133'], 'value': '!='}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '132', 'type': 'argument_list', 'children': []}; {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'data'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '/'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '147', 'type': 'argument_list', 'children': []}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'rgbcolors'}; {'id': '151', 'type': 'list_comprehension', 'children': ['152', '161']}; {'id': '152', 'type': 'subscript', 'children': ['153', '157']}; {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '157', 'type': 'slice', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '159', 'type': 'colon', 'children': []}; {'id': '160', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '161', 'type': 'for_in_clause', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'hexcolors'}; {'id': '167', 'type': 'list_comprehension', 'children': ['168', '176']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'rgb2hex'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '173']}; {'id': '171', 'type': 'list_splat', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '173', 'type': 'keyword_argument', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'normalised'}; {'id': '175', 'type': 'True', 'children': []}; {'id': '176', 'type': 'for_in_clause', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'rgbcolors'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '182', 'type': 'attribute', 'children': ['183', '188']}; {'id': '183', 'type': 'subscript', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'colname'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '189', 'type': 'function_definition', 'children': ['190', '191', '193']}; {'id': '190', 'type': 'function_name', 'children': [], 'value': 'prec'}; {'id': '191', 'type': 'parameters', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'try_statement', 'children': ['195', '212']}; {'id': '195', 'type': 'block', 'children': ['196', '210']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'easydev'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '203', 'type': 'argument_list', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '205', 'type': 'subscript', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'pd_options'}; {'id': '209', 'type': 'string', 'children': [], 'value': "'precision'"}; {'id': '210', 'type': 'return_statement', 'children': ['211']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '212', 'type': 'except_clause', 'children': ['213']}; {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'return_statement', 'children': ['215']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '219', 'type': 'list_comprehension', 'children': ['220', '224']}; {'id': '220', 'type': 'call', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'prec'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '224', 'type': 'for_in_clause', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'html_formatter'}; {'id': '230', 'type': 'string', 'children': [], 'value': '\'<p style="background-color:{0}">{1}</p>\''}; {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '238']}; {'id': '233', 'type': 'subscript', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'colname'}; {'id': '238', 'type': 'list_comprehension', 'children': ['239', '246']}; {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'html_formatter'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '243', 'type': 'argument_list', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '246', 'type': 'for_in_clause', 'children': ['247', '250']}; {'id': '247', 'type': 'pattern_list', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'hexcolors'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'data'} | def add_bgcolor(self, colname, cmap='copper', mode='absmax',
threshold=2):
try:
cmap = cmap_builder(cmap)
except:
pass
data = self.df[colname].values
if len(data) == 0:
return
if mode == 'clip':
data = [min(x, threshold)/float(threshold) for x in data]
elif mode == 'absmax':
m = abs(data.min())
M = abs(data.max())
M = max([m, M])
if M != 0:
data = (data / M + 1)/2.
elif mode == 'max':
if data.max() != 0:
data = data / float(data.max())
rgbcolors = [cmap(x)[0:3] for x in data]
hexcolors = [rgb2hex(*x, normalised=True) for x in rgbcolors]
data = self.df[colname].values
def prec(x):
try:
x = easydev.precision(x, self.pd_options['precision'])
return x
except:
return x
data = [prec(x) for x in data]
html_formatter = '<p style="background-color:{0}">{1}</p>'
self.df[colname] = [html_formatter.format(x, y)
for x, y in zip(hexcolors, data)] |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '27', '45', '65']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'LIST_SCHEMA'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '30', 'type': 'call', 'children': ['31', '36']}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '40', '41', '42', '43', '44']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'page'}; {'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': 'cs'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '50', 'type': 'call', 'children': ['51', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59', '62']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'many'}; {'id': '61', 'type': 'True', 'children': []}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'links'}; {'id': '64', 'type': 'True', 'children': []}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Page'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cs'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'l'} | def list(self, filter=None, type=None, sort=None, limit=None, page=None):
schema = self.LIST_SCHEMA
resp = self.service.list(self.base, filter, type, sort, limit, page)
cs, l = self.service.decode(schema, resp, many=True, links=True)
return Page(cs, l) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'signup_handler'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'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', '20', '27', '36', '45', '70', '79', '302', '313', '331']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'current_user'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'is_authenticated'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'oauth_token'}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'token_getter'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '30']}; {'id': '28', 'type': 'not_operator', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'oauth_token'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'session_prefix'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'token_session_key'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '56']}; {'id': '46', 'type': 'not_operator', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '55']}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '54'], 'value': '+'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'session_prefix'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'_autoregister'"}; {'id': '55', 'type': 'False', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'return_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'url_for'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'.login'"}; {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'remote_app'}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'create_registrationform'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '79', 'type': 'if_statement', 'children': ['80', '85']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'validate_on_submit'}; {'id': '84', 'type': 'argument_list', 'children': []}; {'id': '85', 'type': 'block', 'children': ['86', '97', '108', '115', '126', '136', '154', '164', '175', '237', '258', '268', '278', '287']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'account_info'}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'session_prefix'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'_account_info'"}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'session_prefix'}; {'id': '107', 'type': 'string', 'children': [], 'value': "'_response'"}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'oauth_register'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '115', 'type': 'if_statement', 'children': ['116', '119']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '118', 'type': 'None', 'children': []}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'raise_statement', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'OAuthError'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'Could not create user.'"}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '135']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '+'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'session_prefix'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'_autoregister'"}; {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'token_setter'}; {'id': '141', 'type': 'argument_list', 'children': ['142', '143', '146', '151']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'oauth_token'}; {'id': '145', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'secret'}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'oauth_token'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'handlers'}; {'id': '157', 'type': 'subscript', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'current_oauthclient'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'signup_handlers'}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '164', 'type': 'if_statement', 'children': ['165', '168']}; {'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': 'is'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '167', 'type': 'None', 'children': []}; {'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': 'OAuthError'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}; {'id': '173', 'type': 'string', 'children': [], 'value': "'Could not create token for user.'"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '175', 'type': 'if_statement', 'children': ['176', '182', '227']}; {'id': '176', 'type': 'not_operator', 'children': ['177']}; {'id': '177', 'type': 'attribute', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'remote_account'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'extra_data'}; {'id': '182', 'type': 'block', 'children': ['183', '193', '209', '217']}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'account_setup'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}; {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'handlers'}; {'id': '189', 'type': 'string', 'children': [], 'value': "'setup'"}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'account_setup_received'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'send'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200', '203', '206']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '203', 'type': 'keyword_argument', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'account_setup'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'account_setup'}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '216']}; {'id': '211', 'type': 'attribute', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '216', 'type': 'argument_list', 'children': []}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'account_setup_committed'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'send'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '227', 'type': 'else_clause', 'children': ['228']}; {'id': '228', 'type': 'block', 'children': ['229']}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '236']}; {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '236', 'type': 'argument_list', 'children': []}; {'id': '237', 'type': 'if_statement', 'children': ['238', '249']}; {'id': '238', 'type': 'not_operator', 'children': ['239']}; {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'oauth_authenticate'}; {'id': '241', 'type': 'argument_list', 'children': ['242', '245', '246']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'consumer_key'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'require_existing_link'}; {'id': '248', 'type': 'False', 'children': []}; {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'return_statement', 'children': ['251']}; {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'url_for'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}; {'id': '257', 'type': 'string', 'children': [], 'value': "'security.login'"}; {'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': 'session'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '263', 'type': 'argument_list', 'children': ['264', '267']}; {'id': '264', 'type': 'binary_operator', 'children': ['265', '266'], 'value': '+'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'session_prefix'}; {'id': '266', 'type': 'string', 'children': [], 'value': "'_account_info'"}; {'id': '267', 'type': 'None', 'children': []}; {'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': 'session'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '273', 'type': 'argument_list', 'children': ['274', '277']}; {'id': '274', 'type': 'binary_operator', 'children': ['275', '276'], 'value': '+'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'session_prefix'}; {'id': '276', 'type': 'string', 'children': [], 'value': "'_response'"}; {'id': '277', 'type': 'None', 'children': []}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}; {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'next_url'}; {'id': '281', 'type': 'call', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'get_session_next_url'}; {'id': '283', 'type': 'argument_list', 'children': ['284']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '287', 'type': 'if_statement', 'children': ['288', '289', '295']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'next_url'}; {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'return_statement', 'children': ['291']}; {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'next_url'}; {'id': '295', 'type': 'else_clause', 'children': ['296']}; {'id': '296', 'type': 'block', 'children': ['297']}; {'id': '297', 'type': 'return_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'redirect'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}; {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'account_info'}; {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'binary_operator', 'children': ['311', '312'], 'value': '+'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'session_prefix'}; {'id': '312', 'type': 'string', 'children': [], 'value': "'_account_info'"}; {'id': '313', 'type': 'if_statement', 'children': ['314', '320']}; {'id': '314', 'type': 'not_operator', 'children': ['315']}; {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'is_submitted'}; {'id': '319', 'type': 'argument_list', 'children': []}; {'id': '320', 'type': 'block', 'children': ['321']}; {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '324', 'type': 'call', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'fill_form'}; {'id': '326', 'type': 'argument_list', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'account_info'}; {'id': '330', 'type': 'string', 'children': [], 'value': "'user'"}; {'id': '331', 'type': 'return_statement', 'children': ['332']}; {'id': '332', 'type': 'call', 'children': ['333', '334']}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'render_template'}; {'id': '334', 'type': 'argument_list', 'children': ['335', '340', '343', '346', '363', '380']}; {'id': '335', 'type': 'subscript', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '339', 'type': 'string', 'children': [], 'value': "'OAUTHCLIENT_SIGNUP_TEMPLATE'"}; {'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'app_title'}; {'id': '348', 'type': 'call', 'children': ['349', '360']}; {'id': '349', 'type': 'attribute', 'children': ['350', '359']}; {'id': '350', 'type': 'subscript', 'children': ['351', '356']}; {'id': '351', 'type': 'subscript', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '355', 'type': 'string', 'children': [], 'value': "'OAUTHCLIENT_REMOTE_APPS'"}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '360', 'type': 'argument_list', 'children': ['361', '362']}; {'id': '361', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '362', 'type': 'string', 'children': [], 'value': "''"}; {'id': '363', 'type': 'keyword_argument', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'app_description'}; {'id': '365', 'type': 'call', 'children': ['366', '377']}; {'id': '366', 'type': 'attribute', 'children': ['367', '376']}; {'id': '367', 'type': 'subscript', 'children': ['368', '373']}; {'id': '368', 'type': 'subscript', 'children': ['369', '372']}; {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '372', 'type': 'string', 'children': [], 'value': "'OAUTHCLIENT_REMOTE_APPS'"}; {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '377', 'type': 'argument_list', 'children': ['378', '379']}; {'id': '378', 'type': 'string', 'children': [], 'value': "'description'"}; {'id': '379', 'type': 'string', 'children': [], 'value': "''"}; {'id': '380', 'type': 'keyword_argument', 'children': ['381', '382']}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'app_icon'}; {'id': '382', 'type': 'call', 'children': ['383', '394']}; {'id': '383', 'type': 'attribute', 'children': ['384', '393']}; {'id': '384', 'type': 'subscript', 'children': ['385', '390']}; {'id': '385', 'type': 'subscript', 'children': ['386', '389']}; {'id': '386', 'type': 'attribute', 'children': ['387', '388']}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'current_app'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '389', 'type': 'string', 'children': [], 'value': "'OAUTHCLIENT_REMOTE_APPS'"}; {'id': '390', 'type': 'attribute', 'children': ['391', '392']}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'remote'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '394', 'type': 'argument_list', 'children': ['395', '396']}; {'id': '395', 'type': 'string', 'children': [], 'value': "'icon'"}; {'id': '396', 'type': 'None', 'children': []} | def signup_handler(remote, *args, **kwargs):
if current_user.is_authenticated:
return redirect('/')
oauth_token = token_getter(remote)
if not oauth_token:
return redirect('/')
session_prefix = token_session_key(remote.name)
if not session.get(session_prefix + '_autoregister', False):
return redirect(url_for('.login', remote_app=remote.name))
form = create_registrationform(request.form)
if form.validate_on_submit():
account_info = session.get(session_prefix + '_account_info')
response = session.get(session_prefix + '_response')
user = oauth_register(form)
if user is None:
raise OAuthError('Could not create user.', remote)
session.pop(session_prefix + '_autoregister', None)
token = token_setter(remote, oauth_token[0], secret=oauth_token[1],
user=user)
handlers = current_oauthclient.signup_handlers[remote.name]
if token is None:
raise OAuthError('Could not create token for user.', remote)
if not token.remote_account.extra_data:
account_setup = handlers['setup'](token, response)
account_setup_received.send(
remote, token=token, response=response,
account_setup=account_setup
)
db.session.commit()
account_setup_committed.send(remote, token=token)
else:
db.session.commit()
if not oauth_authenticate(remote.consumer_key, user,
require_existing_link=False):
return redirect(url_for('security.login'))
session.pop(session_prefix + '_account_info', None)
session.pop(session_prefix + '_response', None)
next_url = get_session_next_url(remote.name)
if next_url:
return redirect(next_url)
else:
return redirect('/')
account_info = session.get(session_prefix + '_account_info')
if not form.is_submitted():
form = fill_form(form, account_info['user'])
return render_template(
current_app.config['OAUTHCLIENT_SIGNUP_TEMPLATE'],
form=form,
remote=remote,
app_title=current_app.config['OAUTHCLIENT_REMOTE_APPS'][
remote.name].get('title', ''),
app_description=current_app.config['OAUTHCLIENT_REMOTE_APPS'][
remote.name].get('description', ''),
app_icon=current_app.config['OAUTHCLIENT_REMOTE_APPS'][
remote.name].get('icon', None),
) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_csv'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '41']}; {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '33', '34', '35', '36', '37', '38']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'limit'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'csv'"}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'text'} | def list_csv(self, filter=None, type=None, sort=None, limit=None, page=None):
return self.service.list(self.base, filter, type, sort, limit, page, format='csv').text |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_logdir'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '19', '41']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'LogDirFileSchema'}; {'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': 'resp'}; {'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': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '39', '40']}; {'id': '29', 'type': 'binary_operator', 'children': ['30', '38'], 'value': '+'}; {'id': '30', 'type': 'binary_operator', 'children': ['31', '34'], 'value': '+'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'/logdir/'"}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'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': 'service'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'schema'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'resp'}; {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'many'}; {'id': '53', 'type': 'True', 'children': []} | def list_logdir(self, id, filter=None, sort=None):
schema = LogDirFileSchema()
resp = self.service.list(self.base+str(id)+'/logdir/', filter, sort)
return self.service.decode(schema, resp, many=True) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_init_report'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '12', '18']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sections'}; {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'section_names'}; {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'try_statement', 'children': ['19', '86', '90']}; {'id': '19', 'type': 'block', 'children': ['20', '60']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '33']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '32'], 'value': 'is'}; {'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': 'isdir'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '32', 'type': 'False', 'children': []}; {'id': '33', 'type': 'block', 'children': ['34', '51']}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'string', 'children': [], 'value': '"Created directory {}"'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'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': 'os'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'mkdir'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '65']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'this'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_to_create'}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'try_statement', 'children': ['67', '83']}; {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'mkdir'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '82'], 'value': '+'}; {'id': '75', 'type': 'binary_operator', 'children': ['76', '79'], 'value': '+'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'this'}; {'id': '83', 'type': 'except_clause', 'children': ['84']}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'pass_statement', 'children': []}; {'id': '86', 'type': 'except_clause', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '88', 'type': 'block', 'children': ['89']}; {'id': '89', 'type': 'pass_statement', 'children': []}; {'id': '90', 'type': 'finally_clause', 'children': ['91']}; {'id': '91', 'type': 'block', 'children': ['92', '101', '115', '134', '154', '160', '199', '256']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'temp_path'}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'easydev'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'get_package_location'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"reports"'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'augmented_assignment', 'children': ['103', '104'], 'value': '+='}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'temp_path'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '114'], 'value': '+'}; {'id': '105', 'type': 'binary_operator', 'children': ['106', '111'], 'value': '+'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '110'], 'value': '+'}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '110', 'type': 'string', 'children': [], 'value': '"reports"'}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"resources"'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'list', 'children': ['131', '132', '133'], 'value': '[temp_path, "css", "*.css"]'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'temp_path'}; {'id': '132', 'type': 'string', 'children': [], 'value': '"css"'}; {'id': '133', 'type': 'string', 'children': [], 'value': '"*.css"'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'augmented_assignment', 'children': ['136', '137'], 'value': '+='}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '148']}; {'id': '143', 'type': 'attribute', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'list', 'children': ['150', '153'], 'value': "[self.searchpath, '*.css']"}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'searchpath'}; {'id': '153', 'type': 'string', 'children': [], 'value': "'*.css'"}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'augmented_assignment', 'children': ['156', '157'], 'value': '+='}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'extra_css_list'}; {'id': '160', 'type': 'for_statement', 'children': ['161', '162', '163']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'filenames'}; {'id': '163', 'type': 'block', 'children': ['164', '179']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'target'}; {'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': 'sep'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'list', 'children': ['175', '178'], 'value': "[self.directory, 'css' ]"}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'css'"}; {'id': '179', 'type': 'if_statement', 'children': ['180', '190']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '189'], 'value': 'is'}; {'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': 'isfile'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '189', 'type': 'False', 'children': []}; {'id': '190', 'type': 'block', 'children': ['191']}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '199', 'type': 'for_statement', 'children': ['200', '201', '205']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '201', 'type': 'list', 'children': ['202', '203', '204'], 'value': '[\'sorttable.js\', \'highlight.pack.js\', "jquery-1.12.3.min.js"]'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'sorttable.js'"}; {'id': '203', 'type': 'string', 'children': [], 'value': "'highlight.pack.js'"}; {'id': '204', 'type': 'string', 'children': [], 'value': '"jquery-1.12.3.min.js"'}; {'id': '205', 'type': 'block', 'children': ['206', '222']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '209', 'type': 'call', 'children': ['210', '215']}; {'id': '210', 'type': 'attribute', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'list', 'children': ['217', '220', '221'], 'value': "[self.directory, 'js', filename ]"}; {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'js'"}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '222', 'type': 'if_statement', 'children': ['223', '233']}; {'id': '223', 'type': 'comparison_operator', 'children': ['224', '232'], 'value': 'is'}; {'id': '224', 'type': 'call', 'children': ['225', '230']}; {'id': '225', 'type': 'attribute', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '232', 'type': 'False', 'children': []}; {'id': '233', 'type': 'block', 'children': ['234', '248']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}; {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'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': 'os'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'list', 'children': ['245', '246', '247'], 'value': '[temp_path, "javascript", filename]'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'temp_path'}; {'id': '246', 'type': 'string', 'children': [], 'value': '"javascript"'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'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': 'shutil'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '253', 'type': 'argument_list', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '256', 'type': 'for_statement', 'children': ['257', '258', '261']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'extra_js_list'}; {'id': '261', 'type': 'block', 'children': ['262', '273', '289']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}; {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '265', 'type': 'call', 'children': ['266', '271']}; {'id': '266', 'type': 'attribute', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '276', 'type': 'call', 'children': ['277', '282']}; {'id': '277', 'type': 'attribute', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}; {'id': '283', 'type': 'list', 'children': ['284', '287', '288'], 'value': "[self.directory, 'js', basename ]"}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '287', 'type': 'string', 'children': [], 'value': "'js'"}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '289', 'type': 'if_statement', 'children': ['290', '300']}; {'id': '290', 'type': 'comparison_operator', 'children': ['291', '299'], 'value': 'is'}; {'id': '291', 'type': 'call', 'children': ['292', '297']}; {'id': '292', 'type': 'attribute', 'children': ['293', '296']}; {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '299', 'type': 'False', 'children': []}; {'id': '300', 'type': 'block', 'children': ['301']}; {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '306']}; {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'target'} | def _init_report(self):
self.sections = []
self.section_names = []
try:
if os.path.isdir(self.directory) is False:
if self.verbose:
print("Created directory {}".format(self.directory))
os.mkdir(self.directory)
for this in self._to_create:
try:
os.mkdir(self.directory + os.sep + this)
except:
pass
except Exception:
pass
finally:
temp_path = easydev.get_package_location("reports")
temp_path += os.sep + "reports" + os.sep + "resources"
filenames = glob.glob(os.sep.join([temp_path, "css", "*.css"]))
filenames += glob.glob(os.sep.join([self.searchpath, '*.css']))
filenames += self.extra_css_list
for filename in filenames:
target = os.sep.join([self.directory, 'css' ])
if os.path.isfile(target) is False:
shutil.copy(filename, target)
for filename in ['sorttable.js', 'highlight.pack.js', "jquery-1.12.3.min.js"]:
target = os.sep.join([self.directory, 'js', filename ])
if os.path.isfile(target) is False:
filename = os.sep.join([temp_path, "javascript", filename])
shutil.copy(filename, target)
for filename in self.extra_js_list:
basename = os.path.basename(filename)
target = os.sep.join([self.directory, 'js', basename ])
if os.path.isfile(target) is False:
shutil.copy(filename, target) |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_instance'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '5', 'type': 'block', 'children': ['6', '271']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '14']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': 'wrapper'}; {'id': '8', 'type': 'parameters', 'children': ['9', '10', '12']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'list_splat_pattern', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '12', 'type': 'dictionary_splat_pattern', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'block', 'children': ['15', '82', '168', '262']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'func_trans'}; {'id': '18', 'type': 'dictionary', 'children': ['19', '24', '29', '34', '39', '44', '49', '54', '61', '68', '75']}; {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': '"commit"'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Manager'}; {'id': '24', 'type': 'pair', 'children': ['25', '26']}; {'id': '25', 'type': 'string', 'children': [], 'value': '"compare_config"'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'Manager'}; {'id': '29', 'type': 'pair', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': '"commit_check"'}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Manager'}; {'id': '34', 'type': 'pair', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': '"device_info"'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Manager'}; {'id': '39', 'type': 'pair', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"diff_config"'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'Manager'}; {'id': '44', 'type': 'pair', 'children': ['45', '46']}; {'id': '45', 'type': 'string', 'children': [], 'value': '"health_check"'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Manager'}; {'id': '49', 'type': 'pair', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"interface_errors"'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'manager'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'Manager'}; {'id': '54', 'type': 'pair', 'children': ['55', '56']}; {'id': '55', 'type': 'string', 'children': [], 'value': '"op_cmd"'}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'paramiko'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'SSHClient'}; {'id': '61', 'type': 'pair', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"shell_cmd"'}; {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'paramiko'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'SSHClient'}; {'id': '68', 'type': 'pair', 'children': ['69', '70']}; {'id': '69', 'type': 'string', 'children': [], 'value': '"scp_pull"'}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'paramiko'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'SSHClient'}; {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"scp_push"'}; {'id': '77', 'type': 'attribute', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'paramiko'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'SSHClient'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '94', '137']}; {'id': '83', 'type': 'boolean_operator', 'children': ['84', '89'], 'value': 'and'}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': '=='}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '88', 'type': 'string', 'children': [], 'value': '"root"'}; {'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '=='}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '93', 'type': 'string', 'children': [], 'value': '"op_cmd"'}; {'id': '94', 'type': 'block', 'children': ['95', '113', '131']}; {'id': '95', 'type': 'if_statement', 'children': ['96', '100']}; {'id': '96', 'type': 'not_operator', 'children': ['97']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '100', 'type': 'block', 'children': ['101', '107']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '106', 'type': 'string', 'children': [], 'value': '"paramiko"'}; {'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': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'id': '112', 'type': 'argument_list', 'children': []}; {'id': '113', 'type': 'if_statement', 'children': ['114', '118']}; {'id': '114', 'type': 'not_operator', 'children': ['115']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': '_shell'}; {'id': '118', 'type': 'block', 'children': ['119', '125']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '124', 'type': 'string', 'children': [], 'value': '"root"'}; {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'id': '130', 'type': 'argument_list', 'children': []}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'shell_to_cli'}; {'id': '136', 'type': 'argument_list', 'children': []}; {'id': '137', 'type': 'elif_clause', 'children': ['138', '143']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': '=='}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'shell_cmd'"}; {'id': '143', 'type': 'block', 'children': ['144', '162']}; {'id': '144', 'type': 'if_statement', 'children': ['145', '149']}; {'id': '145', 'type': 'not_operator', 'children': ['146']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_shell'}; {'id': '149', 'type': 'block', 'children': ['150', '156']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '155', 'type': 'string', 'children': [], 'value': '"shell"'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'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': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'cli_to_shell'}; {'id': '167', 'type': 'argument_list', 'children': []}; {'id': '168', 'type': 'if_statement', 'children': ['169', '180', '212']}; {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '171', 'type': 'argument_list', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'func_trans'}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '180', 'type': 'block', 'children': ['181']}; {'id': '181', 'type': 'if_statement', 'children': ['182', '189']}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '186'], 'value': 'in'}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '186', 'type': 'list', 'children': ['187', '188'], 'value': "['scp_pull', 'scp_push']"}; {'id': '187', 'type': 'string', 'children': [], 'value': "'scp_pull'"}; {'id': '188', 'type': 'string', 'children': [], 'value': "'scp_push'"}; {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'if_statement', 'children': ['191', '199']}; {'id': '191', 'type': 'not_operator', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': '_scp'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'SCPClient'}; {'id': '199', 'type': 'block', 'children': ['200', '206']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}; {'id': '201', 'type': 'assignment', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '205', 'type': 'string', 'children': [], 'value': '"scp"'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'id': '211', 'type': 'argument_list', 'children': []}; {'id': '212', 'type': 'else_clause', 'children': ['213']}; {'id': '213', 'type': 'block', 'children': ['214', '220', '256']}; {'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': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'disconnect'}; {'id': '219', 'type': 'argument_list', 'children': []}; {'id': '220', 'type': 'if_statement', 'children': ['221', '226', '233', '248']}; {'id': '221', 'type': 'comparison_operator', 'children': ['222', '225'], 'value': '=='}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '225', 'type': 'string', 'children': [], 'value': '"op_cmd"'}; {'id': '226', 'type': 'block', 'children': ['227']}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '232', 'type': 'string', 'children': [], 'value': '"paramiko"'}; {'id': '233', 'type': 'elif_clause', 'children': ['234', '241']}; {'id': '234', 'type': 'comparison_operator', 'children': ['235', '238'], 'value': 'in'}; {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '238', 'type': 'list', 'children': ['239', '240'], 'value': '["scp_pull", "scp_push"]'}; {'id': '239', 'type': 'string', 'children': [], 'value': '"scp_pull"'}; {'id': '240', 'type': 'string', 'children': [], 'value': '"scp_push"'}; {'id': '241', 'type': 'block', 'children': ['242']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'assignment', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '247', 'type': 'string', 'children': [], 'value': '"scp"'}; {'id': '248', 'type': 'else_clause', 'children': ['249']}; {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'assignment', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'conn_type'}; {'id': '255', 'type': 'string', 'children': [], 'value': '"ncclient"'}; {'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': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'connect'}; {'id': '261', 'type': 'argument_list', 'children': []}; {'id': '262', 'type': 'return_statement', 'children': ['263']}; {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'function'}; {'id': '265', 'type': 'argument_list', 'children': ['266', '267', '269']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '267', 'type': 'list_splat', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '269', 'type': 'dictionary_splat', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '271', 'type': 'return_statement', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'wrapper'} | def check_instance(function):
def wrapper(self, *args, **kwargs):
func_trans = {
"commit": manager.Manager,
"compare_config": manager.Manager,
"commit_check": manager.Manager,
"device_info": manager.Manager,
"diff_config": manager.Manager,
"health_check": manager.Manager,
"interface_errors": manager.Manager,
"op_cmd": paramiko.client.SSHClient,
"shell_cmd": paramiko.client.SSHClient,
"scp_pull": paramiko.client.SSHClient,
"scp_push": paramiko.client.SSHClient
}
if self.username == "root" and function.__name__ == "op_cmd":
if not self._session:
self.conn_type = "paramiko"
self.connect()
if not self._shell:
self.conn_type = "root"
self.connect()
self.shell_to_cli()
elif function.__name__ == 'shell_cmd':
if not self._shell:
self.conn_type = "shell"
self.connect()
self.cli_to_shell()
if isinstance(self._session, func_trans[function.__name__]):
if function.__name__ in ['scp_pull', 'scp_push']:
if not isinstance(self._scp, SCPClient):
self.conn_type = "scp"
self.connect()
else:
self.disconnect()
if function.__name__ == "op_cmd":
self.conn_type = "paramiko"
elif function.__name__ in ["scp_pull", "scp_push"]:
self.conn_type = "scp"
else:
self.conn_type = "ncclient"
self.connect()
return function(self, *args, **kwargs)
return wrapper |
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'commit'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '7', 'type': 'string', 'children': [], 'value': '""'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'confirmed'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'at_time'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'synchronize'}; {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'req_format'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '23', 'type': 'block', 'children': ['24', '32', '36', '50', '56', '70', '74', '123', '129', '253']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '27']}; {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'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': 'commands'}; {'id': '31', 'type': 'string', 'children': [], 'value': '\'annotate system ""\''}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'clean_cmds'}; {'id': '35', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '42']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'clean_lines'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'clean_cmds'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'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': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'lock'}; {'id': '55', 'type': 'argument_list', 'children': []}; {'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': '_session'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'load_configuration'}; {'id': '63', 'type': 'argument_list', 'children': ['64', '67']}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'set'"}; {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '73', 'type': 'string', 'children': [], 'value': '""'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '76', '102']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'confirmed'}; {'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': 'results'}; {'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': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '90', '96', '99']}; {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'confirmed'}; {'id': '89', 'type': 'True', 'children': []}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'confirmed'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'synchronize'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'synchronize'}; {'id': '102', 'type': 'else_clause', 'children': ['103']}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'results'}; {'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': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'commit'}; {'id': '113', 'type': 'argument_list', 'children': ['114', '117', '120']}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'at_time'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'at_time'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'synchronize'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'synchronize'}; {'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': 'unlock'}; {'id': '128', 'type': 'argument_list', 'children': []}; {'id': '129', 'type': 'if_statement', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '131', 'type': 'block', 'children': ['132', '139', '150', '154', '251']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}; {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': '=='}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'req_format'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'xml'"}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'return_statement', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ET'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'fromstring'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'tostring'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '153', 'type': 'string', 'children': [], 'value': "''"}; {'id': '154', 'type': 'for_statement', 'children': ['155', '156', '161']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '156', 'type': 'call', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '160', 'type': 'argument_list', 'children': []}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'if_statement', 'children': ['163', '168', '173', '184', '195', '227']}; {'id': '163', 'type': 'comparison_operator', 'children': ['164', '167'], 'value': '=='}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '167', 'type': 'string', 'children': [], 'value': "'commit-check-success'"}; {'id': '168', 'type': 'block', 'children': ['169']}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'augmented_assignment', 'children': ['171', '172'], 'value': '+='}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'configuration check succeeds\\n'"}; {'id': '173', 'type': 'elif_clause', 'children': ['174', '179']}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': '=='}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'commit-success'"}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'augmented_assignment', 'children': ['182', '183'], 'value': '+='}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '183', 'type': 'string', 'children': [], 'value': "'commit complete\\n'"}; {'id': '184', 'type': 'elif_clause', 'children': ['185', '190']}; {'id': '185', 'type': 'comparison_operator', 'children': ['186', '189'], 'value': '=='}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '189', 'type': 'string', 'children': [], 'value': "'ok'"}; {'id': '190', 'type': 'block', 'children': ['191']}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'augmented_assignment', 'children': ['193', '194'], 'value': '+='}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'commit complete\\n'"}; {'id': '195', 'type': 'elif_clause', 'children': ['196', '201']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '200'], 'value': 'is'}; {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '200', 'type': 'None', 'children': []}; {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'if_statement', 'children': ['203', '214']}; {'id': '203', 'type': 'comparison_operator', 'children': ['204', '213'], 'value': '!='}; {'id': '204', 'type': 'binary_operator', 'children': ['205', '212'], 'value': '+'}; {'id': '205', 'type': 'call', 'children': ['206', '211']}; {'id': '206', 'type': 'attribute', 'children': ['207', '210']}; {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '211', 'type': 'argument_list', 'children': []}; {'id': '212', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '213', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '214', 'type': 'block', 'children': ['215']}; {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'augmented_assignment', 'children': ['217', '218'], 'value': '+='}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '226'], 'value': '+'}; {'id': '219', 'type': 'call', 'children': ['220', '225']}; {'id': '220', 'type': 'attribute', 'children': ['221', '224']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '225', 'type': 'argument_list', 'children': []}; {'id': '226', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '227', 'type': 'elif_clause', 'children': ['228', '233']}; {'id': '228', 'type': 'comparison_operator', 'children': ['229', '232'], 'value': 'is'}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '232', 'type': 'None', 'children': []}; {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'if_statement', 'children': ['235', '242']}; {'id': '235', 'type': 'comparison_operator', 'children': ['236', '241'], 'value': '!='}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '240'], 'value': '+'}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '240', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '241', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '242', 'type': 'block', 'children': ['243']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'augmented_assignment', 'children': ['245', '246'], 'value': '+='}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '246', 'type': 'binary_operator', 'children': ['247', '250'], 'value': '+'}; {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '251', 'type': 'return_statement', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '253', 'type': 'return_statement', 'children': ['254']}; {'id': '254', 'type': 'False', 'children': []} | def commit(self, commands="", confirmed=None, comment=None,
at_time=None, synchronize=False, req_format='text'):
if not commands:
commands = 'annotate system ""'
clean_cmds = []
for cmd in clean_lines(commands):
clean_cmds.append(cmd)
self.lock()
self._session.load_configuration(action='set', config=commands)
results = ""
if confirmed:
results = self._session.commit(confirmed=True,
timeout=str(confirmed),
comment=comment,
synchronize=synchronize)
else:
results = self._session.commit(comment=comment, at_time=at_time,
synchronize=synchronize)
self.unlock()
if results:
if req_format == 'xml':
return results
results = ET.fromstring(results.tostring)
out = ''
for i in results.iter():
if i.tag == 'commit-check-success':
out += 'configuration check succeeds\n'
elif i.tag == 'commit-success':
out += 'commit complete\n'
elif i.tag == 'ok':
out += 'commit complete\n'
elif i.text is not None:
if i.text.strip() + '\n' != '\n':
out += i.text.strip() + '\n'
elif i.text is None:
if i.tag + '\n' != '\n':
out += i.tag + '\n'
return out
return False |
Subsets and Splits